List of usage examples for java.lang CharSequence length
int length();
From source file:com.android.google.demo.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;/*from w w w. j ava2s . c o m*/ } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e.toString()); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.length() == 0 ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.apecat.shoppingadvisor.scan.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;/* w ww. j a va 2 s. c o m*/ } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.opemind.cartspage.client.android.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;/*ww w . j a v a2s . co m*/ } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e); } Collection<String> newTexts = new ArrayList<>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.flavik.barcode.recognizer.client.android.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;//from w w w. j ava 2 s. c o m } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e.toString()); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:fr.landel.utils.commons.StringUtils.java
/** * Converts the char sequence in char array. For {@link String}, you should * use {@link String#toCharArray()}.//from ww w .j av a 2 s . c om * * @param sequence * the input sequence * @return the array */ public static char[] toChars(final CharSequence sequence) { Objects.requireNonNull(sequence, ERROR_SEQUENCE); final int length = sequence.length(); char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = sequence.charAt(i); } return chars; }
From source file:br.msf.commons.persistence.springframework.validation.AnnotatedEntityValidator.java
private void validateMaxLength(final String pathPrefix, final Field field, final T target, final Errors errors) throws Exception { field.setAccessible(true);/*from ww w. ja v a2 s . c om*/ final Object fieldValue = field.get(target); final String fieldPath = getFullPath(pathPrefix, field.getName()); if (!errors.hasFieldErrors(fieldPath) && isNotNullCharSequence(fieldValue)) { final MaxLength maxLength = field.getAnnotation(MaxLength.class); final Column column = field.getAnnotation(Column.class); final String errorCode = maxLength != null ? maxLength.errorCode() : Validator.ERROR_MAX_LENGTH; if (maxLength != null || column != null) { int max = 255; if (maxLength != null && column != null) { max = maxLength.value() < column.length() ? maxLength.value() : column.length(); } else if (maxLength != null) { max = maxLength.value(); } else if (column != null) { max = column.length(); } final CharSequence val = (CharSequence) fieldValue; if (val.length() > max) { errors.rejectValue(fieldPath, errorCode, new Object[] { max }, errorCode); } } } }
From source file:br.msf.commons.persistence.springframework.validation.AnnotatedEntityValidator.java
private void validateMinLength(final String pathPrefix, final Field field, final T target, final Errors errors) throws Exception { field.setAccessible(true);//from www .ja v a 2s .c om final Object fieldValue = field.get(target); final String fieldPath = getFullPath(pathPrefix, field.getName()); if (!errors.hasFieldErrors(fieldPath) && isNotNullCharSequence(fieldValue)) { final MinLength minLength = field.getAnnotation(MinLength.class); final CharSequence val = (CharSequence) fieldValue; if (minLength != null && val.length() < minLength.value()) { errors.rejectValue(fieldPath, minLength.errorCode(), new Object[] { minLength.value() }, minLength.errorCode()); } } }
From source file:br.msf.commons.text.EnhancedStringBuilder.java
protected static int length(final CharSequence... sequences) { int length = 0; if (ArrayUtils.isNotEmpty(sequences)) { for (final CharSequence item : sequences) { if (CharSequenceUtils.isNotEmpty(item)) { length += item.length(); }/*from w ww . ja v a 2 s. c o m*/ } } return length; }
From source file:com.acceleratedio.pac_n_zoom.FindTagsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_find_tags); req_str = getIntent().getExtras().getString("requestString"); fil_tags = getIntent().getExtras().getString("tagString").split("(\\s*,\\s*)|(\\s* \\s*)"); Arrays.sort(fil_tags, String.CASE_INSENSITIVE_ORDER); dsply_tags();/*from w w w . j a v a 2 s. c o m*/ tgTxtBar = (EditText) findViewById(R.id.ed_tgs); tgTxtBar.setOnClickListener(this); tgTxtBar.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence key_sqnc, int start, int before, int count) { final StringBuilder strBldr = new StringBuilder(key_sqnc.length()); strBldr.append(key_sqnc); srch_str = strBldr.toString(); dsply_tags(); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.google.zxing.client.android.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;//ww w . jav a 2s.c o m } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e.toString()); } Collection<String> newTexts = new ArrayList<String>(); if (title != null && title.length() > 0) { newTexts.add(title); } if (authors != null && !authors.isEmpty()) { boolean first = true; StringBuilder authorsText = new StringBuilder(); for (String author : authors) { if (first) { first = false; } else { authorsText.append(", "); } authorsText.append(author); } newTexts.add(authorsText.toString()); } if (pages != null && pages.length() > 0) { newTexts.add(pages + "pp."); } String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }