Example usage for java.lang Integer TYPE

List of usage examples for java.lang Integer TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type int .

Usage

From source file:javadz.beanutils.locale.LocaleConvertUtilsBean.java

/**
 *  Create all {@link LocaleConverter} types for specified locale.
 *
 * @param locale The Locale//from  ww w  .ja  v a 2s .  co 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:au.com.addstar.cellblock.configuration.AutoConfig.java

public boolean save() {
    try {/*from  ww w. j  a  v a2s. 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: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//  ww w. j  a va2  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:cn.annoreg.mc.s11n.SerializationManager.java

private void initInternalSerializers() {
    //First part: java internal class.
    {/*from  ww  w  . j  av a2  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:org.eclipse.wb.internal.swing.model.property.editor.accelerator.KeyStrokePropertyEditor.java

/**
 * Prepares {@link Map}'s for key code/name conversion.
 *///from   w  w  w .j  av  a 2s. c o m
private static synchronized void prepareKeyMaps() {
    if (m_keyCodeToName == null) {
        m_keyFields = Lists.newArrayList();
        m_keyCodeToName = Maps.newTreeMap();
        m_keyNameToCode = Maps.newTreeMap();
        // add fields
        try {
            int expected_modifiers = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
            Field[] fields = KeyEvent.class.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                if (field.getModifiers() == expected_modifiers && field.getType() == Integer.TYPE
                        && field.getName().startsWith("VK_")) {
                    String name = field.getName().substring(3);
                    Integer value = (Integer) field.get(null);
                    m_keyFields.add(name);
                    m_keyCodeToName.put(value, name);
                    m_keyNameToCode.put(name, value);
                }
            }
        } catch (Throwable e) {
            DesignerPlugin.log(e);
        }
    }
}

From source file:rb.app.RBSystem.java

/**
 * Evaluate theta_q_f (for the q^th rhs function) at the current parameter.
 *//*w w  w.ja  va 2s  . c  o  m*/
public double eval_theta_q_f(int q) {
    Method meth;

    try {
        // Get a reference to get_n_L_functions, which does not
        // take any arguments

        Class partypes[] = new Class[2];
        partypes[0] = Integer.TYPE;
        partypes[1] = double[].class;

        meth = mAffineFnsClass.getMethod("evaluateF", partypes);
    } catch (NoSuchMethodException nsme) {
        throw new RuntimeException("getMethod for evaluateF failed", nsme);
    }

    Double theta_val;
    try {
        Object arglist[] = new Object[2];
        arglist[0] = new Integer(q);
        arglist[1] = current_parameters.getArray();

        Object theta_obj = meth.invoke(mTheta, arglist);
        theta_val = (Double) theta_obj;
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    } catch (InvocationTargetException ite) {
        throw new RuntimeException(ite.getCause());
    }

    return theta_val.doubleValue();
}

From source file:org.apache.struts2.jasper.compiler.JspUtil.java

/**
 * Produces a String representing a call to the EL interpreter.
 *
 * @param isTagFile    is a tag file/*from   w  ww.ja  v a  2  s  .com*/
 * @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.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  a v  a  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.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Write a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.//from   www .j  a v  a2 s .co m
 * @param out
 * @param instance
 * @param declaredClass
 * @param conf
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf)
        throws IOException {

    Object instanceObj = instance;
    Class declClass = declaredClass;

    if (instanceObj == null) { // null
        instanceObj = new NullInstance(declClass, conf);
        declClass = Writable.class;
    }
    writeClassCode(out, declClass);
    if (declClass.isArray()) { // array
        // If bytearray, just dump it out -- avoid the recursion and
        // byte-at-a-time we were previously doing.
        if (declClass.equals(byte[].class)) {
            Bytes.writeByteArray(out, (byte[]) instanceObj);
        } else if (declClass.equals(Result[].class)) {
            Result.writeArray(out, (Result[]) instanceObj);
        } else {
            //if it is a Generic array, write the element's type
            if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) {
                Class<?> componentType = declaredClass.getComponentType();
                writeClass(out, componentType);
            }

            int length = Array.getLength(instanceObj);
            out.writeInt(length);
            for (int i = 0; i < length; i++) {
                Object item = Array.get(instanceObj, i);
                writeObject(out, item, item.getClass(), conf);
            }
        }
    } else if (List.class.isAssignableFrom(declClass)) {
        List list = (List) instanceObj;
        int length = list.size();
        out.writeInt(length);
        for (int i = 0; i < length; i++) {
            Object elem = list.get(i);
            writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf);
        }
    } else if (declClass == String.class) { // String
        Text.writeString(out, (String) instanceObj);
    } else if (declClass.isPrimitive()) { // primitive type
        if (declClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instanceObj).booleanValue());
        } else if (declClass == Character.TYPE) { // char
            out.writeChar(((Character) instanceObj).charValue());
        } else if (declClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instanceObj).byteValue());
        } else if (declClass == Short.TYPE) { // short
            out.writeShort(((Short) instanceObj).shortValue());
        } else if (declClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instanceObj).intValue());
        } else if (declClass == Long.TYPE) { // long
            out.writeLong(((Long) instanceObj).longValue());
        } else if (declClass == Float.TYPE) { // float
            out.writeFloat(((Float) instanceObj).floatValue());
        } else if (declClass == Double.TYPE) { // double
            out.writeDouble(((Double) instanceObj).doubleValue());
        } else if (declClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declClass);
        }
    } else if (declClass.isEnum()) { // enum
        Text.writeString(out, ((Enum) instanceObj).name());
    } else if (Message.class.isAssignableFrom(declaredClass)) {
        Text.writeString(out, instanceObj.getClass().getName());
        ((Message) instance).writeDelimitedTo(DataOutputOutputStream.constructOutputStream(out));
    } else if (Writable.class.isAssignableFrom(declClass)) { // Writable
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ((Writable) instanceObj).write(out);
    } else if (Serializable.class.isAssignableFrom(declClass)) {
        Class<?> c = instanceObj.getClass();
        Integer code = CLASS_TO_CODE.get(c);
        if (code == null) {
            out.writeByte(NOT_ENCODED);
            Text.writeString(out, c.getName());
        } else {
            writeClassCode(out, c);
        }
        ByteArrayOutputStream bos = null;
        ObjectOutputStream oos = null;
        try {
            bos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(bos);
            oos.writeObject(instanceObj);
            byte[] value = bos.toByteArray();
            out.writeInt(value.length);
            out.write(value);
        } finally {
            if (bos != null)
                bos.close();
            if (oos != null)
                oos.close();
        }
    } else {
        throw new IOException("Can't write: " + instanceObj + " as " + declClass);
    }
}

From source file:org.enerj.apache.commons.beanutils.ConvertUtilsBean.java

/**
 * Remove all registered {@link Converter}s, and re-establish the
 * standard Converters.// ww  w .j av a  2s.c  om
 */
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());

}