List of usage examples for java.lang CharSequence charAt
char charAt(int index);
From source file:org.batoo.common.util.StringUtils.java
/** * Check whether the given CharSequence contains any whitespace characters. * /*from ww w . j av a2 s.co m*/ * @param str * the CharSequence to check (may be <code>null</code>) * @return <code>true</code> if the CharSequence is not empty and contains at least 1 whitespace character * @see java.lang.Character#isWhitespace */ public static boolean containsWhitespace(CharSequence str) { if (!StringUtils.hasLength(str)) { return false; } final int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
From source file:org.batoo.common.util.StringUtils.java
/** * Check whether the given CharSequence has actual text. More specifically, returns <code>true</code> if the string not * <code>null</code>, its length is greater than 0, and it contains at least one non-whitespace character. * <p>// w w w .j av a 2s . co m * * <pre> * StringUtils.hasText(null) = false * StringUtils.hasText("") = false * StringUtils.hasText(" ") = false * StringUtils.hasText("12345") = true * StringUtils.hasText(" 12345 ") = true * </pre> * * @param str * the CharSequence to check (may be <code>null</code>) * @return <code>true</code> if the CharSequence is not <code>null</code>, its length is greater than 0, and it does not contain * whitespace only * @see java.lang.Character#isWhitespace */ public static boolean hasText(CharSequence str) { if (!StringUtils.hasLength(str)) { return false; } final int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
From source file:com.asakusafw.runtime.io.csv.CsvEmitter.java
private void appendEscaped(StringBuilder buffer, CharSequence string) { buffer.append(ESCAPE);// w w w . j av a 2 s . c o m for (int i = 0, n = string.length(); i < n; i++) { char c = string.charAt(i); if (c == ESCAPE) { buffer.append(ESCAPE); } buffer.append(c); } buffer.append(ESCAPE); }
From source file:com.asakusafw.runtime.io.text.csv.CsvFieldReader.java
@Override public boolean nextField() throws IOException { if (lastState.moreFields == false) { nextReadIndex = -1;//from w ww . j a v a 2 s . c o 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.amberfog.countryflagsdemo.BaseFlagFragment.java
protected void initUI(View rootView) { mSpinner = (Spinner) rootView.findViewById(R.id.spinner); mSpinner.setOnItemSelectedListener(mOnItemSelectedListener); mAdapter = new CountryAdapter(getActivity()); mSpinner.setAdapter(mAdapter);// w w w .j a v a 2 s . c om mPhoneEdit = (EditText) rootView.findViewById(R.id.phone); mPhoneEdit.addTextChangedListener(new CustomPhoneNumberFormattingTextWatcher(mOnPhoneChangedListener)); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { char c = source.charAt(i); if (dstart > 0 && !Character.isDigit(c)) { return ""; } } return null; } }; mPhoneEdit.setFilters(new InputFilter[] { filter }); mPhoneEdit.setImeOptions(EditorInfo.IME_ACTION_SEND); mPhoneEdit.setImeActionLabel(getString(R.string.label_send), EditorInfo.IME_ACTION_SEND); mPhoneEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { send(); return true; } return false; } }); }
From source file:com.sbgapps.simplenumberpicker.decimal.DecimalPickerDialog.java
@SuppressLint("SetTextI18n") @NonNull/* w ww .j av a 2 s .c o m*/ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { TypedArray attributes = getContext().obtainStyledAttributes(theme, R.styleable.SimpleNumberPicker); LayoutInflater inflater = getActivity().getLayoutInflater(); @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.snp_dialog_decimal_picker, null); // Init number int color = attributes.getColor(R.styleable.SimpleNumberPicker_snpKeyColor, ContextCompat.getColor(getContext(), android.R.color.secondary_text_light)); numberTextView = (TextView) view.findViewById(R.id.tv_hex_number); numberTextView.setTextColor(color); if (null != savedInstanceState && savedInstanceState.containsKey(ARG_SAVED_VALUE)) numberTextView.setText(savedInstanceState.getString(ARG_SAVED_VALUE)); // Init backspace color = attributes.getColor(R.styleable.SimpleNumberPicker_snpBackspaceColor, ContextCompat.getColor(getContext(), android.R.color.secondary_text_light)); backspaceButton = (ImageButton) view.findViewById(R.id.key_backspace); backspaceButton.setImageDrawable( ThemeUtil.makeSelector(getContext(), R.drawable.snp_ic_backspace_black_24dp, color)); backspaceButton.setOnClickListener(v -> { CharSequence number = numberTextView.getText().subSequence(0, numberTextView.getText().length() - 1); if (1 == number.length() && '-' == number.charAt(0)) number = ""; numberTextView.setText(number); onNumberChanged(); }); backspaceButton.setOnLongClickListener(v -> { numberTextView.setText(""); onNumberChanged(); return true; }); // Create dialog dialog = new AlertDialog.Builder(getContext(), theme).setView(view) .setPositiveButton(android.R.string.ok, (dialog, which) -> { String result = numberTextView.getText().toString(); if (result.isEmpty()) result = "0"; final float number = Float.parseFloat(result); final Activity activity = getActivity(); final Fragment fragment = getParentFragment(); if (activity instanceof DecimalPickerHandler) { final DecimalPickerHandler handler = (DecimalPickerHandler) activity; handler.onDecimalNumberPicked(reference, number); } else if (fragment instanceof DecimalPickerHandler) { final DecimalPickerHandler handler = (DecimalPickerHandler) fragment; handler.onDecimalNumberPicked(reference, number); } dismiss(); }).setNegativeButton(android.R.string.cancel, (dialog, which) -> dismiss()).create(); // Init dialog color = attributes.getColor(R.styleable.SimpleNumberPicker_snpDialogBackground, ContextCompat.getColor(getContext(), android.R.color.white)); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(color)); // Init keys View.OnClickListener listener = v -> { int key = (int) v.getTag(); String id = numberTextView.getText() + Integer.toString(key); numberTextView.setText(id); onNumberChanged(); }; color = attributes.getColor(R.styleable.SimpleNumberPicker_snpKeyColor, ThemeUtil.getThemeAccentColor(getContext())); TypedArray ids = getResources().obtainTypedArray(R.array.snp_key_ids); for (int i = 0; i < NB_KEYS; i++) { TextView key = (TextView) view.findViewById(ids.getResourceId(i, -1)); key.setTag(i); key.setOnClickListener(listener); key.setTextColor(color); } // Init sign TextView sign = (TextView) view.findViewById(R.id.key_sign); if (relative) { sign.setTextColor(color); sign.setOnClickListener(v -> { String number = numberTextView.getText().toString(); if (number.startsWith("-")) { numberTextView.setText(number.substring(1)); } else { numberTextView.setText("-" + number); } onNumberChanged(); }); } else { sign.setVisibility(View.INVISIBLE); } // Init point TextView point = (TextView) view.findViewById(R.id.key_point); if (natural) { point.setVisibility(View.INVISIBLE); } else { point.setTextColor(color); point.setOnClickListener(v -> { if (numberTextView.getText().toString().contains(".")) return; String number = numberTextView.getText().toString(); numberTextView.setText(number + "."); onNumberChanged(); }); } ids.recycle(); attributes.recycle(); return dialog; }
From source file:br.msf.commons.text.EnhancedStringBuilder.java
protected static boolean startsWith(final CharSequence prefix, final int offset, final CharSequence sequence) { if (CharSequenceUtils.isEmptyOrNull(prefix) || CharSequenceUtils.isEmptyOrNull(sequence) || prefix.length() > sequence.length()) { return false; }//from w ww . j a v a 2 s . c om int i = offset, j = 0; int pLen = prefix.length(); while (--pLen >= 0) { if (sequence.charAt(i++) != prefix.charAt(j++)) { return false; } } return true; }
From source file:com.awt.supark.EditCar.java
public void radioListener() { InputFilter charFilter = filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (!Character.isLetterOrDigit(source.charAt(i))) { return ""; }//from w w w.j a v a 2 s. c o m } return null; } }; if (radioNewSrb.isChecked()) { txtCity.setVisibility(View.VISIBLE); licensePlate.setBackgroundDrawable(getResources().getDrawable(R.drawable.licenseplate)); updateLicensePlate(licenseNum); //txtNum.setFilters(new InputFilter[]{filter, new InputFilter.LengthFilter(7), new InputFilter.AllCaps()}); carLicense.setFilters( new InputFilter[] { new InputFilter.LengthFilter(8), new InputFilter.AllCaps(), charFilter }); } else if (radioGeneric.isChecked()) { txtCity.setVisibility(View.GONE); licensePlate.setBackgroundDrawable(getResources().getDrawable(R.drawable.licenseplate2)); // Reset txtCity.setText(""); updateLicensePlate(licenseNum); //txtNum.setFilters(new InputFilter[]{filter, new InputFilter.LengthFilter(12), new InputFilter.AllCaps()}); carLicense.setFilters( new InputFilter[] { new InputFilter.LengthFilter(12), new InputFilter.AllCaps(), charFilter }); } }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static boolean isUpperCase(final CharSequence sequence) { if (isEmpty(sequence)) { return true; }/* w ww .j ava 2 s. c o m*/ for (int i = 0; i < sequence.length(); i++) { char c = sequence.charAt(i); if (c != Character.toUpperCase(c)) { return false; } } return true; }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static boolean isLowerCase(final CharSequence sequence) { if (isEmpty(sequence)) { return true; }/*from www .j ava 2 s . c o m*/ for (int i = 0; i < sequence.length(); i++) { char c = sequence.charAt(i); if (c != Character.toLowerCase(c)) { return false; } } return true; }