List of usage examples for java.lang Byte decode
public static Byte decode(String nm) throws NumberFormatException
From source file:com.l2jfree.gameserver.templates.StatsSet.java
/** * Returns the byte associated to the key put in parameter ("name"). * /* w w w .j av a 2s .co m*/ * @param name : String designating the key in the set * @return byte : value associated to the key */ public final byte getByte(String name) { Object val = get(name); if (val == null) throw new IllegalArgumentException("Byte value required, but not specified"); if (val instanceof Number) return ((Number) val).byteValue(); try { return Byte.decode((String) val); } catch (Exception e) { throw new IllegalArgumentException("Byte value required, but found: " + val); } }
From source file:com.l2jfree.config.L2Properties.java
public byte getByte(String name, String deflt) { String val = getProperty(name, deflt); if (val == null) throw new IllegalArgumentException("Byte value required, but not specified"); try {//w ww.j a va2 s . co m return Byte.decode(val); } catch (Exception e) { throw new IllegalArgumentException("Byte value required, but found: " + val); } }
From source file:com.l2jfree.config.L2Properties.java
public byte getByte(String name, byte deflt) { String val = getProperty(name); if (val == null) return deflt; try {//from w w w. j ava 2s . c o m return Byte.decode(val); } catch (Exception e) { throw new IllegalArgumentException("Byte value required, but found: " + val); } }
From source file:org.crazydog.util.spring.NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the corresponding {@code decode} / {@code valueOf} methods. * <p>Trims the input {@code String} before attempting to parse the number. * Supports numbers in hex format (with leading "0x", "0X" or "#") as well. * * @param text the text to convert * @param targetClass the target class to parse into * @return the parsed number//from w ww . ja va 2 s.com * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see Byte#decode * @see Short#decode * @see Integer#decode * @see Long#decode * @see #decodeBigInteger(String) * @see Float#valueOf * @see Double#valueOf * @see BigDecimal#BigDecimal(String) */ @SuppressWarnings("unchecked") public static <T extends Number> T parseNumber(String text, Class<T> targetClass) { org.springframework.util.Assert.notNull(text, "Text must not be null"); org.springframework.util.Assert.notNull(targetClass, "Target class must not be null"); String trimmed = StringUtils.trimAllWhitespace(text); if (Byte.class == targetClass) { return (T) (isHexNumber(trimmed) ? Byte.decode(trimmed) : Byte.valueOf(trimmed)); } else if (Short.class == targetClass) { return (T) (isHexNumber(trimmed) ? Short.decode(trimmed) : Short.valueOf(trimmed)); } else if (Integer.class == targetClass) { return (T) (isHexNumber(trimmed) ? Integer.decode(trimmed) : Integer.valueOf(trimmed)); } else if (Long.class == targetClass) { return (T) (isHexNumber(trimmed) ? Long.decode(trimmed) : Long.valueOf(trimmed)); } else if (BigInteger.class == targetClass) { return (T) (isHexNumber(trimmed) ? decodeBigInteger(trimmed) : new BigInteger(trimmed)); } else if (Float.class == targetClass) { return (T) Float.valueOf(trimmed); } else if (Double.class == targetClass) { return (T) Double.valueOf(trimmed); } else if (BigDecimal.class == targetClass || Number.class == targetClass) { return (T) new BigDecimal(trimmed); } else { throw new IllegalArgumentException( "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]"); } }
From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java
private Condition parsePlayerCondition(String nodeName, String nodeValue) { if ("skill".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionWithSkill(val); } else if ("race".equalsIgnoreCase(nodeName)) { Race race = Race.valueOf(nodeValue); return new ConditionPlayerRace(race); } else if ("level".equalsIgnoreCase(nodeName)) { int lvl = Integer.decode(nodeValue); return new ConditionPlayerLevel(lvl); } else if ("resting".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.RESTING, val); } else if ("moving".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.MOVING, val); } else if ("running".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.RUNNING, val); } else if ("walking".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.WALKING, val); } else if ("behind".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.BEHIND, val); } else if ("front".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.FRONT, val); } else if ("chaotic".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.CHAOTIC, val); } else if ("olympiad".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.OLYMPIAD, val); } else if ("flying".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerState(PlayerState.FLYING, val); } else if ("hp".equalsIgnoreCase(nodeName)) { int hp = Integer.decode(nodeValue); return new ConditionPlayerHp(hp); } else if ("mp".equalsIgnoreCase(nodeName)) { int mp = Integer.decode(nodeValue); return new ConditionPlayerMp(mp); } else if ("cp".equalsIgnoreCase(nodeName)) { int cp = Integer.decode(nodeValue); return new ConditionPlayerCp(cp); } else if ("attack_stance".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerAttackStance(val); } else if ("grade".equalsIgnoreCase(nodeName)) { int expIndex = Integer.decode(nodeValue); return new ConditionPlayerGrade(expIndex); } else if ("siegezone".equalsIgnoreCase(nodeName)) { int value = Integer.decode(nodeValue); return new ConditionSiegeZone(value, true); } else if ("battle_force".equalsIgnoreCase(nodeName)) { byte battleForce = Byte.decode(nodeValue); return new ConditionForceBuff(battleForce, (byte) 0); } else if ("spell_force".equalsIgnoreCase(nodeName)) { byte spellForce = Byte.decode(nodeValue); return new ConditionForceBuff((byte) 0, spellForce); } else if ("weight".equalsIgnoreCase(nodeName)) { int weight = Integer.decode(nodeValue); return new ConditionPlayerWeight(weight); } else if ("invSize".equalsIgnoreCase(nodeName)) { int size = Integer.decode(nodeValue); return new ConditionPlayerInvSize(size); } else if ("pledgeClass".equalsIgnoreCase(nodeName)) { int pledgeClass = Integer.decode(nodeValue); return new ConditionPlayerPledgeClass(pledgeClass); } else if ("clanHall".equalsIgnoreCase(nodeName)) { List<Integer> array = new ArrayList<Integer>(); StringTokenizer st = new StringTokenizer(nodeValue, ","); while (st.hasMoreTokens()) { array.add(Integer.decode(st.nextToken().trim())); }/*from w w w .ja va 2s . c o m*/ return new ConditionPlayerHasClanHall(array); } else if ("fort".equalsIgnoreCase(nodeName)) { int fort = Integer.decode(nodeValue); return new ConditionPlayerHasFort(fort); } else if ("castle".equalsIgnoreCase(nodeName)) { int castle = Integer.decode(nodeValue); return new ConditionPlayerHasCastle(castle); } else if ("sex".equalsIgnoreCase(nodeName)) { int sex = Integer.decode(nodeValue); return new ConditionPlayerSex(sex); } else if ("flyMounted".equalsIgnoreCase(nodeName)) { boolean val = Boolean.valueOf(nodeValue); return new ConditionPlayerFlyMounted(val); } else if ("landingZone".equalsIgnoreCase(nodeName)) { boolean val = Boolean.valueOf(nodeValue); return new ConditionPlayerLandingZone(val); } else if ("active_skill_id".equalsIgnoreCase(nodeName) || "active_skill_id_lvl".equalsIgnoreCase(nodeName)) { return new ConditionPlayerActiveSkillId(nodeValue); } else if ("agathionId".equalsIgnoreCase(nodeName)) { int agathionId = Integer.decode(nodeValue); return new ConditionAgathionSummoned(agathionId); } else if ("active_effect_id".equalsIgnoreCase(nodeName)) { return new ConditionPlayerActiveEffectId(nodeValue); } else if ("class_id_restriction".equalsIgnoreCase(nodeName)) { List<Integer> array = new ArrayList<Integer>(); StringTokenizer st = new StringTokenizer(nodeValue, ","); while (st.hasMoreTokens()) { array.add(Integer.decode(st.nextToken().trim())); } return new ConditionPlayerClassIdRestriction(array); } else if ("isClanLeader".equalsIgnoreCase(nodeName)) { boolean val = Boolean.parseBoolean(nodeValue); return new ConditionPlayerIsClanLeader(val); } else if ("subclass".equalsIgnoreCase(nodeName)) { boolean val = Boolean.valueOf(nodeValue); return new ConditionPlayerSubclass(val); } else if ("instanceid".equalsIgnoreCase(nodeName)) { List<Integer> array = new ArrayList<Integer>(); StringTokenizer st = new StringTokenizer(nodeValue, ","); while (st.hasMoreTokens()) { array.add(Integer.decode(st.nextToken().trim())); } return new ConditionPlayerInstanceId(array); } throw new IllegalStateException("Invalid attribute at <player>: " + nodeName + "='" + nodeValue + "'"); }
From source file:io.bigio.MessageUtils.java
public static RepMessage createMessage() { RepMessage ret = new RepMessage(); ret.setBooleanValue(rand.nextBoolean()); ret.setByteValue(Byte.decode("0x10")); ret.setShortValue((short) rand.nextInt()); ret.setIntValue(rand.nextInt());/*from w ww . j av a2 s .c om*/ ret.setFloatValue(rand.nextFloat()); ret.setLongValue(rand.nextLong()); ret.setDoubleValue(rand.nextDouble()); ret.setStringValue("Andy is the greatest"); ret.setEcefValue(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.setBooleanArray(new boolean[] { true, false }); ret.setShortArray(new short[] { (short) rand.nextInt(), (short) rand.nextInt() }); ret.setIntArray(new int[] { rand.nextInt(), rand.nextInt(), rand.nextInt() }); ret.setFloatArray(new float[] { rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), rand.nextFloat() }); ret.setLongArray(new long[] { rand.nextLong(), rand.nextLong(), rand.nextLong(), rand.nextLong() }); ret.setDoubleArray(new double[] { rand.nextDouble(), rand.nextDouble() }); ret.setStringArray(new String[] { "Andy", "is", "absolutely", "rad" }); ret.setEnumValue(RepMessage.TestEnum.Test); ret.getBooleanList().add(true); ret.getBooleanList().add(false); ret.getByteList().add(Byte.decode("0x0a")); ret.getByteList().add(Byte.decode("0x00")); ret.getShortList().add((short) rand.nextInt()); ret.getShortList().add((short) rand.nextInt()); ret.getShortList().add((short) rand.nextInt()); ret.getIntList().add(rand.nextInt()); ret.getIntList().add(rand.nextInt()); ret.getIntList().add(rand.nextInt()); ret.getIntList().add(rand.nextInt()); ret.getIntList().add(rand.nextInt()); ret.getFloatList().add(rand.nextFloat()); ret.getFloatList().add(rand.nextFloat()); ret.getLongList().add(rand.nextLong()); ret.getLongList().add(rand.nextLong()); ret.getLongList().add(rand.nextLong()); ret.getLongList().add(rand.nextLong()); ret.getDoubleList().add(rand.nextDouble()); ret.getDoubleList().add(rand.nextDouble()); ret.getDoubleList().add(rand.nextDouble()); ret.getStringList().add("Hi"); ret.getStringList().add("there"); ret.getStringList().add("world"); ret.getEcefList().add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefList().add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefList().add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getBoolean2DList().add(new ArrayList<Boolean>()); ret.getBoolean2DList().get(0).add(true); ret.getBoolean2DList().get(0).add(true); ret.getBoolean2DList().add(new ArrayList<Boolean>()); ret.getBoolean2DList().get(1).add(false); ret.getBoolean2DList().get(1).add(false); ret.getBoolean2DList().add(new ArrayList<Boolean>()); ret.getBoolean2DList().get(2).add(true); ret.getBoolean2DList().get(2).add(false); ret.getByte2DList().add(new ArrayList<Byte>()); ret.getByte2DList().get(0).add(Byte.decode("0x00")); ret.getByte2DList().get(0).add(Byte.decode("0x01")); ret.getByte2DList().add(new ArrayList<Byte>()); ret.getByte2DList().get(1).add(Byte.decode("0x02")); ret.getByte2DList().get(1).add(Byte.decode("0x03")); ret.getByte2DList().add(new ArrayList<Byte>()); ret.getByte2DList().get(2).add(Byte.decode("0x04")); ret.getByte2DList().get(2).add(Byte.decode("0x05")); ret.getShort2DList().add(new ArrayList<Short>()); ret.getShort2DList().get(0).add((short) rand.nextInt()); ret.getShort2DList().get(0).add((short) rand.nextInt()); ret.getShort2DList().add(new ArrayList<Short>()); ret.getShort2DList().get(1).add((short) rand.nextInt()); ret.getShort2DList().get(1).add((short) rand.nextInt()); ret.getShort2DList().add(new ArrayList<Short>()); ret.getShort2DList().get(2).add((short) rand.nextInt()); ret.getShort2DList().get(2).add((short) rand.nextInt()); ret.getInt2DList().add(new ArrayList<Integer>()); ret.getInt2DList().get(0).add(rand.nextInt()); ret.getInt2DList().get(0).add(rand.nextInt()); ret.getInt2DList().add(new ArrayList<Integer>()); ret.getInt2DList().get(1).add(rand.nextInt()); ret.getInt2DList().get(1).add(rand.nextInt()); ret.getInt2DList().add(new ArrayList<Integer>()); ret.getInt2DList().get(2).add(rand.nextInt()); ret.getInt2DList().get(2).add(rand.nextInt()); ret.getFloat2DList().add(new ArrayList<Float>()); ret.getFloat2DList().get(0).add(rand.nextFloat()); ret.getFloat2DList().get(0).add(rand.nextFloat()); ret.getFloat2DList().add(new ArrayList<Float>()); ret.getFloat2DList().get(1).add(rand.nextFloat()); ret.getFloat2DList().get(1).add(rand.nextFloat()); ret.getFloat2DList().add(new ArrayList<Float>()); ret.getFloat2DList().get(2).add(rand.nextFloat()); ret.getFloat2DList().get(2).add(rand.nextFloat()); ret.getLong2DList().add(new ArrayList<Long>()); ret.getLong2DList().get(0).add(rand.nextLong()); ret.getLong2DList().get(0).add(rand.nextLong()); ret.getLong2DList().add(new ArrayList<Long>()); ret.getLong2DList().get(1).add(rand.nextLong()); ret.getLong2DList().get(1).add(rand.nextLong()); ret.getLong2DList().add(new ArrayList<Long>()); ret.getLong2DList().get(2).add(rand.nextLong()); ret.getLong2DList().get(2).add(rand.nextLong()); ret.getDouble2DList().add(new ArrayList<Double>()); ret.getDouble2DList().get(0).add(rand.nextDouble()); ret.getDouble2DList().get(0).add(rand.nextDouble()); ret.getDouble2DList().add(new ArrayList<Double>()); ret.getDouble2DList().get(1).add(rand.nextDouble()); ret.getDouble2DList().get(1).add(rand.nextDouble()); ret.getDouble2DList().add(new ArrayList<Double>()); ret.getDouble2DList().get(2).add(rand.nextDouble()); ret.getDouble2DList().get(2).add(rand.nextDouble()); ret.getString2DList().add(new ArrayList<String>()); ret.getString2DList().get(0).add(Double.toString(rand.nextDouble())); ret.getString2DList().get(0).add(Double.toString(rand.nextDouble())); ret.getString2DList().add(new ArrayList<String>()); ret.getString2DList().get(1).add(Double.toString(rand.nextDouble())); ret.getString2DList().get(1).add(Double.toString(rand.nextDouble())); ret.getString2DList().add(new ArrayList<String>()); ret.getString2DList().get(2).add(Double.toString(rand.nextDouble())); ret.getString2DList().get(2).add(Double.toString(rand.nextDouble())); ret.getEcef2DList().add(new ArrayList<ECEFPos>()); ret.getEcef2DList().get(0).add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcef2DList().get(0).add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcef2DList().add(new ArrayList<ECEFPos>()); ret.getEcef2DList().get(1).add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcef2DList().get(1).add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcef2DList().add(new ArrayList<ECEFPos>()); ret.getEcef2DList().get(2).add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcef2DList().get(2).add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getBooleanMap().put(Integer.toString(rand.nextInt()), Boolean.TRUE); ret.getBooleanMap().put(Integer.toString(rand.nextInt()), Boolean.TRUE); ret.getBooleanMap().put(Integer.toString(rand.nextInt()), Boolean.FALSE); ret.getByteMap().put(Integer.toString(rand.nextInt()), Byte.decode("0x00")); ret.getByteMap().put(Integer.toString(rand.nextInt()), Byte.decode("0x01")); ret.getByteMap().put(Integer.toString(rand.nextInt()), Byte.decode("0x02")); ret.getShortMap().put(Integer.toString(rand.nextInt()), (short) rand.nextInt()); ret.getShortMap().put(Integer.toString(rand.nextInt()), (short) rand.nextInt()); ret.getShortMap().put(Integer.toString(rand.nextInt()), (short) rand.nextInt()); ret.getIntMap().put(Integer.toString(rand.nextInt()), rand.nextInt()); ret.getIntMap().put(Integer.toString(rand.nextInt()), rand.nextInt()); ret.getIntMap().put(Integer.toString(rand.nextInt()), rand.nextInt()); ret.getFloatMap().put(Integer.toString(rand.nextInt()), rand.nextFloat()); ret.getFloatMap().put(Integer.toString(rand.nextInt()), rand.nextFloat()); ret.getFloatMap().put(Integer.toString(rand.nextInt()), rand.nextFloat()); ret.getLongMap().put(Integer.toString(rand.nextInt()), rand.nextLong()); ret.getLongMap().put(Integer.toString(rand.nextInt()), rand.nextLong()); ret.getLongMap().put(Integer.toString(rand.nextInt()), rand.nextLong()); ret.getDoubleMap().put(Integer.toString(rand.nextInt()), rand.nextDouble()); ret.getDoubleMap().put(Integer.toString(rand.nextInt()), rand.nextDouble()); ret.getDoubleMap().put(Integer.toString(rand.nextInt()), rand.nextDouble()); ret.getStringMap().put(Integer.toString(rand.nextInt()), Integer.toString(rand.nextInt())); ret.getStringMap().put(Integer.toString(rand.nextInt()), Integer.toString(rand.nextInt())); ret.getStringMap().put(Integer.toString(rand.nextInt()), Integer.toString(rand.nextInt())); ret.getEcefMap().put(Integer.toString(rand.nextInt()), new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefMap().put(Integer.toString(rand.nextInt()), new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefMap().put(Integer.toString(rand.nextInt()), new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ArrayList l = new ArrayList(); l.add(true); l.add(true); ret.getBooleanListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(false); l.add(false); ret.getBooleanListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(true); l.add(false); ret.getBooleanListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(Byte.decode("0x00")); l.add(Byte.decode("0x01")); ret.getByteListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(Byte.decode("0x02")); l.add(Byte.decode("0x03")); ret.getByteListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(Byte.decode("0x04")); l.add(Byte.decode("0x05")); ret.getByteListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add((short) rand.nextInt()); l.add((short) rand.nextInt()); ret.getShortListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add((short) rand.nextInt()); l.add((short) rand.nextInt()); ret.getShortListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add((short) rand.nextInt()); l.add((short) rand.nextInt()); ret.getShortListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextInt()); l.add(rand.nextInt()); ret.getIntListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextInt()); l.add(rand.nextInt()); ret.getIntListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextInt()); l.add(rand.nextInt()); ret.getIntListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextFloat()); l.add(rand.nextFloat()); ret.getFloatListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextFloat()); l.add(rand.nextFloat()); ret.getFloatListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextFloat()); l.add(rand.nextFloat()); ret.getFloatListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextLong()); l.add(rand.nextLong()); ret.getLongListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextLong()); l.add(rand.nextLong()); ret.getLongListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextLong()); l.add(rand.nextLong()); ret.getLongListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextDouble()); l.add(rand.nextDouble()); ret.getDoubleListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextDouble()); l.add(rand.nextDouble()); ret.getDoubleListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(rand.nextDouble()); l.add(rand.nextDouble()); ret.getDoubleListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(Integer.toString(rand.nextInt())); l.add(Integer.toString(rand.nextInt())); ret.getStringListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(Integer.toString(rand.nextInt())); l.add(Integer.toString(rand.nextInt())); ret.getStringListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(Integer.toString(rand.nextInt())); l.add(Integer.toString(rand.nextInt())); ret.getStringListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); l.add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); l.add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefListMap().put(Integer.toString(rand.nextInt()), l); l = new ArrayList(); l.add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); l.add(new ECEFPos(rand.nextDouble(), rand.nextDouble(), rand.nextDouble())); ret.getEcefListMap().put(Integer.toString(rand.nextInt()), l); return ret; }
From source file:org.apache.catalina.core.NamingContextListener.java
/** * Set the specified environment entries in the naming context. *//* w ww .j a va 2 s . c o m*/ public void addEnvironment(ContextEnvironment env) { Object value = null; // Instantiating a new instance of the correct object type, and // initializing it. String type = env.getType(); try { if (type.equals("java.lang.String")) { value = env.getValue(); } else if (type.equals("java.lang.Byte")) { if (env.getValue() == null) { value = new Byte((byte) 0); } else { value = Byte.decode(env.getValue()); } } else if (type.equals("java.lang.Short")) { if (env.getValue() == null) { value = new Short((short) 0); } else { value = Short.decode(env.getValue()); } } else if (type.equals("java.lang.Integer")) { if (env.getValue() == null) { value = new Integer(0); } else { value = Integer.decode(env.getValue()); } } else if (type.equals("java.lang.Long")) { if (env.getValue() == null) { value = new Long(0); } else { value = Long.decode(env.getValue()); } } else if (type.equals("java.lang.Boolean")) { value = Boolean.valueOf(env.getValue()); } else if (type.equals("java.lang.Double")) { if (env.getValue() == null) { value = new Double(0); } else { value = Double.valueOf(env.getValue()); } } else if (type.equals("java.lang.Float")) { if (env.getValue() == null) { value = new Float(0); } else { value = Float.valueOf(env.getValue()); } } else if (type.equals("java.lang.Character")) { if (env.getValue() == null) { value = new Character((char) 0); } else { if (env.getValue().length() == 1) { value = new Character(env.getValue().charAt(0)); } else { throw new IllegalArgumentException(); } } } else { log(sm.getString("naming.invalidEnvEntryType", env.getName())); } } catch (NumberFormatException e) { log(sm.getString("naming.invalidEnvEntryValue", env.getName())); } catch (IllegalArgumentException e) { log(sm.getString("naming.invalidEnvEntryValue", env.getName())); } // Binding the object to the appropriate name if (value != null) { try { if (debug >= 2) log(" Adding environment entry " + env.getName()); createSubcontexts(envCtx, env.getName()); envCtx.bind(env.getName(), value); } catch (NamingException e) { log(sm.getString("naming.invalidEnvEntryValue", e)); } } }
From source file:org.apache.marmotta.commons.sesame.facading.util.FacadeUtils.java
/** * Transform a value passed as string to the base type (i.e. non-complex type) given as argument * * @param <T>/*w ww . jav a 2 s . c o m*/ * @param value * @param returnType * @return * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") public static <T> T transformToBaseType(String value, Class<T> returnType) throws IllegalArgumentException { // transformation to appropriate primitive type /* * README: the "dirty" cast: "(T) x" instead of "returnType.cast(x)" is required since * .cast does not work for primitive types (int, double, float, etc...). * Somehow it results in a ClassCastException */ if (Integer.class.equals(returnType) || int.class.equals(returnType)) { if (value == null) { return (T) (Integer) (0); } return (T) (Integer.decode(value)); } else if (Long.class.equals(returnType) || long.class.equals(returnType)) { if (value == null) { return (T) (Long) (0L); } return (T) (Long.decode(value)); } else if (Double.class.equals(returnType) || double.class.equals(returnType)) { if (value == null) { return (T) (Double) (0.0); } return (T) (Double.valueOf(value)); } else if (Float.class.equals(returnType) || float.class.equals(returnType)) { if (value == null) { return (T) (Float) (0.0F); } return (T) (Float.valueOf(value)); } else if (Byte.class.equals(returnType) || byte.class.equals(returnType)) { if (value == null) { return (T) (Byte) ((byte) 0); } return (T) (Byte.decode(value)); } else if (Boolean.class.equals(returnType) || boolean.class.equals(returnType)) { return (T) (Boolean.valueOf(value)); } else if (Character.class.equals(returnType) || char.class.equals(returnType)) { if (value == null) { if (Character.class.equals(returnType)) { return null; } else { return (T) new Character((char) 0); } } else if (value.length() > 0) { return (T) (Character) (value.charAt(0)); } else { return null; } } else if (Locale.class.equals(returnType)) { if (value == null) { return null; } else { return returnType.cast(LocaleUtils.toLocale(value)); } } else if (Date.class.equals(returnType)) { if (value == null) { return null; } else { try { return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value).toDate()); } catch (final IllegalArgumentException e) { e.printStackTrace(); return null; } } } else if (DateTime.class.equals(returnType)) { if (value == null) { return null; } else { try { return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value)); } catch (final IllegalArgumentException e) { e.printStackTrace(); return null; } } } else if (String.class.equals(returnType)) { return returnType.cast(value); } else { throw new IllegalArgumentException( "primitive type " + returnType.getName() + " not supported by transformation"); } }
From source file:org.jbpm.formModeler.core.processing.fieldHandlers.NumericFieldHandler.java
public Object getTheValue(Field field, String[] paramValue, String desiredClassName) throws Exception { if (paramValue == null || paramValue.length == 0) return null; if (desiredClassName.equals("byte")) { if (StringUtils.isEmpty(paramValue[0])) return new Byte((byte) 0); else// w w w .jav a 2 s . c o m return Byte.decode(paramValue[0]); } else if (desiredClassName.equals("short")) { if (StringUtils.isEmpty(paramValue[0])) return new Short((short) 0); else return Short.decode(paramValue[0]); } else if (desiredClassName.equals("int")) { if (StringUtils.isEmpty(paramValue[0])) return new Integer(0); else return Integer.decode(paramValue[0]); } else if (desiredClassName.equals("long")) { if (StringUtils.isEmpty(paramValue[0])) return new Long(0L); else return Long.decode(paramValue[0]); } else if (desiredClassName.equals(Byte.class.getName())) { if (StringUtils.isEmpty(paramValue[0])) throw new EmptyNumberException(); return Byte.decode(paramValue[0]); } else if (desiredClassName.equals(Short.class.getName())) { if (StringUtils.isEmpty(paramValue[0])) throw new EmptyNumberException(); return Short.decode(paramValue[0]); } else if (desiredClassName.equals(Integer.class.getName())) { if (StringUtils.isEmpty(paramValue[0])) throw new EmptyNumberException(); return Integer.decode(paramValue[0]); } else if (desiredClassName.equals(Long.class.getName())) { if (StringUtils.isEmpty(paramValue[0])) throw new EmptyNumberException(); return Long.decode(paramValue[0]); } else if (desiredClassName.equals(Double.class.getName()) || desiredClassName.equals("double") || desiredClassName.equals(Float.class.getName()) || desiredClassName.equals("float") || desiredClassName.equals(BigDecimal.class.getName())) { if (StringUtils.isEmpty(paramValue[0])) throw new EmptyNumberException(); DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(new Locale(LocaleManager.currentLang())); if (desiredClassName.equals(BigDecimal.class.getName())) df.setParseBigDecimal(true); String pattern = getFieldPattern(field); if (pattern != null && !"".equals(pattern)) { df.applyPattern(pattern); } else { df.applyPattern("###.##"); } ParsePosition pp = new ParsePosition(0); Number num = df.parse(paramValue[0], pp); if (paramValue[0].length() != pp.getIndex() || num == null) { log.debug("Error on parsing value"); throw new ParseException("Error parsing value", pp.getIndex()); } if (desiredClassName.equals(BigDecimal.class.getName())) { return num; } else if (desiredClassName.equals(Float.class.getName()) || desiredClassName.equals("float")) { return new Float(num.floatValue()); } else if (desiredClassName.equals(Double.class.getName()) || desiredClassName.equals("double")) { return new Double(num.doubleValue()); } } else if (desiredClassName.equals(BigInteger.class.getName())) { if (StringUtils.isEmpty(paramValue[0])) throw new EmptyNumberException(); return new BigInteger(paramValue[0]); } throw new IllegalArgumentException("Invalid class for NumericFieldHandler: " + desiredClassName); }
From source file:org.talend.components.processing.runtime.filterrow.TypeConverterUtils.java
public static Byte parseToByte(Object value) { if (value == null) { return null; } else if (value instanceof Number) { return ((Number) value).byteValue(); } else if (value instanceof Boolean) { return (byte) (((Boolean) value) ? 1 : 0); } else if (value instanceof String) { return Byte.decode((String) value).byteValue(); } else {/*from w w w. j av a 2s . c o m*/ return Byte.valueOf(value.toString()); } }