List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java
/** * Create a HardwareAddress object from its XML representation. * * @param pElement DOM element containing the XML representation of a HardwareAddress object, as created by the * toConfigXML() method. * @throws RuntimeException if unable to instantiate the Hardware address * @see cern.c2mon.shared.common.datatag.address.HardwareAddress#toConfigXML() *///from w w w .ja v a 2 s . co m public final synchronized HardwareAddress fromConfigXML(Element pElement) { Class hwAddressClass = null; HardwareAddressImpl hwAddress = null; try { hwAddressClass = Class.forName(pElement.getAttribute("class")); hwAddress = (HardwareAddressImpl) hwAddressClass.newInstance(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", cnfe); } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", iae); } catch (InstantiationException ie) { ie.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", ie); } NodeList fields = pElement.getChildNodes(); Node fieldNode = null; int fieldsCount = fields.getLength(); String fieldName; String fieldValueString; String fieldTypeName = ""; for (int i = 0; i < fieldsCount; i++) { fieldNode = fields.item(i); if (fieldNode.getNodeType() == Node.ELEMENT_NODE) { fieldName = fieldNode.getNodeName(); if (fieldNode.getFirstChild() != null) { fieldValueString = fieldNode.getFirstChild().getNodeValue(); } else { fieldValueString = ""; } try { Field field = hwAddressClass.getDeclaredField(decodeFieldName(fieldName)); fieldTypeName = field.getType().getName(); if (fieldTypeName.equals("short")) { field.setShort(hwAddress, Short.parseShort(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Short")) { field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString))); } else if (fieldTypeName.equals("int")) { field.setInt(hwAddress, Integer.parseInt(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Integer")) { field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString))); } else if (fieldTypeName.equals("float")) { field.setFloat(hwAddress, Float.parseFloat(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Float")) { field.set(hwAddress, new Float(Float.parseFloat(fieldValueString))); } else if (fieldTypeName.equals("double")) { field.setDouble(hwAddress, Double.parseDouble(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Double")) { field.set(hwAddress, new Double(Double.parseDouble(fieldValueString))); } else if (fieldTypeName.equals("long")) { field.setLong(hwAddress, Long.parseLong(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Long")) { field.set(hwAddress, new Long(Long.parseLong(fieldValueString))); } else if (fieldTypeName.equals("byte")) { field.setByte(hwAddress, Byte.parseByte(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Byte")) { field.set(hwAddress, new Byte(Byte.parseByte(fieldValueString))); } else if (fieldTypeName.equals("char")) { field.setChar(hwAddress, fieldValueString.charAt(0)); } else if (fieldTypeName.equals("java.lang.Character")) { field.set(hwAddress, new Character(fieldValueString.charAt(0))); } else if (fieldTypeName.equals("boolean")) { field.setBoolean(hwAddress, Boolean.getBoolean(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Boolean")) { field.set(hwAddress, new Boolean(Boolean.getBoolean(fieldValueString))); } else if (fieldTypeName.equals("java.util.HashMap")) { field.set(hwAddress, SimpleXMLParser.domNodeToMap(fieldNode)); } else if (field.getType().isEnum()) { Object[] enumConstants = field.getType().getEnumConstants(); for (Object enumConstant : enumConstants) { if (enumConstant.toString().equals(fieldValueString)) { field.set(hwAddress, enumConstant); } } } else { field.set(hwAddress, fieldValueString); } } catch (NoSuchFieldException nsfe) { String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. " + "The following variable does not exist in " + hwAddressClass.toString() + ": \"" + decodeFieldName(fieldName) + "\""; log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new RuntimeException(iae); } catch (NumberFormatException npe) { String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. Field \"" + fieldName + "\" shall not be empty since we expect a \"" + fieldTypeName + "\" value. Please correct the XML configuration for " + hwAddressClass.toString(); log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } } } return hwAddress; }
From source file:ar.com.fdvs.dj.core.layout.Dj2JrCrosstabBuilder.java
private void createMainHeaderCell() { JRDesignCellContents contents = new JRDesignCellContents(); contents.setBackcolor(colors[colors.length - 1][colors[0].length - 1]); contents.setMode(new Byte(Transparency.OPAQUE.getValue())); jrcross.setHeaderCell(contents);//from w w w. j a va 2 s. co m JRDesignTextField element = new JRDesignTextField(); String text = ""; int auxHeight = 0; int auxWidth = 0; if (djcross.isAutomaticTitle()) text = createAutomaticMainHeaderTitle(); else if (djcross.getMainHeaderTitle() != null) text = "\"" + djcross.getMainHeaderTitle() + "\""; for (Iterator iterator = djcross.getColumns().iterator(); iterator.hasNext();) { DJCrosstabColumn col = (DJCrosstabColumn) iterator.next(); auxHeight += col.getHeaderHeight(); } for (Iterator iterator = djcross.getRows().iterator(); iterator.hasNext();) { DJCrosstabRow row = (DJCrosstabRow) iterator.next(); auxWidth += row.getHeaderWidth(); } JRDesignExpression exp = ExpressionUtils.createStringExpression(text); element.setExpression(exp); element.setWidth(auxWidth); element.setHeight(auxHeight); element.setStretchWithOverflow(true); if (djcross.getHeaderStyle() != null) layoutManager.applyStyleToElement(djcross.getHeaderStyle(), element); applyCellBorder(contents); contents.addElement(element); }
From source file:org.hyperic.hq.ui.taglib.OptionMessageListTag.java
protected Iterator getIterator(Object collection) throws JspException { try {// w w w .j a v a2 s. c om return super.getIterator(collection); } catch (ClassCastException e) { List list; if (collection.getClass().isArray()) { if (collection instanceof short[]) { short[] arr = (short[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Short(arr[i])); } } else if (collection instanceof int[]) { int[] arr = (int[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Integer(arr[i])); } } else if (collection instanceof long[]) { long[] arr = (long[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Long(arr[i])); } } else if (collection instanceof float[]) { float[] arr = (float[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Float(arr[i])); } } else if (collection instanceof double[]) { double[] arr = (double[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Double(arr[i])); } } else if (collection instanceof byte[]) { byte[] arr = (byte[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Byte(arr[i])); } } else if (collection instanceof char[]) { char[] arr = (char[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Character(arr[i])); } } else if (collection instanceof boolean[]) { boolean[] arr = (boolean[]) collection; list = new ArrayList(arr.length); for (int i = 0; i < arr.length; ++i) { list.add(new Boolean(arr[i])); } } else { list = new ArrayList(); } } else { list = new ArrayList(); } return list.iterator(); } }
From source file:org.joda.primitives.list.impl.AbstractTestByteList.java
public void testLast_notEmpty() { if (isAddSupported() == false) { return;// www .j a v a2 s . c o m } resetEmpty(); ByteList plist = (ByteList) collection; plist.add((byte) 0); plist.add((byte) 6); assertEquals(new Byte((byte) 6), plist.last()); }
From source file:com.jaspersoft.jasperserver.ws.axis2.RepositoryHelper.java
/** * This method get a string and tries to convert the string into the requested object. * Valid classes are:/*from ww w. ja v a 2 s. c om*/ * java.util.Date (the string is supposed to represent a number of milliseconds) * Number * BigDecimal * Byte * Short * Integer * Long * Float * Double * Boolean * String * java.util.Locale * * The default returned object is of type String * @param str the string representing the value * @param clazz The class of the result (not garanteed) * @return return an Object hopefully of the requested class (or a String) * */ public Object stringToValue(String str, Class clazz) { Object value = str; if (value == null) { return value; } if (java.util.Date.class.getName().equals(clazz.getName())) { value = new java.util.Date(Long.valueOf(value.toString()).longValue()); } else if (java.sql.Date.class.getName().equals(clazz.getName())) { value = new java.sql.Date(Long.valueOf(value.toString()).longValue()); } else if (java.sql.Timestamp.class.getName().equals(clazz.getName())) { value = new java.sql.Timestamp(Long.valueOf(value.toString()).longValue()); } else if (Number.class.isAssignableFrom(clazz)) { value = new java.math.BigDecimal(value.toString()); if (Byte.class.getName().equals(clazz.getName())) { value = new Byte(((Number) value).byteValue()); } else if (Short.class.getName().equals(clazz.getName())) { value = new Short(((Number) value).shortValue()); } else if (Integer.class.getName().equals(clazz.getName())) { value = new Integer(((Number) value).intValue()); } else if (Long.class.getName().equals(clazz.getName())) { value = new Long(((Number) value).longValue()); } else if (Float.class.getName().equals(clazz.getName())) { value = new Float(((Number) value).floatValue()); } else if (Double.class.getName().equals(clazz.getName())) { value = new Double(((Number) value).doubleValue()); } } else if (Boolean.class.getName().equals(clazz.getName())) { value = Boolean.valueOf(value.toString()); } else if (Locale.class.getName().equals(clazz.getName())) { value = LocaleHelper.getInstance().getLocale(str); } else if (DateRange.class.equals(clazz)) { try { value = DateRangeFactory.getInstance(str, Date.class); } catch (InvalidDateRangeExpressionException e) { //if DateRange passed as string with milliseconds we need to parse it Date dateValue = (Date) stringToValue(str, Date.class); value = DateRangeFactory.getInstance(dateValue); } } else if (TimestampRange.class.equals(clazz)) { try { value = DateRangeFactory.getInstance(str, Timestamp.class); } catch (InvalidDateRangeExpressionException e) { //if TimestampRange passed as string with milliseconds we need to parse it Timestamp timestamp = (Timestamp) stringToValue(str, Timestamp.class); value = DateRangeFactory.getInstance(timestamp); } } return value; }
From source file:org.red5.server.service.ConversionUtils.java
/** * Convert string to primitive wrapper like Boolean or Float * @param str String to convert * @param wrapper Primitive wrapper type * @return Converted object *///from w ww . j a v a2 s . c o m public static Object convertStringToWrapper(String str, Class<?> wrapper) { if (wrapper.equals(String.class)) { return str; } else if (wrapper.equals(Boolean.class)) { return new Boolean(str); } else if (wrapper.equals(Double.class)) { return new Double(str); } else if (wrapper.equals(Long.class)) { return new Long(str); } else if (wrapper.equals(Float.class)) { return new Float(str); } else if (wrapper.equals(Integer.class)) { return new Integer(str); } else if (wrapper.equals(Short.class)) { return new Short(str); } else if (wrapper.equals(Byte.class)) { return new Byte(str); } throw new ConversionException("Unable to convert string to: " + wrapper); }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
public void testPrimitive() throws Exception { assertEquals(Boolean.TRUE, ParseUtils.parse(boolean.class, "true")); assertEquals(Boolean.FALSE, ParseUtils.parse(boolean.class, "false")); assertEquals(new Character((char) 10), ParseUtils.parse(char.class, "\n")); assertEquals(new Byte((byte) 10), ParseUtils.parse(byte.class, "10")); assertEquals(new Short((short) 10), ParseUtils.parse(short.class, "10")); assertEquals(new Integer(10), ParseUtils.parse(int.class, "10")); assertEquals(new Long(10), ParseUtils.parse(long.class, "10")); assertEquals(new Float(10), ParseUtils.parse(float.class, "10")); assertEquals(new Double(10), ParseUtils.parse(double.class, "10")); }//w w w . j a v a 2 s . c o m
From source file:org.floggy.synchronization.jme.core.impl.JSONSerializationManagerTest.java
/** * DOCUMENT ME!//from ww w .ja v a2 s. c o m * * @throws Exception DOCUMENT ME! */ public void testReceiveHashtableNotNull() throws Exception { JSONObject jsonObject = new JSONObject(); JSONObject keyValuePair = new JSONObject(); String name = "hashtable"; Hashtable expected = new Hashtable(); JSONArray array = new JSONArray(); JSONObject key = new JSONObject(); JSONObject value = new JSONObject(); Object o = "byte"; key.put("className", o.getClass().getName()); key.put("value", o); o = new Byte((byte) 87); value.put("className", o.getClass().getName()); value.put("value", o); keyValuePair.put("key", key); keyValuePair.put("value", value); array.put(keyValuePair); jsonObject.put(name, array); expected.put("byte", o); Hashtable actual = JSONSerializationManager.receiveHashtable(name, jsonObject); assertEquals(expected, actual); }
From source file:com.fluidops.iwb.api.APIImpl.java
public void setConfigOption(String key, String value) throws Exception { Method found = null;// w w w. ja v a 2s . co m // fbase Config for (Method m : Config.class.getMethods()) { ConfigDoc cfd = m.getAnnotation(ConfigDoc.class); if (cfd != null) if (cfd.name().equals(key)) found = m; } // check if prop exists if (found == null) throw new Exception("Config property does not exist: " + key); // check type if (found.getReturnType().equals(boolean.class)) Boolean.valueOf(value); else if (found.getReturnType().equals(int.class)) new Integer(value); else if (found.getReturnType().equals(long.class)) new Long(value); else if (found.getReturnType().equals(byte.class)) new Byte(value); else if (found.getReturnType().equals(short.class)) new Short(value); else if (found.getReturnType().equals(float.class)) new Float(value); else if (found.getReturnType().equals(double.class)) new Double(value); else if (found.getReturnType().equals(char.class)) Character.valueOf(value.charAt(0)); else if (found.getReturnType().equals(Character.class)) Character.valueOf(value.charAt(0)); else found.getReturnType().getConstructor(String.class).newInstance(value); com.fluidops.config.Config.getConfig().set(key, value); }
From source file:org.openvpms.component.system.common.jxpath.OpenVPMSTypeConverter.java
@Override protected Number allocateNumber(Class type, double value) { if (type == Byte.class || type == byte.class) { return new Byte((byte) value); }//from w w w . j a v a 2s . c om if (type == Short.class || type == short.class) { return new Short((short) value); } if (type == Integer.class || type == int.class) { return new Integer((int) value); } if (type == Long.class || type == long.class) { return new Long((long) value); } if (type == Float.class || type == float.class) { return new Float((float) value); } if (type == Double.class || type == double.class) { return new Double(value); } if (type == BigDecimal.class) { return new BigDecimal(value); } if (type == BigInteger.class) { return BigInteger.valueOf((long) value); } if (type == Money.class) { return new Money(value); } return null; }