Example usage for java.lang Long TYPE

List of usage examples for java.lang Long TYPE

Introduction

In this page you can find the example usage for java.lang Long TYPE.

Prototype

Class TYPE

To view the source code for java.lang Long TYPE.

Click Source Link

Document

The Class instance representing the primitive type long .

Usage

From source file:org.fhcrc.cpl.toolbox.AbstractConvertHelper.java

protected void register() {
    _register(new NullSafeConverter(new BigDecimalConverter()), BigDecimal.class);
    _register(new NullSafeConverter(new BigIntegerConverter()), BigInteger.class);
    _register(new NullSafeConverter(new BooleanArrayConverter()), boolean[].class);
    _register(new ByteConverter(), Byte.TYPE);
    _register(new NullSafeConverter(new ByteConverter()), Byte.class);
    _register(new CharacterConverter(), Character.TYPE);
    _register(new NullSafeConverter(new CharacterConverter()), Character.class);
    _register(new NullSafeConverter(new CharacterArrayConverter()), char[].class);
    _register(new NullSafeConverter(new ClassConverter()), Class.class);
    _register(new NullSafeConverter(new DoubleArrayConverter()), double[].class);
    _register(new FloatArrayConverter(), float[].class);
    _register(new NullSafeConverter(new IntegerArrayConverter()), int[].class);
    _register(new LongConverter(), Long.TYPE);
    _register(new NullSafeConverter(new LongConverter()), Long.class);
    _register(new NullSafeConverter(new LongArrayConverter()), long[].class);
    _register(new ShortConverter(), Short.TYPE);
    _register(new NullSafeConverter(new ShortConverter()), Short.class);
    _register(new NullSafeConverter(new ShortArrayConverter()), short[].class);
    _register(new NullSafeConverter(new StringArrayConverter()), String[].class);
    _register(new NullSafeConverter(new SqlDateConverter()), java.sql.Date.class);
    _register(new NullSafeConverter(new SqlTimeConverter()), java.sql.Time.class);
    _register(new NullSafeConverter(new SqlTimestampConverter()), java.sql.Time.class);
}

From source file:org.openamf.util.OpenAMFUtils.java

public static boolean typesMatch(Class parameterType, Object parameter) {
    log.debug("expected class: " + parameterType.getName());
    if (parameter == null) {
        log.debug("parameter is null");
    } else {//from w w  w . j a v  a 2 s .  c  om
        log.debug("parameter class: " + parameter.getClass().getName());
    }
    boolean typesMatch = parameterType.isInstance(parameter);
    if (!typesMatch) {
        if (parameterType.equals(Boolean.TYPE) && parameter instanceof Boolean) {
            typesMatch = true;
        } else if (parameterType.equals(Character.TYPE) && parameter instanceof Character) {
            typesMatch = true;
        } else if (parameterType.equals(Byte.TYPE) && parameter instanceof Byte) {
            typesMatch = true;
        } else if (parameterType.equals(Short.TYPE) && parameter instanceof Short) {
            typesMatch = true;
        } else if (parameterType.equals(Integer.TYPE) && parameter instanceof Integer) {
            typesMatch = true;
        } else if (parameterType.equals(Long.TYPE) && parameter instanceof Long) {
            typesMatch = true;
        } else if (parameterType.equals(Float.TYPE) && parameter instanceof Float) {
            typesMatch = true;
        } else if (parameterType.equals(Double.TYPE) && parameter instanceof Double) {
            typesMatch = true;
        }
    }
    return typesMatch;
}

From source file:com.sf.ddao.ops.InsertAndGetGeneratedKeySqlOperation.java

public boolean execute(Context context) throws Exception {
    try {//from ww  w  .  j  a  va 2  s.c o m
        final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class);
        PreparedStatement preparedStatement = statementFactory.createStatement(context, true);
        Object res = null;
        preparedStatement.executeUpdate();
        ResultSet resultSet = preparedStatement.getGeneratedKeys();
        if (resultSet.next()) {
            if (method.getReturnType() == Integer.TYPE || method.getReturnType() == Integer.class) {
                res = resultSet.getInt(1);
            } else if (method.getReturnType() == Long.TYPE || method.getReturnType() == Long.class) {
                res = resultSet.getLong(1);
            } else if (method.getReturnType() == BigDecimal.class) {
                res = resultSet.getBigDecimal(1);
            }
        }
        resultSet.close();
        preparedStatement.close();
        callCtx.setLastReturn(res);
        return CONTINUE_PROCESSING;
    } catch (Exception t) {
        throw new DaoException("Failed to execute sql operation for " + method, t);
    }
}

