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:cn.annoreg.mc.s11n.SerializationManager.java
private void initInternalSerializers() { //First part: java internal class. {/* ww w. j a v a 2 s .co m*/ InstanceSerializer ser = new InstanceSerializer<Enum>() { @Override public Enum readInstance(NBTBase nbt) throws Exception { NBTTagCompound tag = (NBTTagCompound) nbt; try { Class enumClass = Class.forName(tag.getString("class")); Object[] objs = (Object[]) enumClass.getMethod("values").invoke(null); return (Enum) objs[tag.getInteger("ordinal")]; } catch (Exception e) { ARModContainer.log.error("Failed in enum deserialization. Class: {}.", tag.getString("class")); e.printStackTrace(); return null; } } @Override public NBTBase writeInstance(Enum obj) throws Exception { NBTTagCompound ret = new NBTTagCompound(); ret.setString("class", obj.getClass().getName()); ret.setByte("ordinal", (byte) ((Enum) obj).ordinal()); return ret; } }; setInstanceSerializerFor(Enum.class, ser); } { DataSerializer ser = new DataSerializer<Byte>() { @Override public Byte readData(NBTBase nbt, Byte obj) throws Exception { return ((NBTTagByte) nbt).func_150290_f(); } @Override public NBTBase writeData(Byte obj) throws Exception { return new NBTTagByte(obj); } }; setDataSerializerFor(Byte.TYPE, ser); setDataSerializerFor(Byte.class, ser); } { DataSerializer ser = new DataSerializer<Byte[]>() { @Override public Byte[] readData(NBTBase nbt, Byte[] obj) throws Exception { return ArrayUtils.toObject(((NBTTagByteArray) nbt).func_150292_c()); } @Override public NBTBase writeData(Byte[] obj) throws Exception { return new NBTTagByteArray(ArrayUtils.toPrimitive(obj)); } }; setDataSerializerFor(Byte[].class, ser); } { DataSerializer ser = new DataSerializer<byte[]>() { @Override public byte[] readData(NBTBase nbt, byte[] obj) throws Exception { return ((NBTTagByteArray) nbt).func_150292_c(); } @Override public NBTBase writeData(byte[] obj) throws Exception { return new NBTTagByteArray(obj); } }; setDataSerializerFor(byte[].class, ser); } { DataSerializer ser = new DataSerializer<Double>() { @Override public Double readData(NBTBase nbt, Double obj) throws Exception { return ((NBTTagDouble) nbt).func_150286_g(); } @Override public NBTBase writeData(Double obj) throws Exception { return new NBTTagDouble(obj); } }; setDataSerializerFor(Double.TYPE, ser); setDataSerializerFor(Double.class, ser); } { DataSerializer ser = new DataSerializer<Float>() { @Override public Float readData(NBTBase nbt, Float obj) throws Exception { return ((NBTTagFloat) nbt).func_150288_h(); } @Override public NBTBase writeData(Float obj) throws Exception { return new NBTTagFloat(obj); } }; setDataSerializerFor(Float.TYPE, ser); setDataSerializerFor(Float.class, ser); } { DataSerializer ser = new DataSerializer<Integer>() { @Override public Integer readData(NBTBase nbt, Integer obj) throws Exception { return ((NBTTagInt) nbt).func_150287_d(); } @Override public NBTBase writeData(Integer obj) throws Exception { return new NBTTagInt(obj); } }; setDataSerializerFor(Integer.TYPE, ser); setDataSerializerFor(Integer.class, ser); } { DataSerializer ser = new DataSerializer<Integer[]>() { @Override public Integer[] readData(NBTBase nbt, Integer[] obj) throws Exception { return ArrayUtils.toObject(((NBTTagIntArray) nbt).func_150302_c()); } @Override public NBTBase writeData(Integer[] obj) throws Exception { return new NBTTagIntArray(ArrayUtils.toPrimitive(obj)); } }; setDataSerializerFor(Integer[].class, ser); } { DataSerializer ser = new DataSerializer<int[]>() { @Override public int[] readData(NBTBase nbt, int[] obj) throws Exception { return ((NBTTagIntArray) nbt).func_150302_c(); } @Override public NBTBase writeData(int[] obj) throws Exception { return new NBTTagIntArray(obj); } }; setDataSerializerFor(int[].class, ser); } { DataSerializer ser = new DataSerializer<Long>() { @Override public Long readData(NBTBase nbt, Long obj) throws Exception { return ((NBTTagLong) nbt).func_150291_c(); } @Override public NBTBase writeData(Long obj) throws Exception { return new NBTTagLong(obj); } }; setDataSerializerFor(Long.TYPE, ser); setDataSerializerFor(Long.class, ser); } { DataSerializer ser = new DataSerializer<Short>() { @Override public Short readData(NBTBase nbt, Short obj) throws Exception { return ((NBTTagShort) nbt).func_150289_e(); } @Override public NBTBase writeData(Short obj) throws Exception { return new NBTTagShort(obj); } }; setDataSerializerFor(Short.TYPE, ser); setDataSerializerFor(Short.class, ser); } { DataSerializer ser = new DataSerializer<String>() { @Override public String readData(NBTBase nbt, String obj) throws Exception { return ((NBTTagString) nbt).func_150285_a_(); } @Override public NBTBase writeData(String obj) throws Exception { return new NBTTagString(obj); } }; setDataSerializerFor(String.class, ser); } { //TODO: Maybe there is a more data-friendly method? DataSerializer ser = new DataSerializer<Boolean>() { @Override public Boolean readData(NBTBase nbt, Boolean obj) throws Exception { return ((NBTTagCompound) nbt).getBoolean("v"); } @Override public NBTBase writeData(Boolean obj) throws Exception { NBTTagCompound tag = new NBTTagCompound(); tag.setBoolean("v", obj); return tag; } }; setDataSerializerFor(Boolean.class, ser); setDataSerializerFor(Boolean.TYPE, ser); } //Second part: Minecraft objects. { DataSerializer ser = new DataSerializer<NBTTagCompound>() { @Override public NBTTagCompound readData(NBTBase nbt, NBTTagCompound obj) throws Exception { return (NBTTagCompound) nbt; } @Override public NBTBase writeData(NBTTagCompound obj) throws Exception { return obj; } }; setDataSerializerFor(NBTTagCompound.class, ser); } { InstanceSerializer ser = new InstanceSerializer<Entity>() { @Override public Entity readInstance(NBTBase nbt) throws Exception { int[] ids = ((NBTTagIntArray) nbt).func_150302_c(); World world = SideHelper.getWorld(ids[0]); if (world != null) { return world.getEntityByID(ids[1]); } return null; } @Override public NBTBase writeInstance(Entity obj) throws Exception { return new NBTTagIntArray(new int[] { obj.dimension, obj.getEntityId() }); } }; setInstanceSerializerFor(Entity.class, ser); } { InstanceSerializer ser = new InstanceSerializer<TileEntity>() { @Override public TileEntity readInstance(NBTBase nbt) throws Exception { int[] ids = ((NBTTagIntArray) nbt).func_150302_c(); World world = SideHelper.getWorld(ids[0]); if (world != null) { return world.getTileEntity(ids[1], ids[2], ids[3]); } return null; } @Override public NBTBase writeInstance(TileEntity obj) throws Exception { return new NBTTagIntArray(new int[] { obj.getWorldObj().provider.dimensionId, obj.xCoord, obj.yCoord, obj.zCoord }); } }; setInstanceSerializerFor(TileEntity.class, ser); } { //TODO this implementation can not be used to serialize player's inventory container. InstanceSerializer ser = new InstanceSerializer<Container>() { @Override public Container readInstance(NBTBase nbt) throws Exception { int[] ids = ((NBTTagIntArray) nbt).func_150302_c(); World world = SideHelper.getWorld(ids[0]); if (world != null) { Entity entity = world.getEntityByID(ids[1]); if (entity instanceof EntityPlayer) { return SideHelper.getPlayerContainer((EntityPlayer) entity, ids[2]); } } return SideHelper.getPlayerContainer(null, ids[2]); } @Override public NBTBase writeInstance(Container obj) throws Exception { EntityPlayer player = SideHelper.getThePlayer(); if (player != null) { //This is on client. The server needs player to get the Container. return new NBTTagIntArray(new int[] { player.worldObj.provider.dimensionId, player.getEntityId(), obj.windowId }); } else { //This is on server. The client doesn't need player (just use thePlayer), use MAX_VALUE here. return new NBTTagIntArray(new int[] { Integer.MAX_VALUE, 0, obj.windowId }); } } }; setInstanceSerializerFor(Container.class, ser); } { InstanceSerializer ser = new InstanceSerializer<World>() { @Override public World readInstance(NBTBase nbt) throws Exception { return SideHelper.getWorld(((NBTTagInt) nbt).func_150287_d()); } @Override public NBTBase writeInstance(World obj) throws Exception { return new NBTTagInt(obj.provider.dimensionId); } }; setInstanceSerializerFor(World.class, ser); } { DataSerializer ser = new DataSerializer<ItemStack>() { @Override public ItemStack readData(NBTBase nbt, ItemStack obj) throws Exception { if (obj == null) { return ItemStack.loadItemStackFromNBT((NBTTagCompound) nbt); } else { obj.readFromNBT((NBTTagCompound) nbt); return obj; } } @Override public NBTBase writeData(ItemStack obj) throws Exception { NBTTagCompound nbt = new NBTTagCompound(); obj.writeToNBT(nbt); return nbt; } }; setDataSerializerFor(ItemStack.class, ser); } { DataSerializer ser = new DataSerializer<Vec3>() { @Override public Vec3 readData(NBTBase nbt, Vec3 obj) throws Exception { NBTTagCompound tag = (NBTTagCompound) nbt; return Vec3.createVectorHelper(tag.getFloat("x"), tag.getFloat("y"), tag.getFloat("z")); } @Override public NBTBase writeData(Vec3 obj) throws Exception { NBTTagCompound nbt = new NBTTagCompound(); nbt.setFloat("x", (float) obj.xCoord); nbt.setFloat("y", (float) obj.yCoord); nbt.setFloat("z", (float) obj.zCoord); return nbt; } }; setDataSerializerFor(Vec3.class, ser); } //network part { DataSerializer ser = new DataSerializer<NetworkTerminal>() { @Override public NetworkTerminal readData(NBTBase nbt, NetworkTerminal obj) throws Exception { return NetworkTerminal.fromNBT(nbt); } @Override public NBTBase writeData(NetworkTerminal obj) throws Exception { return obj.toNBT(); } }; setDataSerializerFor(NetworkTerminal.class, ser); } { Future.FutureSerializer ser = new Future.FutureSerializer(); setDataSerializerFor(Future.class, ser); setInstanceSerializerFor(Future.class, ser); } //misc { DataSerializer ser = new DataSerializer<BitSet>() { @Override public BitSet readData(NBTBase nbt, BitSet obj) throws Exception { NBTTagCompound tag = (NBTTagCompound) nbt; BitSet ret = BitSet.valueOf(tag.getByteArray("l")); return ret; } @Override public NBTBase writeData(BitSet obj) throws Exception { NBTTagCompound tag = new NBTTagCompound(); byte[] barray = obj.toByteArray(); tag.setByteArray("l", barray); return tag; } }; setDataSerializerFor(BitSet.class, ser); } }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testUnaryNumericPromotion() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class); List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath( "//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericPromotion']]//Expression[UnaryExpression]"), ASTExpression.class); int index = 0; assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // Make sure we got them all. assertEquals("All expressions not tested", index, expressions.size()); }
From source file:javadz.beanutils.locale.LocaleConvertUtilsBean.java
/** * Create all {@link LocaleConverter} types for specified locale. * * @param locale The Locale//from ww w . jav a 2 s .c o m * @return The FastHashMap instance contains the all {@link LocaleConverter} types * for the specified locale. * @deprecated This method will be modified to return a Map in the next release. */ protected FastHashMap create(Locale locale) { FastHashMap converter = new DelegateFastHashMap(BeanUtils.createCache()); 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
protected void setField(Field field, String val) { try {// w w w .j a v a 2s. com // deal with IllegalAccessException field.setAccessible(true); if (field.getType() == String.class) { field.set(this, val); } else { Method setter = null; try { setter = this.getClass().getMethod("set" + StringUtil.getTitleCase(field.getName()), String.class); } catch (Exception e) { } if (null != setter) { setter.setAccessible(true); setter.invoke(this, val); } else if (field.getType() == Integer.TYPE) { field.setInt(this, Integer.parseInt(val)); } else if (field.getType() == Float.TYPE) { field.setFloat(this, Float.parseFloat(val)); } else if (field.getType() == Double.TYPE) { field.setDouble(this, Double.parseDouble(val)); } else if (field.getType() == Long.TYPE) { field.setLong(this, Long.parseLong(val)); } else if (field.getType() == Boolean.TYPE) { Boolean bval = StringUtils.isBlank(val) ? null : NumberUtils.isNumber(val) ? (Integer.parseInt(val) != 0) : Boolean.parseBoolean(val) || val.equalsIgnoreCase("T") || val.equalsIgnoreCase("Y") || val.equalsIgnoreCase("YES"); field.setBoolean(this, bval); } else if (field.getType() == Short.TYPE) { field.setShort(this, Short.parseShort(val)); } else if (field.getType() == Date.class) { Date dVal = null; try { dVal = StringUtils.isBlank(val) ? null : NumberUtils.isNumber(val) ? DateUtil.getDate(Integer.parseInt(val)) : DateUtil.parseDate(val, "MM/dd/yyyy"); } catch (ParseException e) { logger.error("Expected date in MM/dd/yyyy format.", e); } field.set(this, dVal); } } } 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 invoke setter for " + field.getName(), e); } }
From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.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 ww . j ava 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(byte[].class)) { return rs.getBytes(index); } else { return rs.getObject(index); } }
From source file:au.com.addstar.cellblock.configuration.AutoConfig.java
public boolean save() { try {//from ww w.j a va2s . c om onPreSave(); YamlConfiguration config = new YamlConfiguration(); Map<String, String> comments = new HashMap<>(); // Add all the category comments comments.putAll(mCategoryComments); // Add all the values for (Field field : getClass().getDeclaredFields()) { ConfigField configField = field.getAnnotation(ConfigField.class); if (configField == null) continue; String optionName = configField.name(); if (optionName.isEmpty()) optionName = field.getName(); field.setAccessible(true); String path = (configField.category().isEmpty() ? "" : configField.category() + ".") + optionName; //$NON-NLS-2$ // Ensure the secion exists if (!configField.category().isEmpty() && !config.contains(configField.category())) config.createSection(configField.category()); if (field.getType().isArray()) { // Integer if (field.getType().getComponentType().equals(Integer.TYPE)) config.set(path, Arrays.asList((Integer[]) field.get(this))); // Float else if (field.getType().getComponentType().equals(Float.TYPE)) config.set(path, Arrays.asList((Float[]) field.get(this))); // Double else if (field.getType().getComponentType().equals(Double.TYPE)) config.set(path, Arrays.asList((Double[]) field.get(this))); // Long else if (field.getType().getComponentType().equals(Long.TYPE)) config.set(path, Arrays.asList((Long[]) field.get(this))); // Short else if (field.getType().getComponentType().equals(Short.TYPE)) config.set(path, Arrays.asList((Short[]) field.get(this))); // Boolean else if (field.getType().getComponentType().equals(Boolean.TYPE)) config.set(path, Arrays.asList((Boolean[]) field.get(this))); // String else if (field.getType().getComponentType().equals(String.class)) config.set(path, Arrays.asList((String[]) field.get(this))); else throw new IllegalArgumentException( "Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-2$ } else if (List.class.isAssignableFrom(field.getType())) { if (field.getGenericType() == null) throw new IllegalArgumentException( "Cannot use type List without specifying generic type for AutoConfiguration"); Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (type.equals(Integer.class) || type.equals(Float.class) || type.equals(Double.class) || type.equals(Long.class) || type.equals(Short.class) || type.equals(Boolean.class) || type.equals(String.class)) { config.set(path, field.get(this)); } else throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName() + "<" + type.toString() + "> for AutoConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$ } else if (Set.class.isAssignableFrom(field.getType())) { if (field.getGenericType() == null) throw new IllegalArgumentException( "Cannot use type Set without specifying generic type for AutoConfiguration"); Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (type.equals(Integer.class) || type.equals(Float.class) || type.equals(Double.class) || type.equals(Long.class) || type.equals(Short.class) || type.equals(Boolean.class) || type.equals(String.class)) { config.set(path, new ArrayList<Object>((Set<?>) field.get(this))); } else throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName() + "<" + type.toString() + "> for AutoConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$ } else { // Integer if (field.getType().equals(Integer.TYPE)) config.set(path, field.get(this)); // Float else if (field.getType().equals(Float.TYPE)) config.set(path, field.get(this)); // Double else if (field.getType().equals(Double.TYPE)) config.set(path, field.get(this)); // Long else if (field.getType().equals(Long.TYPE)) config.set(path, field.get(this)); // Short else if (field.getType().equals(Short.TYPE)) config.set(path, field.get(this)); // Boolean else if (field.getType().equals(Boolean.TYPE)) config.set(path, field.get(this)); // ItemStack else if (field.getType().equals(ItemStack.class)) config.set(path, field.get(this)); // String else if (field.getType().equals(String.class)) config.set(path, field.get(this)); else throw new IllegalArgumentException( "Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-2$ } // Record the comment if (!configField.comment().isEmpty()) comments.put(path, configField.comment()); } String output = config.saveToString(); // Apply comments String category = ""; List<String> lines = new ArrayList<>(Arrays.asList(output.split("\n"))); for (int l = 0; l < lines.size(); l++) { String line = lines.get(l); if (line.startsWith("#")) continue; if (line.trim().startsWith("-")) continue; if (!line.contains(":")) continue; String path; line = line.substring(0, line.indexOf(":")); if (line.startsWith(" ")) path = category + "." + line.substring(2).trim(); else { category = line.trim(); path = line.trim(); } if (comments.containsKey(path)) { String indent = ""; for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == ' ') indent += " "; else break; } // Add in the comment lines String[] commentLines = comments.get(path).split("\n"); lines.add(l++, ""); for (int i = 0; i < commentLines.length; i++) { commentLines[i] = indent + "# " + commentLines[i]; lines.add(l++, commentLines[i]); } } } output = ""; for (String line : lines) output += line + "\n"; FileWriter writer = new FileWriter(mFile); writer.write(output); writer.close(); return true; } catch (IllegalArgumentException | IOException | IllegalAccessException e) { e.printStackTrace(); } return false; }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testBinaryNumericPromotion() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class); List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath( "//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericPromotion']]//Expression[AdditiveExpression]"), ASTExpression.class); int index = 0; // LHS = byte assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // LHS = short assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // LHS = char assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // LHS = int// w w w .j a v a2 s.c o m assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // LHS = long assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // LHS = float assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // LHS = double assertEquals(Double.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // Make sure we got them all. assertEquals("All expressions not tested", index, expressions.size()); }
From source file:org.enerj.apache.commons.beanutils.ConvertUtilsBean.java
/** * Remove all registered {@link Converter}s, and re-establish the * standard Converters.//from w w w . ja v a2 s .co m */ public void deregister() { boolean booleanArray[] = new boolean[0]; byte byteArray[] = new byte[0]; char charArray[] = new char[0]; double doubleArray[] = new double[0]; float floatArray[] = new float[0]; int intArray[] = new int[0]; long longArray[] = new long[0]; short shortArray[] = new short[0]; String stringArray[] = new String[0]; converters.clear(); register(BigDecimal.class, new BigDecimalConverter()); register(BigInteger.class, new BigIntegerConverter()); register(Boolean.TYPE, new BooleanConverter(defaultBoolean)); register(Boolean.class, new BooleanConverter(defaultBoolean)); register(booleanArray.getClass(), new BooleanArrayConverter(booleanArray)); register(Byte.TYPE, new ByteConverter(defaultByte)); register(Byte.class, new ByteConverter(defaultByte)); register(byteArray.getClass(), new ByteArrayConverter(byteArray)); register(Character.TYPE, new CharacterConverter(defaultCharacter)); register(Character.class, new CharacterConverter(defaultCharacter)); register(charArray.getClass(), new CharacterArrayConverter(charArray)); register(Class.class, new ClassConverter()); register(Double.TYPE, new DoubleConverter(defaultDouble)); register(Double.class, new DoubleConverter(defaultDouble)); register(doubleArray.getClass(), new DoubleArrayConverter(doubleArray)); register(Float.TYPE, new FloatConverter(defaultFloat)); register(Float.class, new FloatConverter(defaultFloat)); register(floatArray.getClass(), new FloatArrayConverter(floatArray)); register(Integer.TYPE, new IntegerConverter(defaultInteger)); register(Integer.class, new IntegerConverter(defaultInteger)); register(intArray.getClass(), new IntegerArrayConverter(intArray)); register(Long.TYPE, new LongConverter(defaultLong)); register(Long.class, new LongConverter(defaultLong)); register(longArray.getClass(), new LongArrayConverter(longArray)); register(Short.TYPE, new ShortConverter(defaultShort)); register(Short.class, new ShortConverter(defaultShort)); register(shortArray.getClass(), new ShortArrayConverter(shortArray)); register(String.class, new StringConverter()); register(stringArray.getClass(), new StringArrayConverter(stringArray)); register(Date.class, new SqlDateConverter()); register(Time.class, new SqlTimeConverter()); register(Timestamp.class, new SqlTimestampConverter()); register(File.class, new FileConverter()); register(URL.class, new URLConverter()); }
From source file:org.talend.components.netsuite.NetSuiteDatasetRuntimeImpl.java
/** * Infers an Avro schema for the given FieldDesc. This can be an expensive operation so the schema should be * cached where possible. The return type will be the Avro Schema that can contain the fieldDesc data without loss of * precision./*w w w.jav a 2 s . c o m*/ * * @param fieldDesc the <code>FieldDesc</code> to analyse. * @return the schema for data that the fieldDesc describes. */ public static Schema inferSchemaForField(FieldDesc fieldDesc) { Schema base; if (fieldDesc instanceof CustomFieldDesc) { CustomFieldDesc customFieldInfo = (CustomFieldDesc) fieldDesc; CustomFieldRefType customFieldRefType = customFieldInfo.getCustomFieldType(); if (customFieldRefType == CustomFieldRefType.BOOLEAN) { base = AvroUtils._boolean(); } else if (customFieldRefType == CustomFieldRefType.LONG) { base = AvroUtils._long(); } else if (customFieldRefType == CustomFieldRefType.DOUBLE) { base = AvroUtils._double(); } else if (customFieldRefType == CustomFieldRefType.DATE) { base = AvroUtils._logicalTimestamp(); } else if (customFieldRefType == CustomFieldRefType.STRING) { base = AvroUtils._string(); } else { base = AvroUtils._string(); } } else { Class<?> fieldType = fieldDesc.getValueType(); if (fieldType == Boolean.TYPE || fieldType == Boolean.class) { base = AvroUtils._boolean(); } else if (fieldType == Integer.TYPE || fieldType == Integer.class) { base = AvroUtils._int(); } else if (fieldType == Long.TYPE || fieldType == Long.class) { base = AvroUtils._long(); } else if (fieldType == Float.TYPE || fieldType == Float.class) { base = AvroUtils._float(); } else if (fieldType == Double.TYPE || fieldType == Double.class) { base = AvroUtils._double(); } else if (fieldType == XMLGregorianCalendar.class) { base = AvroUtils._logicalTimestamp(); } else if (fieldType == String.class) { base = AvroUtils._string(); } else if (fieldType.isEnum()) { base = AvroUtils._string(); } else { base = AvroUtils._string(); } } base = fieldDesc.isNullable() ? AvroUtils.wrapAsNullable(base) : base; return base; }
From source file:wicket.util.lang.Objects.java
/** * Returns the value converted numerically to the given class type * /*from w w w . ja v a 2s . c o 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; }