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:demo.config.PropertyConverter.java
/** * Converts the specified value to the target class. If the class is a * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned will * use the wrapper type (Integer.class, Boolean.class, etc). * //ww w . ja v a 2 s.com * @param cls * the target class of the converted value * @param value * the value to convert * @param params * optional parameters used for the conversion * @return the converted value * @throws ConversionException * if the value is not compatible with the requested type * * @since 1.5 */ static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException { if (cls.isInstance(value)) { return value; // no conversion needed } if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) { return toBoolean(value); } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) { return toCharacter(value); } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) { if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) { return toInteger(value); } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) { return toLong(value); } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) { return toByte(value); } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) { return toShort(value); } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) { return toFloat(value); } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) { return toDouble(value); } else if (BigInteger.class.equals(cls)) { return toBigInteger(value); } else if (BigDecimal.class.equals(cls)) { return toBigDecimal(value); } } else if (Date.class.equals(cls)) { return toDate(value, (String) params[0]); } else if (Calendar.class.equals(cls)) { return toCalendar(value, (String) params[0]); } else if (URL.class.equals(cls)) { return toURL(value); } else if (Locale.class.equals(cls)) { return toLocale(value); } else if (isEnum(cls)) { return convertToEnum(cls, value); } else if (Color.class.equals(cls)) { return toColor(value); } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) { return toInternetAddress(value); } else if (InetAddress.class.isAssignableFrom(cls)) { return toInetAddress(value); } throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")" + " can't be converted to a " + cls.getName() + " object"); }
From source file:MethodHashing.java
static String getTypeString(Class cl) { if (cl == Byte.TYPE) { return "B"; } else if (cl == Character.TYPE) { return "C"; } else if (cl == Double.TYPE) { return "D"; } else if (cl == Float.TYPE) { return "F"; } else if (cl == Integer.TYPE) { return "I"; } else if (cl == Long.TYPE) { return "J"; } else if (cl == Short.TYPE) { return "S"; } else if (cl == Boolean.TYPE) { return "Z"; } else if (cl == Void.TYPE) { return "V"; } else if (cl.isArray()) { return "[" + getTypeString(cl.getComponentType()); } else {// ww w . j ava2 s .c om return "L" + cl.getName().replace('.', '/') + ";"; } }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!//from w w w .ja va2 s. c o m * * @param name DOCUMENT ME! * * @return DOCUMENT ME! */ public Object get(String name) { Object value = dynaValues.get(name); if (value != null) { return value; } Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("Unspecified property type for " + name); } if (!type.isPrimitive()) { return value; } if (type == Boolean.TYPE) { return Boolean.FALSE; } else if (type == Byte.TYPE) { return new Byte((byte) 0); } else if (type == Character.TYPE) { return new Character((char) 0); } else if (type == Short.TYPE) { return new Short((short) 0); } else if (type == Integer.TYPE) { return new Integer(0); } else if (type == Long.TYPE) { return new Long(0); } else if (type == Float.TYPE) { return new Float(0.0); } else if (type == Double.TYPE) { return new Double(0); } return null; }
From source file:org.spring4gwt.server.RpcHelper.java
private static String printTypeName(Class<?> type) { // Primitives ////from w ww . j a v a 2s . c o m if (type.equals(Integer.TYPE)) { return "int"; } else if (type.equals(Long.TYPE)) { return "long"; } else if (type.equals(Short.TYPE)) { return "short"; } else if (type.equals(Byte.TYPE)) { return "byte"; } else if (type.equals(Character.TYPE)) { return "char"; } else if (type.equals(Boolean.TYPE)) { return "boolean"; } else if (type.equals(Float.TYPE)) { return "float"; } else if (type.equals(Double.TYPE)) { return "double"; } // Arrays // if (type.isArray()) { Class<?> componentType = type.getComponentType(); return printTypeName(componentType) + "[]"; } // Everything else // return type.getName().replace('$', '.'); }
From source file:org.javelin.sws.ext.bind.internal.BuiltInMappings.java
/** * @param patterns/* w w w . ja va2 s . co m*/ */ public static <T> void initialize(Map<Class<?>, TypedPattern<?>> patterns, Map<QName, TypedPattern<?>> patternsForTypeQNames) { // see: com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl<T> and inner // com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.StringImpl<T> implementations // we have two places where XSD -> Java mapping is defined: // - JAX-RPC 1.1, section 4.2.1 Simple Types // - JAXB 2, section 6.2.2 Atomic Datatype // XML Schema (1.0) Part 2: Datatypes Second Edition, or/and // W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes // conversion of primitive types should be base on "Lexical Mapping" of simple types defined in XSD part 2 // 3.2 Special Built-in Datatypes (#special-datatypes) // 3.2.1 anySimpleType (#anySimpleType) // 3.2.2 anyAtomicType (#anyAtomicType) // 3.3 Primitive Datatypes (#built-in-primitive-datatypes) // 3.3.1 string (#string) { SimpleContentPattern<String> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_STRING, String.class); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); } // 3.3.2 boolean (#boolean) { SimpleContentPattern<Boolean> pattern = SimpleContentPattern .newValuePattern(SweJaxbConstants.XSD_BOOLEAN, Boolean.class); patterns.put(Boolean.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Boolean>() { @Override public String print(Boolean object, Locale locale) { return Boolean.toString(object); } @Override public Boolean parse(String text, Locale locale) throws ParseException { // TODO: should allow "true", "false", "1", "0" return Boolean.parseBoolean(text); } }); } // 3.3.3 decimal (#decimal) { SimpleContentPattern<BigDecimal> pattern = SimpleContentPattern .newValuePattern(SweJaxbConstants.XSD_DECIMAL, BigDecimal.class); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<BigDecimal>() { @Override public String print(BigDecimal object, Locale locale) { return object.toPlainString(); } @Override public BigDecimal parse(String text, Locale locale) throws ParseException { // TODO: should allow (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+) return new BigDecimal(text); } }); } // 3.3.4 float (#float) { SimpleContentPattern<Float> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_FLOAT, Float.class); patterns.put(Float.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Float>() { @Override public String print(Float object, Locale locale) { return Float.toString(object); } @Override public Float parse(String text, Locale locale) throws ParseException { // TODO: should allow (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?|(\+|-)?INF|NaN return Float.parseFloat(text); } }); } // 3.3.5 double (#double) { SimpleContentPattern<Double> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_DOUBLE, Double.class); patterns.put(Double.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Double>() { @Override public String print(Double object, Locale locale) { return Double.toString(object); } @Override public Double parse(String text, Locale locale) throws ParseException { // TODO: should allow (\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?|(\+|-)?INF|NaN return Double.parseDouble(text); } }); } // 3.3.6 duration (#duration) // 3.3.7 dateTime (#dateTime) { SimpleContentPattern<DateTime> pattern = SimpleContentPattern .newValuePattern(SweJaxbConstants.XSD_DATETIME, DateTime.class); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<DateTime>() { private final DateTimeFormatter DTMS = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ"); private final DateTimeFormatter DT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ"); private final DateTimeFormatter DTZMS = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); private final DateTimeFormatter DTZ = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); @Override public DateTime parse(String text, Locale locale) throws ParseException { return null; } @Override public String print(DateTime object, Locale locale) { if (object.getMillisOfSecond() == 0) { return object.getZone() == DateTimeZone.UTC ? DTZ.print(object) : DT.print(object); } else { return object.getZone() == DateTimeZone.UTC ? DTZMS.print(object) : DTMS.print(object); } } }); } // 3.3.8 time (#time) { SimpleContentPattern<DateTime> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_TIME, DateTime.class); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<DateTime>() { private final DateTimeFormatter TMS = DateTimeFormat.forPattern("HH:mm:ss.SSS"); private final DateTimeFormatter T = DateTimeFormat.forPattern("HH:mm:ss"); @Override public DateTime parse(String text, Locale locale) throws ParseException { return null; } @Override public String print(DateTime object, Locale locale) { // TODO: should allow (([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))? if (object.getMillisOfSecond() == 0) return T.print(object); else return TMS.print(object); } }); } // 3.3.9 date (#date) { SimpleContentPattern<DateTime> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_DATE, DateTime.class); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<DateTime>() { private final DateTimeFormatter DT = DateTimeFormat.forPattern("yyyy-MM-ddZZ"); private final DateTimeFormatter DTZ = DateTimeFormat.forPattern("yyyy-MM-dd'Z'"); @Override public DateTime parse(String text, Locale locale) throws ParseException { return null; } @Override public String print(DateTime object, Locale locale) { return object.getZone() == DateTimeZone.UTC ? DTZ.print(object) : DT.print(object); } }); } // 3.3.10 gYearMonth (#gYearMonth) // 3.3.11 gYear (#gYear) // 3.3.12 gMonthDay (#gMonthDay) // 3.3.13 gDay (#gDay) // 3.3.14 gMonth (#gMonth) // 3.3.15 hexBinary (#hexBinary) // 3.3.16 base64Binary (#base64Binary) // 3.3.17 anyURI (#anyURI) // 3.3.18 QName (#QName) // 3.3.19 NOTATION (#NOTATION) // 3.4 Other Built-in Datatypes (#ordinary-built-ins) // 3.4.1 normalizedString (#normalizedString) // 3.4.2 token (#token) // 3.4.3 language (#language) // 3.4.4 NMTOKEN (#NMTOKEN) // 3.4.5 NMTOKENS (#NMTOKENS) // 3.4.6 Name (#Name) // 3.4.7 NCName (#NCName) // 3.4.8 ID (#ID) // 3.4.9 IDREF (#IDREF) // 3.4.10 IDREFS (#IDREFS) // 3.4.11 ENTITY (#ENTITY) // 3.4.12 ENTITIES (#ENTITIES) // 3.4.13 integer (#integer) // 3.4.14 nonPositiveInteger (#nonPositiveInteger) // 3.4.15 negativeInteger (#negativeInteger) // 3.4.16 long (#long) { SimpleContentPattern<Long> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_LONG, Long.class); patterns.put(Long.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Long>() { @Override public String print(Long object, Locale locale) { return Long.toString(object); } @Override public Long parse(String text, Locale locale) throws ParseException { return Long.parseLong(text); } }); } // 3.4.17 int (#int) { SimpleContentPattern<Integer> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_INT, Integer.class); patterns.put(Integer.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Integer>() { @Override public String print(Integer object, Locale locale) { return Integer.toString(object); } @Override public Integer parse(String text, Locale locale) throws ParseException { return Integer.parseInt(text); } }); } // 3.4.18 short (#short) { SimpleContentPattern<Short> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_SHORT, Short.class); patterns.put(Short.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Short>() { @Override public String print(Short object, Locale locale) { return Short.toString(object); } @Override public Short parse(String text, Locale locale) throws ParseException { return Short.parseShort(text); } }); } // 3.4.19 byte (#byte) { SimpleContentPattern<Byte> pattern = SimpleContentPattern.newValuePattern(SweJaxbConstants.XSD_BYTE, Byte.class); patterns.put(Byte.TYPE, pattern); patterns.put(pattern.getJavaType(), pattern); patternsForTypeQNames.put(pattern.getSchemaType(), pattern); pattern.setFormatter(new Formatter<Byte>() { @Override public String print(Byte object, Locale locale) { return Byte.toString(object); } @Override public Byte parse(String text, Locale locale) throws ParseException { return Byte.parseByte(text); } }); } // 3.4.20 nonNegativeInteger (#nonNegativeInteger) // 3.4.21 unsignedLong (#unsignedLong) // 3.4.22 unsignedInt (#unsignedInt) // 3.4.23 unsignedShort (#unsignedShort) // 3.4.24 unsignedByte (#unsignedByte) // 3.4.25 positiveInteger (#positiveInteger) // 3.4.26 yearMonthDuration (#yearMonthDuration) // 3.4.27 dayTimeDuration (#dayTimeDuration) // 3.4.28 dateTimeStamp (#dateTimeStamp) // other simple types // JAXB2 (static): /* class [B class char class java.awt.Image class java.io.File class java.lang.Character class java.lang.Class class java.lang.Void class java.math.BigDecimal class java.math.BigInteger class java.net.URI class java.net.URL class java.util.Calendar class java.util.Date class java.util.GregorianCalendar class java.util.UUID class javax.activation.DataHandler class javax.xml.datatype.Duration class javax.xml.datatype.XMLGregorianCalendar class javax.xml.namespace.QName interface javax.xml.transform.Source class void */ // JAXB2 (additional mappings available at runtime): /* * class com.sun.xml.bind.api.CompositeStructure * class java.lang.Object * class javax.xml.bind.JAXBElement */ }
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 .j a va2 s. c o m 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:com.link_intersystems.lang.Conversions.java
/** * long to float or double/*www . j av a2s . c o m*/ */ private static boolean isPrimitiveLongWidening(Class<?> to) { boolean isWidening = isPrimitiveFloatWidening(to); isWidening |= isIdentity(to, Float.TYPE); return isWidening; }
From source file:com.twitter.elephantbird.pig.piggybank.Invoker.java
private static Class<?> unPrimitivize(Class<?> klass) { if (klass.equals(Integer.TYPE)) { return Integer.class; }//w ww. j a va 2 s. c om if (klass.equals(Long.TYPE)) { return Long.class; } else if (klass.equals(Float.TYPE)) { return Float.class; } else if (klass.equals(Double.TYPE)) { return Double.class; } else if (klass.equals(DOUBLE_ARRAY_CLASS)) { return DOUBLE_ARRAY_CLASS; } else { return klass; } }
From source file:io.openmessaging.rocketmq.utils.BeanUtils.java
public static void setProperties(Class<?> clazz, Object obj, String methodName, Object value) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Class<?> parameterClass = getMethodClass(clazz, methodName); Method setterMethod = clazz.getMethod(methodName, parameterClass); if (parameterClass == Boolean.TYPE) { setterMethod.invoke(obj, Boolean.valueOf(value.toString())); } else if (parameterClass == Integer.TYPE) { setterMethod.invoke(obj, Integer.valueOf(value.toString())); } else if (parameterClass == Double.TYPE) { setterMethod.invoke(obj, Double.valueOf(value.toString())); } else if (parameterClass == Float.TYPE) { setterMethod.invoke(obj, Float.valueOf(value.toString())); } else if (parameterClass == Long.TYPE) { setterMethod.invoke(obj, Long.valueOf(value.toString())); } else/* w w w . j a v a 2 s. c om*/ setterMethod.invoke(obj, value); }
From source file:org.jcommon.com.util.JsonUtils.java
public static String toJson(Object o, boolean encode) { StringBuilder sb = new StringBuilder(); Class<?> type = null;/*from ww w.java2 s.c o m*/ sb.append("{"); try { java.lang.reflect.Field[] fs = o.getClass().getDeclaredFields(); String name, value; for (java.lang.reflect.Field f : fs) { value = null; name = f.getName(); type = f.getType(); java.lang.reflect.Method m = getMethod(o.getClass(), "get" + name); if (m == null) m = getMethod(o.getClass(), "is" + name); if (m != null) { if (String.class == type) { value = (String) m.invoke(o); } else if (java.lang.Integer.class == type || Integer.TYPE == type) { value = String.valueOf((Integer) m.invoke(o)); } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) { value = String.valueOf((Boolean) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { value = String.valueOf((Long) m.invoke(o)); } else if (java.lang.Float.class == type || Float.TYPE == type) { value = String.valueOf((Float) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { logger.info("not map Class:" + type); } } if (value != null) { if (encode) sb.append("\"" + CoderUtils.encode(name) + "\"" + ":\"" + CoderUtils.encode(value) + "\""); else sb.append("\"" + name + "\"" + ":\"" + value + "\""); sb.append(","); } } } catch (Throwable t) { logger.error("", t); } if (sb.lastIndexOf(",") == sb.length() - 1) sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }