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.nway.spring.jdbc.bean.JavassistBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, StringBuilder handler) throws SQLException { if (propType.equals(String.class)) { handler.append("bean.").append(writer).append("(").append("$1.getString(").append(index).append("));"); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getInt(").append(index).append("));"); return rs.getInt(index); } else if (propType.equals(Integer.class)) { handler.append("bean.").append(writer).append("(").append("integerValue($1.getInt(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getLong(").append(index).append("));"); return rs.getLong(index); } else if (propType.equals(Long.class)) { handler.append("bean.").append(writer).append("(").append("longValue($1.getLong(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { handler.append("bean.").append(writer).append("(").append("$1.getDate(").append(index).append("));"); return rs.getDate(index); } else if (propType.equals(java.util.Date.class) || propType.equals(Timestamp.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTimestamp(").append(index) .append("));"); return rs.getTimestamp(index); } else if (propType.equals(Double.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getDouble(").append(index).append("));"); return rs.getDouble(index); } else if (propType.equals(Double.class)) { handler.append("bean.").append(writer).append("(").append("doubleValue($1.getDouble(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getFloat(").append(index).append("));"); return rs.getFloat(index); } else if (propType.equals(Float.class)) { handler.append("bean.").append(writer).append("(").append("floatValue($1.getFloat(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Time.class)) { handler.append("bean.").append(writer).append("(").append("$1.getTime(").append(index).append("));"); return rs.getTime(index); } else if (propType.equals(Boolean.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getBoolean(").append(index).append("));"); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { handler.append("bean.").append(writer).append("(").append("booleanValue($1.getBoolean(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(byte[].class)) { handler.append("bean.").append(writer).append("(").append("$1.getBytes(").append(index).append("));"); return rs.getBytes(index); } else if (BigDecimal.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBigDecimal(").append(index) .append("));"); return rs.getBigDecimal(index); } else if (Blob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getBlob(").append(index).append("));"); return rs.getBlob(index); } else if (Clob.class.equals(propType)) { handler.append("bean.").append(writer).append("(").append("$1.getClob(").append(index).append("));"); return rs.getClob(index); } else if (propType.equals(Short.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getShort(").append(index).append("));"); return rs.getShort(index); } else if (propType.equals(Short.class)) { handler.append("bean.").append(writer).append("(").append("shortValue($1.getShort(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { handler.append("bean.").append(writer).append("(").append("$1.getByte(").append(index).append("));"); return rs.getByte(index); } else if (propType.equals(Byte.class)) { handler.append("bean.").append(writer).append("(").append("byteValue($1.getByte(").append(index) .append("),$1.wasNull()));"); return JdbcUtils.getResultSetValue(rs, index, Byte.class); } else {// ww w . j av a 2 s .c o m handler.append("bean.").append(writer).append("(").append("(").append(propType.getName()).append(")") .append("$1.getObject(").append(index).append("));"); return rs.getObject(index); } }
From source file:com.qmetry.qaf.automation.data.BaseDataBean.java
/** * This will fill random data except those properties which has skip=true in * {@link Randomizer} annotation. Use {@link Randomizer} annotation to * specify data value to be generated for specific property. * /*from ww w. j a va 2 s . c o m*/ * @see Randomizer */ public void fillRandomData() { Field[] fields = getFields(); for (Field field : fields) { logger.debug("NAME :: " + field.getName()); if (!(Modifier.isFinal(field.getModifiers()))) { RandomizerTypes type = RandomizerTypes.MIXED; int len = 10; long min = 0, max = 0; String prefix = "", suffix = ""; String format = ""; String[] list = {}; Randomizer randomizer = field.getAnnotation(Randomizer.class); if (randomizer != null) { if (randomizer.skip()) { continue; } type = field.getType() == Date.class ? RandomizerTypes.DIGITS_ONLY : randomizer.type(); len = randomizer.length(); prefix = randomizer.prefix(); suffix = randomizer.suffix(); min = randomizer.minval(); max = min > randomizer.maxval() ? min : randomizer.maxval(); format = randomizer.format(); list = randomizer.dataset(); } else { // @Since 2.1.2 randomizer annotation is must for random // value // generation continue; } String str = ""; if ((list == null) || (list.length == 0)) { str = StringUtil.isBlank(format) ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY), !type.equals(RandomizerTypes.LETTERS_ONLY)) : StringUtil.getRandomString(format); } else { str = getRandomValue(list); } try { // deal with IllegalAccessException field.setAccessible(true); Method setter = null; try { setter = this.getClass().getMethod("set" + StringUtil.getTitleCase(field.getName()), String.class); } catch (Exception e) { } if ((field.getType() == String.class) || (null != setter)) { if ((list == null) || (list.length == 0)) { if ((min == max) && (min == 0)) { str = StringUtil.isBlank(format) ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY), !type.equals(RandomizerTypes.LETTERS_ONLY)) : StringUtil.getRandomString(format); } else { str = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min); } } String rStr = prefix + str + suffix; if (null != setter) { setter.setAccessible(true); setter.invoke(this, rStr); } else { field.set(this, rStr); } } else { String rStr = ""; if ((min == max) && (min == 0)) { rStr = RandomStringUtils.random(len, false, true); } else { rStr = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min); } if (field.getType() == Integer.TYPE) { field.setInt(this, Integer.parseInt(rStr)); } else if (field.getType() == Float.TYPE) { field.setFloat(this, Float.parseFloat(rStr)); } else if (field.getType() == Double.TYPE) { field.setDouble(this, Double.parseDouble(rStr)); } else if (field.getType() == Long.TYPE) { field.setLong(this, Long.parseLong(rStr)); } else if (field.getType() == Short.TYPE) { field.setShort(this, Short.parseShort(rStr)); } else if (field.getType() == Date.class) { logger.info("filling date " + rStr); int days = Integer.parseInt(rStr); field.set(this, DateUtil.getDate(days)); } else if (field.getType() == Boolean.TYPE) { field.setBoolean(this, RandomUtils.nextBoolean()); } } } catch (IllegalArgumentException e) { logger.error("Unable to fill random data in field " + field.getName(), e); } catch (IllegalAccessException e) { logger.error("Unable to Access " + field.getName(), e); } catch (InvocationTargetException e) { logger.error("Unable to Access setter for " + field.getName(), e); } } } }
From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int.// w ww.j a va2s.com * * @param value The value to be passed into the setter method. * @param type The setter's parameter type. * @return boolean True if the value is compatible. */ private boolean isCompatibleType(Object value, Class<?> type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } else { return false; } }
From source file:org.enerj.apache.commons.beanutils.locale.LocaleConvertUtilsBean.java
/** * Create all {@link LocaleConverter} types for specified locale. * * @param locale The Locale/* w w w . j a va 2 s . c o m*/ * @return The FastHashMap instance contains the all {@link LocaleConverter} types * for the specified locale. */ protected FastHashMap create(Locale locale) { FastHashMap converter = new FastHashMap(); converter.setFast(false); converter.put(BigDecimal.class, new BigDecimalLocaleConverter(locale, applyLocalized)); converter.put(BigInteger.class, new BigIntegerLocaleConverter(locale, applyLocalized)); converter.put(Byte.class, new ByteLocaleConverter(locale, applyLocalized)); converter.put(Byte.TYPE, new ByteLocaleConverter(locale, applyLocalized)); converter.put(Double.class, new DoubleLocaleConverter(locale, applyLocalized)); converter.put(Double.TYPE, new DoubleLocaleConverter(locale, applyLocalized)); converter.put(Float.class, new FloatLocaleConverter(locale, applyLocalized)); converter.put(Float.TYPE, new FloatLocaleConverter(locale, applyLocalized)); converter.put(Integer.class, new IntegerLocaleConverter(locale, applyLocalized)); converter.put(Integer.TYPE, new IntegerLocaleConverter(locale, applyLocalized)); converter.put(Long.class, new LongLocaleConverter(locale, applyLocalized)); converter.put(Long.TYPE, new LongLocaleConverter(locale, applyLocalized)); converter.put(Short.class, new ShortLocaleConverter(locale, applyLocalized)); converter.put(Short.TYPE, new ShortLocaleConverter(locale, applyLocalized)); converter.put(String.class, new StringLocaleConverter(locale, applyLocalized)); // conversion format patterns of java.sql.* types should correspond to default // behaviour of toString and valueOf methods of these classes converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd")); converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss")); converter.put(java.sql.Timestamp.class, new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S")); converter.setFast(true); return converter; }
From source file:tiemens.util.instancer.antlr.InstancerCode.java
@SuppressWarnings("unused") private Constructor<?> getConstructorByFind(Class<?> dclz, Class<?>[] parameterTypes) throws NoSuchMethodException { Constructor<?> ret = null; try {/* w ww. j a v a 2s. co m*/ ret = dclz.getConstructor(parameterTypes); } catch (SecurityException e) { throw e; } catch (NoSuchMethodException e) { // // try to correct java.lang.Long into java.lang.Type.long // i.e. Long to long // for (int i = 0, n = parameterTypes.length; i < n; i++) { Class<?> c = parameterTypes[i]; if (c.equals(Long.class)) { c = java.lang.Long.TYPE; } else if (c.equals(Integer.class)) { c = java.lang.Integer.TYPE; } else if (c.equals(Double.class)) { c = java.lang.Double.TYPE; } else if (c.equals(java.lang.Float.class)) { c = java.lang.Float.TYPE; } parameterTypes[i] = c; } ret = dclz.getConstructor(parameterTypes); } finally { } return ret; }
From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java
public Object[] loadColsAsArrays() throws IOException { initColNameMap();/*from w w w. j av a 2 s . c o m*/ ColumnDescriptor[] columns = getColumns(); Object[] valueLists = new Object[columns.length]; for (int i = 0; i < valueLists.length; i++) { if (!columns[i].load) continue; Class clazz = columns[i].clazz; if (clazz.isPrimitive()) { if (clazz.equals(Double.TYPE)) valueLists[i] = new DoubleArray(); else if (clazz.equals(Float.TYPE)) valueLists[i] = new FloatArray(); else if (clazz.equals(Integer.TYPE)) valueLists[i] = new IntegerArray(); } else { valueLists[i] = new ArrayList(); } } BufferedReader reader = null; try { reader = getReader(); int line = 0; String s; for (int skip = 0; skip < _skipLines; skip++) { //noinspection UnusedAssignment s = reader.readLine(); line++; } while ((s = reader.readLine()) != null) { line++; if ("".equals(s.trim())) continue; String[] fields = parseLine(s); for (int i = 0; i < fields.length && i < columns.length; i++) { if (!columns[i].load) continue; String value = fields[i]; Class clazz = columns[i].clazz; if (clazz.isPrimitive()) { if (clazz.equals(Double.TYPE)) ((DoubleArray) valueLists[i]).add(Double.parseDouble(value)); else if (clazz.equals(Float.TYPE)) ((FloatArray) valueLists[i]).add(Float.parseFloat(value)); else if (clazz.equals(Integer.TYPE)) ((IntegerArray) valueLists[i]).add(Integer.parseInt(value)); } else { try { if ("".equals(value)) ((List<Object>) valueLists[i]).add(columns[i].missingValues); else ((List<Object>) valueLists[i]).add(ConvertUtils.convert(value, columns[i].clazz)); } catch (Exception x) { if (_throwOnErrors) throw new ConversionException( "Conversion error: line " + line + " column " + (i + 1), x); ((List<Object>) valueLists[i]).add(columns[i].errorValues); } } } } } finally { if (null != reader) reader.close(); } Object[] returnArrays = new Object[columns.length]; for (int i = 0; i < columns.length; i++) { if (!columns[i].load) continue; Class clazz = columns[i].clazz; if (clazz.isPrimitive()) { if (clazz.equals(Double.TYPE)) returnArrays[i] = ((DoubleArray) valueLists[i]).toArray(null); else if (clazz.equals(Float.TYPE)) returnArrays[i] = ((FloatArray) valueLists[i]).toArray(null); else if (clazz.equals(Integer.TYPE)) returnArrays[i] = ((IntegerArray) valueLists[i]).toArray(null); } else { Object[] values = (Object[]) Array.newInstance(columns[i].clazz, ((List) valueLists[i]).size()); returnArrays[i] = ((List<Object>) valueLists[i]).toArray(values); } } return returnArrays; }
From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Gets default value. * @return default value./*from w ww. j a va2 s . c om*/ */ public Object getDefaultValue() { if (defaultValue != null) return this.defaultValue; Class cls = getType(); if (primitiveWrapperClass != null) { if (cls.equals(Boolean.TYPE)) return new Boolean(false); else if (cls.equals(Byte.TYPE)) return new Byte((byte) 0); else if (cls.equals(Character.TYPE)) return new Character((char) 0); else if (cls.equals(Double.TYPE)) return new Double((double) 0); else if (cls.equals(Float.TYPE)) return new Float((float) 0); else if (cls.equals(Integer.TYPE)) return new Integer((int) 0); else if (cls.equals(Long.TYPE)) return new Long((long) 0); else if (cls.equals(Short.TYPE)) return new Short((short) 0); else return null; } else return null; }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * //from w ww .ja va 2s .co m * @param json * @param key * @param toField * @return * @throws JSONException */ public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException { final Object o = json.get(key); final Class<?> fieldType = toField.getType(); if (o != JSONObject.NULL) { if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) { return json.getInt(key); } else if (fieldType.equals(String.class)) { return o; } else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) { return json.getLong(key); } else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) { return json.getBoolean(key); } else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) { return (float) json.getDouble(key); } else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) { return json.getDouble(key); } else { return o; } } return JSONObject.NULL; }
From source file:org.ocelotds.dashboard.services.ServiceToolsTest.java
/** * Test of getInstanceOfClass method, of class ServiceTools. * * @throws com.fasterxml.jackson.core.JsonProcessingException *///from ww w . java 2 s.c o m @Test public void testGetInstanceOfClass() throws JsonProcessingException { System.out.println("getTemplateOfClass"); ObjectMapper om = new ObjectMapper(); Result r = new Result(); String expResult = om.writeValueAsString(r); Class cls = Boolean.class; Object result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Boolean.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Integer.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Integer.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Long.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0L); cls = Long.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0l); cls = Float.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Float.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Double.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Double.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Float[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(new Float[] { 0.1f, 0.1f }); cls = Result.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(r); cls = Result[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(new Result[] { r, r }); cls = Locale.class; result = instance.getInstanceOfClass(cls); assertThat(result).isInstanceOf(Locale.class); cls = Serializable.class; result = instance.getInstanceOfClass(cls); assertThat(result).isNull(); }