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: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  . ja  va  2 s . c  om
    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 boolean isBlankOrNull(final CharSequence sequence) {
    if (isEmptyOrNull(sequence)) {
        return true;
    }//from  w  w w .  ja  v a 2s.c o  m
    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:net.dv8tion.jda.core.EmbedBuilder.java

/**
 * Appends to 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  w w.j a  v  a  2 s .c o  m
 *         the string to append to the description of the embed
 *
 * @throws java.lang.IllegalArgumentException
 *         <ul>
 *             <li>If the provided {@code description} String is null</li>
 *             <li>If the length of {@code description} is greater than {@link net.dv8tion.jda.core.entities.MessageEmbed#TEXT_MAX_LENGTH}.</li>
 *         </ul>
 *
 * @return the builder after the description has been set
 */
public EmbedBuilder appendDescription(CharSequence description) {
    Args.notNull(description, "description");
    Args.check(this.description.length() + description.length() <= MessageEmbed.TEXT_MAX_LENGTH,
            "Description cannot be longer than %d characters.", MessageEmbed.TEXT_MAX_LENGTH);
    this.description.append(description);
    return this;
}

From source file:com.mirth.connect.plugins.datatypes.hl7v2.XMLEncodedHL7Handler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    logger.trace("ending element: " + localName);
    inElement = false;/*from ww w  . j av a2 s .co  m*/

    String[] localNameArray = StringUtils.split(localName, ID_DELIMETER);

    /*
     * Once we see the closing of MSH.1 or MSH.2 tags, we know that the separator characters
     * have been added to the output buffer, so we can grab them and set the local variables.
     */
    if ((localNameArray.length == 1) && (localNameArray[0].equals(ER7Reader.MESSAGE_ROOT_ID))) {
        return;
    } else if (localNameArray.length == 2) {
        if (isHeaderSegment(localNameArray[0])) {
            if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '1')) {
                fieldSeparator = String.valueOf(output.charAt(output.length() - 1));
                return;
            } else if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '2')) {
                CharSequence separators = output.subSequence(4, output.length());
                componentSeparator = String.valueOf(separators.charAt(0));
                repetitionSeparator = String.valueOf(separators.charAt(1));
                escapeCharacter = separators.length() > 2 ? String.valueOf(separators.charAt(2)) : "";
                subcomponentSeparator = separators.length() > 3 ? String.valueOf(separators.charAt(3)) : "";
            }
        }
    }

    int currentDelimeterCount = localNameArray.length - 1;

    /*
     * We don't want to have tailing separators, so once we get to the last element of a nested
     * level, we delete the last character.
     */
    if (currentDelimeterCount > previousDelimeterCount) {
        previousDelimeterCount = currentDelimeterCount;
    } else if (currentDelimeterCount < previousDelimeterCount && previousDelimiterLength > 0) {
        output.deleteCharAt(output.length() - 1);
        previousDelimeterCount = currentDelimeterCount;
    }

    /*
     * The number of periods in the element tells us the level. So, MSH is at level 0, MSH.3 is
     * at level 1, MSH.3.1 at level 2, and so on. We can use this to determine which seperator
     * to append once the element is closed.
     * 
     * MIRTH-2078: Only add the last character if the root delimiter is 0 (HL7Message) or the
     * current element level is deeper than the root level. This only pertains to partial XML
     * messages where the root is a field or component.
     */
    if (rootLevel == 0 || currentDelimeterCount >= rootLevel) {
        switch (currentDelimeterCount) {
        case 0:
            output.append(segmentSeparator);
            break;
        case 1:
            output.append(fieldSeparator);
            break;
        case 2:
            output.append(componentSeparator);
            previousDelimiterLength = componentSeparator.length();
            break;
        case 3:
            output.append(subcomponentSeparator);
            previousDelimiterLength = subcomponentSeparator.length();
            break;
        default:
            break;
        }
    }
}

