Example usage for java.lang Character getNumericValue

List of usage examples for java.lang Character getNumericValue

Introduction

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

Prototype

public static int getNumericValue(int codePoint) 

Source Link

Document

Returns the int value that the specified character (Unicode code point) represents.

Usage

From source file:com.maxl.java.aips2sqlite.RealExpertInfo.java

private String calcEAN13Checksum(String ean12_str) {
    // Sum of all uneven digits
    int unevenSum = 0;
    for (int i = 0; i < ean12_str.length(); i += 2) {
        unevenSum += Character.getNumericValue(ean12_str.charAt(i));
    }/*from  w w w . j av a2s.  c  om*/
    // Sum of all even digits
    int evenSum = 0;
    for (int i = 1; i < ean12_str.length(); i += 2) {
        evenSum += Character.getNumericValue(ean12_str.charAt(i));
    }
    // Checksum = 90 - total sum
    String checkSum = String.valueOf(90 - (3 * evenSum + unevenSum));

    return checkSum;
}

From source file:com.swg.parse.docx.NewExtract.java

private void commentHandeler(String comment) {
    isHeader = false;//from  ww w.  j a v a 2 s . c om
    if (comment == "") {
        //do nothing
    } else if (comment.contains("labelException")) {
        TempLab = comment.substring(comment.indexOf(" = ") + 3, comment.indexOf(","));
    } else if (comment.contains("colNum")) {
        for (int i = 0; i < comment.length(); i++) {
            if (comment.charAt(i) == '=' && comment.charAt(i + 1) == ' ' && isDigit(comment.charAt(i + 2))) {
                char c = comment.charAt(i + 2);
                ManualColNum = Character.getNumericValue(c);
            }
        }
    } else if (comment.contains("rowNum")) {
        for (int i = 0; i < comment.length(); i++) {
            if (comment.charAt(i) == '=' && comment.charAt(i + 1) == ' ' && isDigit(comment.charAt(i + 2))) {
                char c = comment.charAt(i + 2);
                ManualRowNum = Character.getNumericValue(c);
            }
        }
    } else if (comment.contains("isHeader")) {
        isHeader = true;
    } else if (comment.contains("TableTitle")) {
        TableTitle = "";
        boolean keepGoing = false;
        for (int i = 0; i < comment.length() - 2; i++) {
            if (comment.charAt(i) == '=' && comment.charAt(i + 1) == ' ' && isLetter(comment.charAt(i + 2))) {
                keepGoing = true;
            }
            if (keepGoing)
                TableTitle = TableTitle + comment.charAt(i + 2);
        }
    }
}

From source file:ca.oson.json.Oson.java

