List of usage examples for java.lang Float TYPE
Class TYPE
To view the source code for java.lang Float TYPE.
Click Source Link
From source file:com.puppycrawl.tools.checkstyle.api.AutomaticBean.java
/** * Creates a BeanUtilsBean that is configured to use * type converters that throw a ConversionException * instead of using the default value when something * goes wrong./* w ww.j a v a 2s.c o m*/ * * @return a configured BeanUtilsBean */ private static BeanUtilsBean createBeanUtilsBean() { final ConvertUtilsBean cub = new ConvertUtilsBean(); cub.register(new BooleanConverter(), Boolean.TYPE); cub.register(new BooleanConverter(), Boolean.class); cub.register(new ArrayConverter(boolean[].class, new BooleanConverter()), boolean[].class); cub.register(new ByteConverter(), Byte.TYPE); cub.register(new ByteConverter(), Byte.class); cub.register(new ArrayConverter(byte[].class, new ByteConverter()), byte[].class); cub.register(new CharacterConverter(), Character.TYPE); cub.register(new CharacterConverter(), Character.class); cub.register(new ArrayConverter(char[].class, new CharacterConverter()), char[].class); cub.register(new DoubleConverter(), Double.TYPE); cub.register(new DoubleConverter(), Double.class); cub.register(new ArrayConverter(double[].class, new DoubleConverter()), double[].class); cub.register(new FloatConverter(), Float.TYPE); cub.register(new FloatConverter(), Float.class); cub.register(new ArrayConverter(float[].class, new FloatConverter()), float[].class); cub.register(new IntegerConverter(), Integer.TYPE); cub.register(new IntegerConverter(), Integer.class); cub.register(new ArrayConverter(int[].class, new IntegerConverter()), int[].class); cub.register(new LongConverter(), Long.TYPE); cub.register(new LongConverter(), Long.class); cub.register(new ArrayConverter(long[].class, new LongConverter()), long[].class); cub.register(new ShortConverter(), Short.TYPE); cub.register(new ShortConverter(), Short.class); cub.register(new ArrayConverter(short[].class, new ShortConverter()), short[].class); cub.register(new RelaxedStringArrayConverter(), String[].class); // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp // do not use defaults in the default configuration of ConvertUtilsBean return new BeanUtilsBean(cub, new PropertyUtilsBean()); }
From source file:com.link_intersystems.lang.Conversions.java
/** * <em>java language specification - 5.1.2 Widening Primitive Conversion</em> * ./* w w w. ja v a 2 s . c o 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.briljantframework.data.vector.Convert.java
@SuppressWarnings("unchecked") private static <T> T convertNumber(Class<T> cls, Number num) { if (cls.equals(Double.class) || cls.equals(Double.TYPE)) { return (T) (Double) num.doubleValue(); } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) { return (T) (Float) num.floatValue(); } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) { return (T) (Long) num.longValue(); } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) { return (T) (Integer) num.intValue(); } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) { return (T) (Short) num.shortValue(); } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) { return (T) (Byte) num.byteValue(); } else if (Complex.class.equals(cls)) { return cls.cast(Complex.valueOf(num.doubleValue())); } else if (Logical.class.equals(cls)) { return cls.cast(num.intValue() == 1 ? Logical.TRUE : Logical.FALSE); } else if (Boolean.class.equals(cls)) { return cls.cast(num.intValue() == 1); } else {/*from ww w.j a v a2 s. c om*/ return Na.of(cls); } }
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 . j a v a2s. com 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.kordamp.ezmorph.primitive.FloatMorpher.java
public Class<?> morphsTo() { return Float.TYPE; }
From source file:org.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java
/** * Test the conversion from Strings.//from w w w.java 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:org.kordamp.ezmorph.object.NumberMorpher.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. * * @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 *//* w w w. j ava 2s .c o m*/ public NumberMorpher(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"); } if (defaultValue != null && !type.isInstance(defaultValue)) { throw new MorphException("Default value must be of type " + type); } this.type = type; setDefaultValue(defaultValue); }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.primitive.FloatMorpher.java
public Class morphsTo() { return Float.TYPE; }
From source file:ClassUtils.java
/** * Helper for invoking an instance method that takes a single parameter. * This method also handles parameters of primitive type. * //from w ww . j a v a 2 s.c om * @param cl * The class that the instance belongs to * @param instance * The object on which we will invoke the method * @param methodName * The method name * @param param * The parameter * @throws Throwable */ public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable { Class paramClass; if (param instanceof Integer) paramClass = Integer.TYPE; else if (param instanceof Long) paramClass = Long.TYPE; else if (param instanceof Short) paramClass = Short.TYPE; else if (param instanceof Boolean) paramClass = Boolean.TYPE; else if (param instanceof Double) paramClass = Double.TYPE; else if (param instanceof Float) paramClass = Float.TYPE; else if (param instanceof Character) paramClass = Character.TYPE; else if (param instanceof Byte) paramClass = Byte.TYPE; else paramClass = param.getClass(); Method method = cl.getMethod(methodName, new Class[] { paramClass }); try { return method.invoke(instance, new Object[] { param }); } catch (InvocationTargetException e) { throw e.getCause(); } }
From source file:org.briljantframework.data.vector.ConvertTest.java
@Test public void testTo_convertToFloat() throws Exception { assertEquals(10.0, Convert.to(Float.class, 10), 0); assertEquals(10.0, Convert.to(Float.class, 10.0), 0); assertEquals(10.0, Convert.to(Float.class, 10.0f), 0); assertEquals(10.0, Convert.to(Float.class, 10l), 0); assertEquals(10.0, Convert.to(Float.class, (short) 10), 0); assertEquals(10.0, Convert.to(Float.class, (byte) 10), 0); assertEquals(10.0, Convert.to(Float.class, Complex.valueOf(10)), 0); assertEquals(1.0, Convert.to(Float.class, Logical.TRUE), 0); assertEquals(1.0, Convert.to(Float.class, true), 0); assertEquals(10.0, Convert.to(Float.TYPE, 10), 0); assertEquals(10.0, Convert.to(Float.TYPE, 10.0), 0); assertEquals(10.0, Convert.to(Float.TYPE, 10.0f), 0); assertEquals(10.0, Convert.to(Float.TYPE, 10l), 0); assertEquals(10.0, Convert.to(Float.TYPE, (short) 10), 0); assertEquals(10.0, Convert.to(Float.TYPE, (byte) 10), 0); assertEquals(10.0, Convert.to(Float.TYPE, Complex.valueOf(10)), 0); assertEquals(1.0, Convert.to(Float.TYPE, Logical.TRUE), 0); assertEquals(1.0, Convert.to(Float.TYPE, true), 0); }