From source file:ca.etsmtl.applets.etsmobile.ProfileActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.student_profile);
    handler = new ProfileHandler(this);
    handlerBandwith = new BandwithHandler(this);
    btnLogin = (Button) findViewById(R.id.profile_login_btn);
    btnLogin.setOnClickListener(this);

    // nav bar//  w w w .  j  a  v a 2  s .  c o  m
    navBar = (NavBar) findViewById(R.id.navBar1);
    navBar.setTitle(R.drawable.navbar_profil_title);
    navBar.hideRightButton();
    navBar.hideLoading();

    name = (TextView) findViewById(R.id.student_profile_name);
    lastname = (TextView) findViewById(R.id.student_profile_lastname);
    solde = (TextView) findViewById(R.id.student_profile_solde);
    codeP = (TextView) findViewById(R.id.student_profile_codePermanent);
    progess = (ProgressBar) findViewById(R.id.bandwith_progress);
    bandwith_used = (TextView) findViewById(R.id.bandwith_used_lbl);
    bandwith_max = (TextView) findViewById(R.id.bandwith_max);

    phase_input = (TextView) findViewById(R.id.bandwith_phase_input);

    credits_done = (TextView) findViewById(R.id.student_profile_credit_done);
    credit_failed = (TextView) findViewById(R.id.student_profile_credits_failed);
    credits_now = (TextView) findViewById(R.id.student_profile_credits_now);

    programme = (TextView) findViewById(R.id.student_profile_programme);
    moyenne = (TextView) findViewById(R.id.student_profile_moy);

    phase_input.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() >= 1) {
                if (appt_input.getText().length() > 4) {
                    getBandwith(s.toString(), appt_input.getText().toString());
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    appt_input = (TextView) findViewById(R.id.bandwith_appt_input);

    appt_input.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() >= 3) {
                if (phase_input.getText().length() >= 1) {
                    getBandwith(phase_input.getText().toString(), s.toString());
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    creds = new UserCredentials(prefs);
    if (creds.hasBandwithInfo()) {
        phase_input.setText(creds.getPhase());
        appt_input.setText(creds.getAppt());
    }
    doLogin();
}

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

@Override
protected CharSequence proccessMinify(final CharSequence originalContent, final CompressorSettings settings)
        throws Exception {
    Reader reader = null;/*  w w  w . ja v  a 2s .  c om*/
    Writer writer = null;

    try {
        reader = new CharSequenceReader(originalContent);
        com.yahoo.platform.yui.compressor.JavaScriptCompressor compressor = new com.yahoo.platform.yui.compressor.JavaScriptCompressor(
                reader, new MavenErrorReporter(settings.getLog(), settings.isShowJsWarnings()));

        final StringBuilder out = new StringBuilder(originalContent.length());
        writer = new StringBuilderWriter(out);
        try {
            compressor.compress(writer, LINE_BREAK_POS, false, settings.isVerbose(), true, false);
        } catch (Exception e) {
            throw new YUICompressorException(
                    "An Error has occurred while compressing javascript. Probably there is a bad practice on the source...",
                    e);
        }
        writer.flush();
        return out;
    } finally {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(writer);
    }
}

From source file:RadixTree.java

/**
 * Tests if the string is contained in the set
 * //from w  w w  .  j  av  a2 s . c o  m
 * @param string
 * @return <code>true</code> if the entire string is contained in
 *         the tree
 */
public boolean contains(CharSequence string) {
    if (!caseSensitive) {
        string = string.toString().toLowerCase();
    }

    return findPredecessor(string).length() == string.length();
}

From source file:lucee.commons.lang.StringUtil.java

public static String insertAt(String str, CharSequence substring, int pos) {

    if (isEmpty(substring))
        return str;

    int len = str.length();

    StringBuilder sb = new StringBuilder(len + substring.length());

    if (pos > len)
        pos = len;//  w  w w. j  a v  a  2 s  .  c  o  m

    if (pos > 0)
        sb.append(str.substring(0, pos));

    sb.append(substring);
    sb.append(str.substring(pos));

    return sb.toString();
}

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 www.j  a  v  a 2s  .  c  o m*/
    return hash;
}

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

public static int countRepetitionChain(final CharSequence sequence) {
    if (length(sequence) < 2) {
        return length(sequence);
    }//from w ww.jav a 2s  .  com
    int max = 1;
    int count = 1;
    char lookupChar = sequence.charAt(0);
    for (int i = 1; i < sequence.length(); i++) {
        if (sequence.charAt(i) == lookupChar) {
            count++;
        } else {
            lookupChar = sequence.charAt(i);
            if (count > max) {
                max = count;
            }
            count = 1;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}