Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:com.conx.logistics.kernel.bpm.impl.jbpm.core.mock.BPMGuvnorUtil.java

protected boolean isEmpty(final CharSequence str) {
    if (str == null || str.length() == 0) {
        return true;
    }/*from   w  w  w . j  a va  2s  .co m*/
    for (int i = 0, length = str.length(); i < length; i++) {
        if (str.charAt(i) != ' ') {
            return false;
        }
    }
    return true;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static int countDigitChain(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return 0;
    } else if (length(sequence) == 1) {
        return hasDigit(sequence) ? 1 : 0;
    }//w w w. ja v  a2s  .c  o  m
    int max = 0;
    int count = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (Character.isDigit(sequence.charAt(i))) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 0;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:org.linphone.setup.WizardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.setup_wizard, container, false);

    username = (EditText) view.findViewById(R.id.setup_username);
    ImageView usernameOkIV = (ImageView) view.findViewById(R.id.setup_username_ok);
    addXMLRPCUsernameHandler(username, usernameOkIV);

    inputFilterCharacters = new String(acceptedChars);
    if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
        inputFilterCharacters = new String(acceptedCharsForPhoneNumbers);
    }/* w ww.j a va  2s.  c  o m*/
    InputFilter filter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            if (end > start) {
                for (int index = start; index < end; index++) {
                    if (!inputFilterCharacters.contains(String.valueOf(source.charAt(index)))) {
                        return "";
                    }
                }
            }
            return null;
        }
    };
    username.setFilters(new InputFilter[] { filter });

    password = (EditText) view.findViewById(R.id.setup_password);
    passwordConfirm = (EditText) view.findViewById(R.id.setup_password_confirm);

    ImageView passwordOkIV = (ImageView) view.findViewById(R.id.setup_password_ok);
    addXMLRPCPasswordHandler(password, passwordOkIV);

    ImageView passwordConfirmOkIV = (ImageView) view.findViewById(R.id.setup_confirm_password_ok);
    addXMLRPCConfirmPasswordHandler(password, passwordConfirm, passwordConfirmOkIV);

    email = (EditText) view.findViewById(R.id.setup_email);
    ImageView emailOkIV = (ImageView) view.findViewById(R.id.setup_email_ok);
    addXMLRPCEmailHandler(email, emailOkIV);

    errorMessage = (TextView) view.findViewById(R.id.setup_error);

    createAccount = (ImageView) view.findViewById(R.id.setup_create);
    createAccount.setEnabled(false);
    createAccount.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    createAccount(getUsername(), password.getText().toString(), email.getText().toString(),
                            false);
                }
            });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                }
            });
            builder.setMessage(getString(R.string.setup_confirm_username).replace("%s", getUsername()));
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });

    if (getResources().getBoolean(R.bool.pre_fill_email_in_wizard)) {
        Account[] accounts = AccountManager.get(getActivity()).getAccountsByType("com.google");

        for (Account account : accounts) {
            if (isEmailCorrect(account.name)) {
                String possibleEmail = account.name;
                email.setText(possibleEmail);
                break;
            }
        }
    }

    return view;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static int countLowercaseChain(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return 0;
    } else if (length(sequence) == 1) {
        return hasLowercase(sequence) ? 1 : 0;
    }/*from ww w.  ja  va 2 s  .  c  o m*/
    int max = 0;
    int count = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (Character.isLowerCase(sequence.charAt(i))) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 0;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static int countUppercaseChain(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return 0;
    } else if (length(sequence) == 1) {
        return hasUppercase(sequence) ? 1 : 0;
    }//w w  w . ja va  2 s  .com
    int max = 0;
    int count = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (Character.isUpperCase(sequence.charAt(i))) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 0;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:org.linphone.setup.RegisterFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.setup_register, container, false);

    username = (EditText) view.findViewById(R.id.setup_username);
    ImageView usernameOkIV = (ImageView) view.findViewById(R.id.setup_username_ok);
    addXMLRPCUsernameHandler(username, usernameOkIV);

    inputFilterCharacters = new String(acceptedChars);
    if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
        inputFilterCharacters = new String(acceptedCharsForPhoneNumbers);
    }/*from   w w w.j  ava 2 s .  c o  m*/
    InputFilter filter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            if (end > start) {
                for (int index = start; index < end; index++) {
                    if (!inputFilterCharacters.contains(String.valueOf(source.charAt(index)))) {
                        return "";
                    }
                }
            }
            return null;
        }
    };
    username.setFilters(new InputFilter[] { filter });

    password = (EditText) view.findViewById(R.id.setup_password);
    passwordConfirm = (EditText) view.findViewById(R.id.setup_password_confirm);

    ImageView passwordOkIV = (ImageView) view.findViewById(R.id.setup_password_ok);
    addXMLRPCPasswordHandler(password, passwordOkIV);

    ImageView passwordConfirmOkIV = (ImageView) view.findViewById(R.id.setup_confirm_password_ok);
    addXMLRPCConfirmPasswordHandler(password, passwordConfirm, passwordConfirmOkIV);

    email = (EditText) view.findViewById(R.id.setup_email);
    ImageView emailOkIV = (ImageView) view.findViewById(R.id.setup_email_ok);
    addXMLRPCEmailHandler(email, emailOkIV);

    errorMessage = (TextView) view.findViewById(R.id.setup_error);

    createAccount = (Button) view.findViewById(R.id.setup_create);
    createAccount.setEnabled(false);
    createAccount.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    createAccount(getUsername(), password.getText().toString(), email.getText().toString(),
                            false);
                }
            });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                }
            });
            builder.setMessage(getString(R.string.setup_confirm_username).replace("%s", getUsername()));
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });

    if (getResources().getBoolean(R.bool.pre_fill_email_in_wizard)) {
        Account[] accounts = AccountManager.get(getActivity()).getAccountsByType("com.google");

        for (Account account : accounts) {
            if (isEmailCorrect(account.name)) {
                String possibleEmail = account.name;
                email.setText(possibleEmail);
                break;
            }
        }
    }

    return view;
}

