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:com.link_intersystems.lang.Conversions.java
/** * <em>java language specification - 5.1.2 Widening Primitive Conversion</em> * ./* w w w.jav a2 s. co m*/ * * <code> * <blockquote>The following 19 specific conversions on primitive types * are called the widening primitive conversions: * <ul> * <li>byte to short, int, long, float, or double</li> * <li>short to int, long, float, or double</li> * <li>char to int, long, float, or double</li> * <li>int to long, float, or double</li> * <li>long to float or double</li> * <li>float to double</li> * </blockquote> * </code> * * @param from * the base type * @param to * the widening type * @return true if from to to is a primitive widening. * @since 1.0.0.0 */ public static boolean isPrimitiveWidening(Class<?> from, Class<?> to) { Assert.isTrue(Primitives.isPrimitive(from), PARAMETER_MUST_BE_A_PRIMITIVE, "form"); Assert.isTrue(Primitives.isPrimitive(to), PARAMETER_MUST_BE_A_PRIMITIVE, "to"); boolean isPrimitiveWidening = false; if (isIdentity(from, Byte.TYPE)) { isPrimitiveWidening = isPrimitiveByteWidening(to); } else if (isIdentity(from, Short.TYPE)) { isPrimitiveWidening = isPrimitiveShortWidening(to); } else if (isIdentity(from, Character.TYPE)) { isPrimitiveWidening = isPrimitiveCharacterWidening(to); } else if (isIdentity(from, Integer.TYPE)) { isPrimitiveWidening = isPrimitiveIntegerWidening(to); } else if (isIdentity(from, Long.TYPE)) { isPrimitiveWidening = isPrimitiveLongWidening(to); } else if (isIdentity(from, Float.TYPE)) { isPrimitiveWidening = isPrimitiveFloatWidening(to); } /* * must be a double - no widening available */ return isPrimitiveWidening; }
From source file:org.wings.template.DefaultPropertyValueConverter.java
/** * Describe <code>convertPropertyValue</code> method here. * * @param value an <code>Object</code> value * @param targetClass a <code>Class</code> value * @return <description>//from w w w. jav a2s . c o m * @throws UnsupportedOperationException if an error occurs * @throws java.lang.UnsupportedOperationException * <description> */ public Object convertPropertyValue(String value, Class targetClass) throws UnsupportedOperationException { if (value == null || "null".equals(value)) { return null; } // end of if () if (targetClass == String.class) { return value; } // end of if () if (targetClass == Boolean.TYPE || targetClass == Boolean.class) { return Boolean.valueOf(value); } if (targetClass == Integer.TYPE || targetClass == Integer.class) { return Integer.valueOf(value); } if (targetClass == Long.TYPE || targetClass == Long.class) { return Long.valueOf(value); } if (targetClass == Short.TYPE || targetClass == Short.class) { return Short.valueOf(value); } if (targetClass == Byte.TYPE || targetClass == Byte.class) { return Byte.valueOf(value); } if (targetClass == Float.TYPE || targetClass == Float.class) { return Float.valueOf(value); } if (targetClass == Double.TYPE || targetClass == Double.class) { return Double.valueOf(value); } if (targetClass == Character.TYPE || targetClass == Character.class) { return new Character(value.charAt(0)); } if (targetClass == StringBuffer.class) { return new StringBuffer(value); } // end of if () if (SIcon.class.isAssignableFrom(targetClass)) { return ResourceFactory.makeIcon(value); } if (targetClass == Color.class) { return ResourceFactory.makeColor(value); } if (targetClass == SDimension.class) { return ResourceFactory.makeDimension(value); } if (targetClass == SFont.class) { return TemplateUtil.parseFont(value); } if (Resource.class.isAssignableFrom(targetClass)) { return new ClassPathResource(value); } if (CSSAttributeSet.class.isAssignableFrom(targetClass)) { return ResourceFactory.makeAttributeSet(value); } if (StyleSheet.class.isAssignableFrom(targetClass)) { StyleSheet result; try { CSSStyleSheet styleSheet = new CSSStyleSheet(); InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(value); styleSheet.read(in); in.close(); result = styleSheet; } catch (Exception e) { log.warn("Exception", e); result = null; } return result; } if (ComponentCG.class.isAssignableFrom(targetClass)) { return ResourceFactory.makeComponentCG(value); } throw new UnsupportedOperationException("cannot create object of type " + targetClass.getName()); }
From source file:org.batoo.common.reflect.ReflectHelper.java
/** * Converts the number into number Type/* w ww . java2 s . com*/ * * @param value * the number value * @param numberType * the number type * @return the converted number value * * @since 2.0.1 */ public static Number convertNumber(Number value, Class<?> numberType) { if (value == null) { return null; } if (numberType.isAssignableFrom(value.getClass())) { return value; } if ((numberType == Integer.class) || (numberType == Integer.TYPE)) { return value.intValue(); } if ((numberType == Long.class) || (numberType == Long.TYPE)) { return value.longValue(); } if ((numberType == Short.class) || (numberType == Short.TYPE)) { return value.shortValue(); } if ((numberType == Byte.class) || (numberType == Byte.TYPE)) { return value.byteValue(); } if ((numberType == Float.class) || (numberType == Float.TYPE)) { return value.floatValue(); } if ((numberType == Double.class) || (numberType == Double.TYPE)) { return value.doubleValue(); } if (numberType == BigDecimal.class) { return BigDecimal.valueOf(value.doubleValue()); } if (numberType == BigInteger.class) { return BigInteger.valueOf(value.longValue()); } throw new IllegalArgumentException(numberType + " not supported"); }
From source file:org.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java
/** * Test the conversion from Strings./* w ww . j a v a 2 s. co m*/ */ @Test public void fromStrings() { GlobalConverter converter = new NumberConverter(new MockConfiguration()); Byte bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(bw); Short sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(sw); Integer iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(iw); Long lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(lw); Float fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(fw); Double dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(dw); byte b = (Byte) converter.convertFromStrings(Byte.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(b, 0); short s = (Short) converter.convertFromStrings(Short.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(s, 0); int i = (Integer) converter.convertFromStrings(Integer.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(i, 0); long l = (Long) converter.convertFromStrings(Long.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(l, 0); float f = (Float) converter.convertFromStrings(Float.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(f, 0, 0); double d = (Double) converter.convertFromStrings(Double.TYPE, null, "testExpr", ArrayUtils.toArray((String) null)); assertEquals(d, 0, 0); bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("1")); assertEquals((byte) bw, 1); sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("1")); assertEquals((short) sw, 1); iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("1")); assertEquals((int) iw, 1); lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("1")); assertEquals((long) lw, 1l); fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("1")); assertEquals(1f, fw, 0); dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("1")); assertEquals(1d, dw, 0); bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(bw); sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(sw); iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(iw); lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(lw); fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(fw); dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray(" ")); assertNull(dw); b = (Byte) converter.convertFromStrings(Byte.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(b, 0); s = (Short) converter.convertFromStrings(Short.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(s, 0); i = (Integer) converter.convertFromStrings(Integer.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(i, 0); l = (Long) converter.convertFromStrings(Long.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(l, 0); f = (Float) converter.convertFromStrings(Float.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(0, f, 0); d = (Double) converter.convertFromStrings(Double.TYPE, null, "testExpr", ArrayUtils.toArray(" ")); assertEquals(d, 0, 0); try { converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } try { converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } try { converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } try { converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } try { converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } try { converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("bad")); fail("Should have failed"); } catch (ConversionException ce) { // Expected } }
From source file:it.greenvulcano.gvesb.http.ProtocolFactory.java
/** * * @param objectClass/*w w w. ja v a2s .com*/ * Object class to instantiate * @param node * The configuration of constructor parameters. * @return */ private static Object createObjectUsingConstructor(Class<?> objectClass, Node node) throws Exception { NodeList paramList = XMLConfig.getNodeList(node, "constructor-param"); Class<?>[] types = new Class[paramList.getLength()]; Object[] params = new Object[types.length]; for (int i = 0; i < types.length; ++i) { Node paramNode = paramList.item(i); String type = XMLConfig.get(paramNode, "@type"); String value = XMLConfig.getDecrypted(paramNode, "@value"); Class<?> cls = null; if (type.equals("byte")) { cls = Byte.TYPE; } else if (type.equals("boolean")) { cls = Boolean.TYPE; } else if (type.equals("char")) { cls = Character.TYPE; } else if (type.equals("double")) { cls = Double.TYPE; } else if (type.equals("float")) { cls = Float.TYPE; } else if (type.equals("int")) { cls = Integer.TYPE; } else if (type.equals("long")) { cls = Long.TYPE; } else if (type.equals("short")) { cls = Short.TYPE; } else if (type.equals("String")) { cls = String.class; } types[i] = cls; params[i] = cast(value, cls); } Constructor<?> constr = objectClass.getConstructor(types); return constr.newInstance(params); }
From source file:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java
public Class<?> getWrappedClass(Class<?> target) { if (target.isPrimitive() == false) { return target; }//from w w w . j a v a 2 s. c o m if (target == Integer.TYPE) { return Integer.class; } if (target == Long.TYPE) { return Long.class; } if (target == Byte.TYPE) { return Byte.class; } if (target == Short.TYPE) { return Short.class; } if (target == Float.TYPE) { return Short.class; } if (target == Double.TYPE) { return Double.class; } if (target == Character.TYPE) { return Character.class; } if (target == Boolean.TYPE) { return Boolean.class; } throw new RuntimeException("Unmapped basic type: " + target); }
From source file:org.thingsplode.synapse.serializers.jackson.adapters.ParameterWrapperDeserializer.java
@Override public ParameterWrapper deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode node = jp.readValueAsTree(); if (node != null && node.size() > 0 && node.isContainerNode()) { ParameterWrapper pw = ParameterWrapper.create(); ArrayNode paramsNode = (ArrayNode) node.get("params"); Iterator<JsonNode> elemIterator = paramsNode.elements(); while (elemIterator.hasNext()) { JsonNode currentNode = elemIterator.next(); if (currentNode.getNodeType() == JsonNodeType.OBJECT) { try { String paramid = ((ObjectNode) currentNode).get("paramid").asText(); String typeName = ((ObjectNode) currentNode).get("type").asText(); Class paramType = null; if (null != typeName) switch (typeName) { case "long": paramType = Long.TYPE; break; case "byte": paramType = Byte.TYPE; break; case "short": paramType = Short.TYPE; break; case "int": paramType = Integer.TYPE; break; case "float": paramType = Float.TYPE; break; case "double": paramType = Double.TYPE; break; case "boolean": paramType = Boolean.TYPE; break; case "char": paramType = Character.TYPE; break; default: paramType = Class.forName(typeName); break; }/*w w w. jav a 2 s . c o m*/ Object parameterObject = jp.getCodec().treeToValue(currentNode.get("value"), paramType); pw.add(paramid, paramType, parameterObject); } catch (ClassNotFoundException ex) { throw new JsonParseException(jp, ex.getMessage()); } } } return pw; } else { return null; } }
From source file:org.kuali.rice.krad.util.DataTypeUtil.java
/** * Determines if the given class is enough like a "long" to store values of it as a SearchableAttributeLongValue * @param type the class to determine the type of * @return true if it is like a "long", false otherwise *///from w ww . jav a 2 s.c o m public static boolean isIntsy(Class<?> type) { return java.lang.Integer.class.isAssignableFrom(type) || java.lang.Long.class.isAssignableFrom(type) || java.lang.Short.class.isAssignableFrom(type) || java.lang.Byte.class.isAssignableFrom(type) || java.math.BigInteger.class.isAssignableFrom(type) || type.equals(Integer.TYPE) || type.equals(Long.TYPE) || type.equals(Short.TYPE) || type.equals(Byte.TYPE); }
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 {// w w w .ja va 2s . com 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.kordamp.ezmorph.primitive.ShortMorpher.java
public Class<?> morphsTo() { return Short.TYPE; }