List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:com.github.dozermapper.core.converters.EnumConverter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public Object convert(Class destClass, Object srcObj) { if (null == srcObj) { MappingUtils.throwMappingException("Cannot convert null to enum of type " + destClass); }//w w w . ja va 2s. co m try { if ((srcObj.getClass().equals(Byte.class)) || (srcObj.getClass().equals(Byte.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Byte) srcObj).intValue()); } else if ((srcObj.getClass().equals(Short.class)) || (srcObj.getClass().equals(Short.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Short) srcObj).intValue()); } else if ((srcObj.getClass().equals(Integer.class)) || (srcObj.getClass().equals(Integer.TYPE))) { return EnumUtils.getEnumList(destClass).get((Integer) srcObj); } else if ((srcObj.getClass().equals(Long.class)) || (srcObj.getClass().equals(Long.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Long) srcObj).intValue()); } else { return Enum.valueOf(destClass, srcObj.toString()); } } catch (Exception e) { MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to enum of type " + destClass, e); } return srcObj; }
From source file:Main.java
/** * This method converts a given number into a target class. This method does not change the value (except when * explicitly casting to a more general type, e.g. from double to int), just the internal type representation. While * this is unnecessary while using normal java code, reflection based access to method parameters is a bit more * difficult. As far as possible, this method will prevent the ArgumentMismatch error when passing numbers as * parameters.//from w ww .ja v a 2 s . c o m * <p/> * If the value can not be converted to the given target class, it will be returned unchanged. * * @param targetClass Class to which the number should be converted, if possible. * @param value Number value to convert. * @return 'value' converted to an instance of 'targetClass'. */ public static Object convertNumber(final Class targetClass, final Number value) { if (targetClass.equals(Double.class) || targetClass.equals(Double.TYPE)) return value.doubleValue(); if (targetClass.equals(Integer.class) || targetClass.equals(Integer.TYPE)) return value.intValue(); if (targetClass.equals(Long.class) || targetClass.equals(Long.TYPE)) return value.longValue(); if (targetClass.equals(Short.class) || targetClass.equals(Short.TYPE)) return value.shortValue(); if (targetClass.equals(Byte.class) || targetClass.equals(Byte.TYPE)) return value.byteValue(); if (targetClass.equals(Character.class) || targetClass.equals(Character.TYPE)) return value.intValue(); if (targetClass.equals(Float.class) || targetClass.equals(Float.TYPE)) return value.floatValue(); return value; }
From source file:org.ralasafe.db.JavaBeanColumnAdapter.java
private void initSetterMethod(Object o) throws Exception { Class valueClass;/*from ww w .ja v a2s . c o m*/ Class clas = o.getClass(); if (className.equals("int")) valueClass = Integer.TYPE; else if (className.equals("float")) valueClass = Float.TYPE; else if (className.equals("long")) valueClass = Long.TYPE; else if (className.equals("double")) valueClass = Double.TYPE; else if (className.equals("boolean")) valueClass = Boolean.TYPE; else valueClass = Class.forName(className); setter = clas.getMethod(setterStr, new Class[] { valueClass }); }
From source file:com.gemstone.gemfire.test.junit.rules.serializable.SerializableTimeoutTest.java
@Test public void fieldTimeoutShouldExist() throws Exception { Field field = Timeout.class.getDeclaredField(FIELD_TIMEOUT); assertThat(field.getType()).isEqualTo(Long.TYPE); }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>// w w w . jav a 2s . c om * * <p>If the input array is <code>null</code>, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1L], 0, 2L) = [2L, 1L] * ArrayUtils.add([2L, 6L], 2, 10L) = [2L, 6L, 10L] * ArrayUtils.add([2L, 6L], 0, -4L) = [-4L, 2L, 6L] * ArrayUtils.add([2L, 6L, 3L], 2, 1L) = [2L, 6L, 1L, 3L] * </pre> * * @param array the array to add the element to, may be <code>null</code> * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static long[] add(long[] array, int index, long element) { return (long[]) add(array, index, new Long(element), Long.TYPE); }
From source file:org.lunarray.model.descriptor.util.PrimitiveUtil.java
/** * Default constructor.//w w w .j a v a2 s . c om */ private PrimitiveUtil() { this.primitivesToClasses = new HashMap<Class<?>, Class<?>>(); this.primitivesToClasses.put(Byte.TYPE, Byte.class); this.primitivesToClasses.put(Integer.TYPE, Integer.class); this.primitivesToClasses.put(Double.TYPE, Double.class); this.primitivesToClasses.put(Float.TYPE, Float.class); this.primitivesToClasses.put(Long.TYPE, Long.class); this.primitivesToClasses.put(Short.TYPE, Short.class); this.primitivesToClasses.put(Character.TYPE, Character.class); this.primitivesToClasses.put(Boolean.TYPE, Boolean.class); }
From source file:com.autonomy.aci.client.annotations.ConversionServiceImpl.java
public ConversionServiceImpl() { registerConverter(new StringToDoubleConverter(), String.class, Double.class); registerConverter(new StringToDoubleConverter(), String.class, Double.TYPE); registerConverter(new StringToByteConverter(), String.class, Byte.class); registerConverter(new StringToByteConverter(), String.class, Byte.TYPE); registerConverter(new StringToIntegerConverter(), String.class, Integer.class); registerConverter(new StringToIntegerConverter(), String.class, Integer.TYPE); registerConverter(new StringToFloatConverter(), String.class, Float.class); registerConverter(new StringToFloatConverter(), String.class, Float.TYPE); registerConverter(new StringToShortConverter(), String.class, Short.class); registerConverter(new StringToShortConverter(), String.class, Short.TYPE); registerConverter(new StringToCharacterConverter(), String.class, Character.class); registerConverter(new StringToCharacterConverter(), String.class, Character.TYPE); registerConverter(new StringToBooleanConverter(), String.class, Boolean.class); registerConverter(new StringToBooleanConverter(), String.class, Boolean.TYPE); registerConverter(new StringToLongConverter(), String.class, Long.class); registerConverter(new StringToLongConverter(), String.class, Long.TYPE); }
From source file:com.csipsimple.backup.Columns.java
public Columns(String[] names, Class<?>[] classes) { this.names = new ArrayList<String>(Arrays.asList(names)); types = new ArrayList<Type>(names.length); for (int i = 0; i < names.length; i++) { if (classes[i] == String.class) { types.add(i, Type.STRING); } else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) { types.add(i, Type.INT); } else if (classes[i] == Long.TYPE || classes[i] == Long.class) { types.add(i, Type.LONG); } else if (classes[i] == Float.TYPE || classes[i] == Float.class) { types.add(i, Type.FLOAT); } else if (classes[i] == Double.TYPE || classes[i] == Double.class) { types.add(i, Type.DOUBLE); } else if (classes[i] == Boolean.TYPE || classes[i] == Boolean.class) { types.add(i, Type.BOOLEAN); }//from ww w . ja v a 2s .c o m } }
From source file:org.kordamp.ezmorph.object.NumberMorpher.java
/** * Creates a new morpher for the target type. * * @param type must be a primitive or wrapper type. BigDecimal and BigInteger * are also supported./*www . j a va2 s .c o m*/ */ public NumberMorpher(Class<?> type) { super(false); if (type == null) { throw new MorphException("Must specify a type"); } if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type) && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type) && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type) && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type) && !BigDecimal.class.isAssignableFrom(type)) { throw new MorphException("Must specify a Number subclass"); } this.type = type; }
From source file:org.exolab.castor.xml.parsing.primitive.objects.PrimitiveObjectFactory.java
private PrimitiveObjectFactory() { typeHandlers.put(String.class, PrimitiveString.class); typeHandlers.put(Enum.class, PrimitiveEnum.class); typeHandlers.put(Integer.TYPE, PrimitiveInteger.class); typeHandlers.put(Integer.class, PrimitiveInteger.class); typeHandlers.put(Boolean.TYPE, PrimitiveBoolean.class); typeHandlers.put(Boolean.class, PrimitiveBoolean.class); typeHandlers.put(Double.TYPE, PrimitiveDouble.class); typeHandlers.put(Double.class, PrimitiveDouble.class); typeHandlers.put(Long.TYPE, PrimitiveLong.class); typeHandlers.put(Long.class, PrimitiveLong.class); typeHandlers.put(Character.TYPE, PrimitiveChar.class); typeHandlers.put(Character.class, PrimitiveChar.class); typeHandlers.put(Short.TYPE, PrimitiveShort.class); typeHandlers.put(Short.class, PrimitiveShort.class); typeHandlers.put(Float.TYPE, PrimitiveFloat.class); typeHandlers.put(Float.class, PrimitiveFloat.class); typeHandlers.put(Byte.TYPE, PrimitiveByte.class); typeHandlers.put(Byte.class, PrimitiveByte.class); typeHandlers.put(BigInteger.class, PrimitiveBigInteger.class); typeHandlers.put(BigDecimal.class, PrimitiveBigDecimal.class); }