List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:org.lightadmin.core.util.NumberUtils.java
@SuppressWarnings("unchecked") public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass) throws IllegalArgumentException { Assert.notNull(number, "Number must not be null"); Assert.notNull(targetClass, "Target class must not be null"); if (targetClass.isInstance(number)) { return (T) number; } else if (targetClass.equals(byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); }/*from w w w . j a va 2s . c o m*/ return (T) new Byte(number.byteValue()); } else if (targetClass.equals(short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return (T) new Short(number.shortValue()); } else if (targetClass.equals(int.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return (T) new Integer(number.intValue()); } else if (targetClass.equals(long.class)) { return (T) new Long(number.longValue()); } else if (targetClass.equals(float.class)) { return (T) Float.valueOf(number.toString()); } else if (targetClass.equals(double.class)) { return (T) Double.valueOf(number.toString()); } else { return org.springframework.util.NumberUtils.convertNumberToTargetClass(number, targetClass); } }
From source file:com.baculsoft.beanutils.test.TestBeanUtil2.java
@Test public void testCopy() throws Throwable { PojoExample pojoSource = new PojoExample(); pojoSource.setStringProp("String Property"); pojoSource.setBooleanProp(true);/*w w w .j a v a2s .c o m*/ pojoSource.setBooleanProp1(Boolean.TRUE); pojoSource.setDateProp(new Date()); pojoSource.setByteProp1(new Byte((byte) 11)); pojoSource.setIntProp1(new Integer(15125)); pojoSource.setLongProp1(new Long(20053215235l)); pojoSource.setFloatProp1(new Float(20053215235f)); PojoExample pojoTarget = new PojoExample(); pojoDescriptor.copy(pojoSource, pojoTarget); pojoDescriptor.reset(pojoTarget); PojoExample pojoTarget2 = new PojoExample(); PojoExample pojoTarget3 = new PojoExample(); BeanUtils.copyProperties(pojoSource, pojoTarget2); org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3); long t1 = System.currentTimeMillis(); for (int i = 0; i < 50; i++) { pojoDescriptor.copy(pojoSource, pojoTarget); } t1 = System.currentTimeMillis() - t1; long t2 = System.currentTimeMillis(); for (int i = 0; i < 50; i++) { BeanUtils.copyProperties(pojoSource, pojoTarget2); } t2 = System.currentTimeMillis() - t2; long t3 = System.currentTimeMillis(); for (int i = 0; i < 50; i++) { org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3); } t3 = System.currentTimeMillis() - t3; System.out.println("Time to copy properties "); System.out.println("this class: t1 ---> " + t1); System.out.println("spring-beans: t2 --->" + t2); System.out.println("apache commons: t3 --->" + t3); System.out.println(pojoDescriptor.describe(pojoTarget).equals(pojoDescriptor.describe(pojoTarget2))); assertEquals(pojoDescriptor.describe(pojoTarget), pojoDescriptor.describe(pojoTarget2)); }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>//from w w w.j a va2 s. c om * * <p>If the input array is <code>null</code>, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 3) = [2, 6, 3] * ArrayUtils.add([2, 6], 0, 1) = [1, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be <code>null</code> * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static byte[] add(byte[] array, int index, byte element) { return (byte[]) add(array, index, new Byte(element), Byte.TYPE); }
From source file:com.linkedin.paldb.impl.GenerateTestData.java
public static Object[] generateCompoundKeys(int count) { Object[] res = new Object[count]; Random random = new Random(345); for (int i = 0; i < count; i++) { Object[] k = new Object[] { new Byte((byte) random.nextInt(10)), new Integer(i) }; res[i] = k;/*from w w w. ja v a 2 s. com*/ } return res; }
From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.ByteCalculator.java
public Object mul(Object obj1, Object obj2) { Byte byteData1 = (Byte) obj1; Byte byteData2 = (Byte) obj2; return (Object) (new Byte((byte) (byteData1.byteValue() * byteData2.byteValue()))); }
From source file:com.healthmarketscience.jackcess.DataTypes.java
public static int toSQLType(byte dataType) throws SQLException { Integer i = (Integer) SQL_TYPES.get(new Byte(dataType)); if (i != null) { return i.intValue(); } else {/*from w ww.j av a2 s . c om*/ throw new SQLException("Unsupported data type: " + dataType); } }
From source file:com.jaspersoft.studio.components.chart.model.enums.JFreeChartAxisLocationEnum.java
/** * *///from w w w . j av a 2 s .co m public static JFreeChartAxisLocationEnum getByValue(byte value) { return getByValue(new Byte(value)); }
From source file:org.floggy.synchronization.jme.core.impl.JSONSerializationManager.java
/** * DOCUMENT ME!//from w ww . j a va2 s . c o m * * @param name DOCUMENT ME! * @param jsonObject DOCUMENT ME! * * @return DOCUMENT ME! * * @throws JSONException DOCUMENT ME! */ public static Byte receiveByte(String name, JSONObject jsonObject) throws JSONException { Object value = jsonObject.opt(name); if (value != null) { if (value instanceof Byte) { return ((Byte) value); } else if (value instanceof Integer) { return new Byte(((Integer) value).byteValue()); } } return null; }
From source file:Main.java
/** * Convert and join an array of bytes into one string. * * @param array Array of objects to join as strings. * @return Converted and joined objects. *//*from w w w . ja v a2 s . c om*/ public static String join(final byte array[]) { Byte bytes[] = new Byte[array.length]; for (int i = 0; i < bytes.length; i++) { bytes[i] = new Byte(array[i]); } return join(bytes, null); }
From source file:org.rifidi.emulator.io.comm.serial.SerialCommunicationIncomingMessageHandler.java
public void run() { // byte[] message = null; DataBuffer<byte[]> newBuffer = host.getReceiveBuffer(); ArrayList<Byte> receivedData = new ArrayList<Byte>(); boolean keepRunning = true; DataInputStream dataStream = new DataInputStream(serialIn); while (keepRunning) { boolean eof = false; /* Read as fully as we can */ while (!eof) { try { /* Attempt to read in a byte */ receivedData.add(new Byte(dataStream.readByte())); if (dataStream.available() <= 0) { eof = true;//from w w w . j a va 2s .c o m } } catch (EOFException eofe) { /* Indicate end of file */ eof = true; } catch (IOException e) { logger.error(e.getMessage()); eof = true; } } /* Check that we have something to "receive" */ if (!receivedData.isEmpty()) { logger.debug("Back in the if statement"); /* Construct an array of bytes */ byte[] receivedBytes = new byte[receivedData.size()]; for (int i = 0; i < receivedData.size(); i++) { receivedBytes[i] = receivedData.get(i).byteValue(); } receivedData.clear(); if (keepRunning) { /* Actually add to the receive buffer */ try { logger.debug("Adding to buffer: " + receivedBytes); List<byte[]> listOfBytes = this.host.getProtocol().removeProtocol(receivedBytes); for (byte[] b : listOfBytes) { newBuffer.addToBuffer(b); } String x = ""; for (byte i : receivedBytes) { x += String.format("%1$02x", i) + " "; } this.host.getConsoleLogger().info("<INPUT> " + x + "</INPUT>"); } catch (DataBufferInterruptedException e) { logger.error(e.getMessage()); keepRunning = false; } catch (ProtocolValidationException e) { logger.error(e.getMessage()); keepRunning = false; } } } } }