From source file:Main.java

private static boolean isAssignableFrom(Class<?> parameterType, Object value) {
    if (parameterType.isPrimitive()) {
        if (value == null) {
            return false;
        }/*from ww  w.  j a  v a  2s . c o m*/
        Class<?> valueClass = value.getClass();

        if (parameterType == Boolean.TYPE) {
            return valueClass == Boolean.class;
        } else if (parameterType == Byte.TYPE) {
            return valueClass == Byte.class;
        } else if (parameterType == Character.TYPE) {
            return valueClass == Character.class;
        } else if (parameterType == Short.TYPE) {
            return valueClass == Short.class || valueClass == Byte.class;
        } else if (parameterType == Integer.TYPE) {
            return valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class
                    || valueClass == Byte.class;
        } else if (parameterType == Long.TYPE) {
            return valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class
                    || valueClass == Short.class || valueClass == Byte.class;
        } else if (parameterType == Float.TYPE) {
            return valueClass == Float.class || valueClass == Long.class || valueClass == Integer.class
                    || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class;
        } else if (parameterType == Double.TYPE) {
            return valueClass == Double.class || valueClass == Float.class || valueClass == Long.class
                    || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class
                    || valueClass == Byte.class;
        } else {
            return false;
        }
    } else {
        return value == null || parameterType.isAssignableFrom(value.getClass());
    }
}

From source file:org.apache.lens.ml.AlgoArgParser.java

/**
 * Extracts feature names. If the algo has any parameters associated with @AlgoParam annotation, those are set
 * as well./* w  ww.j  a  v a 2s.  c o m*/
 *
 * @param algo the algo
 * @param args    the args
 * @return List of feature column names.
 */
public static List<String> parseArgs(MLAlgo algo, String[] args) {
    List<String> featureColumns = new ArrayList<String>();
    Class<? extends MLAlgo> algoClass = algo.getClass();
    // Get param fields
    Map<String, Field> fieldMap = new HashMap<String, Field>();

    for (Field fld : algoClass.getDeclaredFields()) {
        fld.setAccessible(true);
        AlgoParam paramAnnotation = fld.getAnnotation(AlgoParam.class);
        if (paramAnnotation != null) {
            fieldMap.put(paramAnnotation.name(), fld);
        }
    }

    for (int i = 0; i < args.length; i += 2) {
        String key = args[i].trim();
        String value = args[i + 1].trim();

        try {
            if ("feature".equalsIgnoreCase(key)) {
                featureColumns.add(value);
            } else if (fieldMap.containsKey(key)) {
                Field f = fieldMap.get(key);
                if (String.class.equals(f.getType())) {
                    f.set(algo, value);
                } else if (Integer.TYPE.equals(f.getType())) {
                    f.setInt(algo, Integer.parseInt(value));
                } else if (Double.TYPE.equals(f.getType())) {
                    f.setDouble(algo, Double.parseDouble(value));
                } else if (Long.TYPE.equals(f.getType())) {
                    f.setLong(algo, Long.parseLong(value));
                } else {
                    // check if the algo provides a deserializer for this param
                    String customParserClass = algo.getConf().getProperties().get("lens.ml.args." + key);
                    if (customParserClass != null) {
                        Class<? extends CustomArgParser<?>> clz = (Class<? extends CustomArgParser<?>>) Class
                                .forName(customParserClass);
                        CustomArgParser<?> parser = clz.newInstance();
                        f.set(algo, parser.parse(value));
                    } else {
                        LOG.warn("Ignored param " + key + "=" + value + " as no parser found");
                    }
                }
            }
        } catch (Exception exc) {
            LOG.error("Error while setting param " + key + " to " + value + " for algo " + algo);
        }
    }
    return featureColumns;
}

From source file:com.textuality.lifesaver2.Columns.java

public Columns(Context context, String[] names, Class<?>[] classes, String key1, String key2) {
    this.mNames = names;
    mTypes = new Type[names.length];
    mKey1 = key1;//ww  w. j  av a 2 s. c  o  m
    mKey2 = key2;
    mNameFinder = new NameFinder(context);
    for (int i = 0; i < names.length; i++) {

        if (classes[i] == String.class)
            mTypes[i] = Type.STRING;
        else if (classes[i] == Integer.TYPE || classes[i] == Integer.class)
            mTypes[i] = Type.INT;
        else if (classes[i] == Long.TYPE || classes[i] == Long.class)
            mTypes[i] = Type.LONG;
        else if (classes[i] == Float.TYPE || classes[i] == Float.class)
            mTypes[i] = Type.FLOAT;
        else if (classes[i] == Double.TYPE || classes[i] == Double.class)
            mTypes[i] = Type.DOUBLE;
    }
}

From source file:io.github.benas.jpopulator.impl.DefaultRandomizer.java

/**
 * Generate a random value for the given type.
 *
 * @param type the type for which a random value will be generated
 * @return a random value for the given type or null if the type is not supported
 *///w  w w.  ja  va 2  s.c  om
public static Object getRandomValue(final Class type) {

    /*
     * String and Character types
     */
    if (type.equals(String.class)) {
        return RandomStringUtils.randomAlphabetic(ConstantsUtil.DEFAULT_STRING_LENGTH);
    }
    if (type.equals(Character.TYPE) || type.equals(Character.class)) {
        return RandomStringUtils.randomAlphabetic(1).charAt(0);
    }

    /*
     * Boolean type
     */
    if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) {
        return ConstantsUtil.RANDOM.nextBoolean();
    }

    /*
     * Numeric types
     */
    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return (byte) (ConstantsUtil.RANDOM.nextInt());
    }
    if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return (short) (ConstantsUtil.RANDOM.nextInt());
    }
    if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return ConstantsUtil.RANDOM.nextInt();
    }
    if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return ConstantsUtil.RANDOM.nextLong();
    }
    if (type.equals(Double.TYPE) || type.equals(Double.class)) {
        return ConstantsUtil.RANDOM.nextDouble();
    }
    if (type.equals(Float.TYPE) || type.equals(Float.class)) {
        return ConstantsUtil.RANDOM.nextFloat();
    }
    if (type.equals(BigInteger.class)) {
        return new BigInteger(
                Math.abs(ConstantsUtil.RANDOM.nextInt(ConstantsUtil.DEFAULT_BIG_INTEGER_NUM_BITS_LENGTH)),
                ConstantsUtil.RANDOM);
    }
    if (type.equals(BigDecimal.class)) {
        return new BigDecimal(ConstantsUtil.RANDOM.nextDouble());
    }
    if (type.equals(AtomicLong.class)) {
        return new AtomicLong(ConstantsUtil.RANDOM.nextLong());
    }
    if (type.equals(AtomicInteger.class)) {
        return new AtomicInteger(ConstantsUtil.RANDOM.nextInt());
    }

    /*
     * Date and time types
     */
    if (type.equals(java.util.Date.class)) {
        return ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue();
    }
    if (type.equals(java.sql.Date.class)) {
        return new java.sql.Date(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(java.sql.Time.class)) {
        return new java.sql.Time(ConstantsUtil.RANDOM.nextLong());
    }
    if (type.equals(java.sql.Timestamp.class)) {
        return new java.sql.Timestamp(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(Calendar.class)) {
        return Calendar.getInstance();
    }
    if (type.equals(org.joda.time.DateTime.class)) {
        return new org.joda.time.DateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.LocalDate.class)) {
        return new org.joda.time.LocalDate(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.LocalTime.class)) {
        return new org.joda.time.LocalTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.LocalDateTime.class)) {
        return new org.joda.time.LocalDateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
    }
    if (type.equals(org.joda.time.Duration.class)) {
        return new org.joda.time.Duration(Math.abs(ConstantsUtil.RANDOM.nextLong()));
    }
    if (type.equals(org.joda.time.Period.class)) {
        return new org.joda.time.Period(Math.abs(ConstantsUtil.RANDOM.nextInt()));
    }
    if (type.equals(org.joda.time.Interval.class)) {
        long startDate = Math.abs(ConstantsUtil.RANDOM.nextInt());
        long endDate = startDate + Math.abs(ConstantsUtil.RANDOM.nextInt());
        return new org.joda.time.Interval(startDate, endDate);
    }

    /*
     * Enum type
     */
    if (type.isEnum() && type.getEnumConstants().length > 0) {
        Object[] enumConstants = type.getEnumConstants();
        return enumConstants[ConstantsUtil.RANDOM.nextInt(enumConstants.length)];
    }

    /*
     * Return null for any unsupported type
     */
    return null;

}

From source file:org.apache.lens.ml.TrainerArgParser.java

/**
 * Extracts feature names. If the trainer has any parameters associated with @TrainerParam annotation, those are set
 * as well.//from w w w  . j a va 2s  .  co m
 *
 * @param trainer
 *          the trainer
 * @param args
 *          the args
 * @return List of feature column names.
 */
