Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:br.msf.maven.compressor.processor.CssCompressor.java

@Override
protected CharSequence proccessMinify(final CharSequence originalContent, final CompressorSettings settings)
        throws Exception {
    Reader reader = null;/*from www  .jav a2 s  .co m*/
    Writer writer = null;

    try {
        reader = new CharSequenceReader(originalContent);
        com.yahoo.platform.yui.compressor.CssCompressor compressor = new com.yahoo.platform.yui.compressor.CssCompressor(
                reader);

        final StringBuilder out = new StringBuilder(originalContent.length());
        writer = new StringBuilderWriter(out);
        compressor.compress(writer, LINE_BREAK_POS);
        writer.flush();
        return out;
    } finally {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(writer);
    }
}

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

public static boolean isUpperCase(final CharSequence sequence) {
    if (isEmpty(sequence)) {
        return true;
    }/*from   w ww.j a  va 2s .  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;
    }/*  w  w w  . ja va2 s  . c om*/
    for (int i = 0; i < sequence.length(); i++) {
        char c = sequence.charAt(i);
        if (c != Character.toLowerCase(c)) {
            return false;
        }
    }
    return true;
}

From source file:com.insthub.O2OMobile.Activity.C15_EditPriceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c15_edit_price);
    mMyService = (MY_SERVICE) getIntent().getSerializableExtra(SERVICE);
    nTitle = (TextView) findViewById(R.id.top_view_title);
    nTitle.setText(getString(R.string.modify_service));
    mBack = (ImageView) findViewById(R.id.top_view_back);
    mType = (TextView) findViewById(R.id.service_type);
    mPrice = (EditText) findViewById(R.id.price);
    mSave = (Button) findViewById(R.id.save);
    if (mMyService != null) {
        mType.setText(mMyService.service_type.title);
        mPrice.setText(mMyService.price);
        mPrice.setSelection(mMyService.price.length());
    }//from  w  w  w .  j  av  a 2 s.co  m
    mServiceModel = new ServiceModel(this);
    mServiceModel.addResponseListener(this);
    mSave.setOnClickListener(this);
    mBack.setOnClickListener(this);
    mPrice.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (s.toString().length() > 0) {
                if (s.toString().substring(0, 1).equals(".")) {
                    s = s.toString().substring(1, s.length());
                    mPrice.setText(s);
                }
            }
            if (s.toString().length() > 1) {
                if (s.toString().substring(0, 1).equals("0")) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        s = s.toString().substring(1, s.length());
                        mPrice.setText(s);
                        CharSequence charSequencePirce = mPrice.getText();
                        if (charSequencePirce instanceof Spannable) {
                            Spannable spanText = (Spannable) charSequencePirce;
                            Selection.setSelection(spanText, charSequencePirce.length());
                        }
                    }
                }
            }
            boolean flag = false;
            for (int i = 0; i < s.toString().length() - 1; i++) {
                String getstr = s.toString().substring(i, i + 1);
                if (getstr.equals(".")) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                int i = s.toString().indexOf(".");
                if (s.toString().length() - 3 > i) {
                    String getstr = s.toString().substring(0, i + 3);
                    mPrice.setText(getstr);
                    CharSequence charSequencePirce = mPrice.getText();
                    if (charSequencePirce instanceof Spannable) {
                        Spannable spanText = (Spannable) charSequencePirce;
                        Selection.setSelection(spanText, charSequencePirce.length());
                    }
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }
    });
}

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

public static boolean hasAccents(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return false;
    }// ww w .  ja v a2s. c  o  m
    for (int i = 0; i < sequence.length(); i++) {
        char c = sequence.charAt(i);
        if (LatinCharacterUtils.isDecoratedLetter(c)) {
            return true;
        }
    }
    return false;
}

From source file:CharArrayMap.java

private int getHashCode(CharSequence text) {
    int code;/*from   w  w  w. j a v  a  2 s  .c o  m*/
    if (ignoreCase) {
        code = 0;
        int len = text.length();
        for (int i = 0; i < len; i++) {
            code = code * 31 + Character.toLowerCase(text.charAt(i));
        }
    } else {
        if (false && text instanceof String) {
            code = text.hashCode();
        } else {
            code = 0;
            int len = text.length();
            for (int i = 0; i < len; i++) {
                code = code * 31 + text.charAt(i);
            }
        }
    }
    return code;
}

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;
    }/* w ww.java  2s . c  o 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:github.daneren2005.dsub.util.Util.java

public static int getStringDistance(CharSequence s, CharSequence t) {
    if (s == null || t == null) {
        throw new IllegalArgumentException("Strings must not be null");
    }//  w w w.java2 s . com

    int n = s.length();
    int m = t.length();

    if (n == 0) {
        return m;
    } else if (m == 0) {
        return n;
    }

    if (n > m) {
        final CharSequence tmp = s;
        s = t;
        t = tmp;
        n = m;
        m = t.length();
    }

    int p[] = new int[n + 1];
    int d[] = new int[n + 1];
    int _d[];

    int i;
    int j;
    char t_j;
    int cost;

    for (i = 0; i <= n; i++) {
        p[i] = i;
    }

    for (j = 1; j <= m; j++) {
        t_j = t.charAt(j - 1);
        d[0] = j;

        for (i = 1; i <= n; i++) {
            cost = s.charAt(i - 1) == t_j ? 0 : 1;
            d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
        }

        _d = p;
        p = d;
        d = _d;
    }

    return p[n];
}

From source file:net.dv8tion.jda.core.EmbedBuilder.java

/**
 * Sets the Description of the embed. This is where the main chunk of text for an embed is typically placed.
 *
 * <p><b><a href="http://i.imgur.com/lbchtwk.png">Example</a></b>
 *
 * @param  description//from  w ww .  ja va  2  s.com
 *         the description of the embed, {@code null} to reset
 *
 * @throws java.lang.IllegalArgumentException
 *         If the length of {@code description} is greater than {@link net.dv8tion.jda.core.entities.MessageEmbed#TEXT_MAX_LENGTH}
 *
 * @return the builder after the description has been set
 */
public EmbedBuilder setDescription(CharSequence description) {
    if (description == null || description.length() < 1) {
        this.description = new StringBuilder();
    } else {
        Args.check(description.length() <= MessageEmbed.TEXT_MAX_LENGTH,
                "Description cannot be longer than %d characters.", MessageEmbed.TEXT_MAX_LENGTH);
        this.description = new StringBuilder(description);
    }
    return this;
}

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.
 */// w  w w.j  a  v a 2  s .com
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;
}