Example usage for java.lang Byte TYPE

List of usage examples for java.lang Byte TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type byte .

Usage

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

/**
 * <em>java language specification - 5.1.2 Widening Primitive Conversion</em>
 * .//w  w w  .j  ava2 s . c om
 *
 * <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:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java

/**
 * Creates a new morpher for the target type with a default value.<br>
 * The defaultValue should be of the same class as the target type.
 * //w  ww.ja  v a  2  s  . c  o  m
 * @param type must be a primitive or wrapper type. BigDecimal and BigInteger are also supported.
 * @param defaultValue return value if the value to be morphed is null
 */
public JsonNumberMorpher(Class<?> type, Number defaultValue) {
    super(true);

    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.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java

/**
 * Test the conversion from Strings.//from  w ww. j a v a2 s  .com
 */
@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: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);
}

From source file:org.seasar.mayaa.impl.util.ObjectUtil.java

protected static Class loadPrimitiveClass(String className) {
    if (StringUtil.isEmpty(className)) {
        throw new IllegalArgumentException();
    }// ww  w. j  av  a  2  s.  c o  m
    if ("short".equals(className)) {
        return Short.TYPE;
    } else if ("int".equals(className)) {
        return Integer.TYPE;
    } else if ("long".equals(className)) {
        return Long.TYPE;
    } else if ("float".equals(className)) {
        return Float.TYPE;
    } else if ("double".equals(className)) {
        return Double.TYPE;
    } else if ("byte".equals(className)) {
        return Byte.TYPE;
    } else if ("char".equals(className)) {
        return Character.TYPE;
    } else if ("boolean".equals(className)) {
        return Boolean.TYPE;
    } else if ("void".equals(className)) {
        return Void.TYPE;
    }
    return null;
}

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  . java2s .  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.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>// w  ww.j a  v a  2 s.  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:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java

public Class<?> getWrappedClass(Class<?> target) {
    if (target.isPrimitive() == false) {
        return target;
    }// w  ww . ja  va 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.batoo.common.reflect.ReflectHelper.java

/**
 * Converts the number into number Type//from ww w . j ava 2s  . co  m
 * 
 * @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.brekka.phalanx.core.services.impl.AbstractCryptoService.java

protected byte[] toBytes(Object obj) {
    byte[] retVal;
    if (obj == null) {
        throw new NullPointerException("An object to encrypt must be specified");
    }/*ww  w . jav  a2s . c  o  m*/
    Class<?> clazz = obj.getClass();
    if (clazz.isArray() && clazz.getComponentType() == Byte.TYPE) {
        retVal = (byte[]) obj;
    } else if (obj instanceof InternalPrivateKeyToken) {
        InternalPrivateKeyToken pkt = (InternalPrivateKeyToken) obj;
        retVal = encodePrivateKey(pkt);
    } else if (obj instanceof InternalSecretKeyToken) {
        InternalSecretKeyToken iskt = (InternalSecretKeyToken) obj;
        retVal = encodeSecretKey(iskt);
    } else {
        throw new IllegalArgumentException(
                String.format("Unsupport type conversion from '%s'", clazz.getName()));
    }
    return retVal;
}