List of usage examples for java.lang Short TYPE
Class TYPE
To view the source code for java.lang Short TYPE.
Click Source Link
From source file:org.briljantframework.data.vector.Convert.java
@SuppressWarnings("unchecked") private static <T> T convertLogical(Class<T> cls, Logical log) { if (cls.equals(Double.class) || cls.equals(Double.TYPE)) { return (T) (Double) (log == Logical.TRUE ? 1.0 : 0.0); } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) { return (T) (Float) (log == Logical.TRUE ? 1.0f : 0.0f); } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) { return (T) (Long) (log == Logical.TRUE ? 1l : 0l); } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) { return (T) (Integer) (log == Logical.TRUE ? 1 : 0); } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) { return (T) (Short) (log == Logical.TRUE ? (short) 1 : (short) 0); } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) { return (T) (Byte) (log == Logical.TRUE ? (byte) 1 : (byte) 0); } else if (Complex.class.equals(cls)) { return cls.cast(log == Logical.TRUE ? Complex.ONE : Complex.ZERO); } else if (Boolean.class.equals(cls)) { return cls.cast(log == Logical.TRUE); } else {//w ww .j av a 2 s . c o m return Na.of(cls); } }
From source file:cc.aileron.accessor.TypeConvertorImpl.java
/** * default constractor/*from w w w. j av a 2 s . c om*/ */ @Inject public TypeConvertorImpl() { map.put(Boolean.TYPE, new C() { @Override public Boolean convert(final java.lang.Number number) { return number.intValue() != 0; } }); map.put(Byte.TYPE, new C() { @Override public Byte convert(final java.lang.Number number) { return number.byteValue(); } }); map.put(Short.TYPE, new C() { @Override public Short convert(final java.lang.Number number) { return number.shortValue(); } }); map.put(Integer.TYPE, new C() { @Override public Integer convert(final java.lang.Number number) { return number.intValue(); } }); map.put(Long.TYPE, new C() { @Override public Long convert(final java.lang.Number number) { return number.longValue(); } }); map.put(Float.TYPE, new C() { @Override public Float convert(final java.lang.Number number) { return number.floatValue(); } }); map.put(Double.TYPE, new C() { @Override public Double convert(final java.lang.Number number) { return number.doubleValue(); } }); }
From source file:org.trianacode.taskgraph.tool.ClassLoaders.java
public static Class forName(String className) throws ClassNotFoundException { className = getTextClassName(className); boolean isArray = false; int dims = 0; if (className.endsWith("[]")) { isArray = true;/* w w w .j a v a 2s .c om*/ dims = className.substring(className.indexOf("[]"), className.length()).length() / 2; className = className.substring(0, className.indexOf("[]")); } Class cls; if (className.equals("boolean")) { cls = Boolean.TYPE; } else if (className.equals("char")) { cls = Character.TYPE; } else if (className.equals("byte")) { cls = Byte.TYPE; } else if (className.equals("short")) { cls = Short.TYPE; } else if (className.equals("int")) { cls = Integer.TYPE; } else if (className.equals("long")) { cls = Long.TYPE; } else if (className.equals("float")) { cls = Float.TYPE; } else if (className.equals("double")) { cls = Double.TYPE; } else if (className.equals("void")) { cls = void.class; } else { cls = loadClass(className); } if (isArray) { Object arr = Array.newInstance(cls, new int[dims]); cls = arr.getClass(); } return cls; }
From source file:com.github.michalbednarski.intentslab.Utils.java
public static Object getDefaultValueForPrimitveClass(Class<?> aClass) { if (aClass == Boolean.TYPE) { return false; } else if (aClass == Byte.TYPE) { return (byte) 0; } else if (aClass == Character.TYPE) { return 0; } else if (aClass == Short.TYPE) { return (short) 0; } else if (aClass == Integer.TYPE) { return 0; } else if (aClass == Long.TYPE) { return (long) 0; } else if (aClass == Float.TYPE) { return 0; } else if (aClass == Double.TYPE) { return 0; } else {/*from w ww. java 2s .c o m*/ throw new RuntimeException("Not primitive type"); } }
From source file:com.manydesigns.elements.util.Util.java
public static boolean isNumericType(Class type) { return Number.class.isAssignableFrom(type) || type == Integer.TYPE || type == Byte.TYPE || type == Short.TYPE || type == Long.TYPE || type == Float.TYPE || type == Double.TYPE; }
From source file:org.soybeanMilk.SbmUtils.java
/** * ?<code>type</code>?//from www .j av a 2 s. com * @param type * @return * @date 2010-12-31 */ public static Type wrapType(Type type) { if (!isClassType(type)) return type; else if (!narrowToClass(type).isPrimitive()) return type; else if (Byte.TYPE.equals(type)) return Byte.class; else if (Short.TYPE.equals(type)) return Short.class; else if (Integer.TYPE.equals(type)) return Integer.class; else if (Long.TYPE.equals(type)) return Long.class; else if (Float.TYPE.equals(type)) return Float.class; else if (Double.TYPE.equals(type)) return Double.class; else if (Boolean.TYPE.equals(type)) return Boolean.class; else if (Character.TYPE.equals(type)) return Character.class; else return type; }
From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java
/** * Create and return a <code>DynaClass</code> instance for our test * <code>DynaBean</code>./* ww w. ja va 2 s . c o m*/ */ protected DynaClass createDynaClass() { int intArray[] = new int[0]; String stringArray[] = new String[0]; DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] { new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE), new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE), new DynaProperty("intArray", intArray.getClass()), new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE), new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE), new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class), new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE), new DynaProperty("stringArray", stringArray.getClass()), new DynaProperty("stringIndexed", stringArray.getClass()), new DynaProperty("stringProperty", String.class), }); return (dynaClass); }
From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java
public Object morph(Object value) { if (value != null && type.isAssignableFrom(value.getClass())) { // no conversion needed return value; }/* ww w . java 2s . c o m*/ String str = String.valueOf(value).trim(); if (!type.isPrimitive() && (value == null || str.length() == 0 || "null".equalsIgnoreCase(str))) { // if empty string and class != primitive treat it like null return null; } try { if (isDecimalNumber(type)) { if (Float.class.isAssignableFrom(type) || Float.TYPE == type) { return morphToFloat(str); } else if (Double.class.isAssignableFrom(type) || Double.TYPE == type) { return morphToDouble(str); } else { return morphToBigDecimal(str); } } else { if (Byte.class.isAssignableFrom(type) || Byte.TYPE == type) { return morphToByte(str); } else if (Short.class.isAssignableFrom(type) || Short.TYPE == type) { return morphToShort(str); } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) { return morphToInteger(str); } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) { return morphToLong(str); } else { return morphToBigInteger(str); } } } catch (ConvertErrorException e) { // JsonPropertyConvertContext.setConvertError((ConvertErrorException) e); return null; } }
From source file:io.nuun.plugin.configuration.common.ConfigurationMembersInjector.java
@Override public void injectMembers(T instance) { NuunProperty injectConfigAnnotation = null; // The annotation is actual NuunProperty.class if (clonedAnno.annotationType() == NuunProperty.class) { injectConfigAnnotation = field.getAnnotation(NuunProperty.class); } else { // The annotation has the NuunProperty annotation on it we proxy it injectConfigAnnotation = AssertUtils.annotationProxyOf(NuunProperty.class, clonedAnno); }/*from w w w. ja v a 2 s. co m*/ String configurationParameterName = injectConfigAnnotation.value(); // Pre verification // if (StringUtils.isEmpty(configurationParameterName)) { log.error("Value for annotation {} on field {} can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); throw new PluginException("Value for annotation %s on field %s can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); } if (!configuration.containsKey(configurationParameterName) && injectConfigAnnotation.mandatory()) { throw new PluginException("\"%s\" must be in one properties file for field %s.", configurationParameterName, field.toGenericString()); } try { this.field.setAccessible(true); Class<?> type = field.getType(); if (type == Integer.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setInt(instance, configuration.getInt(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setInt(instance, injectConfigAnnotation.defaultIntValue()); } } else if (type == Integer.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Integer(configuration.getInt(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Integer(injectConfigAnnotation.defaultIntValue())); } } else if (type == Boolean.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setBoolean(instance, configuration.getBoolean(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue()); } } else if (type == Boolean.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Boolean(configuration.getBoolean(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Boolean(injectConfigAnnotation.defaultBooleanValue())); } } else if (type == Short.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setShort(instance, configuration.getShort(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setShort(instance, injectConfigAnnotation.defaultShortValue()); } } else if (type == Short.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Short(configuration.getShort(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Short(injectConfigAnnotation.defaultShortValue())); } } else if (type == Byte.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setByte(instance, configuration.getByte(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setByte(instance, injectConfigAnnotation.defaultByteValue()); } } else if (type == Byte.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Byte(configuration.getByte(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Byte(injectConfigAnnotation.defaultByteValue())); } } else if (type == Long.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setLong(instance, configuration.getLong(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setLong(instance, injectConfigAnnotation.defaultLongValue()); } } else if (type == Long.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Long(configuration.getLong(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Long(injectConfigAnnotation.defaultLongValue())); } } else if (type == Float.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setFloat(instance, configuration.getFloat(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setFloat(instance, injectConfigAnnotation.defaultFloatValue()); } } else if (type == Float.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Float(configuration.getFloat(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Float(injectConfigAnnotation.defaultFloatValue())); } } else if (type == Double.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setDouble(instance, configuration.getDouble(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue()); } } else if (type == Double.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Double(configuration.getDouble(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Double(injectConfigAnnotation.defaultDoubleValue())); } } else if (type == Character.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setChar(instance, configuration.getString(configurationParameterName).charAt(0)); } } else if (type == Character.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Character(configuration.getString(configurationParameterName).charAt(0))); } } else { Object property = getProperty(configurationParameterName, injectConfigAnnotation); field.set(instance, property); } } catch (IllegalArgumentException ex) { log.error("Wrong argument or argument type during configuration injection", ex); } catch (IllegalAccessException ex) { log.error("Illegal access during configuration injection", ex); } catch (InstantiationException ex) { log.error("Impossible to instantiate value converter", ex); } finally { this.field.setAccessible(false); } }
From source file:com.adobe.acs.commons.data.Variant.java
@SuppressWarnings("squid:S3776") public final <T> void setValue(T val) { if (val == null) { return;//from w w w.j a va2 s . co m } Class type = val.getClass(); if (type == Variant.class) { Variant v = (Variant) val; longVal = v.longVal; doubleVal = v.doubleVal; stringVal = v.stringVal; booleanVal = v.booleanVal; dateVal = v.dateVal; } else if (type == Byte.TYPE || type == Byte.class) { setLongVal(((Byte) val).longValue()); } else if (type == Integer.TYPE || type == Integer.class) { setLongVal(((Integer) val).longValue()); } else if (type == Long.TYPE || type == Long.class) { setLongVal((Long) val); } else if (type == Short.TYPE || type == Short.class) { setLongVal(((Short) val).longValue()); } else if (type == Float.TYPE || type == Float.class) { setDoubleVal((Double) val); } else if (type == Double.TYPE || type == Double.class) { setDoubleVal((Double) val); } else if (type == Boolean.TYPE || type == Boolean.class) { setBooleanVal((Boolean) val); } else if (type == String.class) { setStringVal((String) val); } else if (type == Date.class) { setDateVal((Date) val); } else if (type == Instant.class) { setDateVal(new Date(((Instant) val).toEpochMilli())); } else if (type == Calendar.class) { setDateVal(((Calendar) val).getTime()); } else { setStringVal(String.valueOf(val)); } }