List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:org.apache.hadoop.dfs.ClusterTestDFS.java
/** * Make a data generator.//from www . j a va2 s .co m * Allows optional use of high quality PRNG by setting property * hadoop.random.class to the full class path of a subclass of * java.util.Random such as "...util.MersenneTwister". * The property test.dfs.random.seed can supply a seed for reproducible * testing (a default is set here if property is not set.) */ private Random makeRandomDataGenerator() { long seed = conf.getLong("test.dfs.random.seed", 0xB437EF); try { if (randomDataGeneratorCtor == null) { // lazy init String rndDataGenClassname = conf.get("hadoop.random.class", "java.util.Random"); Class<?> clazz = Class.forName(rndDataGenClassname); randomDataGeneratorCtor = clazz.getConstructor(Long.TYPE); } if (randomDataGeneratorCtor != null) { Object arg[] = { new Long(seed) }; return (Random) randomDataGeneratorCtor.newInstance(arg); } } catch (ClassNotFoundException absorb) { } catch (NoSuchMethodException absorb) { } catch (SecurityException absorb) { } catch (InstantiationException absorb) { } catch (IllegalAccessException absorb) { } catch (IllegalArgumentException absorb) { } catch (InvocationTargetException absorb) { } // last resort return new java.util.Random(seed); }
From source file:com.thinkbiganalytics.policy.BasePolicyAnnotationTransformer.java
public Object convertStringToObject(String value, Class type) { if (type.isEnum()) { return Enum.valueOf(type, value); } else if (String.class.equals(type)) { return value; }//from www . j av a2 s . co m if (StringUtils.isBlank(value)) { return null; } else if (Number.class.equals(type)) { return NumberUtils.createNumber(value); } else if (Integer.class.equals(type) || Integer.TYPE.equals(type)) { return new Integer(value); } else if (Long.class.equals(type) || Long.TYPE.equals(type)) { return Long.valueOf(value); } else if (Double.class.equals(type) || Double.TYPE.equals(type)) { return Double.valueOf(value); } else if (Float.class.equals(type) || Float.TYPE.equals(type)) { return Float.valueOf(value); } else if (Pattern.class.equals(type)) { return Pattern.compile(value); } else if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) { return BooleanUtils.toBoolean(value); } else { throw new IllegalArgumentException( "Unable to convert the value " + value + " to an object of type " + type.getName()); } }
From source file:org.enerj.apache.commons.beanutils.ConvertUtilsBean.java
/** * Remove all registered {@link Converter}s, and re-establish the * standard Converters./*from w w w . j a v a2 s. 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()); }
From source file:org.apache.hadoop.hbase.wal.TestWALFactory.java
@Test(timeout = 300000) public void testAppendClose() throws Exception { TableName tableName = TableName.valueOf(currentTest.getMethodName()); HRegionInfo regioninfo = new HRegionInfo(tableName, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false);/*from w w w. java 2 s . c om*/ final WAL wal = wals.getWAL(regioninfo.getEncodedNameAsBytes()); final AtomicLong sequenceId = new AtomicLong(1); final int total = 20; HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(tableName.getName())); for (int i = 0; i < total; i++) { WALEdit kvs = new WALEdit(); kvs.add(new KeyValue(Bytes.toBytes(i), tableName.getName(), tableName.getName())); wal.append(htd, regioninfo, new WALKey(regioninfo.getEncodedNameAsBytes(), tableName, System.currentTimeMillis()), kvs, sequenceId, true, null); } // Now call sync to send the data to HDFS datanodes wal.sync(); int namenodePort = cluster.getNameNodePort(); final Path walPath = DefaultWALProvider.getCurrentFileName(wal); // Stop the cluster. (ensure restart since we're sharing MiniDFSCluster) try { DistributedFileSystem dfs = (DistributedFileSystem) cluster.getFileSystem(); dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); TEST_UTIL.shutdownMiniDFSCluster(); try { // wal.writer.close() will throw an exception, // but still call this since it closes the LogSyncer thread first wal.shutdown(); } catch (IOException e) { LOG.info(e); } fs.close(); // closing FS last so DFSOutputStream can't call close LOG.info("STOPPED first instance of the cluster"); } finally { // Restart the cluster while (cluster.isClusterUp()) { LOG.error("Waiting for cluster to go down"); Thread.sleep(1000); } assertFalse(cluster.isClusterUp()); cluster = null; for (int i = 0; i < 100; i++) { try { cluster = TEST_UTIL.startMiniDFSClusterForTestWAL(namenodePort); break; } catch (BindException e) { LOG.info("Sleeping. BindException bringing up new cluster"); Threads.sleep(1000); } } cluster.waitActive(); fs = cluster.getFileSystem(); LOG.info("STARTED second instance."); } // set the lease period to be 1 second so that the // namenode triggers lease recovery upon append request Method setLeasePeriod = cluster.getClass().getDeclaredMethod("setLeasePeriod", new Class[] { Long.TYPE, Long.TYPE }); setLeasePeriod.setAccessible(true); setLeasePeriod.invoke(cluster, 1000L, 1000L); try { Thread.sleep(1000); } catch (InterruptedException e) { LOG.info(e); } // Now try recovering the log, like the HMaster would do final FileSystem recoveredFs = fs; final Configuration rlConf = conf; class RecoverLogThread extends Thread { public Exception exception = null; public void run() { try { FSUtils.getInstance(fs, rlConf).recoverFileLease(recoveredFs, walPath, rlConf, null); } catch (IOException e) { exception = e; } } } RecoverLogThread t = new RecoverLogThread(); t.start(); // Timeout after 60 sec. Without correct patches, would be an infinite loop t.join(60 * 1000); if (t.isAlive()) { t.interrupt(); throw new Exception("Timed out waiting for WAL.recoverLog()"); } if (t.exception != null) throw t.exception; // Make sure you can read all the content WAL.Reader reader = wals.createReader(fs, walPath); int count = 0; WAL.Entry entry = new WAL.Entry(); while (reader.next(entry) != null) { count++; assertTrue("Should be one KeyValue per WALEdit", entry.getEdit().getCells().size() == 1); } assertEquals(total, count); reader.close(); // Reset the lease period setLeasePeriod.invoke(cluster, new Object[] { new Long(60000), new Long(3600000) }); }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>// w w w . j a va2 s.c o m * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a long to the given primitive number class *///from ww w .j av a2 s . co m static Number coerceToPrimitiveNumber(long pValue, Class pClass) throws ElException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte((byte) pValue); } else if (pClass == Short.class || pClass == Short.TYPE) { return PrimitiveObjects.getShort((short) pValue); } else if (pClass == Integer.class || pClass == Integer.TYPE) { return PrimitiveObjects.getInteger((int) pValue); } else if (pClass == Long.class || pClass == Long.TYPE) { return PrimitiveObjects.getLong(pValue); } else if (pClass == Float.class || pClass == Float.TYPE) { return PrimitiveObjects.getFloat((float) pValue); } else if (pClass == Double.class || pClass == Double.TYPE) { return PrimitiveObjects.getDouble((double) pValue); } else { return PrimitiveObjects.getInteger(0); } }
From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java
private final Class<?> getClassForName(String type) { try {//ww w. j a v a 2 s.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); } }
From source file:cn.annoreg.mc.s11n.SerializationManager.java
private void initInternalSerializers() { //First part: java internal class. {/*from w w w.ja va 2s. c om*/ 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:wicket.util.lang.Objects.java
/** * Returns the value converted numerically to the given class type * /* w ww . j ava 2 s . c o m*/ * This method also detects when arrays are being converted and converts the * components of one array to the type of the other. * * @param value * an object to be converted to the given type * @param toType * class type to be converted to * @return converted value of the type given, or value if the value cannot * be converted to the given type. */ public static Object convertValue(Object value, Class toType) { Object result = null; if (value != null) { /* If array -> array then convert components of array individually */ if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) { result = new Integer((int) longValue(value)); } if ((toType == Double.class) || (toType == Double.TYPE)) { result = new Double(doubleValue(value)); } if ((toType == Boolean.class) || (toType == Boolean.TYPE)) { result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; } if ((toType == Byte.class) || (toType == Byte.TYPE)) { result = new Byte((byte) longValue(value)); } if ((toType == Character.class) || (toType == Character.TYPE)) { result = new Character((char) longValue(value)); } if ((toType == Short.class) || (toType == Short.TYPE)) { result = new Short((short) longValue(value)); } if ((toType == Long.class) || (toType == Long.TYPE)) { result = new Long(longValue(value)); } if ((toType == Float.class) || (toType == Float.TYPE)) { result = new Float(doubleValue(value)); } if (toType == BigInteger.class) { result = bigIntValue(value); } if (toType == BigDecimal.class) { result = bigDecValue(value); } if (toType == String.class) { result = stringValue(value); } } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns the virtual machine's Class object for the named primitive type.<br/> * If the type is not a primitive type, {@code null} is returned. * * @param name the name of the type//from ww w. j a v a 2s . com * @return the Class instance representing the primitive type */ private static Class<?> getPrimitiveType(String name) { name = StringUtils.defaultIfEmpty(name, ""); if (name.equals("int")) return Integer.TYPE; if (name.equals("short")) return Short.TYPE; if (name.equals("long")) return Long.TYPE; if (name.equals("float")) return Float.TYPE; if (name.equals("double")) return Double.TYPE; if (name.equals("byte")) return Byte.TYPE; if (name.equals("char")) return Character.TYPE; if (name.equals("boolean")) return Boolean.TYPE; if (name.equals("void")) return Void.TYPE; return null; }