Example usage for java.lang Float TYPE

List of usage examples for java.lang Float TYPE

Introduction

In this page you can find the example usage for java.lang Float TYPE.

Prototype

Class TYPE

To view the source code for java.lang Float TYPE.

Click Source Link

Document

The Class instance representing the primitive type float .

Usage

From source file:cn.annoreg.mc.s11n.SerializationManager.java

private void initInternalSerializers() {
    //First part: java internal class.
    {/*from   ww w.j a va 2  s . c o 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:au.com.addstar.cellblock.configuration.AutoConfig.java

public boolean save() {
    try {//  w  ww  . j ava  2s. c o m
        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: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>/*from  w ww. j a  va2  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(byte[].class)) {
        return rs.getBytes(index);

    } else {
        return rs.getObject(index);

    }

}

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  ww  . j  av a  2s  .c  om*/
    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.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./*from w w  w .j ava  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:org.enerj.apache.commons.beanutils.ConvertUtilsBean.java

/**
 * Remove all registered {@link Converter}s, and re-establish the
 * standard Converters.//from ww w . j  a va2s.  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.apache.struts2.jasper.compiler.JspUtil.java

/**
 * Produces a String representing a call to the EL interpreter.
 *
 * @param isTagFile    is a tag file//  w  ww  .  j  a v  a2s. c o m
 * @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: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 ww  . ja v  a  2  s.  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.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java

/**
 * Write a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.//from   w w  w  .j  ava 2  s  . 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.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

private final Class<?> getClassForName(String type) {
    try {// w  w w  . ja  va  2s.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);
    }
}