Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjectorTest.java

public org.apache.commons.configuration.Configuration mockConfiguration(Field field, boolean isInconfig) {
    if (field == null) {
        return null;
    }/*from   w w w.ja v a2 s.c om*/
    org.apache.commons.configuration.Configuration configuration = mock(
            org.apache.commons.configuration.Configuration.class);
    when(configuration.containsKey(field.getName())).thenReturn(isInconfig);
    if (isInconfig) {
        Class<?> type = field.getType();
        String configParamName = field.getAnnotation(Configuration.class).value();
        if (type.isArray()) {
            type = type.getComponentType();

            if (type == Integer.TYPE || type == Integer.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Integer.MAX_VALUE) });
            } else if (type == Boolean.TYPE || type == Boolean.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "true" });
            } else if (type == Short.TYPE || type == Short.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Short.MAX_VALUE) });
            } else if (type == Byte.TYPE || type == Byte.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Byte.MAX_VALUE) });
            } else if (type == Long.TYPE || type == Long.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Long.MAX_VALUE) });
            } else if (type == Float.TYPE || type == Float.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Float.MAX_VALUE) });
            } else if (type == Double.TYPE || type == Double.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Double.MAX_VALUE) });
            } else if (type == Character.TYPE || type == Character.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "t" });
            } else if (type == String.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "test" });
            } else
                throw new IllegalArgumentException("Type " + type + " cannot be mocked");
        } else {
            if (type == Integer.TYPE || type == Integer.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Integer.MAX_VALUE));
            } else if (type == Boolean.TYPE || type == Boolean.class) {
                when(configuration.getString(configParamName)).thenReturn("true");
            } else if (type == Short.TYPE || type == Short.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Short.MAX_VALUE));
            } else if (type == Byte.TYPE || type == Byte.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Byte.MAX_VALUE));
            } else if (type == Long.TYPE || type == Long.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Long.MAX_VALUE));
            } else if (type == Float.TYPE || type == Float.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Float.MAX_VALUE));
            } else if (type == Double.TYPE || type == Double.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Double.MAX_VALUE));
            } else if (type == Character.TYPE || type == Character.class) {
                when(configuration.getString(configParamName)).thenReturn("t");
            } else if (type == String.class) {
                when(configuration.getString(configParamName)).thenReturn("test");
            } else
                throw new IllegalArgumentException("Type " + type + " cannot be mocked");
        }
    }
    return configuration;
}

From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java

public void fillWithNullRefs() {
    for (int i = 0; i < parameters.size(); i++) {
        VariableReference ref = parameters.get(i);
        if (ref == null) {
            Class<?> expected = getExpectedParameterType(i);
            Object value = null;//from   w  w w  . j ava2 s  .  co  m
            if (expected.isPrimitive()) {
                //can't fill a primitive with null
                if (expected.equals(Integer.TYPE)) {
                    value = 0;
                } else if (expected.equals(Float.TYPE)) {
                    value = 0f;
                } else if (expected.equals(Double.TYPE)) {
                    value = 0d;
                } else if (expected.equals(Long.TYPE)) {
                    value = 0L;
                } else if (expected.equals(Boolean.TYPE)) {
                    value = false;
                } else if (expected.equals(Short.TYPE)) {
                    value = Short.valueOf("0");
                } else if (expected.equals(Character.TYPE)) {
                    value = 'a';
                }
            }
            parameters.set(i, new ConstantValue(tc, new GenericClass(expected), value));
        }
    }
}

From source file:nl.strohalm.cyclos.controls.members.MemberProfileAction.java

@Override
protected DataBinder<Member> initDataBinderForRead(final ActionContext context) {
    final BeanBinder<Member> dataBinder = (BeanBinder<Member>) super.initDataBinderForRead(context);
    dataBinder.registerBinder("hideEmail", PropertyBinder.instance(Boolean.TYPE, "hideEmail"));
    return dataBinder;
}

From source file:nl.knaw.dans.common.ldap.repo.LdapMapper.java

