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:io.coala.guice.config.ConfigMembersInjector.java

@Override
public void injectMembers(final T instance) {
    final InjectConfig injectConfigAnnotation = field.getAnnotation(InjectConfig.class);
    final String configurationParameterName = injectConfigAnnotation.name();
    try {/*from w  ww  . j  a v  a2 s.c om*/
        final Class<?> type = this.field.getType();
        if (type == Integer.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setInt(instance, this.configuration.getInt(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setInt(instance, injectConfigAnnotation.defaultIntValue());
            }
        } else if (type == Boolean.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setBoolean(instance, this.configuration.getBoolean(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue());
            }

        } else if (type == Short.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setShort(instance, this.configuration.getShort(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setShort(instance, injectConfigAnnotation.defaultShortValue());
            }
        } else if (type == Byte.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setByte(instance, this.configuration.getByte(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setByte(instance, injectConfigAnnotation.defaultByteValue());
            }
        } else if (type == Long.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setLong(instance, this.configuration.getLong(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setLong(instance, injectConfigAnnotation.defaultLongValue());
            }
        } else if (type == Float.TYPE) {
            if (this.configuration.containsKey(configurationParameterName)) {
                this.field.setFloat(instance, this.configuration.getFloat(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setFloat(instance, injectConfigAnnotation.defaultFloatValue());
            }
        } else if (type == Double.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setDouble(instance, this.configuration.getDouble(configurationParameterName));
            } else {
                LOG.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                this.field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue());
            }
        } else if (type == Character.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                this.field.setChar(instance,
                        this.configuration.getString(configurationParameterName).charAt(0));
            }
        } else {
            final Object property = getProperty(configurationParameterName, injectConfigAnnotation);
            this.field.set(instance, property);
        }
    } catch (final Throwable ex) {
        LOG.error("Problem injecting configuration", ex);
    }
}

From source file:org.mycore.frontend.cli.MCRCommand.java

/**
 * Creates a new MCRCommand./*  ww w  . j a  v a  2  s .  c o m*/
 * 
 * @param format
 *            the command syntax, e.g. "save document {0} to directory {1}"
 * @param methodSignature
 *            the method to invoke, e.g. "miless.commandline.DocumentCommands.saveDoc int String"
 * @param helpText
 *            the helpt text for this command
 */
public MCRCommand(String format, String methodSignature, String helpText) {
    StringTokenizer st = new StringTokenizer(methodSignature, " ");

    String token = st.nextToken();
    int point = token.lastIndexOf(".");

    className = token.substring(0, point);
    methodName = token.substring(point + 1);
    int numParameters = st.countTokens();
    parameterTypes = new Class<?>[numParameters];
    messageFormat = new MessageFormat(format, Locale.ROOT);

    for (int i = 0; i < numParameters; i++) {
        token = st.nextToken();

        Format f = null;
        switch (token) {
        case "int":
            parameterTypes[i] = Integer.TYPE;
            f = NumberFormat.getIntegerInstance(Locale.ROOT);
            break;
        case "long":
            parameterTypes[i] = Long.TYPE;
            f = NumberFormat.getIntegerInstance(Locale.ROOT);
            break;
        case "String":
            parameterTypes[i] = String.class;
            break;
        default:
            unsupportedArgException(methodSignature, token);
        }
        messageFormat.setFormat(i, f);
    }

    int pos = format.indexOf("{");
    suffix = pos == -1 ? format : format.substring(0, pos);

    if (helpText != null) {
        help = helpText;
    } else {
        help = "No help text available for this command";
    }
}

From source file:org.spring4gwt.server.RpcHelper.java

private static String printTypeName(Class<?> type) {
    // Primitives
    ////  w ww . j av a 2 s. c o m
    if (type.equals(Integer.TYPE)) {
        return "int";
    } else if (type.equals(Long.TYPE)) {
        return "long";
    } else if (type.equals(Short.TYPE)) {
        return "short";
    } else if (type.equals(Byte.TYPE)) {
        return "byte";
    } else if (type.equals(Character.TYPE)) {
        return "char";
    } else if (type.equals(Boolean.TYPE)) {
        return "boolean";
    } else if (type.equals(Float.TYPE)) {
        return "float";
    } else if (type.equals(Double.TYPE)) {
        return "double";
    }

    // Arrays
    //
    if (type.isArray()) {
        Class<?> componentType = type.getComponentType();
        return printTypeName(componentType) + "[]";
    }

    // Everything else
    //
    return type.getName().replace('$', '.');
}

From source file:org.pentaho.ui.xul.binding.BindingUtil.java

private static Class getObjectClassOrType(Object o) {
    if (o instanceof Boolean) {
        return Boolean.TYPE;
    } else 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 Short) {
        return Short.TYPE;
    } else if (o instanceof Long) {
        return Long.TYPE;
    } else {//www. j  av  a2  s  .co  m
        return o.getClass();
    }
}

From source file:org.apache.hadoop.yarn.factories.impl.pb.RpcServerFactoryPBImpl.java

@Override
public Server getServer(Class<?> protocol, Object instance, InetSocketAddress addr, Configuration conf,
        SecretManager<? extends TokenIdentifier> secretManager, int numHandlers, String portRangeConfig) {

    Constructor<?> constructor = serviceCache.get(protocol);
    if (constructor == null) {
        Class<?> pbServiceImplClazz = null;
        try {/*  www  . j  a  va  2s .c o  m*/
            pbServiceImplClazz = localConf.getClassByName(getPbServiceImplClassName(protocol));
        } catch (ClassNotFoundException e) {
            throw new YarnRuntimeException(
                    "Failed to load class: [" + getPbServiceImplClassName(protocol) + "]", e);
        }
        try {
            constructor = pbServiceImplClazz.getConstructor(protocol);
            constructor.setAccessible(true);
            serviceCache.putIfAbsent(protocol, constructor);
        } catch (NoSuchMethodException e) {
            throw new YarnRuntimeException("Could not find constructor with params: " + Long.TYPE + ", "
                    + InetSocketAddress.class + ", " + Configuration.class, e);
        }
    }

    Object service = null;
    try {
        service = constructor.newInstance(instance);
    } catch (InvocationTargetException e) {
        throw new YarnRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new YarnRuntimeException(e);
    } catch (InstantiationException e) {
        throw new YarnRuntimeException(e);
    }

    Class<?> pbProtocol = service.getClass().getInterfaces()[0];
    Method method = protoCache.get(protocol);
    if (method == null) {
        Class<?> protoClazz = null;
        try {
            protoClazz = localConf.getClassByName(getProtoClassName(protocol));
        } catch (ClassNotFoundException e) {
            throw new YarnRuntimeException("Failed to load class: [" + getProtoClassName(protocol) + "]", e);
        }
        try {
            method = protoClazz.getMethod("newReflectiveBlockingService", pbProtocol.getInterfaces()[0]);
            method.setAccessible(true);
            protoCache.putIfAbsent(protocol, method);
        } catch (NoSuchMethodException e) {
            throw new YarnRuntimeException(e);
        }
    }

    try {
        return createServer(pbProtocol, addr, conf, secretManager, numHandlers,
                (BlockingService) method.invoke(null, service), portRangeConfig);
    } catch (InvocationTargetException e) {
        throw new YarnRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new YarnRuntimeException(e);
    } catch (IOException e) {
        throw new YarnRuntimeException(e);
    }
}

From source file:org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogWriter.java

@Override
public void init(FileSystem fs, Path path, Configuration conf, boolean overwritable) throws IOException {
    super.init(fs, path, conf, overwritable);
    boolean compress = initializeCompressionContext(conf, path);
    // Create a SF.Writer instance.
    try {//  w ww  .  j a v  a2s  .c  om
        // reflection for a version of SequenceFile.createWriter that doesn't
        // automatically create the parent directory (see HBASE-2312)
        this.writer = (SequenceFile.Writer) SequenceFile.class
                .getMethod("createWriter",
                        new Class[] { FileSystem.class, Configuration.class, Path.class, Class.class,
                                Class.class, Integer.TYPE, Short.TYPE, Long.TYPE, Boolean.TYPE,
                                CompressionType.class, CompressionCodec.class, Metadata.class })
                .invoke(null,
                        new Object[] { fs, conf, path, HLogKey.class, WALEdit.class,
                                Integer.valueOf(FSUtils.getDefaultBufferSize(fs)),
                                Short.valueOf((short) conf.getInt("hbase.regionserver.hlog.replication",
                                        FSUtils.getDefaultReplication(fs, path))),
                                Long.valueOf(conf.getLong("hbase.regionserver.hlog.blocksize",
                                        FSUtils.getDefaultBlockSize(fs, path))),
                                Boolean.valueOf(false) /*createParent*/, SequenceFile.CompressionType.NONE,
                                new DefaultCodec(), createMetadata(conf, compress) });
    } catch (InvocationTargetException ite) {
        // function was properly called, but threw it's own exception
        throw new IOException(ite.getCause());
    } catch (Exception e) {
        // ignore all other exceptions. related to reflection failure
    }

    // if reflection failed, use the old createWriter
    if (this.writer == null) {
        LOG.debug("new createWriter -- HADOOP-6840 -- not available");
        this.writer = SequenceFile.createWriter(fs, conf, path, HLogKey.class, WALEdit.class,
                FSUtils.getDefaultBufferSize(fs),
                (short) conf.getInt("hbase.regionserver.hlog.replication",
                        FSUtils.getDefaultReplication(fs, path)),
                conf.getLong("hbase.regionserver.hlog.blocksize", FSUtils.getDefaultBlockSize(fs, path)),
                SequenceFile.CompressionType.NONE, new DefaultCodec(), null, createMetadata(conf, compress));
    } else {
        if (LOG.isTraceEnabled())
            LOG.trace("Using new createWriter -- HADOOP-6840");
    }

    this.writer_out = getSequenceFilePrivateFSDataOutputStreamAccessible();
    if (LOG.isTraceEnabled())
        LOG.trace("Path=" + path + ", compression=" + compress);
}

From source file:org.rhq.core.domain.server.PersistenceUtility.java

@SuppressWarnings("unchecked")
// used in hibernate.jsp
public static Object cast(String value, Type hibernateType) {
    if (hibernateType instanceof PrimitiveType) {
        Class<?> type = ((PrimitiveType) hibernateType).getPrimitiveClass();
        if (type.equals(Byte.TYPE)) {
            return Byte.valueOf(value);
        } else if (type.equals(Short.TYPE)) {
            return Short.valueOf(value);
        } else if (type.equals(Integer.TYPE)) {
            return Integer.valueOf(value);
        } else if (type.equals(Long.TYPE)) {
            return Long.valueOf(value);
        } else if (type.equals(Float.TYPE)) {
            return Float.valueOf(value);
        } else if (type.equals(Double.TYPE)) {
            return Double.valueOf(value);
        } else if (type.equals(Boolean.TYPE)) {
            return Boolean.valueOf(value);
        }/*from ww  w .jav  a  2  s  .  c o  m*/
    } else if (hibernateType instanceof EntityType) {
        String entityName = ((EntityType) hibernateType).getAssociatedEntityName();
        try {
            Class<?> entityClass = Class.forName(entityName);
            Object entity = entityClass.newInstance();

            Field primaryKeyField = entityClass.getDeclaredField("id");
            primaryKeyField.setAccessible(true);
            primaryKeyField.setInt(entity, Integer.valueOf(value));
            return entity;
        } catch (Throwable t) {
            throw new IllegalArgumentException("Type[" + entityName + "] must have PK field named 'id'");
        }
    } else if (hibernateType instanceof CustomType) {
        if (Enum.class.isAssignableFrom(hibernateType.getReturnedClass())) {
            Class<? extends Enum<?>> enumClass = hibernateType.getReturnedClass();
            Enum<?>[] enumValues = enumClass.getEnumConstants();
            try {
                int enumOrdinal = Integer.valueOf(value);
                try {
                    return enumValues[enumOrdinal];
                } catch (ArrayIndexOutOfBoundsException aioobe) {
                    throw new IllegalArgumentException("There is no " + enumClass.getSimpleName()
                            + " enum with ordinal '" + enumOrdinal + "'");
                }
            } catch (NumberFormatException nfe) {
                String ucaseValue = value.toUpperCase();
                for (Enum<?> nextEnum : enumValues) {
                    if (nextEnum.name().toUpperCase().equals(ucaseValue)) {
                        return nextEnum;
                    }
                }
                throw new IllegalArgumentException(
                        "There is no " + enumClass.getSimpleName() + " enum with name '" + value + "'");
            }
        }
    }
    return value;
}

From source file:com.projity.util.ClassUtils.java

/**
 * Given a type, return its default value.  If type is unknown, a new one is constructed
 * @param clazz//  w ww  .  ja  va2 s  . c  o  m
 * @return
 */
public static Object getDefaultValueForType(Class clazz) {
    if (clazz == String.class)
        return defaultString;
    else if (clazz == Double.class || clazz == Double.TYPE)
        return defaultDouble;
    else if (clazz == Integer.class || clazz == Integer.TYPE)
        return defaultInteger;
    else if (clazz == Long.class || clazz == Long.TYPE)
        return defaultLong;
    else if (clazz == Float.class || clazz == Float.TYPE)
        return defaultFloat;
    else if (clazz == Boolean.class)
        return defaultBoolean;
    else if (clazz == Rate.class)
        return defaultRate;
    else {
        try {
            System.out.println("making default for class" + clazz);
            return clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}

From source file:com.opencsv.bean.BeanFieldDate.java

/**
 * Converts the input to/from a date object.
 * <p>This method should work with any type derived from {@link java.util.Date}
 * as long as it has a constructor taking one long that specifies the number
 * of milliseconds since the epoch. The following types are explicitly
 * supported:/*w w w  .  j a  v  a 2  s . com*/
 * <ul><li>java.util.Date</li>
 * <li>java.sql.Date</li>
 * <li>java.sql.Time</li>
 * <li>java.sql.Timestamp</li></ul></p>
 *
 * @param <U> The type to be converted to
 * @param value The string to be converted into a date/time type or vice
 *   versa
 * @param fieldType The class of the destination field
 * @return The object resulting from the conversion
 * @throws CsvDataTypeMismatchException If the conversion fails
 */
private <U> U convertDate(Object value, Class<U> fieldType) throws CsvDataTypeMismatchException {
    U o;

    if (value instanceof String) {
        Date d;
        try {
            d = getFormat().parse((String) value);
            o = fieldType.getConstructor(Long.TYPE).newInstance(d.getTime());
        }
        // I would have prefered a CsvBeanIntrospectionException, but that
        // would have broken backward compatibility. This is not completely
        // illogical: I know all of the data types I expect here, and they
        // should all be instantiated with no problems. Ergo, this must be
        // the wrong data type.
        // Multi-catch in Java 7
        catch (ParseException e) {
            CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, fieldType);
            csve.initCause(e);
            throw csve;
        } catch (InstantiationException e) {
            CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, fieldType);
            csve.initCause(e);
            throw csve;
        } catch (IllegalAccessException e) {
            CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, fieldType);
            csve.initCause(e);
            throw csve;
        } catch (NoSuchMethodException e) {
            CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, fieldType);
            csve.initCause(e);
            throw csve;
        } catch (InvocationTargetException e) {
            CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, fieldType);
            csve.initCause(e);
            throw csve;
        }
    } else if (Date.class.isAssignableFrom(value.getClass())) {
        o = fieldType.cast(getFormat().format((Date) value));
    } else {
        throw new CsvDataTypeMismatchException(value, fieldType, NOT_DATE);
    }

    return o;
}

From source file:com.link_intersystems.lang.Conversions.java

/**
 * int to long, float, or double//from  w  ww  .ja va  2  s.  c  o  m
 */
private static boolean isPrimitiveIntegerWidening(Class<?> to) {
    boolean isWidening = isPrimitiveLongWidening(to);

    isWidening |= isIdentity(to, Long.TYPE);

    return isWidening;
}