We can finally use isEmpty(), given Android 2.3.3+ is required

git-svn-id: https://zxing.googlecode.com/svn/trunk@2819 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-06-17 12:42:56 +00:00
parent 03354c4757
commit f6df6000d5
33 changed files with 80 additions and 80 deletions

View file

@ -116,7 +116,7 @@ final class DecodeHintManager {
static Map<DecodeHintType,?> parseDecodeHints(Uri inputUri) { static Map<DecodeHintType,?> parseDecodeHints(Uri inputUri) {
String query = inputUri.getEncodedQuery(); String query = inputUri.getEncodedQuery();
if (query == null || query.length() == 0) { if (query == null || query.isEmpty()) {
return null; return null;
} }
@ -157,7 +157,7 @@ final class DecodeHintManager {
if (hintType.getValueType().equals(Boolean.class)) { if (hintType.getValueType().equals(Boolean.class)) {
// A boolean hint: a few values for false, everything else is true. // A boolean hint: a few values for false, everything else is true.
// An empty parameter is simply a flag-style parameter, assuming true // An empty parameter is simply a flag-style parameter, assuming true
if (parameterText.length() == 0) { if (parameterText.isEmpty()) {
hints.put(hintType, Boolean.TRUE); hints.put(hintType, Boolean.TRUE);
} else if ("0".equals(parameterText) || } else if ("0".equals(parameterText) ||
"false".equalsIgnoreCase(parameterText) || "false".equalsIgnoreCase(parameterText) ||

View file

@ -76,7 +76,7 @@ public final class HelpActivity extends Activity {
webView.restoreState(icicle); webView.restoreState(icicle);
} else if (intent != null) { } else if (intent != null) {
String page = intent.getStringExtra(REQUESTED_PAGE_KEY); String page = intent.getStringExtra(REQUESTED_PAGE_KEY);
if (page != null && page.length() > 0) { if (page != null && !page.isEmpty()) {
webView.loadUrl(BASE_URL + page); webView.loadUrl(BASE_URL + page);
} else { } else {
webView.loadUrl(BASE_URL + DEFAULT_PAGE); webView.loadUrl(BASE_URL + DEFAULT_PAGE);
@ -94,7 +94,7 @@ public final class HelpActivity extends Activity {
@Override @Override
protected void onSaveInstanceState(Bundle state) { protected void onSaveInstanceState(Bundle state) {
String url = webView.getUrl(); String url = webView.getUrl();
if (url != null && url.length() > 0) { if (url != null && !url.isEmpty()) {
webView.saveState(state); webView.saveState(state);
state.putBoolean(WEBVIEW_STATE_PRESENT, true); state.putBoolean(WEBVIEW_STATE_PRESENT, true);
} }

View file

@ -172,7 +172,7 @@ public final class LocaleManager {
public static String getCountry(Context context) { public static String getCountry(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String countryOverride = prefs.getString(PreferencesActivity.KEY_SEARCH_COUNTRY, null); String countryOverride = prefs.getString(PreferencesActivity.KEY_SEARCH_COUNTRY, null);
if (countryOverride != null && countryOverride.length() > 0 && !"-".equals(countryOverride)) { if (countryOverride != null && !countryOverride.isEmpty() && !"-".equals(countryOverride)) {
return countryOverride; return countryOverride;
} }
return getSystemCountry(); return getSystemCountry();

View file

@ -46,7 +46,7 @@ final class BrowseBookListener implements AdapterView.OnItemClickListener {
} }
String pageId = items.get(itemOffset).getPageId(); String pageId = items.get(itemOffset).getPageId();
String query = SearchBookContentsResult.getQuery(); String query = SearchBookContentsResult.getQuery();
if (LocaleManager.isBookSearchUrl(activity.getISBN()) && pageId.length() > 0) { if (LocaleManager.isBookSearchUrl(activity.getISBN()) && !pageId.isEmpty()) {
String uri = activity.getISBN(); String uri = activity.getISBN();
int equals = uri.indexOf('='); int equals = uri.indexOf('=');
String volumeId = uri.substring(equals + 1); String volumeId = uri.substring(equals + 1);

View file

@ -121,7 +121,7 @@ public final class SearchBookContentsActivity extends Activity {
queryTextView = (EditText) findViewById(R.id.query_text_view); queryTextView = (EditText) findViewById(R.id.query_text_view);
String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY); String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
if (initialQuery != null && initialQuery.length() > 0) { if (initialQuery != null && !initialQuery.isEmpty()) {
// Populate the search box but don't trigger the search // Populate the search box but don't trigger the search
queryTextView.setText(initialQuery); queryTextView.setText(initialQuery);
} }
@ -155,7 +155,7 @@ public final class SearchBookContentsActivity extends Activity {
private void launchSearch() { private void launchSearch() {
String query = queryTextView.getText().toString(); String query = queryTextView.getText().toString();
if (query != null && query.length() > 0) { if (query != null && !query.isEmpty()) {
NetworkTask oldTask = networkTask; NetworkTask oldTask = networkTask;
if (oldTask != null) { if (oldTask != null) {
oldTask.cancel(true); oldTask.cancel(true);
@ -244,25 +244,25 @@ public final class SearchBookContentsActivity extends Activity {
try { try {
String pageId = json.getString("page_id"); String pageId = json.getString("page_id");
String pageNumber = json.getString("page_number"); String pageNumber = json.getString("page_number");
if (pageNumber.length() > 0) { if (pageNumber.isEmpty()) {
pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber;
} else {
// This can happen for text on the jacket, and possibly other reasons. // This can happen for text on the jacket, and possibly other reasons.
pageNumber = getString(R.string.msg_sbc_unknown_page); pageNumber = getString(R.string.msg_sbc_unknown_page);
} else {
pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber;
} }
// Remove all HTML tags and encoded characters. Ideally the server would do this. // Remove all HTML tags and encoded characters. Ideally the server would do this.
String snippet = json.optString("snippet_text"); String snippet = json.optString("snippet_text");
boolean valid = true; boolean valid = true;
if (snippet.length() > 0) { if (snippet.isEmpty()) {
snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')';
valid = false;
} else {
snippet = TAG_PATTERN.matcher(snippet).replaceAll(""); snippet = TAG_PATTERN.matcher(snippet).replaceAll("");
snippet = LT_ENTITY_PATTERN.matcher(snippet).replaceAll("<"); snippet = LT_ENTITY_PATTERN.matcher(snippet).replaceAll("<");
snippet = GT_ENTITY_PATTERN.matcher(snippet).replaceAll(">"); snippet = GT_ENTITY_PATTERN.matcher(snippet).replaceAll(">");
snippet = QUOTE_ENTITY_PATTERN.matcher(snippet).replaceAll("'"); snippet = QUOTE_ENTITY_PATTERN.matcher(snippet).replaceAll("'");
snippet = QUOT_ENTITY_PATTERN.matcher(snippet).replaceAll("\""); snippet = QUOT_ENTITY_PATTERN.matcher(snippet).replaceAll("\"");
} else {
snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')';
valid = false;
} }
return new SearchBookContentsResult(pageId, pageNumber, snippet, valid); return new SearchBookContentsResult(pageId, pageNumber, snippet, valid);
} catch (JSONException e) { } catch (JSONException e) {

View file

@ -56,7 +56,9 @@ public final class SearchBookContentsListItem extends LinearLayout {
public void set(SearchBookContentsResult result) { public void set(SearchBookContentsResult result) {
pageNumberView.setText(result.getPageNumber()); pageNumberView.setText(result.getPageNumber());
String snippet = result.getSnippet(); String snippet = result.getSnippet();
if (snippet.length() > 0) { if (snippet.isEmpty()) {
snippetView.setText("");
} else {
if (result.getValidSnippet()) { if (result.getValidSnippet()) {
String lowerQuery = SearchBookContentsResult.getQuery().toLowerCase(Locale.getDefault()); String lowerQuery = SearchBookContentsResult.getQuery().toLowerCase(Locale.getDefault());
String lowerSnippet = snippet.toLowerCase(Locale.getDefault()); String lowerSnippet = snippet.toLowerCase(Locale.getDefault());
@ -77,8 +79,6 @@ public final class SearchBookContentsListItem extends LinearLayout {
// This may be an error message, so don't try to bold the query terms within it // This may be an error message, so don't try to bold the query terms within it
snippetView.setText(snippet); snippetView.setText(snippet);
} }
} else {
snippetView.setText("");
} }
} }
} }

View file

@ -47,7 +47,7 @@ abstract class ContactEncoder {
return null; return null;
} }
String result = s.trim(); String result = s.trim();
return result.length() == 0 ? null : result; return result.isEmpty() ? null : result;
} }
static void doAppend(StringBuilder newContents, static void doAppend(StringBuilder newContents,
@ -78,7 +78,7 @@ abstract class ContactEncoder {
Collection<String> uniques = new HashSet<String>(2); Collection<String> uniques = new HashSet<String>(2);
for (String value : values) { for (String value : values) {
String trimmed = trim(value); String trimmed = trim(value);
if (trimmed != null && trimmed.length() > 0 && !uniques.contains(trimmed)) { if (trimmed != null && !trimmed.isEmpty() && !uniques.contains(trimmed)) {
newContents.append(prefix).append(':').append(fieldFormatter.format(trimmed)).append(terminator); newContents.append(prefix).append(':').append(fieldFormatter.format(trimmed)).append(terminator);
String display = formatter == null ? trimmed : formatter.format(trimmed); String display = formatter == null ? trimmed : formatter.format(trimmed);
newDisplayContents.append(display).append('\n'); newDisplayContents.append(display).append('\n');

View file

@ -112,20 +112,20 @@ final class QRCodeEncoder {
} }
if (format == null || format == BarcodeFormat.QR_CODE) { if (format == null || format == BarcodeFormat.QR_CODE) {
String type = intent.getStringExtra(Intents.Encode.TYPE); String type = intent.getStringExtra(Intents.Encode.TYPE);
if (type == null || type.length() == 0) { if (type == null || type.isEmpty()) {
return false; return false;
} }
this.format = BarcodeFormat.QR_CODE; this.format = BarcodeFormat.QR_CODE;
encodeQRCodeContents(intent, type); encodeQRCodeContents(intent, type);
} else { } else {
String data = intent.getStringExtra(Intents.Encode.DATA); String data = intent.getStringExtra(Intents.Encode.DATA);
if (data != null && data.length() > 0) { if (data != null && !data.isEmpty()) {
contents = data; contents = data;
displayContents = data; displayContents = data;
title = activity.getString(R.string.contents_text); title = activity.getString(R.string.contents_text);
} }
} }
return contents != null && contents.length() > 0; return contents != null && !contents.isEmpty();
} }
// Handles send intents from multitude of Android applications // Handles send intents from multitude of Android applications
@ -158,7 +158,7 @@ final class QRCodeEncoder {
} }
// Trim text to avoid URL breaking. // Trim text to avoid URL breaking.
if (theContents == null || theContents.length() == 0) { if (theContents == null || theContents.isEmpty()) {
throw new WriterException("Empty EXTRA_TEXT"); throw new WriterException("Empty EXTRA_TEXT");
} }
contents = theContents; contents = theContents;
@ -208,7 +208,7 @@ final class QRCodeEncoder {
throw new WriterException("Result was not an address"); throw new WriterException("Result was not an address");
} }
encodeQRCodeContents((AddressBookParsedResult) parsedResult); encodeQRCodeContents((AddressBookParsedResult) parsedResult);
if (contents == null || contents.length() == 0) { if (contents == null || contents.isEmpty()) {
throw new WriterException("No content to encode"); throw new WriterException("No content to encode");
} }
} }
@ -216,7 +216,7 @@ final class QRCodeEncoder {
private void encodeQRCodeContents(Intent intent, String type) { private void encodeQRCodeContents(Intent intent, String type) {
if (type.equals(Contents.Type.TEXT)) { if (type.equals(Contents.Type.TEXT)) {
String data = intent.getStringExtra(Intents.Encode.DATA); String data = intent.getStringExtra(Intents.Encode.DATA);
if (data != null && data.length() > 0) { if (data != null && !data.isEmpty()) {
contents = data; contents = data;
displayContents = data; displayContents = data;
title = activity.getString(R.string.contents_text); title = activity.getString(R.string.contents_text);
@ -271,7 +271,7 @@ final class QRCodeEncoder {
urls, urls,
note); note);
// Make sure we've encoded at least one field. // Make sure we've encoded at least one field.
if (encoded[1].length() > 0) { if (!encoded[1].isEmpty()) {
contents = encoded[0]; contents = encoded[0];
displayContents = encoded[1]; displayContents = encoded[1];
title = activity.getString(R.string.contents_contact); title = activity.getString(R.string.contents_contact);
@ -304,7 +304,7 @@ final class QRCodeEncoder {
toIterable(contact.getURLs()), toIterable(contact.getURLs()),
null); null);
// Make sure we've encoded at least one field. // Make sure we've encoded at least one field.
if (encoded[1].length() > 0) { if (!encoded[1].isEmpty()) {
contents = encoded[0]; contents = encoded[0];
displayContents = encoded[1]; displayContents = encoded[1];
title = activity.getString(R.string.contents_contact); title = activity.getString(R.string.contents_contact);

View file

@ -36,12 +36,12 @@ public final class HistoryItem {
public String getDisplayAndDetails() { public String getDisplayAndDetails() {
StringBuilder displayResult = new StringBuilder(); StringBuilder displayResult = new StringBuilder();
if (display == null || display.length() == 0) { if (display == null || display.isEmpty()) {
displayResult.append(result.getText()); displayResult.append(result.getText());
} else { } else {
displayResult.append(display); displayResult.append(display);
} }
if (details != null && details.length() > 0) { if (details != null && !details.isEmpty()) {
displayResult.append(" : ").append(details); displayResult.append(" : ").append(details);
} }
return displayResult.toString(); return displayResult.toString();

View file

@ -82,7 +82,7 @@ public final class AddressBookResultHandler extends ResultHandler {
super(activity, result); super(activity, result);
AddressBookParsedResult addressResult = (AddressBookParsedResult) result; AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
String[] addresses = addressResult.getAddresses(); String[] addresses = addressResult.getAddresses();
boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0] != null && addresses[0].length() > 0; boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0] != null && !addresses[0].isEmpty();
String[] phoneNumbers = addressResult.getPhoneNumbers(); String[] phoneNumbers = addressResult.getPhoneNumbers();
boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0; boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
String[] emails = addressResult.getEmails(); String[] emails = addressResult.getEmails();
@ -175,7 +175,7 @@ public final class AddressBookResultHandler extends ResultHandler {
int namesLength = contents.length(); int namesLength = contents.length();
String pronunciation = result.getPronunciation(); String pronunciation = result.getPronunciation();
if (pronunciation != null && pronunciation.length() > 0) { if (pronunciation != null && !pronunciation.isEmpty()) {
contents.append("\n("); contents.append("\n(");
contents.append(pronunciation); contents.append(pronunciation);
contents.append(')'); contents.append(')');
@ -196,7 +196,7 @@ public final class AddressBookResultHandler extends ResultHandler {
ParsedResult.maybeAppend(result.getURLs(), contents); ParsedResult.maybeAppend(result.getURLs(), contents);
String birthday = result.getBirthday(); String birthday = result.getBirthday();
if (birthday != null && birthday.length() > 0) { if (birthday != null && !birthday.isEmpty()) {
Date date = parseDate(birthday); Date date = parseDate(birthday);
if (date != null) { if (date != null) {
ParsedResult.maybeAppend(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date.getTime()), contents); ParsedResult.maybeAppend(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date.getTime()), contents);

View file

@ -262,7 +262,7 @@ public abstract class ResultHandler {
StringBuilder aggregatedNotes = new StringBuilder(); StringBuilder aggregatedNotes = new StringBuilder();
if (urls != null) { if (urls != null) {
for (String url : urls) { for (String url : urls) {
if (url != null && url.length() > 0) { if (url != null && !url.isEmpty()) {
aggregatedNotes.append('\n').append(url); aggregatedNotes.append('\n').append(url);
} }
} }
@ -274,7 +274,7 @@ public abstract class ResultHandler {
} }
if (nicknames != null) { if (nicknames != null) {
for (String nickname : nicknames) { for (String nickname : nicknames) {
if (nickname != null && nickname.length() > 0) { if (nickname != null && !nickname.isEmpty()) {
aggregatedNotes.append('\n').append(nickname); aggregatedNotes.append('\n').append(nickname);
} }
} }
@ -371,7 +371,7 @@ public abstract class ResultHandler {
final void sendMMSFromUri(String uri, String subject, String body) { final void sendMMSFromUri(String uri, String subject, String body) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri)); Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
// The Messaging app needs to see a valid subject or else it will treat this an an SMS. // The Messaging app needs to see a valid subject or else it will treat this an an SMS.
if (subject == null || subject.length() == 0) { if (subject == null || subject.isEmpty()) {
putExtra(intent, "subject", activity.getString(R.string.msg_default_mms_subject)); putExtra(intent, "subject", activity.getString(R.string.msg_default_mms_subject));
} else { } else {
putExtra(intent, "subject", subject); putExtra(intent, "subject", subject);
@ -399,9 +399,9 @@ public abstract class ResultHandler {
* @param address The address to find * @param address The address to find
* @param title An optional title, e.g. the name of the business at this address * @param title An optional title, e.g. the name of the business at this address
*/ */
final void searchMap(String address, CharSequence title) { final void searchMap(String address, String title) {
String query = address; String query = address;
if (title != null && title.length() > 0) { if (title != null && !title.isEmpty()) {
query += " (" + title + ')'; query += " (" + title + ')';
} }
launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query)))); launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query))));
@ -510,7 +510,7 @@ public abstract class ResultHandler {
} }
private static void putExtra(Intent intent, String key, String value) { private static void putExtra(Intent intent, String key, String value) {
if (value != null && value.length() > 0) { if (value != null && !value.isEmpty()) {
intent.putExtra(key, value); intent.putExtra(key, value);
} }
} }
@ -519,7 +519,7 @@ public abstract class ResultHandler {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
String customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, String customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH,
null); null);
if (customProductSearch != null && customProductSearch.trim().length() == 0) { if (customProductSearch != null && customProductSearch.trim().isEmpty()) {
return null; return null;
} }
return customProductSearch; return customProductSearch;

View file

@ -94,7 +94,7 @@ final class BookResultInfoRetriever extends SupplementalInfoRetriever {
Collection<String> newTexts = new ArrayList<String>(); Collection<String> newTexts = new ArrayList<String>();
maybeAddText(title, newTexts); maybeAddText(title, newTexts);
maybeAddTextSeries(authors, newTexts); maybeAddTextSeries(authors, newTexts);
maybeAddText(pages == null || pages.length() == 0 ? null : pages + "pp.", newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts);
String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
+ "/search?tbm=bks&source=zxing&q="; + "/search?tbm=bks&source=zxing&q=";

View file

@ -156,7 +156,7 @@ public abstract class SupplementalInfoRetriever extends AsyncTask<Object,Object,
} }
static void maybeAddText(String text, Collection<String> texts) { static void maybeAddText(String text, Collection<String> texts) {
if (text != null && text.length() > 0) { if (text != null && !text.isEmpty()) {
texts.add(text); texts.add(text);
} }
} }

View file

@ -55,7 +55,7 @@ final class TitleRetriever extends SupplementalInfoRetriever {
Matcher m = TITLE_PATTERN.matcher(contents); Matcher m = TITLE_PATTERN.matcher(contents);
if (m.find()) { if (m.find()) {
String title = m.group(1); String title = m.group(1);
if (title != null && title.length() > 0) { if (title != null && !title.isEmpty()) {
if (title.length() > MAX_TITLE_LEN) { if (title.length() > MAX_TITLE_LEN) {
title = title.substring(0, MAX_TITLE_LEN) + "..."; title = title.substring(0, MAX_TITLE_LEN) + "...";
} }

View file

@ -208,7 +208,7 @@ public final class ShareActivity extends Activity {
// Don't require a name to be present, this contact might be just a phone number. // Don't require a name to be present, this contact might be just a phone number.
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if (name != null && name.length() > 0) { if (name != null && !name.isEmpty()) {
bundle.putString(ContactsContract.Intents.Insert.NAME, massageContactData(name)); bundle.putString(ContactsContract.Intents.Insert.NAME, massageContactData(name));
} }
@ -224,7 +224,7 @@ public final class ShareActivity extends Activity {
int phonesNumberColumn = phonesCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); int phonesNumberColumn = phonesCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (phonesCursor.moveToNext() && foundPhone < Contents.PHONE_KEYS.length) { while (phonesCursor.moveToNext() && foundPhone < Contents.PHONE_KEYS.length) {
String number = phonesCursor.getString(phonesNumberColumn); String number = phonesCursor.getString(phonesNumberColumn);
if (number != null && number.length() > 0) { if (number != null && !number.isEmpty()) {
bundle.putString(Contents.PHONE_KEYS[foundPhone], massageContactData(number)); bundle.putString(Contents.PHONE_KEYS[foundPhone], massageContactData(number));
} }
foundPhone++; foundPhone++;
@ -245,7 +245,7 @@ public final class ShareActivity extends Activity {
if (methodsCursor.moveToNext()) { if (methodsCursor.moveToNext()) {
String data = methodsCursor.getString( String data = methodsCursor.getString(
methodsCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS)); methodsCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS));
if (data != null && data.length() > 0) { if (data != null && !data.isEmpty()) {
bundle.putString(ContactsContract.Intents.Insert.POSTAL, massageContactData(data)); bundle.putString(ContactsContract.Intents.Insert.POSTAL, massageContactData(data));
} }
} }
@ -265,7 +265,7 @@ public final class ShareActivity extends Activity {
int emailColumn = emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA); int emailColumn = emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
while (emailCursor.moveToNext() && foundEmail < Contents.EMAIL_KEYS.length) { while (emailCursor.moveToNext() && foundEmail < Contents.EMAIL_KEYS.length) {
String email = emailCursor.getString(emailColumn); String email = emailCursor.getString(emailColumn);
if (email != null && email.length() > 0) { if (email != null && !email.isEmpty()) {
bundle.putString(Contents.EMAIL_KEYS[foundEmail], massageContactData(email)); bundle.putString(Contents.EMAIL_KEYS[foundEmail], massageContactData(email));
} }
foundEmail++; foundEmail++;

View file

@ -82,7 +82,7 @@ public final class WifiConfigManager extends AsyncTask<WifiParsedResult,Object,O
changeNetworkUnEncrypted(wifiManager, theWifiResult); changeNetworkUnEncrypted(wifiManager, theWifiResult);
} else { } else {
String password = theWifiResult.getPassword(); String password = theWifiResult.getPassword();
if (password != null && password.length() != 0) { if (password != null && !password.isEmpty()) {
if (networkType == NetworkType.WEP) { if (networkType == NetworkType.WEP) {
changeNetworkWEP(wifiManager, theWifiResult); changeNetworkWEP(wifiManager, theWifiResult);
} else if (networkType == NetworkType.WPA) { } else if (networkType == NetworkType.WPA) {
@ -186,19 +186,19 @@ public final class WifiConfigManager extends AsyncTask<WifiParsedResult,Object,O
/** /**
* Encloses the incoming string inside double quotes, if it isn't already quoted. * Encloses the incoming string inside double quotes, if it isn't already quoted.
* @param string the input string * @param s the input string
* @return a quoted string, of the form "input". If the input string is null, it returns null * @return a quoted string, of the form "input". If the input string is null, it returns null
* as well. * as well.
*/ */
private static String convertToQuotedString(String string) { private static String convertToQuotedString(String s) {
if (string == null || string.length() == 0) { if (s == null || s.isEmpty()) {
return null; return null;
} }
// If already quoted, return as-is // If already quoted, return as-is
if (string.charAt(0) == '"' && string.charAt(string.length() - 1) == '"') { if (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
return string; return s;
} }
return '\"' + string + '\"'; return '\"' + s + '\"';
} }
/** /**

View file

@ -44,7 +44,7 @@ public final class EmailAddressResultParser extends ResultParser {
String subject = null; String subject = null;
String body = null; String body = null;
if (nameValues != null) { if (nameValues != null) {
if (emailAddress.length() == 0) { if (emailAddress.isEmpty()) {
emailAddress = nameValues.get("to"); emailAddress = nameValues.get("to");
} }
subject = nameValues.get("subject"); subject = nameValues.get("subject");

View file

@ -47,7 +47,7 @@ public abstract class ParsedResult {
} }
public static void maybeAppend(String value, StringBuilder result) { public static void maybeAppend(String value, StringBuilder result) {
if (value != null && value.length() > 0) { if (value != null && !value.isEmpty()) {
// Don't add a newline before the first value // Don't add a newline before the first value
if (result.length() > 0) { if (result.length() > 0) {
result.append('\n'); result.append('\n');

View file

@ -230,7 +230,7 @@ public abstract class ResultParser {
if (trim) { if (trim) {
element = element.trim(); element = element.trim();
} }
if (element.length() > 0) { if (!element.isEmpty()) {
matches.add(element); matches.add(element);
} }
i++; i++;

View file

@ -278,7 +278,7 @@ public final class VCardResultParser extends ResultParser {
List<String> result = new ArrayList<String>(lists.size()); List<String> result = new ArrayList<String>(lists.size());
for (List<String> list : lists) { for (List<String> list : lists) {
String value = list.get(0); String value = list.get(0);
if (value != null && value.length() > 0) { if (value != null && !value.isEmpty()) {
result.add(value); result.add(value);
} }
} }

View file

@ -37,7 +37,7 @@ public final class WifiResultParser extends ResultParser {
return null; return null;
} }
String ssid = matchSinglePrefixedField("S:", rawText, ';', false); String ssid = matchSinglePrefixedField("S:", rawText, ';', false);
if (ssid == null || ssid.length() == 0) { if (ssid == null || ssid.isEmpty()) {
return null; return null;
} }
String pass = matchSinglePrefixedField("P:", rawText, ';', false); String pass = matchSinglePrefixedField("P:", rawText, ';', false);

View file

@ -46,7 +46,7 @@ public final class DataMatrixWriter implements Writer {
@Override @Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) { public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) {
if (contents.length() == 0) { if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents"); throw new IllegalArgumentException("Found empty contents");
} }

View file

@ -50,7 +50,7 @@ public abstract class OneDimensionalCodeWriter implements Writer {
int width, int width,
int height, int height,
Map<EncodeHintType,?> hints) throws WriterException { Map<EncodeHintType,?> hints) throws WriterException {
if (contents.length() == 0) { if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents"); throw new IllegalArgumentException("Found empty contents");
} }

View file

@ -191,7 +191,7 @@ final class FieldParser {
} }
static String parseFieldsInGeneralPurpose(String rawInformation) throws NotFoundException{ static String parseFieldsInGeneralPurpose(String rawInformation) throws NotFoundException{
if(rawInformation.length() == 0) { if (rawInformation.isEmpty()) {
return null; return null;
} }

View file

@ -51,7 +51,7 @@ public final class QRCodeWriter implements Writer {
int height, int height,
Map<EncodeHintType,?> hints) throws WriterException { Map<EncodeHintType,?> hints) throws WriterException {
if (contents.length() == 0) { if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents"); throw new IllegalArgumentException("Found empty contents");
} }

View file

@ -198,7 +198,7 @@ public final class CalendarEventGenerator implements GeneratorSource {
private String getEventNameField() throws GeneratorException { private String getEventNameField() throws GeneratorException {
String inputName = eventName.getText(); String inputName = eventName.getText();
if (inputName.length() < 1) { if (inputName.isEmpty()) {
throw new GeneratorException("Event name must be at least 1 character."); throw new GeneratorException("Event name must be at least 1 character.");
} }
if (inputName.contains("\n")) { if (inputName.contains("\n")) {
@ -216,7 +216,7 @@ public final class CalendarEventGenerator implements GeneratorSource {
private String getLocationField() throws GeneratorException { private String getLocationField() throws GeneratorException {
String locationString = location.getText(); String locationString = location.getText();
if (locationString.length() < 1) { if (locationString.isEmpty()) {
return ""; return "";
} }
if (locationString.contains("\n")) { if (locationString.contains("\n")) {
@ -228,7 +228,7 @@ public final class CalendarEventGenerator implements GeneratorSource {
private String getDescriptionField() throws GeneratorException { private String getDescriptionField() throws GeneratorException {
String descriptionString = description.getText(); String descriptionString = description.getText();
if (descriptionString.length() < 1) { if (descriptionString.isEmpty()) {
return ""; return "";
} }
if (descriptionString.contains("\n")) { if (descriptionString.contains("\n")) {

View file

@ -170,7 +170,7 @@ public final class ContactInfoGenerator implements GeneratorSource {
private String getNameField() throws GeneratorException { private String getNameField() throws GeneratorException {
String input = name.getText(); String input = name.getText();
if (input.length() < 1) { if (input.isEmpty()) {
throw new GeneratorException("Name must be at least 1 character."); throw new GeneratorException("Name must be at least 1 character.");
} }
return input; return input;
@ -186,7 +186,7 @@ public final class ContactInfoGenerator implements GeneratorSource {
private String getTelField() throws GeneratorException { private String getTelField() throws GeneratorException {
String input = Validators.filterNumber(tel.getText()); String input = Validators.filterNumber(tel.getText());
if (input.length() < 1) { if (input.isEmpty()) {
return ""; return "";
} }
Validators.validateNumber(input); Validators.validateNumber(input);
@ -206,7 +206,7 @@ public final class ContactInfoGenerator implements GeneratorSource {
private String getEmailField() throws GeneratorException { private String getEmailField() throws GeneratorException {
String input = email.getText(); String input = email.getText();
if (input.length() < 1) { if (input.isEmpty()) {
return ""; return "";
} }
Validators.validateEmail(input); Validators.validateEmail(input);

View file

@ -50,7 +50,7 @@ public final class EmailGenerator implements GeneratorSource {
private String getEmailField() throws GeneratorException { private String getEmailField() throws GeneratorException {
String input = email.getText(); String input = email.getText();
if (input.length() < 1) { if (input.isEmpty()) {
throw new GeneratorException("Email must be present."); throw new GeneratorException("Email must be present.");
} }
Validators.validateEmail(input); Validators.validateEmail(input);

View file

@ -57,7 +57,7 @@ public final class GeoLocationGenerator implements GeneratorSource {
@Override @Override
public String getText() throws GeneratorException { public String getText() throws GeneratorException {
String que = getQueryField(); String que = getQueryField();
if (que != null && que.length() > 0) { if (que != null && !que.isEmpty()) {
if (getLatitudeField() == null) { if (getLatitudeField() == null) {
latitude.setText("0"); latitude.setText("0");
} }
@ -68,7 +68,7 @@ public final class GeoLocationGenerator implements GeneratorSource {
String lat = getLatitudeField(); String lat = getLatitudeField();
String lon = getLongitudeField(); String lon = getLongitudeField();
if (que != null && que.length() > 0) { if (que != null && !que.isEmpty()) {
return "geo:" + lat + ',' + lon + "?q=" + que; return "geo:" + lat + ',' + lon + "?q=" + que;
} }
return "geo:" + lat + ',' + lon; return "geo:" + lat + ',' + lon;

View file

@ -51,7 +51,7 @@ public final class PhoneNumberGenerator implements GeneratorSource {
private String getTelField() throws GeneratorException { private String getTelField() throws GeneratorException {
String input = number.getText(); String input = number.getText();
if (input.length() < 1) { if (input.isEmpty()) {
throw new GeneratorException("Phone number must be present."); throw new GeneratorException("Phone number must be present.");
} }
input = Validators.filterNumber(input); input = Validators.filterNumber(input);

View file

@ -54,7 +54,7 @@ public final class SmsAddressGenerator implements GeneratorSource {
String output = inputNumber; String output = inputNumber;
// we add the text only if there actually is something in the field. // we add the text only if there actually is something in the field.
if (inputMessage.length() > 0) { if (!inputMessage.isEmpty()) {
output += ':' + inputMessage; output += ':' + inputMessage;
} }
@ -63,7 +63,7 @@ public final class SmsAddressGenerator implements GeneratorSource {
private String getTelField() throws GeneratorException { private String getTelField() throws GeneratorException {
String input = number.getText(); String input = number.getText();
if (input.length() < 1) { if (input.isEmpty()) {
throw new GeneratorException("Phone number must be present."); throw new GeneratorException("Phone number must be present.");
} }
input = Validators.filterNumber(input); input = Validators.filterNumber(input);

View file

@ -49,7 +49,7 @@ public final class TextGenerator implements GeneratorSource {
String getTextField() throws GeneratorException { String getTextField() throws GeneratorException {
String input = text.getText(); String input = text.getText();
if (input.length() == 0) { if (input.isEmpty()) {
throw new GeneratorException("Text should be at least 1 character."); throw new GeneratorException("Text should be at least 1 character.");
} }
return input; return input;

View file

@ -69,7 +69,7 @@ public final class WifiGenerator implements GeneratorSource {
StringBuilder output = new StringBuilder(100); StringBuilder output = new StringBuilder(100);
output.append("WIFI:"); output.append("WIFI:");
output.append("S:").append(ssid).append(';'); output.append("S:").append(ssid).append(';');
if (type != null && type.length() > 0 && !"nopass".equals(type)) { if (type != null && !type.isEmpty() && !"nopass".equals(type)) {
maybeAppend(output, "T:", type); maybeAppend(output, "T:", type);
} }
maybeAppend(output, "P:", password); maybeAppend(output, "P:", password);
@ -81,14 +81,14 @@ public final class WifiGenerator implements GeneratorSource {
} }
private static void maybeAppend(StringBuilder output, String prefix, String value) { private static void maybeAppend(StringBuilder output, String prefix, String value) {
if (value != null && value.length() > 0) { if (value != null && !value.isEmpty()) {
output.append(prefix).append(value).append(';'); output.append(prefix).append(value).append(';');
} }
} }
private static String parseTextField(String name, HasText textBox) throws GeneratorException { private static String parseTextField(String name, HasText textBox) throws GeneratorException {
String input = textBox.getText(); String input = textBox.getText();
if (input.length() < 1) { if (input.isEmpty()) {
return ""; return "";
} }
if (input.contains("\n")) { if (input.contains("\n")) {
@ -99,7 +99,7 @@ public final class WifiGenerator implements GeneratorSource {
private String getSsidField() throws GeneratorException { private String getSsidField() throws GeneratorException {
String input = ssid.getText(); String input = ssid.getText();
if (input.length() < 1) { if (input.isEmpty()) {
throw new GeneratorException("SSID must be at least 1 character."); throw new GeneratorException("SSID must be at least 1 character.");
} }
String parsed = parseTextField("SSID", ssid); String parsed = parseTextField("SSID", ssid);