private Object getPrimitive(Class<?> type, String s) throws NamingException {
    Object value = s;/*from  w w  w .  ja  v  a2 s  .  c  o m*/
    if (Integer.TYPE.equals(type)) {
        value = Integer.parseInt(s);
    } else if (Boolean.TYPE.equals(type)) {
        value = new Boolean("TRUE".equals(s));
    } else if (Long.TYPE.equals(type)) {
        value = Long.parseLong(s);
    } else if (Float.TYPE.equals(type)) {
        value = Float.parseFloat(s);
    } else if (Double.TYPE.equals(type)) {
        value = Double.parseDouble(s);
    } else if (Byte.TYPE.equals(type)) {
        value = Byte.parseByte(s);
    } else if (Short.TYPE.equals(type)) {
        value = Short.parseShort(s);
    }
    return value;
}

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

private void initInternalSerializers() {
    //First part: java internal class.
    {//  w  w  w .java2s  .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:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Gets the bean size intern./* w  w w.  ja va 2 s .  c  o  m*/
 *
 * @param bean the bean
 * @param clazz the clazz
 * @param m the m
 * @param classNameMatcher the class name matcher
 * @param fieldNameMatcher the field name matcher
 * @return the bean size intern
 */
public static int getBeanSizeIntern(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m,
        Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) {
    if (classNameMatcher.match(clazz.getName()) == false) {
        return 0;
    }
    if (clazz.isArray() == true) {
        if (clazz == boolean[].class) {
            return (((boolean[]) bean).length * 4);
        } else if (clazz == char[].class) {
            return (((char[]) bean).length * 2);
        } else if (clazz == byte[].class) {
            return (((byte[]) bean).length * 1);
        } else if (clazz == short[].class) {
            return (((short[]) bean).length * 2);
        } else if (clazz == int[].class) {
            return (((int[]) bean).length * 4);
        } else if (clazz == long[].class) {
            return (((long[]) bean).length * 4);
        } else if (clazz == float[].class) {
            return (((float[]) bean).length * 4);
        } else if (clazz == double[].class) {
            return (((double[]) bean).length * 8);
        } else {
            int length = Array.getLength(bean);
            int ret = (length * 4);
            for (int i = 0; i < length; ++i) {
                ret += getBeanSize(Array.get(bean, i), m, classNameMatcher, fieldNameMatcher);
            }
            return ret;
        }
    }
    int ret = 0;
    try {
        for (Field f : clazz.getDeclaredFields()) {
            int mod = f.getModifiers();
            if (Modifier.isStatic(mod) == true) {
                continue;
            }
            if (fieldNameMatcher.match(clazz.getName() + "." + f.getName()) == false) {
                continue;
            }
            if (f.getType() == Boolean.TYPE) {
                ret += 4;
            } else if (f.getType() == Character.TYPE) {
                ret += 2;
            } else if (f.getType() == Byte.TYPE) {
                ret += 1;
            } else if (f.getType() == Short.TYPE) {
                ret += 2;
            } else if (f.getType() == Integer.TYPE) {
                ret += 4;
            } else if (f.getType() == Long.TYPE) {
                ret += 8;
            } else if (f.getType() == Float.TYPE) {
                ret += 4;
            } else if (f.getType() == Double.TYPE) {
                ret += 8;
            } else {

                ret += 4;
                Object o = null;
                try {
                    o = readField(bean, f);
                    if (o == null) {
                        continue;
                    }
                } catch (NoClassDefFoundError ex) {
                    // nothing
                    continue;
                }
                int nestedsize = getBeanSize(o, o.getClass(), m, classNameMatcher, fieldNameMatcher);
                ret += nestedsize;
            }
        }
    } catch (NoClassDefFoundError ex) {
        // ignore here.
    }
    if (clazz == Object.class || clazz.getSuperclass() == null) {
        return ret;
    }
    ret += getBeanSizeIntern(bean, clazz.getSuperclass(), m, classNameMatcher, fieldNameMatcher);
    return ret;
}

From source file:nl.strohalm.cyclos.controls.members.MemberProfileAction.java

@Override
@SuppressWarnings("unchecked")
protected DataBinder<Member> initDataBinderForWrite(final ActionContext context) {
    final BeanBinder<Member> dataBinder = (BeanBinder<Member>) super.initDataBinderForWrite(context);
    dataBinder.registerBinder("hideEmail", PropertyBinder.instance(Boolean.TYPE, "hideEmail"));

    final BeanBinder<? extends User> userBinder = BeanBinder.instance(getUserClass(), "user");
    userBinder.registerBinder("username", PropertyBinder.instance(String.class, "username"));
    dataBinder.registerBinder("user", userBinder);

    // Add another custom field value attribute: hidden
    final BeanCollectionBinder collectionBinder = (BeanCollectionBinder) dataBinder.getMappings()
            .get("customValues");
    final BeanBinder elementBinder = (BeanBinder) collectionBinder.getElementBinder();
    elementBinder.registerBinder("hidden", PropertyBinder.instance(Boolean.TYPE, "hidden"));

    return dataBinder;
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);//from   www  .  ja  v a2 s . c o m
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                System.out.println("Could not display action icons in menu");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}

From source file:org.apache.jackrabbit.core.fs.db.OracleFileSystem.java

/**
 * Creates a temporary oracle.sql.BLOB instance via reflection and spools
 * the contents of the specified stream.
 *//*  w w  w .  j  av a 2 s.c o m*/
protected Blob createTemporaryBlob(InputStream in) throws Exception {
    /*
    BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
    blob.open(BLOB.MODE_READWRITE);
    OutputStream out = blob.getBinaryOutputStream();
    ...
    out.flush();
    out.close();
    blob.close();
    return blob;
    */
    Method createTemporary = blobClass.getMethod("createTemporary",
            new Class[] { Connection.class, Boolean.TYPE, Integer.TYPE });
    Object blob = createTemporary.invoke(null, new Object[] { con, Boolean.FALSE, durationSessionConstant });
    Method open = blobClass.getMethod("open", new Class[] { Integer.TYPE });
    open.invoke(blob, new Object[] { modeReadWriteConstant });
    Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]);
    OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob, null);
    try {
        IOUtils.copy(in, out);
    } finally {
        try {
            out.flush();
        } catch (IOException ioe) {
        }
        out.close();
    }
    Method close = blobClass.getMethod("close", new Class[0]);
    close.invoke(blob, null);
    return (Blob) blob;
}

