Example usage for java.lang Character valueOf

List of usage examples for java.lang Character valueOf

Introduction

In this page you can find the example usage for java.lang Character valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Character valueOf(char c) 

Source Link

Document

Returns a Character instance representing the specified char value.

Usage

From source file:com.fluidops.iwb.api.APIImpl.java

public void setConfigOption(String key, String value) throws Exception {
    Method found = null;/*from   w  ww.j a  v  a  2 s .c  o m*/
    // fbase Config
    for (Method m : Config.class.getMethods()) {
        ConfigDoc cfd = m.getAnnotation(ConfigDoc.class);
        if (cfd != null)
            if (cfd.name().equals(key))
                found = m;
    }

    // check if prop exists
    if (found == null)
        throw new Exception("Config property does not exist: " + key);

    // check type
    if (found.getReturnType().equals(boolean.class))
        Boolean.valueOf(value);
    else if (found.getReturnType().equals(int.class))
        new Integer(value);
    else if (found.getReturnType().equals(long.class))
        new Long(value);
    else if (found.getReturnType().equals(byte.class))
        new Byte(value);
    else if (found.getReturnType().equals(short.class))
        new Short(value);
    else if (found.getReturnType().equals(float.class))
        new Float(value);
    else if (found.getReturnType().equals(double.class))
        new Double(value);
    else if (found.getReturnType().equals(char.class))
        Character.valueOf(value.charAt(0));
    else if (found.getReturnType().equals(Character.class))
        Character.valueOf(value.charAt(0));
    else
        found.getReturnType().getConstructor(String.class).newInstance(value);

    com.fluidops.config.Config.getConfig().set(key, value);
}

From source file:org.droidparts.reflect.util.TypeHelper.java

