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:org.codehaus.groovy.grails.web.pages.GroovyPageParser.java

private static boolean match(CharSequence pat, CharSequence text, int start) {
    int ix = start, ixz = text.length(), ixy = start + pat.length();
    if (ixz > ixy) {
        ixz = ixy;//  w  ww .ja v  a2  s.  com
    }
    if (pat.length() > ixz - start) {
        return false;
    }

    for (; ix < ixz; ix++) {
        if (Character.toLowerCase(text.charAt(ix)) != Character.toLowerCase(pat.charAt(ix - start))) {
            return false;
        }
    }
    return true;
}

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

public static boolean isBlankOrNull(final CharSequence sequence) {
    if (isEmptyOrNull(sequence)) {
        return true;
    }/*  w  w w  .j a v  a  2  s . com*/
    int first;
    /* finds the first non-space char index */
    for (first = 0; first < sequence.length(); first++) {
        if (!Character.isWhitespace(sequence.charAt(first))) {
            break;
        }
    }
    return first >= sequence.length();
}

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

private static boolean startsWith(CharSequence prefix, final int offset, final CharSequence sequence) {
    if (isEmptyOrNull(prefix) || isEmptyOrNull(sequence) || prefix.length() > sequence.length()) {
        return false;
    }//from  w w w .j  a v a 2s  .co m
    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.eaio.util.text.HumanTime.java

/**
 * Parses a {@link CharSequence} argument and returns a {@link HumanTime} instance.
 * // ww w.j a  va 2s.c  om
 * @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:br.msf.commons.util.CharSequenceUtils.java

/**
 * Removes accents and graphical symbols from words, like tilde, cute, and so on.
 *
 * @param sequence Sequence witch the its accents must be removed.
 * @return The sequence without accents.
 *//*from   w w  w  . j a  v  a  2 s  .  c om*/
protected static StringBuilder removeAccentsInternal(final CharSequence sequence) {
    if (sequence == null) {
        return null;
    }
    final StringBuilder builder = new StringBuilder(sequence.length());
    for (int i = 0; i < sequence.length(); i++) {
        builder.append(LatinCharacterUtils.undecorateLetter(sequence.charAt(i)));
    }
    return builder;
}

From source file:com.amazon.carbonado.layout.LayoutFactory.java

private long mixInHash(long hash, CharSequence value, int multiplier) {
    for (int i = value.length(); --i >= 0;) {
        hash = hash * multiplier + value.charAt(i);
    }/*from   w w  w .j ava  2s  .  c om*/
    return hash;
}

From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java

private CharSequence reverseComplement(CharSequence selectedReadRegion) {
    MutableString s = new MutableString();
    s.setLength(selectedReadRegion.length());
    int j = 0;//from   w  w w  .  j  av a2s . c om
    for (int i = s.length() - 1; i >= 0; i--) {
        char base = selectedReadRegion.charAt(i);
        switch (base) {
        case 'A':
            base = 'T';
            break;
        case 'C':
            base = 'G';
            break;
        case '>':
            base = '<';
            break;
        case '<':
            base = '>';
            break;
        case 'T':
            base = 'A';
            break;
        case 'G':
            base = 'C';
            break;
        default:
            base = 'N';
            break;
        }
        s.charAt(j++, base);

    }
    return s;
}

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

public static int countVowelChain(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return 0;
    } else if (length(sequence) == 1) {
        return hasVowel(sequence) ? 1 : 0;
    }// w ww .  j av a  2s. c om
    int max = 0;
    int count = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (isVowel(sequence.charAt(i))) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 0;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:org.egov.android.view.activity.EditProfileActivity.java

/**
 * To initialize and set the layout for the ProfileActivity.Set click listeners to the save
 * changes, change picture and calendar icon. Here we have checked the api level to set the
 * layout. If api level is greater than 13, then call activity_edit_profile layout else call
 * activity_lower_version_edit_profile layout. activity_edit_profile layout contains
 * EGovRoundedImageView component which is not supported in lower api levels. get all the user
 * profile field values from the intent that is passed from the Profile Activity and displays
 * those values to the corresponding UI fields of EditProfile Layout StorageManager is the
 * interface to the systems' storage service. The storage manager handles storage-related items.
 * profile picture is stored in /egovernments/profile directory on device storage area. profile
 * picture is displayed using setImageBitmap method.
 */// w  w  w  .ja va 2 s. com
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    apiLevel = AndroidLibrary.getInstance().getSession().getInt("api_level", 0);
    if (apiLevel > 13) {
        setContentView(R.layout.activity_edit_profile);
    } else {
        setContentView(R.layout.activity_lower_version_edit_profile);
    }

    ((Button) findViewById(R.id.editprofile_doEditprofile)).setOnClickListener(this);
    ((Button) findViewById(R.id.changepicture)).setOnClickListener(this);
    ((ImageView) findViewById(R.id.edit_profile_calendar)).setOnClickListener(this);

    mobileNo = getIntent().getExtras().getString("mobileNo");
    userName = getIntent().getExtras().getString("userName");
    mailId = getIntent().getExtras().getString("mailId");
    gender = getIntent().getExtras().getString("gender");
    altContactNumber = getIntent().getExtras().getString("altContactNumber");
    dateOfBirth = getIntent().getExtras().getString("dateOfBirth");
    panCardNumber = getIntent().getExtras().getString("panCardNumber");
    aadhaarCardNumber = getIntent().getExtras().getString("aadhaarCardNumber");

    ((EditText) findViewById(R.id.edit_profile_name)).setText(userName);
    ((EditText) findViewById(R.id.edit_profile_alt_contact)).setText(altContactNumber);
    ((EditText) findViewById(R.id.edit_profile_pan)).setText(panCardNumber);
    ((EditText) findViewById(R.id.edit_profile_aadhaar)).setText(aadhaarCardNumber);
    ((TextView) findViewById(R.id.edit_profile_dob)).setText(dateOfBirth);

    InputFilter filter = new InputFilter() {
        @Override
        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 "";
                }
            }
            return null;
        }
    };

    ((EditText) findViewById(R.id.edit_profile_pan)).setFilters(new InputFilter[] { filter });

    int selected_gender = (gender.equalsIgnoreCase("male")) ? R.id.male
            : (gender.equalsIgnoreCase("female")) ? R.id.female : R.id.male;

    ((RadioGroup) findViewById(R.id.gender)).check(selected_gender);

    StorageManager sm = new StorageManager();
    Object[] obj = sm.getStorageInfo(EditProfileActivity.this);
    profPath = obj[0].toString() + "/egovernments/profile";
    String path = profPath + "/photo_" + mobileNo + ".jpg";
    profileImage = new File(profPath + "/photo_temp_user.jpg");
    File imgFile = new File(path);
    if (imgFile.exists()) {
        ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(_getBitmapImage(path));
    }
    if (profileImage.exists()) {
        profileImage.delete();
    }
}

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

public static int countConsonantChain(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return 0;
    } else if (length(sequence) == 1) {
        return hasConsonant(sequence) ? 1 : 0;
    }/*from  w  w w.j  a  va2s .co  m*/
    int max = 0;
    int count = 0;
    for (int i = 0; i < sequence.length(); i++) {
        if (isConsonant(sequence.charAt(i))) {
            count++;
        } else {
            if (count > max) {
                max = count;
            }
            count = 0;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}