From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java

/**
 * Returns a new value that is not equal to oldVal. The returned object
 * will always be a NEW instance compatible with oldVal. This differs from
 * {@link #modifyObject(MatchMakerObject, PropertyDescriptor, Object)} in that
 * this does not take mutability into account.
 * /*from   w  w  w  .j  av  a  2  s .c  om*/
 * @param mmo The object to which the property belongs.  You might need this
 *  if you have a special case for certain types of objects.
 * @param property The property that should be modified.  It belongs to mmo.
 * @param oldVal The existing value of the property.
 */
private Object getNewDifferentValue(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal)
        throws IOException {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
        if (oldVal == null)
            newVal = new Integer(0);
        else {
            newVal = ((Integer) oldVal) + 1;
        }
    } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) {
        if (oldVal == null)
            newVal = new Short("0");
        else {
            Integer temp = (Short) oldVal + 1;
            newVal = Short.valueOf(temp.toString());
        }
    } else if (property.getPropertyType() == String.class) {
        // make sure it's unique
        newVal = "new " + oldVal;

    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        if (oldVal == null) {
            newVal = new Boolean(false);
        } else {
            newVal = new Boolean(!((Boolean) oldVal).booleanValue());
        }
    } else if (property.getPropertyType() == Long.class) {
        if (oldVal == null) {
            newVal = new Long(0L);
        } else {
            newVal = new Long(((Long) oldVal).longValue() + 1L);
        }
    } else if (property.getPropertyType() == BigDecimal.class) {
        if (oldVal == null) {
            newVal = new BigDecimal(0);
        } else {
            newVal = new BigDecimal(((BigDecimal) oldVal).longValue() + 1L);
        }
    } else if (property.getPropertyType() == MungeSettings.class) {
        newVal = new MungeSettings();
        Integer processCount = ((MatchMakerSettings) newVal).getProcessCount();
        if (processCount == null) {
            processCount = new Integer(0);
        } else {
            processCount = new Integer(processCount + 1);
        }
        ((MatchMakerSettings) newVal).setProcessCount(processCount);
    } else if (property.getPropertyType() == MergeSettings.class) {
        newVal = new MergeSettings();
        Integer processCount = ((MatchMakerSettings) newVal).getProcessCount();
        if (processCount == null) {
            processCount = new Integer(0);
        } else {
            processCount = new Integer(processCount + 1);
        }
        ((MatchMakerSettings) newVal).setProcessCount(processCount);
    } else if (property.getPropertyType() == SQLTable.class) {
        newVal = new SQLTable();
    } else if (property.getPropertyType() == ViewSpec.class) {
        newVal = new ViewSpec("*", "test_table", "true");
    } else if (property.getPropertyType() == File.class) {
        newVal = File.createTempFile("mmTest", ".tmp");
        ((File) newVal).deleteOnExit();
    } else if (property.getPropertyType() == PlFolder.class) {
        newVal = new PlFolder();
    } else if (property.getPropertyType() == ProjectMode.class) {
        if (oldVal == ProjectMode.BUILD_XREF) {
            newVal = ProjectMode.FIND_DUPES;
        } else {
            newVal = ProjectMode.BUILD_XREF;
        }
    } else if (property.getPropertyType() == MergeActionType.class) {
        if (oldVal == MergeActionType.AUGMENT) {
            newVal = MergeActionType.SUM;
        } else {
            newVal = MergeActionType.AUGMENT;
        }
    } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) {
        newVal = new MatchMakerTranslateGroup();
    } else if (property.getPropertyType() == MatchMakerObject.class) {
        newVal = new TestingAbstractMatchMakerObject();
    } else if (property.getPropertyType() == SQLColumn.class) {
        newVal = new SQLColumn();
    } else if (property.getPropertyType() == Date.class) {
        newVal = new Date();
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
    } else if (property.getPropertyType() == Project.class) {
        newVal = new Project();
        ((Project) newVal).setName("Fake_Project_" + System.currentTimeMillis());
    } else if (property.getPropertyType() == SQLIndex.class) {
        return new SQLIndex("new index", false, "", "HASHED", "");
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            newVal = new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == ChildMergeActionType.class) {
        if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) {
            newVal = ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT;
        } else {
            newVal = ChildMergeActionType.DELETE_ALL_DUP_CHILD;
        }
    } else if (property.getPropertyType() == MungeResultStep.class
            || property.getPropertyType() == DeDupeResultStep.class) {
        newVal = new DeDupeResultStep();
    } else if (property.getPropertyType() == TableMergeRules.class) {
        if (oldVal == null) {
            newVal = mmo;
        } else {
            newVal = null;
        }
    } else if (property.getPropertyType() == PoolFilterSetting.class) {
        if (oldVal != PoolFilterSetting.EVERYTHING) {
            newVal = PoolFilterSetting.EVERYTHING;
        } else {
            newVal = PoolFilterSetting.INVALID_ONLY;
        }
    } else if (property.getPropertyType() == AutoValidateSetting.class) {
        if (oldVal != AutoValidateSetting.NOTHING) {
            newVal = AutoValidateSetting.NOTHING;
        } else {
            newVal = AutoValidateSetting.SERP_CORRECTABLE;
        }
    } else if (property.getPropertyType() == Point.class) {
        if (oldVal == null) {
            newVal = new Point(0, 0);
        } else {
            newVal = new Point(((Point) oldVal).x + 1, ((Point) oldVal).y + 1);
        }
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") from " + mmo.getClass());
    }

    if (newVal instanceof MatchMakerObject) {
        ((MatchMakerObject) newVal).setSession(session);
    }
    return newVal;
}