public static Object parseValue(Class<?> valCls, String valStr) throws IllegalArgumentException {
    if (isByte(valCls)) {
        return Byte.valueOf(valStr);
    } else if (isShort(valCls)) {
        return Short.valueOf(valStr);
    } else if (isInteger(valCls)) {
        return Integer.valueOf(valStr);
    } else if (isLong(valCls)) {
        return Long.valueOf(valStr);
    } else if (isFloat(valCls)) {
        if (valStr.equals("-")) {
            return Float.valueOf("0");
        } else {/*from  ww w  . j ava2 s.  c om*/
            return Float.valueOf(valStr);
        }

    } else if (isDouble(valCls)) {
        return Double.valueOf(valStr);
    } else if (isBoolean(valCls)) {
        return Boolean.valueOf(valStr);
    } else if (isCharacter(valCls)) {
        return Character.valueOf((valStr.length() == 0) ? ' ' : valStr.charAt(0));
    } else if (isString(valCls)) {
        return valStr;
    } else if (isEnum(valCls)) {
        return instantiateEnum(valCls, valStr);
    } else if (isUUID(valCls)) {
        return UUID.fromString(valStr);
    } else if (isDate(valCls)) {
        // fIX: date fixed wort app

        Date dateObj = null;
        try {
            dateObj = SimpleDateFormatFactory.getInstance().getFormatter().parse(String.valueOf(valStr));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dateObj;

    } else if (isJsonObject(valCls) || isJsonArray(valCls)) {
        try {
            return isJsonObject(valCls) ? new JSONObject(valStr) : new JSONArray(valStr);
        } catch (JSONException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        throw new IllegalArgumentException(
                "Unable to convert '" + valStr + "' to " + valCls.getSimpleName() + ".");
    }
}

From source file:com.itemanalysis.psychometrics.statistics.TwoWayTable.java

public double getRowCumPct(char rowValue) {
    return getRowCumPct(Character.valueOf(rowValue));
}

From source file:org.mili.core.properties.Props.java

private static <T> T getValue(String k, Object s, Class<T> c) {
    Validate.notNull(c);//  w ww.ja va  2s . com
    Validate.notEmpty(k);
    if (c == Byte.class) {
        return s == null ? getValue(k, "0", c) : (T) Byte.valueOf(s.toString());
    } else if (c == Boolean.class) {
        return s == null ? getValue(k, "false", c) : (T) Boolean.valueOf(s.toString());
    } else if (c == Short.class) {
        return s == null ? getValue(k, "0", c) : (T) Short.valueOf(s.toString());
    } else if (c == Integer.class) {
        return s == null ? getValue(k, "0", c) : (T) Integer.valueOf(s.toString());
    } else if (c == Float.class) {
        return s == null ? getValue(k, "0", c) : (T) Float.valueOf(s.toString());
    } else if (c == Long.class) {
        return s == null ? getValue(k, "0", c) : (T) Long.valueOf(s.toString());
    } else if (c == Double.class) {
        return s == null ? getValue(k, "0", c) : (T) Double.valueOf(s.toString());
    } else if (c == Character.class) {
        return s == null ? (T) Character.valueOf(' ') : (T) Character.valueOf(s.toString().charAt(0));
    } else if (c == String.class) {
        return s == null ? null : (T) String.valueOf(s);
    } else {
        return (T) s;
        /*
         * throw new IllegalArgumentException("no supported type found[" + c.getName() +
         * "] for property[" + k + "].");
         */
    }

}

From source file:org.openmrs.module.reporting.cohort.definition.util.CohortExpressionParser.java

/**
 * Elements in this list can be: an Integer, indicating a 1-based index into a search history a
 * BooleanOperator (AND, OR, NOT) a CohortDefinition a PatientSearch another List of the same form,
 * which indicates a parenthetical expression
 *///from   w  w  w.  ja  va2 s.c  o m
public static List<Object> parseIntoTokens(String expression) {

    List<Object> tokens = new ArrayList<Object>();
    try {
        StreamTokenizer st = new StreamTokenizer(new StringReader(expression));
        for (Character c : characterWords) {
            st.ordinaryChar(c);
        }
        while (st.nextToken() != StreamTokenizer.TT_EOF) {
            if (st.ttype == StreamTokenizer.TT_NUMBER) {
                Integer thisInt = new Integer((int) st.nval);
                if (thisInt < 1) {
                    log.error("number < 1");
                    return null;
                }
                tokens.add(thisInt);
            } else if (openParenthesesWords.contains(Character.valueOf((char) st.ttype))) {
                tokens.add("(");
            } else if (closeParenthesesWords.contains(Character.valueOf((char) st.ttype))) {
                tokens.add(")");
            } else if (st.ttype == StreamTokenizer.TT_WORD) {
                tokens.add(st.sval);
            }
        }
        return parseIntoTokens(tokens);
    } catch (Exception ex) {
        log.error("Error in description string: " + expression, ex);
        return null;
    }
}

From source file:com.edgenius.wiki.search.service.AbstractSearchService.java

/**
 * //from w  w w . ja v  a2  s  .  com
 * @param keyword
 * @param advance
 * @return 2 elements: first is keyword query with advance query criteria. Last is highlight query.
 * @throws ParseException
 */
private Query[] createQuery(String keyword, String... advance) throws ParseException {

    //default value
    int advKeyword = 0;
    String space = null;
    int srcType = 0;
    long from = 0, to = 0;
    //group by space - need filter out some special type
    boolean groupBySpace = false;
    if (advance != null) {
        //parse all possible type
        for (String str : advance) {
            if (str.length() < 2)
                continue;

            if (str.charAt(0) == SearchService.ADV_KEYWORD_TYPE)
                advKeyword = NumberUtils.toInt(str.substring(1));

            if (str.charAt(0) == SearchService.ADV_SPACE)
                space = str.substring(1);

            if (str.charAt(0) == SearchService.ADV_SOURCE_TYPES)
                srcType = NumberUtils.toInt(str.substring(1));

            if (str.charAt(0) == SearchService.ADV_DATE_SCOPE) {
                String fromStr = str.substring(1);
                int sep = fromStr.indexOf(":");
                if (sep != -1) {
                    from = NumberUtils.toLong(fromStr.substring(0, sep));
                    to = NumberUtils.toLong(fromStr.substring(sep + 1));
                    if (from != 0 && to == 0) {
                        //from: (to is missed)
                        to = new Date().getTime();
                    }
                } else {
                    from = NumberUtils.toLong(fromStr);
                    to = new Date().getTime();
                }
            }

            if (str.charAt(0) == SearchService.ADV_GROUP_BY && NumberUtils
                    .toInt(Character.valueOf(str.charAt(1)).toString()) == SearchService.GROUP_SPACE) {
                groupBySpace = true;
            }

        }
    }

    keyword = QueryParser.escape(StringUtils.trimToEmpty(keyword));
    QueryParser parser = new QueryParser(LuceneConfig.VERSION, FieldName.CONTENT,
            searcherFactory.getAnalyzer());

    if (advKeyword == SearchService.KEYWORD_EXACT)
        keyword = "\"" + keyword + "\"";
    else if (advKeyword == SearchService.KEYWORD_ALL) {
        String[] words = keyword.split(" ");
        StringBuffer buf = new StringBuffer();
        for (String word : words) {
            buf.append("+").append(word).append(" ");
        }
        keyword = buf.toString().trim();
    }

    //highlight query on return result, could be null
    Query hlQuery = null;
    if (keyword.length() > 0) {
        //Lucene throw exception if keyword is empty
        hlQuery = parser.parse(keyword);
    }
    //date scope
    if (from != 0 && to != 0) {
        keyword += " [" + from + " TO " + to + "]";
    }
    Query keyQuery = parser.parse(keyword);

    Query spaceQuery = null;

    //space scope
    if (!StringUtils.isBlank(space)) {
        //as here is not necessary to limit search type: as only page, comment, pageTag, attachment 
        //has UNSEARCH_SPACE_UNIXNAME field, so the search type is already restrict these four types
        spaceQuery = new TermQuery(new Term(FieldName.UNSEARCH_SPACE_UNIXNAME, space.trim().toLowerCase()));
    }

    //type filter
    List<Query> typeQueries = null;
    if (srcType != 0) {
        typeQueries = new ArrayList<Query>();
        TermQuery tq;
        if ((srcType & SearchService.INDEX_PAGE) > 0) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_PAGE + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_SPACE) > 0 && !groupBySpace) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_SPACE + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_COMMENT) > 0) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_COMMENT + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_ROLE) > 0 && !groupBySpace) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_ROLE + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_USER) > 0 && !groupBySpace) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_USER + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_TAGONPAGE) > 0) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_PAGE_TAG + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_TAGONSPACE) > 0 && !groupBySpace) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_SPACE_TAG + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_ATTACHMENT) > 0) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_ATTACHMENT + ""));
            typeQueries.add(tq);
        }
        if ((srcType & SearchService.INDEX_WIDGET) > 0 && !groupBySpace) {
            tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_WIDGET + ""));
            typeQueries.add(tq);
        }
    }

    BooleanQuery query = new BooleanQuery();
    boolean queryIsEmpty = true;
    if (keyQuery != null) {
        queryIsEmpty = false;
        query.add(keyQuery, Occur.MUST);
    }
    if (spaceQuery != null) {
        queryIsEmpty = false;
        query.add(spaceQuery, Occur.MUST);
    }
    if (groupBySpace && (typeQueries == null || typeQueries.size() == 0)) {
        //users don't choose any special type, but sort by space, so it need give limitation on search type
        //so far - page, comment, attachment, tag on page are for Space type
        typeQueries = new ArrayList<Query>();
        TermQuery tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_PAGE + ""));
        typeQueries.add(tq);
        tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_COMMENT + ""));
        typeQueries.add(tq);
        tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_COMMENT + ""));
        typeQueries.add(tq);
        tq = new TermQuery(new Term(FieldName.DOC_TYPE, SharedConstants.SEARCH_PAGE_TAG + ""));
        typeQueries.add(tq);
    }

    if (typeQueries != null && typeQueries.size() > 0) {
        BooleanQuery typeQuery = new BooleanQuery();
        for (Query typeQ : typeQueries) {
            typeQuery.add(typeQ, Occur.SHOULD);
        }
        queryIsEmpty = false;
        query.add(typeQuery, Occur.MUST);
    }

    return new Query[] { queryIsEmpty ? null : query, hlQuery };
}