private <E, R> BigDecimal json2BigDecimal(FieldData objectDTO) {
    if (objectDTO == null || !objectDTO.json2Java) {
        return null;
    }/*from   w w  w .ja  v a 2s.com*/

    E value = (E) objectDTO.valueToProcess;
    Class<R> returnType = objectDTO.returnType;

    if (value != null && value.toString().trim().length() > 0) {
        String valueToProcess = value.toString().trim();
        BigDecimal valueToReturn = null;

        try {
            Function function = objectDTO.getDeserializer();

            if (function != null) {
                try {
                    Object returnedValue = null;

                    if (function instanceof Json2DataMapperFunction) {
                        DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                objectDTO.level, getPrettyIndentation());
                        returnedValue = ((Json2DataMapperFunction) function).apply(classData);

                    } else if (function instanceof Json2FieldDataFunction) {
                        Json2FieldDataFunction f = (Json2FieldDataFunction) function;
                        FieldData fieldData = objectDTO.clone();

                        returnedValue = f.apply(fieldData);

                    } else if (function instanceof Json2BigDecimalFunction) {
                        return ((Json2BigDecimalFunction) function).apply(valueToProcess);
                    } else {
                        returnedValue = function.apply(valueToProcess);
                    }

                    if (returnedValue instanceof Optional) {
                        returnedValue = ObjectUtil.unwrap(returnedValue);
                    }

                    if (returnedValue == null) {
                        return null;

                    } else if (Number.class.isAssignableFrom(returnedValue.getClass())
                            || returnedValue.getClass().isPrimitive()) {

                        if (returnedValue instanceof BigDecimal) {
                            valueToReturn = (BigDecimal) returnedValue;
                        } else if (returnedValue instanceof String) {
                            valueToReturn = new BigDecimal((String) returnedValue);

                        } else if (returnedValue instanceof Integer) {
                            valueToReturn = new BigDecimal((Integer) returnedValue);
                        } else if (returnedValue instanceof Long) {
                            valueToReturn = new BigDecimal((Long) returnedValue);
                        } else if (returnedValue instanceof Short) {
                            valueToReturn = new BigDecimal((Short) returnedValue);
                        } else if (returnedValue instanceof Double) {
                            valueToReturn = new BigDecimal((Double) returnedValue);
                        } else if (returnedValue instanceof Float) {
                            valueToReturn = new BigDecimal((Float) returnedValue);
                        } else if (returnedValue instanceof BigInteger) {
                            valueToReturn = new BigDecimal((BigInteger) returnedValue);
                        } else if (returnedValue instanceof Byte) {
                            valueToReturn = new BigDecimal((Byte) returnedValue);
                        } else if (returnedValue instanceof AtomicInteger) {
                            valueToReturn = new BigDecimal(((AtomicInteger) returnedValue).intValue());
                        } else if (returnedValue instanceof AtomicLong) {
                            valueToReturn = new BigDecimal(((AtomicLong) returnedValue).longValue());
                        } else {
                            valueToReturn = new BigDecimal(((Number) returnedValue).doubleValue());
                        }

                    } else if (returnedValue instanceof Character) {
                        char c = (Character) returnedValue;
                        valueToReturn = new BigDecimal(Character.getNumericValue((Character) returnedValue));

                    } else if (returnedValue instanceof Boolean) {
                        if ((Boolean) returnedValue)
                            valueToReturn = new BigDecimal(1);
                        else
                            valueToReturn = new BigDecimal(0);

                    } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = new BigDecimal((Integer) ((Enum) returnedValue).ordinal());

                    } else if (Date.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = new BigDecimal(((Date) returnedValue).getTime());

                    } else {
                        valueToReturn = new BigDecimal((returnedValue.toString()));
                    }

                    return valueToReturn;

                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                valueToReturn = new BigDecimal(valueToProcess);
            }

            if (valueToReturn != null) {
                Long min = objectDTO.getMin();
                Long max = objectDTO.getMax();

                if (min != null && valueToReturn.compareTo(new BigDecimal(min)) < 0) {
                    return new BigDecimal(min);
                }

                if (max != null && valueToReturn.compareTo(new BigDecimal(max)) > 0) {
                    valueToReturn = new BigDecimal(max);
                }

                Integer precision = objectDTO.getPrecision();
                if (precision != null && precision < valueToReturn.precision()) {
                    valueToReturn = (BigDecimal) NumberUtil.setPrecision(valueToReturn, precision,
                            getRoundingMode());
                }

                Integer scale = objectDTO.getScale();
                if (scale != null) {
                    valueToReturn = valueToReturn.setScale(scale, getRoundingMode());
                }

                return valueToReturn;
            }

        } catch (Exception ex) {
            //ex.printStackTrace();
        }

    }

    return json2BigDecimalDefault(objectDTO);
}

From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java

public static boolean matchDay(Calendar cal, String repeat_ptn) { // ??????????
    if (repeat_ptn == null || "".equals(repeat_ptn)) {
        return false;
    }//  ww w .  j  a v a2s. co  m
    if (repeat_ptn.startsWith("M")) {
        int month_day;
        // ?
        if (repeat_ptn.substring(1, 3).equals("XX")) {
            month_day = cal.getActualMaximum(Calendar.DATE);
        } else {
            month_day = Integer.parseInt(repeat_ptn.substring(1, 3));
        }
        int ptn_day = cal.get(Calendar.DAY_OF_MONTH);
        return (month_day == ptn_day);
    }
    if (repeat_ptn.startsWith("Y")) {
        int year_month = Integer.parseInt(repeat_ptn.substring(1, 3));
        int year_day = Integer.parseInt(repeat_ptn.substring(3, 5));
        int ptn_month = cal.get(Calendar.MONTH);
        int ptn_day = cal.get(Calendar.DAY_OF_MONTH);
        return (year_day == ptn_day && (year_month - 1) == ptn_month);
    } else if (repeat_ptn.startsWith("W")) {
        int dow = cal.get(Calendar.DAY_OF_WEEK);
        int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
        if (repeat_ptn.length() == 9 || dowim == Character.getNumericValue(repeat_ptn.charAt(8))) {
            if (dow == Calendar.SUNDAY) {
                return repeat_ptn.matches("W1........?");
            }
            if (dow == Calendar.MONDAY) {
                return repeat_ptn.matches("W.1.......?");
            }
            if (dow == Calendar.TUESDAY) {
                return repeat_ptn.matches("W..1......?");
            }
            if (dow == Calendar.WEDNESDAY) {
                return repeat_ptn.matches("W...1.....?");
            }
            if (dow == Calendar.THURSDAY) {
                return repeat_ptn.matches("W....1....?");
            }
            if (dow == Calendar.FRIDAY) {
                return repeat_ptn.matches("W.....1...?");
            }
            if (dow == Calendar.SATURDAY) {
                return repeat_ptn.matches("W......1..?");
            }
        }
        return false;
    } else {
        return true;
    }
}

