List of usage examples for java.lang CharSequence length
int length();
From source file:com.eaio.util.text.HumanTime.java
/** * Parses a {@link CharSequence} argument and returns a {@link HumanTime} instance. * //from www .j a v a 2 s . c o m * @param s the char sequence, may not be <code>null</code> * @return an instance, never <code>null</code> */ public static HumanTime eval(final CharSequence s) { HumanTime out = new HumanTime(0L); int num = 0; int start = 0; int end = 0; State oldState = State.IGNORED; for (char c : new Iterable<Character>() { /** * @see java.lang.Iterable#iterator() */ public Iterator<Character> iterator() { return new Iterator<Character>() { private int p = 0; /** * @see java.util.Iterator#hasNext() */ public boolean hasNext() { return p < s.length(); } /** * @see java.util.Iterator#next() */ public Character next() { return s.charAt(p++); } /** * @see java.util.Iterator#remove() */ public void remove() { throw new UnsupportedOperationException(); } }; } }) { State newState = getState(c); if (oldState != newState) { if (oldState == State.NUMBER && (newState == State.IGNORED || newState == State.UNIT)) { num = Integer.parseInt(s.subSequence(start, end).toString()); } else if (oldState == State.UNIT && (newState == State.IGNORED || newState == State.NUMBER)) { out.nTimes(s.subSequence(start, end).toString(), num); num = 0; } start = end; } ++end; oldState = newState; } if (oldState == State.UNIT) { out.nTimes(s.subSequence(start, end).toString(), num); } return out; }
From source file:CharArrayMap.java
private boolean equals(CharSequence text1, char[] text2) { int len = text1.length(); if (len != text2.length) return false; if (ignoreCase) { for (int i = 0; i < len; i++) { if (Character.toLowerCase(text1.charAt(i)) != text2[i]) return false; }//from ww w .j a v a2 s. co m } else { for (int i = 0; i < len; i++) { if (text1.charAt(i) != text2[i]) return false; } } return true; }
From source file:com.asakusafw.runtime.io.text.csv.CsvFieldReader.java
@Override public boolean nextField() throws IOException { if (lastState.moreFields == false) { nextReadIndex = -1;// w w w . j av a2 s .co m currentFieldIndex = -1; lastState = State.AFTER_RECORD; return false; } State state = State.BEGIN_FIELD; CharSequence line = currentLine; assert line != null; fieldBuffer.setLength(0); int index = nextReadIndex; do { int c = index == line.length() ? EOF : line.charAt(index++); switch (state) { case BEGIN_FIELD: state = doBeginField(c); break; case BARE_BODY: state = doBareBody(c); break; case QUOTE_BODY: state = doQuoteBody(c); break; case QUOTE_BODY_SAW_QUOTE: state = doQuoteBodySawQuote(c); break; default: throw new AssertionError(lastState); } } while (state.moreCharacters); nextReadIndex = index; currentFieldIndex++; lastState = state; return true; }
From source file:com.nextgis.maplibui.formcontrol.AutoTextEdit.java
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences) throws JSONException { ControlHelper.setClearAction(this); JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); mAllowSaveNewValue = attributes.optBoolean(JSON_ALLOW_NEW_VALUES); if (!ControlHelper.isEnabled(fields, mFieldName)) { setEnabled(false);/* ww w. j a v a 2 s .com*/ setTextColor(Color.GRAY); } String lastValue = null; if (ControlHelper.hasKey(savedState, mFieldName)) lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else if (null != featureCursor) { int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) lastValue = featureCursor.getString(column); } else if (mIsShowLast) lastValue = preferences.getString(mFieldName, null); mAliasValueMap = new HashMap<>(); if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) { MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); if (null == map) throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited"); String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME); long id = attributes.getLong(JSON_NGW_ID_KEY); for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWLookupTable) { NGWLookupTable table = (NGWLookupTable) map.getLayer(i); if (table.getRemoteId() != id || !table.getAccountName().equals(account)) continue; for (Map.Entry<String, String> entry : table.getData().entrySet()) { mAliasValueMap.put(entry.getValue(), entry.getKey()); if (entry.getKey().equals(lastValue)) lastValue = entry.getValue(); } break; } } } else { JSONArray values = attributes.getJSONArray(JSON_VALUES_KEY); for (int j = 0; j < values.length(); j++) { JSONObject keyValue = values.getJSONObject(j); String value = keyValue.getString(JSON_VALUE_NAME_KEY); String alias = keyValue.getString(JSON_VALUE_ALIAS_KEY); mAliasValueMap.put(alias, value); if (value.equals(lastValue)) lastValue = alias; } } setText(lastValue); mAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, new ArrayList<>(mAliasValueMap.keySet())); setAdapter(mAdapter); setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus && getText().length() == 0) { postDelayed(new Runnable() { @Override public void run() { showDropDown(); } }, 100); } } }); addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.length() < 1) getOnFocusChangeListener().onFocusChange(AutoTextEdit.this, true); } @Override public void afterTextChanged(Editable editable) { } }); }
From source file:de.cosmocode.lucene.DefaultLuceneQuery.java
@Override public DefaultLuceneQuery addUnescapedField(final String key, final CharSequence value, final boolean mandatory) { if (key == null || value == null || value.length() == 0) { setLastSuccessful(false);/* w ww .ja va2 s . co m*/ return this; } if (mandatory) queryArguments.append("+"); queryArguments.append(key).append(":(").append(value).append(") "); setLastSuccessful(true); return this; }
From source file:org.greencheek.utils.environment.propertyplaceholder.resolver.value.VariablePlaceholderValueResolver.java
private int findPlaceholderEndIndex(CharSequence buf, int startIndex) { int index = startIndex + this.placeholderPrefix.length(); int withinNestedPlaceholder = 0; while (index < buf.length()) { if (substringMatch(buf, index, this.placeholderSuffix)) { if (withinNestedPlaceholder > 0) { withinNestedPlaceholder--; index = index + this.placeholderSuffix.length(); } else { return index; }// ww w .j a va 2 s. c om } else if (substringMatch(buf, index, this.simplePrefix)) { withinNestedPlaceholder++; index = index + this.simplePrefix.length(); } else { index++; } } return -1; }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static boolean endsWith(final CharSequence suffix, final CharSequence sequence) { return startsWith(suffix, length(sequence) - suffix.length(), sequence); }
From source file:br.msf.commons.util.CharSequenceUtils.java
/** * Returns the combined length of all non-null given sequences. * The null ones are considered zero length. * <p/>/*from w w w.ja v a 2 s. c o m*/ * If no sequence is given (null or empty array), this will return <tt>zero (0)</tt>. * * @param sequences The sequences to be analysed. * @return The sum of the given sequence lengths. */ public static int length(final CharSequence... sequences) { int length = 0; if (ArrayUtils.isNotEmpty(sequences)) { for (CharSequence item : sequences) { if (isNotEmpty(item)) { length += item.length(); } } } return length; }
From source file:com.gmail.at.faint545.activities.SpeedLimitActivity.java
private void initListeners() { valueEditText.addTextChangedListener(new TextWatcher() { @Override// w ww.j a v a2s.c om public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (s.length() < 1) ok.setEnabled(false); else ok.setEnabled(true); } }); ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String value = valueEditText.getText().toString(); new SpeedLimitTask(SpeedLimitActivity.this, target.buildURL(), target.getApiKey()).execute(value); } }); }
From source file:com.intellij.lang.jsgraphql.ide.annotator.JSGraphQLAnnotator.java
@Nullable @Override/*from www . jav a 2 s . c o m*/ public JSGraphQLAnnotationResult collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) { try { boolean isJavaScript = file instanceof JSFile; if (isJavaScript || file instanceof JSGraphQLFile) { CharSequence buffer = editor.getDocument().getCharsSequence(); if (isJavaScript) { // replace the JS with line-preserving whitespace to be ignored by GraphQL buffer = getWhitespacePaddedGraphQL(file, buffer); } if (buffer.length() > 0) { final String environment = JSGraphQLLanguageInjectionUtil.getEnvironment(file); final AnnotationsResponse annotations = JSGraphQLNodeLanguageServiceClient .getAnnotations(buffer.toString(), file.getProject(), environment); return new JSGraphQLAnnotationResult(annotations, editor); } } else if (file instanceof JSGraphQLSchemaFile) { // no external annotation support yet for schema files return new JSGraphQLAnnotationResult(new AnnotationsResponse(), editor); } } catch (Throwable e) { if (e instanceof ProcessCanceledException) { // annotation was cancelled, e.g. due to an editor being closed return null; } log.error("Error during doAnnotate", e); } return null; }