From source file:Base64.java

/**
 * Decode a Base-64 string into a byte array.
 * /*from w w  w . j  av  a 2s  . c  o  m*/
 * @param b64
 *            The Base-64 encoded string.
 * @return The decoded bytes.
 * @throws java.io.IOException
 *             If the argument is not a valid Base-64 encoding.
 */
public static byte[] decode(String b64) throws IOException {
    ByteArrayOutputStream result = new ByteArrayOutputStream(b64.length() / 3);
    int state = 0, i;
    byte temp = 0;

    for (i = 0; i < b64.length(); i++) {
        if (Character.isWhitespace(b64.charAt(i))) {
            continue;
        }
        if (b64.charAt(i) == BASE_64_PAD) {
            break;
        }

        int pos = BASE_64.indexOf(b64.charAt(i));
        if (pos < 0) {
            throw new IOException("non-Base64 character " + b64.charAt(i));
        }
        switch (state) {
        case 0:
            temp = (byte) (pos - BASE_64.indexOf('A') << 2);
            state = 1;
            break;

        case 1:
            temp |= (byte) (pos - BASE_64.indexOf('A') >>> 4);
            result.write(temp);
            temp = (byte) ((pos - BASE_64.indexOf('A') & 0x0f) << 4);
            state = 2;
            break;

        case 2:
            temp |= (byte) ((pos - BASE_64.indexOf('A') & 0x7f) >>> 2);
            result.write(temp);
            temp = (byte) ((pos - BASE_64.indexOf('A') & 0x03) << 6);
            state = 3;
            break;

        case 3:
            temp |= (byte) (pos - BASE_64.indexOf('A') & 0xff);
            result.write(temp);
            state = 0;
            break;

        default:
            throw new Error("this statement should be unreachable");
        }
    }

    if (i < b64.length() && b64.charAt(i) == BASE_64_PAD) {
        switch (state) {
        case 0:
        case 1:
            throw new IOException("malformed Base64 sequence");

        case 2:
            for (; i < b64.length(); i++) {
                if (!Character.isWhitespace(b64.charAt(i))) {
                    break;
                }
            }
            // We must see a second pad character here.
            if (b64.charAt(i) != BASE_64_PAD) {
                throw new IOException("malformed Base64 sequence");
            }
            i++;
            // Fall-through.

        case 3:
            i++;
            for (; i < b64.length(); i++) {
                // We should only see whitespace after this.
                if (!Character.isWhitespace(b64.charAt(i))) {
                    System.out.println(Character.valueOf(b64.charAt(i)));
                    throw new IOException("malformed Base64 sequence");
                }
            }
        }
    } else {
        if (state != 0) {
            throw new IOException("malformed Base64 sequence");
        }
    }

    return result.toByteArray();
}