From source file:au.org.ala.delta.translation.PrintFile.java

/**
 * Returns the number of leading spaces in the supplied text.
 * // ww w.  ja va 2 s  .c o m
 * @param text
 *            the text to count leading spaces of.
 * @return the number of leading spaces in the supplied text or zero if the
 *         parameter is null.
 */
private int numLeadingSpaces(CharSequence text) {
    if ((text == null) || (text.length() == 0)) {
        return 0;
    }
    int numSpaces = 0;
    while (text.charAt(numSpaces) == ' ') {
        numSpaces++;
    }
    return numSpaces;
}

From source file:com.j_o.android.imdb_client.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mediaList = new ArrayList<Media>();
    mediaGrid = (GridView) findViewById(R.id.media_grid_view);
    editTxMediaSearch = (EditText) findViewById(R.id.edit_search_media);

    // Input filter that not allow special characters.
    InputFilter filter = new InputFilter() {
        @Override//from w w w  . ja v a  2s  .  co  m
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {

            if (source instanceof SpannableStringBuilder) {
                SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source;
                for (int i = end - 1; i >= start; i--) {
                    char currentChar = source.charAt(i);
                    if (!Character.isLetterOrDigit(currentChar) && !Character.isSpaceChar(currentChar)) {
                        sourceAsSpannableBuilder.delete(i, i + 1);
                    }
                }
                return source;
            } else {
                StringBuilder filteredStringBuilder = new StringBuilder();
                for (int i = 0; i < end; i++) {
                    char currentChar = source.charAt(i);
                    if (Character.isLetterOrDigit(currentChar) || Character.isSpaceChar(currentChar)) {
                        filteredStringBuilder.append(currentChar);
                    }
                }
                return filteredStringBuilder.toString();
            }
        }
    };
    editTxMediaSearch.setFilters(new InputFilter[] { filter });

    editTxMediaSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                new AskForMediaAsyncTaks().execute(editTxMediaSearch.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editTxMediaSearch.getWindowToken(), 0);
                return true;
            }
            return false;
        }

    });

}