From source file:ca.oson.json.Oson.java

private <E, R> Long json2Long(FieldData objectDTO) {
    if (objectDTO == null || !objectDTO.json2Java) {
        return null;
    }//from   w w  w . j  a  v a 2  s  . co  m

    E value = (E) objectDTO.valueToProcess;
    Class<R> returnType = objectDTO.returnType;

    Long valueToReturn = null;

    if (value != null && value.toString().trim().length() > 0) {
        String valueToProcess = value.toString().trim();

        try {
            Function function = objectDTO.getDeserializer();

            if (function != null) {
                try {
                    Object returnedValue = null;

                    if (function instanceof Json2DataMapperFunction) {
                        DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                objectDTO.level, getPrettyIndentation());
                        returnedValue = ((Json2DataMapperFunction) function).apply(classData);

                    } else if (function instanceof Json2FieldDataFunction) {
                        Json2FieldDataFunction f = (Json2FieldDataFunction) function;
                        FieldData fieldData = objectDTO.clone();

                        returnedValue = f.apply(fieldData);

                    } else if (function instanceof Json2LongFunction) {
                        return ((Json2LongFunction) function).apply(valueToProcess);
                    } else {
                        returnedValue = function.apply(valueToProcess);
                    }

                    if (returnedValue instanceof Optional) {
                        returnedValue = ObjectUtil.unwrap(returnedValue);
                    }

                    if (returnedValue == null) {
                        return null;

                        //  || returnedValue.getClass().isPrimitive()
                    } else if (Number.class.isAssignableFrom(returnedValue.getClass())) {

                        if (returnedValue instanceof Long) {
                            valueToReturn = (Long) returnedValue;

                        } else if (returnedValue instanceof String) {
                            valueToReturn = Long
                                    .parseLong(NumberUtil.removeTrailingDecimalZeros(returnedValue));
                            //  byte, double, float, int, long, and short.
                        } else if (returnedValue instanceof Integer) {
                            valueToReturn = ((Integer) returnedValue).longValue();
                        } else if (returnedValue instanceof Double) {
                            valueToReturn = ((Double) returnedValue).longValue();
                        } else if (returnedValue instanceof Float) {
                            valueToReturn = ((Float) returnedValue).longValue();
                        } else if (returnedValue instanceof Byte) {
                            valueToReturn = ((Byte) returnedValue).longValue();
                        } else if (returnedValue instanceof Short) {
                            valueToReturn = ((Short) returnedValue).longValue();
                        } else if (returnedValue instanceof BigInteger) {
                            valueToReturn = ((BigInteger) returnedValue).longValue();
                        } else if (returnedValue instanceof BigDecimal) {
                            valueToReturn = ((BigDecimal) returnedValue).longValue();
                        } else if (returnedValue instanceof AtomicInteger) {
                            valueToReturn = ((AtomicInteger) returnedValue).longValue();
                        } else if (returnedValue instanceof AtomicLong) {
                            valueToReturn = ((AtomicLong) returnedValue).longValue();
                        } else {
                            valueToReturn = ((Number) returnedValue).longValue();
                        }

                    } else if (returnedValue instanceof Character) {
                        valueToReturn = Long.valueOf((Character.getNumericValue((Character) returnedValue)));

                    } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = Long.valueOf(((Enum) returnedValue).ordinal());

                    } else if (returnedValue instanceof Boolean) {
                        if ((Boolean) returnedValue)
                            valueToReturn = 1l;
                        else
                            valueToReturn = 0l;

                    } else if (Date.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = ((Date) returnedValue).getTime();

                    } else {
                        valueToReturn = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(returnedValue));
                    }

                    return valueToReturn;

                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                valueToReturn = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(valueToProcess));
            }

            if (valueToReturn != null) {
                Long min = objectDTO.getMin();
                Long max = objectDTO.getMax();
                if (min != null && min > valueToReturn.longValue()) {
                    return min.longValue();
                }

                if (max != null && valueToReturn.compareTo(Long.valueOf(max)) > 0) {
                    valueToReturn = Long.valueOf(max);
                }

                return valueToReturn;
            }

        } catch (Exception ex) {
            //ex.printStackTrace();
        }

    }

    return json2LongDefault(objectDTO);
}

