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
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * // w w w . j a v a2s .co m * <p> * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return (rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return (rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return (rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return (rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return (rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return (rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return (rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else { return rs.getObject(index); } }
From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java
private final Class<?> getClassForName(String type) { try {/* www . ja va2s. co m*/ if (type.equals("boolean") || type.equals("java.lang.Boolean")) { return Boolean.TYPE; } else if (type.equals("byte") || type.equals("java.lang.Byte")) { return Byte.TYPE; } else if (type.equals("char") || type.equals("java.lang.Character")) { return Character.TYPE; } else if (type.equals("double") || type.equals("java.lang.Double")) { return Double.TYPE; } else if (type.equals("float") || type.equals("java.lang.Float")) { return Float.TYPE; } else if (type.equals("int") || type.equals("java.lang.Integer")) { return Integer.TYPE; } else if (type.equals("long") || type.equals("java.lang.Long")) { return Long.TYPE; } else if (type.equals("short") || type.equals("java.lang.Short")) { return Short.TYPE; } else if (type.equals("String")) { return Class.forName("java.lang." + type, true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } if (type.endsWith("[]")) { // see http://stackoverflow.com/questions/3442090/java-what-is-this-ljava-lang-object final StringBuilder arrayTypeNameBuilder = new StringBuilder(30); int index = 0; while ((index = type.indexOf('[', index)) != -1) { arrayTypeNameBuilder.append('['); index++; } arrayTypeNameBuilder.append('L'); // always needed for Object arrays // remove bracket from type name get array component type type = type.replace("[]", ""); arrayTypeNameBuilder.append(type); arrayTypeNameBuilder.append(';'); // finalize object array name return Class.forName(arrayTypeNameBuilder.toString(), true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } else { return Class.forName(ResourceList.getClassNameFromResourcePath(type), true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } } catch (final ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java
/** * Write a {@link Writable}, {@link String}, primitive type, or an array of * the preceding.//from w ww . j a v a2s .c o m * @param out * @param instance * @param declaredClass * @param conf * @throws IOException */ @SuppressWarnings("unchecked") static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf) throws IOException { Object instanceObj = instance; Class declClass = declaredClass; if (instanceObj == null) { // null instanceObj = new NullInstance(declClass, conf); declClass = Writable.class; } writeClassCode(out, declClass); if (declClass.isArray()) { // array // If bytearray, just dump it out -- avoid the recursion and // byte-at-a-time we were previously doing. if (declClass.equals(byte[].class)) { Bytes.writeByteArray(out, (byte[]) instanceObj); } else { //if it is a Generic array, write the element's type if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) { Class<?> componentType = declaredClass.getComponentType(); writeClass(out, componentType); } int length = Array.getLength(instanceObj); out.writeInt(length); for (int i = 0; i < length; i++) { Object item = Array.get(instanceObj, i); writeObject(out, item, item.getClass(), conf); } } } else if (List.class.isAssignableFrom(declClass)) { List list = (List) instanceObj; int length = list.size(); out.writeInt(length); for (int i = 0; i < length; i++) { Object elem = list.get(i); writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf); } } else if (declClass == String.class) { // String Text.writeString(out, (String) instanceObj); } else if (declClass.isPrimitive()) { // primitive type if (declClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instanceObj).booleanValue()); } else if (declClass == Character.TYPE) { // char out.writeChar(((Character) instanceObj).charValue()); } else if (declClass == Byte.TYPE) { // byte out.writeByte(((Byte) instanceObj).byteValue()); } else if (declClass == Short.TYPE) { // short out.writeShort(((Short) instanceObj).shortValue()); } else if (declClass == Integer.TYPE) { // int out.writeInt(((Integer) instanceObj).intValue()); } else if (declClass == Long.TYPE) { // long out.writeLong(((Long) instanceObj).longValue()); } else if (declClass == Float.TYPE) { // float out.writeFloat(((Float) instanceObj).floatValue()); } else if (declClass == Double.TYPE) { // double out.writeDouble(((Double) instanceObj).doubleValue()); } else if (declClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declClass); } } else if (declClass.isEnum()) { // enum Text.writeString(out, ((Enum) instanceObj).name()); } else if (Message.class.isAssignableFrom(declaredClass)) { Text.writeString(out, instanceObj.getClass().getName()); ((Message) instance).writeDelimitedTo(DataOutputOutputStream.constructOutputStream(out)); } else if (Writable.class.isAssignableFrom(declClass)) { // Writable Class<?> c = instanceObj.getClass(); Integer code = CLASS_TO_CODE.get(c); if (code == null) { out.writeByte(NOT_ENCODED); Text.writeString(out, c.getName()); } else { writeClassCode(out, c); } ((Writable) instanceObj).write(out); } else if (Serializable.class.isAssignableFrom(declClass)) { Class<?> c = instanceObj.getClass(); Integer code = CLASS_TO_CODE.get(c); if (code == null) { out.writeByte(NOT_ENCODED); Text.writeString(out, c.getName()); } else { writeClassCode(out, c); } ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(instanceObj); byte[] value = bos.toByteArray(); out.writeInt(value.length); out.write(value); } finally { if (bos != null) bos.close(); if (oos != null) oos.close(); } } else if (Scan.class.isAssignableFrom(declClass)) { Scan scan = (Scan) instanceObj; byte[] scanBytes = ProtobufUtil.toScan(scan).toByteArray(); out.writeInt(scanBytes.length); out.write(scanBytes); } else { throw new IOException("Can't write: " + instanceObj + " as " + declClass); } }
From source file:org.apache.struts2.jasper.compiler.JspUtil.java
/** * Produces a String representing a call to the EL interpreter. * * @param isTagFile is a tag file/*from w ww. j a v a 2s. c om*/ * @param expression a String containing zero or more "${}" expressions * @param expectedType the expected type of the interpreted result * @param fnmapvar Variable pointing to a function map. * @param XmlEscape True if the result should do XML escaping * @return a String representing a call to the EL interpreter. */ public static String interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar, boolean XmlEscape) { /* * Determine which context object to use. */ String jspCtxt = null; if (isTagFile) jspCtxt = "this.getJspContext()"; else jspCtxt = "_jspx_page_context"; /* * Determine whether to use the expected type's textual name * or, if it's a primitive, the name of its correspondent boxed * type. */ String targetType = expectedType.getName(); String primitiveConverterMethod = null; if (expectedType.isPrimitive()) { if (expectedType.equals(Boolean.TYPE)) { targetType = Boolean.class.getName(); primitiveConverterMethod = "booleanValue"; } else if (expectedType.equals(Byte.TYPE)) { targetType = Byte.class.getName(); primitiveConverterMethod = "byteValue"; } else if (expectedType.equals(Character.TYPE)) { targetType = Character.class.getName(); primitiveConverterMethod = "charValue"; } else if (expectedType.equals(Short.TYPE)) { targetType = Short.class.getName(); primitiveConverterMethod = "shortValue"; } else if (expectedType.equals(Integer.TYPE)) { targetType = Integer.class.getName(); primitiveConverterMethod = "intValue"; } else if (expectedType.equals(Long.TYPE)) { targetType = Long.class.getName(); primitiveConverterMethod = "longValue"; } else if (expectedType.equals(Float.TYPE)) { targetType = Float.class.getName(); primitiveConverterMethod = "floatValue"; } else if (expectedType.equals(Double.TYPE)) { targetType = Double.class.getName(); primitiveConverterMethod = "doubleValue"; } } if (primitiveConverterMethod != null) { XmlEscape = false; } /* * Build up the base call to the interpreter. */ // XXX - We use a proprietary call to the interpreter for now // as the current standard machinery is inefficient and requires // lots of wrappers and adapters. This should all clear up once // the EL interpreter moves out of JSTL and into its own project. // In the future, this should be replaced by code that calls // ExpressionEvaluator.parseExpression() and then cache the resulting // expression objects. The interpreterCall would simply select // one of the pre-cached expressions and evaluate it. // Note that PageContextImpl implements VariableResolver and // the generated Servlet/SimpleTag implements FunctionMapper, so // that machinery is already in place (mroth). targetType = toJavaSourceType(targetType); StringBuilder call = new StringBuilder( "(" + targetType + ") " + "org.apache.struts2.jasper.runtime.PageContextImpl.proprietaryEvaluate" + "(" + Generator.quote(expression) + ", " + targetType + ".class, " + "(PageContext)" + jspCtxt + ", " + fnmapvar + ", " + XmlEscape + ")"); /* * Add the primitive converter method if we need to. */ if (primitiveConverterMethod != null) { call.insert(0, "("); call.append(")." + primitiveConverterMethod + "()"); } return call.toString(); }
From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java
public Object getSpawnPacket() { Class<?> Entity = Util.getCraftClass("Entity"); Class<?> EntityLiving = Util.getCraftClass("EntityLiving"); Class<?> EntityEnderDragon = Util.getCraftClass("EntityEnderDragon"); Object packet = null;/* ww w . j a v a2 s . c o m*/ try { this.dragon = EntityEnderDragon.getConstructor(new Class[] { Util.getCraftClass("World") }) .newInstance(new Object[] { getWorld() }); Method setLocation = Util.getMethod(EntityEnderDragon, "setLocation", new Class[] { Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE }); setLocation.invoke(this.dragon, new Object[] { Integer.valueOf(getX()), Integer.valueOf(getY()), Integer.valueOf(getZ()), Integer.valueOf(getPitch()), Integer.valueOf(getYaw()) }); Method setInvisible = Util.getMethod(EntityEnderDragon, "setInvisible", new Class[] { Boolean.TYPE }); setInvisible.invoke(this.dragon, new Object[] { Boolean.valueOf(isVisible()) }); Method setCustomName = Util.getMethod(EntityEnderDragon, "setCustomName", new Class[] { String.class }); setCustomName.invoke(this.dragon, new Object[] { this.name }); Method setHealth = Util.getMethod(EntityEnderDragon, "setHealth", new Class[] { Float.TYPE }); setHealth.invoke(this.dragon, new Object[] { Float.valueOf(this.health) }); Field motX = Util.getField(Entity, "motX"); motX.set(this.dragon, Byte.valueOf(getXvel())); Field motY = Util.getField(Entity, "motY"); motY.set(this.dragon, Byte.valueOf(getYvel())); Field motZ = Util.getField(Entity, "motZ"); motZ.set(this.dragon, Byte.valueOf(getZvel())); Method getId = Util.getMethod(EntityEnderDragon, "getId", new Class[0]); this.id = ((Number) getId.invoke(this.dragon, new Object[0])).intValue(); Class<?> PacketPlayOutSpawnEntityLiving = Util.getCraftClass("PacketPlayOutSpawnEntityLiving"); packet = PacketPlayOutSpawnEntityLiving.getConstructor(new Class[] { EntityLiving }) .newInstance(new Object[] { this.dragon }); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return packet; }
From source file:com.thinkbiganalytics.policy.BasePolicyAnnotationTransformer.java
public Object convertStringToObject(String value, Class type) { if (type.isEnum()) { return Enum.valueOf(type, value); } else if (String.class.equals(type)) { return value; }//from w w w. j av a 2 s . co m if (StringUtils.isBlank(value)) { return null; } else if (Number.class.equals(type)) { return NumberUtils.createNumber(value); } else if (Integer.class.equals(type) || Integer.TYPE.equals(type)) { return new Integer(value); } else if (Long.class.equals(type) || Long.TYPE.equals(type)) { return Long.valueOf(value); } else if (Double.class.equals(type) || Double.TYPE.equals(type)) { return Double.valueOf(value); } else if (Float.class.equals(type) || Float.TYPE.equals(type)) { return Float.valueOf(value); } else if (Pattern.class.equals(type)) { return Pattern.compile(value); } else if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) { return BooleanUtils.toBoolean(value); } else { throw new IllegalArgumentException( "Unable to convert the value " + value + " to an object of type " + type.getName()); } }
From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java
/** * Write a {@link Writable}, {@link String}, primitive type, or an array of * the preceding.//from w w w . j a v a 2s .c o m * @param out * @param instance * @param declaredClass * @param conf * @throws IOException */ @SuppressWarnings("unchecked") public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf) throws IOException { Object instanceObj = instance; Class declClass = declaredClass; if (instanceObj == null) { // null instanceObj = new NullInstance(declClass, conf); declClass = Writable.class; } writeClassCode(out, declClass); if (declClass.isArray()) { // array // If bytearray, just dump it out -- avoid the recursion and // byte-at-a-time we were previously doing. if (declClass.equals(byte[].class)) { Bytes.writeByteArray(out, (byte[]) instanceObj); } else if (declClass.equals(Result[].class)) { Result.writeArray(out, (Result[]) instanceObj); } else { //if it is a Generic array, write the element's type if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) { Class<?> componentType = declaredClass.getComponentType(); writeClass(out, componentType); } int length = Array.getLength(instanceObj); out.writeInt(length); for (int i = 0; i < length; i++) { Object item = Array.get(instanceObj, i); writeObject(out, item, item.getClass(), conf); } } } else if (List.class.isAssignableFrom(declClass)) { List list = (List) instanceObj; int length = list.size(); out.writeInt(length); for (int i = 0; i < length; i++) { Object elem = list.get(i); writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf); } } else if (declClass == String.class) { // String Text.writeString(out, (String) instanceObj); } else if (declClass.isPrimitive()) { // primitive type if (declClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instanceObj).booleanValue()); } else if (declClass == Character.TYPE) { // char out.writeChar(((Character) instanceObj).charValue()); } else if (declClass == Byte.TYPE) { // byte out.writeByte(((Byte) instanceObj).byteValue()); } else if (declClass == Short.TYPE) { // short out.writeShort(((Short) instanceObj).shortValue()); } else if (declClass == Integer.TYPE) { // int out.writeInt(((Integer) instanceObj).intValue()); } else if (declClass == Long.TYPE) { // long out.writeLong(((Long) instanceObj).longValue()); } else if (declClass == Float.TYPE) { // float out.writeFloat(((Float) instanceObj).floatValue()); } else if (declClass == Double.TYPE) { // double out.writeDouble(((Double) instanceObj).doubleValue()); } else if (declClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declClass); } } else if (declClass.isEnum()) { // enum Text.writeString(out, ((Enum) instanceObj).name()); } else if (Message.class.isAssignableFrom(declaredClass)) { Text.writeString(out, instanceObj.getClass().getName()); ((Message) instance).writeDelimitedTo(DataOutputOutputStream.constructOutputStream(out)); } else if (Writable.class.isAssignableFrom(declClass)) { // Writable Class<?> c = instanceObj.getClass(); Integer code = CLASS_TO_CODE.get(c); if (code == null) { out.writeByte(NOT_ENCODED); Text.writeString(out, c.getName()); } else { writeClassCode(out, c); } ((Writable) instanceObj).write(out); } else if (Serializable.class.isAssignableFrom(declClass)) { Class<?> c = instanceObj.getClass(); Integer code = CLASS_TO_CODE.get(c); if (code == null) { out.writeByte(NOT_ENCODED); Text.writeString(out, c.getName()); } else { writeClassCode(out, c); } ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(instanceObj); byte[] value = bos.toByteArray(); out.writeInt(value.length); out.write(value); } finally { if (bos != null) bos.close(); if (oos != null) oos.close(); } } else { throw new IOException("Can't write: " + instanceObj + " as " + declClass); } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>/* w w w . j ava2 s .co m*/ * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a long to the given primitive number class *//* w ww . j av a 2 s . c o m*/ static Number coerceToPrimitiveNumber(long pValue, Class pClass) throws ElException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte((byte) pValue); } else if (pClass == Short.class || pClass == Short.TYPE) { return PrimitiveObjects.getShort((short) pValue); } else if (pClass == Integer.class || pClass == Integer.TYPE) { return PrimitiveObjects.getInteger((int) pValue); } else if (pClass == Long.class || pClass == Long.TYPE) { return PrimitiveObjects.getLong(pValue); } else if (pClass == Float.class || pClass == Float.TYPE) { return PrimitiveObjects.getFloat((float) pValue); } else if (pClass == Double.class || pClass == Double.TYPE) { return PrimitiveObjects.getDouble((double) pValue); } else { return PrimitiveObjects.getInteger(0); } }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns the virtual machine's Class object for the named primitive type.<br/> * If the type is not a primitive type, {@code null} is returned. * * @param name the name of the type//w w w . j av a 2s . com * @return the Class instance representing the primitive type */ private static Class<?> getPrimitiveType(String name) { name = StringUtils.defaultIfEmpty(name, ""); if (name.equals("int")) return Integer.TYPE; if (name.equals("short")) return Short.TYPE; if (name.equals("long")) return Long.TYPE; if (name.equals("float")) return Float.TYPE; if (name.equals("double")) return Double.TYPE; if (name.equals("byte")) return Byte.TYPE; if (name.equals("char")) return Character.TYPE; if (name.equals("boolean")) return Boolean.TYPE; if (name.equals("void")) return Void.TYPE; return null; }