public static List<String> parseArgs(MLTrainer trainer, String[] args) {
    List<String> featureColumns = new ArrayList<String>();
    Class<? extends MLTrainer> trainerClass = trainer.getClass();
    // Get param fields
    Map<String, Field> fieldMap = new HashMap<String, Field>();

    for (Field fld : trainerClass.getDeclaredFields()) {
        fld.setAccessible(true);
        TrainerParam paramAnnotation = fld.getAnnotation(TrainerParam.class);
        if (paramAnnotation != null) {
            fieldMap.put(paramAnnotation.name(), fld);
        }
    }

    for (int i = 0; i < args.length; i += 2) {
        String key = args[i].trim();
        String value = args[i + 1].trim();

        try {
            if ("feature".equalsIgnoreCase(key)) {
                featureColumns.add(value);
            } else if (fieldMap.containsKey(key)) {
                Field f = fieldMap.get(key);
                if (String.class.equals(f.getType())) {
                    f.set(trainer, value);
                } else if (Integer.TYPE.equals(f.getType())) {
                    f.setInt(trainer, Integer.parseInt(value));
                } else if (Double.TYPE.equals(f.getType())) {
                    f.setDouble(trainer, Double.parseDouble(value));
                } else if (Long.TYPE.equals(f.getType())) {
                    f.setLong(trainer, Long.parseLong(value));
                } else {
                    // check if the trainer provides a deserializer for this param
                    String customParserClass = trainer.getConf().getProperties().get("lens.ml.args." + key);
                    if (customParserClass != null) {
                        Class<? extends CustomArgParser<?>> clz = (Class<? extends CustomArgParser<?>>) Class
                                .forName(customParserClass);
                        CustomArgParser<?> parser = clz.newInstance();
                        f.set(trainer, parser.parse(value));
                    } else {
                        LOG.warn("Ignored param " + key + "=" + value + " as no parser found");
                    }
                }
            }
        } catch (Exception exc) {
            LOG.error("Error while setting param " + key + " to " + value + " for trainer " + trainer);
        }
    }
    return featureColumns;
}

From source file:loon.LGame.java

private static Class<?> getType(Object o) {
    if (o instanceof Integer) {
        return Integer.TYPE;
    } else if (o instanceof Float) {
        return Float.TYPE;
    } else if (o instanceof Double) {
        return Double.TYPE;
    } else if (o instanceof Long) {
        return Long.TYPE;
    } else if (o instanceof Short) {
        return Short.TYPE;
    } else if (o instanceof Short) {
        return Short.TYPE;
    } else if (o instanceof Boolean) {
        return Boolean.TYPE;
    } else {/* w  ww  . ja  v a  2s  .com*/
        return o.getClass();
    }
}

From source file:org.jcommon.com.util.config.ConfigLoader.java

/**
 * //from  w  w  w.  j av a  2s. c o m
 * @param conn
 * @param config
 * @param table{key,value,map,list}
 */
public static void loadConf4db(Connection conn, PreparedStatement ps, BaseConfigMBean config, String[] table) {
    ResultSet rs = null;
    String key_ = table[0];
    String value_ = table[1];
    try {
        rs = ps.executeQuery();

        Class<?> type = null;
        String name;
        String value;
        while (rs.next()) {
            name = rs.getString(key_);
            value = rs.getString(value_);
            java.lang.reflect.Field f = null;
            try {
                f = config.getClass().getDeclaredField(name);
            } catch (java.lang.NoSuchFieldException e) {
                continue;
            }

            if (f != null)
                type = f.getType();
            Object args = null;
            java.lang.reflect.Method m = getMethod(config.getClass(), "set" + name);
            if (m != null && notNull(value) && type != null) {
                if (String.class == type) {
                    args = value;
                } else if (java.lang.Integer.class == type || Integer.TYPE == type) {
                    args = Integer.valueOf(value);
                } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) {
                    args = Boolean.parseBoolean(value);
                } else if (java.lang.Long.class == type || Long.TYPE == type) {
                    args = Long.valueOf(value);
                } else if (java.lang.Float.class == type || Float.TYPE == type) {
                    args = Float.valueOf(value);
                } else {
                    logger.info("not map Class:" + type);
                }
                m.invoke(config, args);
                logger.info(name + ":" + value);
            } else if (notNull(value))
                logger.warn("can't find element:" + value);
        }
    } catch (Exception e) {
        logger.error("load config error:", e);
    } finally {
        try {
            conn.close();
            ps.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            logger.error("load config error:", e);
        }
        conn = null;
    }
}