From source file:org.elasticsearch.hadoop.util.StringUtils.java

public static int levenshteinDistance(CharSequence one, CharSequence another, int threshold) {
    int n = one.length();
    int m = another.length();

    // if one string is empty, the edit distance is necessarily the length of the other
    if (n == 0) {
        return m <= threshold ? m : -1;
    } else if (m == 0) {
        return n <= threshold ? n : -1;
    }// w  w  w.j ava 2s.c o  m

    if (n > m) {
        // swap the two strings to consume less memory
        final CharSequence tmp = one;
        one = another;
        another = tmp;
        n = m;
        m = another.length();
    }

    int p[] = new int[n + 1]; // 'previous' cost array, horizontally
    int d[] = new int[n + 1]; // cost array, horizontally
    int _d[]; // placeholder to assist in swapping p and d

    // fill in starting table values
    final int boundary = Math.min(n, threshold) + 1;
    for (int i = 0; i < boundary; i++) {
        p[i] = i;
    }

    // these fills ensure that the value above the rightmost entry of our
    // stripe will be ignored in following loop iterations
    Arrays.fill(p, boundary, p.length, Integer.MAX_VALUE);
    Arrays.fill(d, Integer.MAX_VALUE);

    for (int j = 1; j <= m; j++) {
        final char t_j = another.charAt(j - 1);
        d[0] = j;

        // compute stripe indices, constrain to array size
        final int min = Math.max(1, j - threshold);
        final int max = (j > Integer.MAX_VALUE - threshold) ? n : Math.min(n, j + threshold);

        // the stripe may lead off of the table if s and t are of different sizes
        if (min > max) {
            return -1;
        }

        // ignore entry left of leftmost
        if (min > 1) {
            d[min - 1] = Integer.MAX_VALUE;
        }

        // iterates through [min, max] in s
        for (int i = min; i <= max; i++) {
            if (one.charAt(i - 1) == t_j) {
                // diagonally left and up
                d[i] = p[i - 1];
            } else {
                // 1 + minimum of cell to the left, to the top, diagonally left and up
                d[i] = 1 + Math.min(Math.min(d[i - 1], p[i]), p[i - 1]);
            }
        }

        // copy current distance counts to 'previous row' distance counts
        _d = p;
        p = d;
        d = _d;
    }

    // if p[n] is greater than the threshold, there's no guarantee on it being the correct
    // distance
    if (p[n] <= threshold) {
        return p[n];
    }
    return -1;
}

From source file:org.apache.tajo.cli.tsql.TajoCli.java

private void initCommands() {
    List<Completer> compList = new ArrayList<>();
    for (Class clazz : registeredCommands) {
        TajoShellCommand cmd = null;//from  w w  w.j  a v a2  s  .com

        try {
            Constructor cons = clazz.getConstructor(new Class[] { TajoCliContext.class });
            cmd = (TajoShellCommand) cons.newInstance(context);
        } catch (Exception e) {
            System.err.println(e.getMessage());
            throw new RuntimeException(e.getMessage());
        }

        // make completers for console auto-completion
        compList.add(cmd.getArgumentCompleter());

        commands.put(cmd.getCommand(), cmd);
        for (String alias : cmd.getAliases()) {
            commands.put(alias, cmd);
        }
    }

    cliCompleter = new AggregateCompleter(compList);

    sqlCompleter = new ArgumentCompleter(new ArgumentCompleter.AbstractArgumentDelimiter() {
        @Override
        public boolean isDelimiterChar(CharSequence buf, int pos) {
            char c = buf.charAt(pos);
            return Character.isWhitespace(c) || !(Character.isLetterOrDigit(c)) && c != '_';
        }
    }, new StringsCompleter(getKeywords()));
}