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

public static int convertValueToInt(CharSequence charSeq, int defaultValue) {
    if (charSeq == null)
        return defaultValue;

    String nm = charSeq.toString();

    // XXX This code is copied from Integer.decode() so we don't
    // have to instantiate an Integer!

    int sign = 1;
    int index = 0;
    int len = nm.length();
    int base = 10;

    if ('-' == nm.charAt(0)) {
        sign = -1;/*  ww  w .j a  v  a  2s  . c  o m*/
        index++;
    }

    if ('0' == nm.charAt(index)) {
        //  Quick check for a zero by itself
        if (index == (len - 1))
            return 0;

        char c = nm.charAt(index + 1);

        if ('x' == c || 'X' == c) {
            index += 2;
            base = 16;
        } else {
            index++;
            base = 8;
        }
    } else if ('#' == nm.charAt(index)) {
        index++;
        base = 16;
    }

    return Integer.parseInt(nm.substring(index), base) * sign;
}

From source file:com.shishu.utility.url.TableUtil.java

/**
 * Convert given Utf8 instance to String
 *
 * @param utf8//w  w w .j  av  a  2 s.c  o m
 *          Utf8 object
 * @return string-ifed Utf8 object or null if Utf8 instance is null
 */
public static String toString(CharSequence cs) {
    return (cs == null ? null : cs.toString());
}

From source file:Main.java

/**
 * Parses an XML string and generates an XML document.
 * @param xml The XML to parse//from   w  ww.j a va  2s. c o m
 * @return An XML doucument.
 */
public static Document parseXML(CharSequence xml) {
    StringReader sr = new StringReader(xml.toString());
    return parseXML(new InputSource(sr));
}

From source file:Main.java

public static final int convertValueToInt(CharSequence charSeq, int defaultValue) {
    if (null == charSeq)
        return defaultValue;

    String nm = charSeq.toString();

    // XXX This code is copied from Integer.decode() so we don't
    // have to instantiate an Integer!

    int value;//  www .j a v  a  2  s.  c o  m
    int sign = 1;
    int index = 0;
    int len = nm.length();
    int base = 10;

    if ('-' == nm.charAt(0)) {
        sign = -1;
        index++;
    }

    if ('0' == nm.charAt(index)) {
        //  Quick check for a zero by itself
        if (index == (len - 1))
            return 0;

        char c = nm.charAt(index + 1);

        if ('x' == c || 'X' == c) {
            index += 2;
            base = 16;
        } else {
            index++;
            base = 8;
        }
    } else if ('#' == nm.charAt(index)) {
        index++;
        base = 16;
    }

    return Integer.parseInt(nm.substring(index), base) * sign;
}

From source file:Main.java

/**
 * Generate a SpannableString that styles a specific sub-sequence of a CharSequence object.
 *
 * @param sequence    The original text.
 * @param subSequence A sub-sequence of the original text.
 * @param styleSpan   The style to be applied to the sub-sequence.
 * @return A SpannableString with the style applied to only the sub-sequence of the original
 * text./*from w ww .j  a v  a2  s  .  c  o m*/
 */
public static SpannableString spanSubstring(CharSequence sequence, CharSequence subSequence,
        StyleSpan styleSpan) {
    SpannableString spannableString = new SpannableString(sequence);
    int startIndex = spannableString.toString().indexOf(subSequence.toString());
    int endIndex = startIndex + subSequence.toString().length();
    spannableString.setSpan(styleSpan, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}

From source file:Main.java

public static int indexOfIgnoreCase(final CharSequence[] array, final CharSequence value) {
    final int length = array.length;
    for (int i = 0; i < length; i++) {
        final CharSequence item = array[i];
        if (item == null && value == null)
            return i;
        if (item != null && value != null && item.toString().equalsIgnoreCase(value.toString()))
            return i;
    }//from   www .j a  v  a 2s  . c o  m
    return -1;
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * Gets image.//from   www.  j  av  a2 s  .c  o m
 *
 * @param file the file
 * @return the image
 */
public static BufferedImage getImage(final CharSequence file) {
    if (file.toString().startsWith("http")) {
        try {
            BufferedImage read = ImageIO.read(new URL(file.toString()));
            assert null != read;
            return read;
        } catch (Throwable e) {
            throw new RuntimeException("Error reading " + file, e);
        }
    }
    FileSystem fileSystem = getFileSystem(file.toString());
    Path path = new Path(file.toString());
    try {
        if (!fileSystem.exists(path))
            throw new IllegalArgumentException("Not Found: " + path);
        try (FSDataInputStream open = fileSystem.open(path)) {
            return ImageIO.read(open);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:cc.kave.commons.utils.json.legacy.GsonUtil.java

public static <T> T deserialize(final CharSequence json, final Type classOfT) {
    return deserialize(json.toString(), classOfT);
}

From source file:Main.java

/**
 * utility to get the part of a charsequence that is not the NCName
 * fragment./* w w  w .jav  a 2s  . c om*/
 * 
 * @param s
 *        the charsequence to split
 * @return the prefix split at the last non-ncname character, or the whole
 *         input if no ncname is found
 */
public static String getNCNamePrefix(CharSequence s) {
    if (s.length() > 1 && s.charAt(0) == '_' && s.charAt(1) == ':') {
        return s.toString();
    }
    int localPartStartIndex = getNCNameSuffixIndex(s);
    if (localPartStartIndex > -1) {
        return s.toString().substring(0, localPartStartIndex);
    } else {
        return s.toString();
    }
}

From source file:Main.java

/**
 * Indicates if the passed node has a child node of the passed name 
 * @param element The node to inspect//from  w w  w  .  j  a  va  2s.c  om
 * @param nodeName The name of the child node to look for
 * @param caseSensitive true for a case sensitive node, false for case insensitive
 * @return true if the named child node exists, false otherwise
 */
public static boolean hasChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive) {
    if (element == null)
        return false;
    if (nodeName == null)
        return false;
    final String name = nodeName.toString().trim();
    if (name.isEmpty())
        return false;
    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 true;
        } else {
            if (node.getNodeName().equalsIgnoreCase(name))
                return true;
        }
    }
    return false;
}