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:org.apache.hadoop.hbase.io.HbaseObjectWritable.java
/** * Write a {@link Writable}, {@link String}, primitive type, or an array of * the preceding./*from ww w . j a va 2s . com*/ * @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: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;/* w w w . j av a 2s . co 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 a v a 2 s . c o 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:com.sun.faces.el.impl.Coercions.java
/** * Coerces a long to the given primitive number class *///from w w w . ja v a2s. 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: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>/*from ww w .j av a 2s. c o 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: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//from w w w .j av a 2 s. 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; }
From source file:wicket.util.lang.Objects.java
/** * Returns the value converted numerically to the given class type * /*from w ww .ja v a 2 s. co m*/ * This method also detects when arrays are being converted and converts the * components of one array to the type of the other. * * @param value * an object to be converted to the given type * @param toType * class type to be converted to * @return converted value of the type given, or value if the value cannot * be converted to the given type. */ public static Object convertValue(Object value, Class toType) { Object result = null; if (value != null) { /* If array -> array then convert components of array individually */ if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) { result = new Integer((int) longValue(value)); } if ((toType == Double.class) || (toType == Double.TYPE)) { result = new Double(doubleValue(value)); } if ((toType == Boolean.class) || (toType == Boolean.TYPE)) { result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; } if ((toType == Byte.class) || (toType == Byte.TYPE)) { result = new Byte((byte) longValue(value)); } if ((toType == Character.class) || (toType == Character.TYPE)) { result = new Character((char) longValue(value)); } if ((toType == Short.class) || (toType == Short.TYPE)) { result = new Short((short) longValue(value)); } if ((toType == Long.class) || (toType == Long.TYPE)) { result = new Long(longValue(value)); } if ((toType == Float.class) || (toType == Float.TYPE)) { result = new Float(doubleValue(value)); } if (toType == BigInteger.class) { result = bigIntValue(value); } if (toType == BigDecimal.class) { result = bigDecValue(value); } if (toType == String.class) { result = stringValue(value); } } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:com.offbynull.coroutines.instrumenter.MethodAnalyzer.java
private CacheVariables allocateCacheVariableSlots(VariableTable varTable, TypeTracker invocationReturnTypes, boolean invocationFoundWrappedInTryCatch) { Variable intReturnCacheVar = null;/*from w w w .j a v a 2 s. com*/ Variable longReturnCacheVar = null; Variable floatReturnCacheVar = null; Variable doubleReturnCacheVar = null; Variable objectReturnCacheVar = null; Variable throwableCacheVar = null; if (invocationReturnTypes.intFound) { intReturnCacheVar = varTable.acquireExtra(Integer.TYPE); } if (invocationReturnTypes.longFound) { longReturnCacheVar = varTable.acquireExtra(Long.TYPE); } if (invocationReturnTypes.floatFound) { floatReturnCacheVar = varTable.acquireExtra(Float.TYPE); } if (invocationReturnTypes.doubleFound) { doubleReturnCacheVar = varTable.acquireExtra(Double.TYPE); } if (invocationReturnTypes.objectFound) { objectReturnCacheVar = varTable.acquireExtra(Object.class); } if (invocationFoundWrappedInTryCatch) { throwableCacheVar = varTable.acquireExtra(Throwable.class); } return new CacheVariables(intReturnCacheVar, longReturnCacheVar, floatReturnCacheVar, doubleReturnCacheVar, objectReturnCacheVar, throwableCacheVar); }
From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java
public static Class<?> getTypeForPrimitive(Class<?> primitiveType) { if (primitiveType == Boolean.TYPE) { return Boolean.class; } else if (primitiveType == Integer.TYPE) { return Integer.class; } else if (primitiveType == Long.TYPE) { return Long.class; } else if (primitiveType == Float.TYPE) { return Float.class; } else if (primitiveType == Double.TYPE) { return Double.class; } else if (primitiveType == Character.TYPE) { return Character.class; } else if (primitiveType == Byte.TYPE) { return Byte.class; } else if (primitiveType == Short.TYPE) { return Short.class; }/*from w ww . ja v a 2 s. c om*/ return primitiveType; }
From source file:org.apache.jasper.compiler.JspUtil.java
/** * Produces a String representing a call to the EL interpreter. * @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. *//*from w w w .j a v a2s.co m*/ 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 = "pageContext"; /* * 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); StringBuffer call = new StringBuffer( "(" + targetType + ") " + "org.apache.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(); }