Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

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

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:Main.java

protected static void updateSignature(final Signature signature, final boolean relaxed,
        final boolean ischeduleRelaxed, final CharSequence header, final String fv) throws SignatureException {
    if (relaxed | ischeduleRelaxed) {
        if (deepDebug) {
            trace("#" + header.toString().toLowerCase() + ":-");
        }//from w ww  .  jav a  2  s .  c  om
        signature.update(header.toString().toLowerCase().getBytes());
        signature.update(":".getBytes());
        String headerValue = fv.substring(fv.indexOf(':') + 1);
        headerValue = headerValue.replaceAll("\r\n[\t ]", " ");
        headerValue = headerValue.replaceAll("[\t ]+", " ");

        if (ischeduleRelaxed) {
            headerValue = headerValue.replaceAll(" , ", ",");
        }

        headerValue = headerValue.trim();
        signature.update(headerValue.getBytes());
        if (deepDebug) {
            trace("#" + headerValue + "#");
        }
    } else {
        signature.update(fv.getBytes());
        if (deepDebug) {
            trace("#" + fv + "#");
        }
    }
}

From source file:Main.java

/**
 * Given either a Spannable String or a regular String and a token, apply
 * the given CharacterStyle to the span between the tokens, and also remove
 * tokens./*from  w w  w  . j  a  va 2  s. c  om*/
 * <p/>
 * For example, {@code setSpanBetweenTokens("Hello ##world##!", "##",
 *new ForegroundColorSpan(0xFFFF0000));} will return a CharSequence
 * {@code "Hello world!"} with {@code world} in red.
 *
 * @param text  The text, with the tokens, to adjust.
 * @param token The token string; there should be at least two instances of
 *              token in text.
 * @param cs    The style to apply to the CharSequence. WARNING: You cannot
 *              send the same two instances of this parameter, otherwise the
 *              second call will remove the original span.
 * @return A Spannable CharSequence with the new style applied.
 * @see <a href="http://developer.android.com/reference/android/text/style/CharacterStyle
 * .html">Character Style</a>
 */
public static CharSequence setSpanBetweenTokens(CharSequence text, String token, CharacterStyle... cs) {
    // Start and end refer to the points where the span will apply
    int tokenLen = token.length();
    int start = text.toString().indexOf(token) + tokenLen;
    int end = text.toString().indexOf(token, start);

    if (start > -1 && end > -1) {
        // Copy the spannable string to a mutable spannable string
        SpannableStringBuilder ssb = new SpannableStringBuilder(text);
        for (CharacterStyle c : cs) {
            ssb.setSpan(c, start, end, 0);
        }

        // Delete the tokens before and after the span
        ssb.delete(end, end + tokenLen);
        ssb.delete(start - tokenLen, start);

        text = ssb;
    }

    return text;
}

From source file:Main.java

public static InputStream toInputStream(CharSequence input) {
    return new ByteArrayInputStream(input.toString().getBytes());
}

From source file:Main.java

/**
 * Helper Method. Searches through the child nodes of a node and returns the first node with a matching name.
 * Do we need this ?//from   w w  w .j av  a  2  s .c  o m
 * @param element The node to read from
 * @param nodeName String The name of the node
 * @param caseSensitive If true, the node name searcher will be case sensitive
 * @return Node the located node or null if one was not found
 */

public static Node getChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive) {
    if (element == null)
        return null;
    if (nodeName == null)
        return null;
    final String name = nodeName.toString().trim();
    if (name.isEmpty())
        return null;
    NodeList list = element.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node node = list.item(i);
        if (caseSensitive) {
            if (node.getNodeName().equals(name))
                return node;
        } else {
            if (node.getNodeName().equalsIgnoreCase(name))
                return node;
        }
    }
    return null;
}

From source file:Main.java

/**
 * Gets the part of a char sequence that is not the NCName suffix fragment
 * // w  ww. j  a v  a 2s .c om
 * @param cs
 *           The character sequence.
 * @return Returns the prefix split at the last non-NCName character, or the
 *         whole input if no NCName is found.
 */
public static String getNCNamePrefix(CharSequence cs) {
    int localPartStartIndex = getNCNameSuffixIndex(cs);
    if (localPartStartIndex != -1) {
        return cs.toString().substring(0, localPartStartIndex);
    } else {
        return cs.toString();
    }
}

From source file:Main.java

/**
 * Gets the longest NCName that is a suffix of a character sequence.
 * //w  w w  . j a  v a 2  s.com
 * @param cs
 *           The character sequence.
 * @return Returns the string which is the longest suffix of the character
 *         sequence <code>s</code> that is an NCName, or <code>null</code> if
 *         the character sequence <code>s</code> does not have a suffix that
 *         is an NCName.
 */
public static String getNCNameSuffix(CharSequence cs) {
    int localPartStartIndex = getNCNameSuffixIndex(cs);
    if (localPartStartIndex != -1) {
        return cs.toString().substring(localPartStartIndex);
    } else {
        return null;
    }
}

From source file:com.axibase.tsd.driver.jdbc.strategies.Consumer.java

private static void processComments(StatementContext context, CharSequence comments) {
    if (StringUtils.isBlank(comments)) {
        return;//w  w  w.  java 2s .c om
    }
    final String json = comments.toString();
    if (logger.isTraceEnabled()) {
        logger.trace(json);
    }
    try {
        final Comments commentsObject = JsonMappingUtil.mapToComments(json);
        fillWarnings(commentsObject.getWarnings(), context);
        fillErrors(commentsObject.getErrors(), context);
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Wrong error format: {}", e.getMessage());
        }
    }
}

From source file:Main.java

public static void replaceAll(CharSequence s, int start, int end, StringBuilder sb2, String[] s10,
        String[] s20) {//from   ww w .  j a v  a  2  s.  co  m
    replaceAll(s.toString(), start, end, sb2, s10, s20);
}

From source file:Main.java

public static byte[] toByteArray(CharSequence input) {
    if (input == null)
        return new byte[0];
    return input.toString().getBytes();
}

From source file:fr.landel.utils.assertor.utils.AssertorEnum.java

/**
 * Prepare the next step to validate if the {@link Enum} has the specified
 * name (insensitive case)//from www  .  j  a v a 2s .  c  om
 * 
 * <p>
 * precondition: {@link Enum} cannot be null and {@code name} cannot be
 * {@code null} or empty
 * </p>
 * 
 * @param step
 *            the previous step
 * @param name
 *            the enumeration property name
 * @param message
 *            the message if invalid
 * @param <T>
 *            the enumeration type
 * @return the next step
 */
public static <T extends Enum<T>> StepAssertor<T> hasNameIgnoreCase(final StepAssertor<T> step,
        final CharSequence name, final MessageAssertor message) {

    final BiPredicate<T, Boolean> checker = (object, not) -> object.name().equalsIgnoreCase(name.toString());

    return AssertorEnum.hasName(step, name, MSG.ENUM.NAME, checker, message);
}