From source file:ca.oson.json.Oson.java

private <E, R> R json2Integer(FieldData objectDTO) {
    if (objectDTO == null || !objectDTO.json2Java) {
        return null;
    }/*w  w  w . j ava 2  s.c om*/

    E value = (E) objectDTO.valueToProcess;
    Class<R> returnType = objectDTO.returnType;

    if (value != null && value.toString().trim().length() > 0) {
        String valueToProcess = value.toString().trim();
        Integer valueToReturn = null;

        try {
            Function function = objectDTO.getDeserializer();

            if (function != null) {
                try {
                    Object returnedValue = null;

                    if (function instanceof Json2DataMapperFunction) {
                        DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                objectDTO.level, getPrettyIndentation());
                        returnedValue = ((Json2DataMapperFunction) function).apply(classData);

                    } else if (function instanceof Json2FieldDataFunction) {
                        Json2FieldDataFunction f = (Json2FieldDataFunction) function;
                        FieldData fieldData = objectDTO.clone();

                        returnedValue = f.apply(fieldData);

                    } else if (function instanceof Json2IntegerFunction) {
                        return (R) ((Json2IntegerFunction) function).apply(valueToProcess);
                    } else {
                        returnedValue = function.apply(valueToProcess);
                    }

                    if (returnedValue instanceof Optional) {
                        returnedValue = ObjectUtil.unwrap(returnedValue);
                    }

                    if (returnedValue == null) {
                        return null;

                    } else if (Number.class.isAssignableFrom(returnedValue.getClass())
                            || returnedValue.getClass().isPrimitive()) {

                        if (returnedValue instanceof Integer) {
                            valueToReturn = (Integer) returnedValue;
                        } else if (returnedValue instanceof String) {
                            valueToReturn = Integer
                                    .parseInt(NumberUtil.removeTrailingDecimalZeros(returnedValue));
                            //  byte, double, float, int, long, and short.
                        } else if (returnedValue instanceof Long) {
                            valueToReturn = ((Long) returnedValue).intValue();
                        } else if (returnedValue instanceof Byte) {
                            valueToReturn = ((Byte) returnedValue).intValue();
                        } else if (returnedValue instanceof Short) {
                            valueToReturn = ((Short) returnedValue).intValue();
                        } else if (returnedValue instanceof Float) {
                            valueToReturn = ((Float) returnedValue).intValue();
                        } else if (returnedValue instanceof Double) {
                            valueToReturn = ((Double) returnedValue).intValue();
                        } else if (returnedValue instanceof BigInteger) {
                            valueToReturn = ((BigInteger) returnedValue).intValue();
                        } else if (returnedValue instanceof BigDecimal) {
                            valueToReturn = ((BigDecimal) returnedValue).intValue();
                        } else if (returnedValue instanceof AtomicInteger) {
                            valueToReturn = ((AtomicInteger) returnedValue).intValue();
                        } else if (returnedValue instanceof AtomicLong) {
                            valueToReturn = ((AtomicLong) returnedValue).intValue();
                        } else {
                            valueToReturn = ((Number) returnedValue).intValue();
                        }

                    } else if (returnedValue instanceof Character) {
                        valueToReturn = Character.getNumericValue((Character) returnedValue);

                    } else if (returnedValue instanceof Boolean) {
                        if ((Boolean) returnedValue)
                            valueToReturn = 1;
                        else
                            valueToReturn = 0;

                    } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = ((Enum) returnedValue).ordinal();

                    } else if (Date.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = (int) ((Date) returnedValue).getTime();

                    } else {
                        valueToReturn = Integer.parseInt(NumberUtil.removeTrailingDecimalZeros(returnedValue));
                    }

                    return (R) valueToReturn;

                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                valueToReturn = Integer.parseInt(NumberUtil.removeTrailingDecimalZeros(valueToProcess));
            }

            if (valueToReturn != null) {
                Long min = objectDTO.getMin();
                Long max = objectDTO.getMax();
                if (min != null && min > valueToReturn.longValue()) {
                    return (R) (Integer) min.intValue();
                }

                if (max != null && valueToReturn.longValue() > max) {
                    valueToReturn = Integer.valueOf(max.intValue());
                }

                return (R) valueToReturn;
            }

        } catch (Exception ex) {
            //ex.printStackTrace();
        }

    }

    return json2IntegerDefault(objectDTO);
}