List of usage examples for java.lang Double TYPE
Class TYPE
To view the source code for java.lang Double TYPE.
Click Source Link
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 w w . ja v a 2 s. c o m * * @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//ww w . ja v a 2s . c om * @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: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 w w w.j av a2s . 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:tiemens.util.instancer.antlr.InstancerCode.java
@SuppressWarnings("unused") private Constructor<?> getConstructorByFind(Class<?> dclz, Class<?>[] parameterTypes) throws NoSuchMethodException { Constructor<?> ret = null; try {//from w ww. ja v a 2 s . 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 www . java2s. 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./* w ww. j ava2s . 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:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testLiterals() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Literals.class); List<ASTLiteral> literals = convertList(acu.findChildNodesWithXPath("//Literal"), ASTLiteral.class); int index = 0; // String s = "s"; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(String.class, literals.get(index++).getType()); // boolean boolean1 = false; assertEquals(Boolean.TYPE, literals.get(index).getFirstDescendantOfType(ASTBooleanLiteral.class).getType()); assertEquals(Boolean.TYPE, literals.get(index++).getType()); // boolean boolean2 = true; assertEquals(Boolean.TYPE, literals.get(index).getFirstDescendantOfType(ASTBooleanLiteral.class).getType()); assertEquals(Boolean.TYPE, literals.get(index++).getType()); // Object obj = null; assertNull(literals.get(index).getFirstDescendantOfType(ASTNullLiteral.class).getType()); assertNull(literals.get(index++).getType()); // byte byte1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // byte byte2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // byte byte3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // short short3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char3 = 007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // char char4 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // int int1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // int int4 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // long long1 = 0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long2 = 0x0F; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long3 = -007; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // long long4 = 0L; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long5 = 0x0Fl; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long6 = -007L; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Long.TYPE, literals.get(index++).getType()); // long long7 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // float float1 = 0.0f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float2 = -10e+01f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float3 = 0x08.08p3f; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Float.TYPE, literals.get(index++).getType()); // float float4 = 0xFF; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // float float5 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // double double1 = 0.0; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double2 = -10e+01; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double3 = 0x08.08p3; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Double.TYPE, literals.get(index++).getType()); // double double4 = 0xFF; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Integer.TYPE, literals.get(index++).getType()); // double double5 = 'a'; assertEquals(0, literals.get(index).jjtGetNumChildren()); assertEquals(Character.TYPE, literals.get(index++).getType()); // Make sure we got them all. assertEquals("All literals not tested", index, literals.size()); }
From source file:org.apache.openejb.math.stat.descriptive.DescriptiveStatistics.java
/** * Returns an estimate for the pth percentile of the stored values. * <p>//from w w w. jav a2s . co m * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>IllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws IllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * values */ public double getPercentile(final double p) { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] { Double.TYPE }) .invoke(percentileImpl, new Object[] { Double.valueOf(p) }); } catch (final NoSuchMethodException e1) { // Setter guard should prevent throw MathRuntimeException.createIllegalArgumentException(UNSUPPORTED_METHOD_MESSAGE, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (final IllegalAccessException e2) { throw MathRuntimeException.createIllegalArgumentException(ILLEGAL_ACCESS_MESSAGE, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (final InvocationTargetException e3) { throw MathRuntimeException.createIllegalArgumentException(e3.getCause()); } } return apply(percentileImpl); }
From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, String processorName, String beanName, MethodVisitor mv) throws SQLException { if (propType.equals(String.class)) { visitMethod(mv, index, beanName, "Ljava/lang/String;", "getString", writer); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { visitMethod(mv, index, beanName, "I", "getInt", writer); return rs.getInt(index); } else if (propType.equals(Integer.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_INTEGER, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { visitMethod(mv, index, beanName, "J", "getLong", writer); return rs.getLong(index); } else if (propType.equals(Long.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_LONG, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Date;", "getDate", writer); return rs.getDate(index); } else if (propType.equals(java.util.Date.class)) { visitMethodCast(mv, index, beanName, PROPERTY_TYPE_DATE, "java/util/Date", writer); return rs.getTimestamp(index); } else if (propType.equals(Timestamp.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Timestamp;", "getTimestamp", writer); return rs.getTimestamp(index); } else if (propType.equals(Time.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Time;", "getTime", writer); return rs.getTime(index); } else if (propType.equals(Double.TYPE)) { visitMethod(mv, index, beanName, "D", "getDouble", writer); return rs.getDouble(index); } else if (propType.equals(Double.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_DOUBLE, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { visitMethod(mv, index, beanName, "F", "getFloat", writer); return rs.getFloat(index); } else if (propType.equals(Float.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_FLOAT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Boolean.TYPE)) { visitMethod(mv, index, beanName, "Z", "getBoolean", writer); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BOOLEAN, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(Clob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Clob;", "getClob", writer); return rs.getClob(index); } else if (propType.equals(Blob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Blob;", "getBlob", writer); return rs.getBlob(index); } else if (propType.equals(byte[].class)) { visitMethod(mv, index, beanName, "[B", "getBytes", writer); return rs.getBytes(index); } else if (propType.equals(Short.TYPE)) { visitMethod(mv, index, beanName, "S", "getShort", writer); return rs.getShort(index); } else if (propType.equals(Short.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_SHORT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { visitMethod(mv, index, beanName, "B", "getByte", writer); return rs.getByte(index); } else if (propType.equals(Byte.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BYTE, writer, processorName); return rs.getByte(index); } else {/*from www . ja v a2 s.c o m*/ visitMethodCast(mv, index, beanName, PROPERTY_TYPE_OTHER, propType.getName().replace('.', '/'), writer); return rs.getObject(index); } }