From source file:com.itemanalysis.psychometrics.statistics.TwoWayTable.java

public long getColCumFreq(char colValue) {
    return getColCumFreq(Character.valueOf(colValue));
}

From source file:edu.umd.cs.findbugs.util.Strings.java

/**
 * Unescape XML entities and illegal characters in the given string. This
 * enhances the functionality of//from  w ww .  j av  a 2  s  . c  om
 * org.apache.commons.lang.StringEscapeUtils.unescapeXml by unescaping
 * low-valued unprintable characters, which are not permitted by the W3C XML
 * 1.0 specification.
 *
 * @param s
 *            a string
 * @return the same string with XML entities/escape sequences unescaped
 * @see <a href="http://www.w3.org/TR/REC-xml/#charsets">Extensible Markup
 *      Language (XML) 1.0 (Fifth Edition)</a>
 * @see <a
 *      href="http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#unescapeXml(java.lang.String)">org.apache.commons.lang.StringEscapeUtils
 *      javadoc</a>
 */
public static String unescapeXml(String s) {

    initializeEscapeMap();

    /*
     * we can't escape the string if the pattern doesn't compile! (but that
     * should never happen since the pattern is static)
     */
    if (!initializeUnescapePattern()) {
        return s;
    }

    if (s == null || s.length() == 0) {
        return s;
    }

    /*
     * skip this expensive check entirely if there are no substrings
     * resembling Unicode escape sequences in the string to be unescaped
     */
    if (s.contains("\\u")) {
        StringBuffer sUnescaped = new StringBuffer();
        Matcher m = unescapePattern.matcher(s);
        while (m.find() == true) {
            String slashes = m.group(1);
            String digits = m.group(3);
            int escapeCode;
            try {
                escapeCode = Integer.parseInt(digits, 16);
            } catch (NumberFormatException nfe) {
                /*
                 * the static regular expression string should guarantee
                 * that this exception is never thrown
                 */
                System.err.println("Impossible error: escape sequence '" + digits
                        + "' is not a valid hex number!  " + "Exception: " + nfe.toString());
                return s;
            }
            if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) {
                Character escapedSequence = Character.valueOf((char) escapeCode);
                /*
                 * slashes are apparently escaped when the string buffer is
                 * converted to a string, so double them to make sure the
                 * correct number appear in the final representation
                 */
                m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString());
            }
        }
        m.appendTail(sUnescaped);
        s = sUnescaped.toString();
    }
    return StringEscapeUtils.unescapeXml(s);
}

From source file:com.github.gerbsen.math.Frequency.java

/**
 * Returns the percentage of values that are equal to v
 * (as a proportion between 0 and 1).// w  w w . j  a  v  a  2s  .  c o m
 *
 * @param v the value to lookup
 * @return the proportion of values equal to v
 */
public double getPct(char v) {
    return getPct(Character.valueOf(v));
}