List of usage examples for java.lang Byte MAX_VALUE
byte MAX_VALUE
To view the source code for java.lang Byte MAX_VALUE.
Click Source Link
From source file:com.milaboratory.util.Math.java
public static byte min(byte[] array) { byte min = Byte.MAX_VALUE; for (byte b : array) if (b < min) min = b;/* w ww.j a v a 2 s .c om*/ return min; }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert// w w w . j a v a2 s .c o m * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class targetClass) throws IllegalArgumentException { if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return 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 new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:com.p5solutions.core.utils.NumberUtils.java
public static boolean isByte(String value) { if (isNatural(value)) { Long v = NumberUtils.valueOf(value.toString(), Long.class); if (v >= Byte.MIN_VALUE && v <= Byte.MAX_VALUE) { return true; }/*from w w w.ja v a2 s . com*/ } return false; }
From source file:io.github.benas.jpopulator.randomizers.validation.MinValueRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @param minValue the minimum threshold for the generated value * @return a random value (greater than maxValue) for the given type or null if the type is not supported *///from w w w .j a v a2s. c o m public static Object getRandomValue(final Class type, final long minValue) { if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) randomDataGenerator.nextLong(minValue, Byte.MAX_VALUE); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) randomDataGenerator.nextLong(minValue, Short.MAX_VALUE); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return (int) randomDataGenerator.nextLong(minValue, Integer.MAX_VALUE); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return randomDataGenerator.nextLong(minValue, Long.MAX_VALUE); } if (type.equals(BigInteger.class)) { return new BigInteger(String.valueOf(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE))); } if (type.equals(BigDecimal.class)) { return new BigDecimal(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE)); } return null; }
From source file:Base64Utils.java
public static byte[] base64Decode(char[] data, int off, int len) { char[] ibuf = new char[4]; int ibufcount = 0; byte[] obuf = new byte[len / 4 * 3 + 3]; int obufcount = 0; for (int i = off; i < off + len; i++) { char ch = data[i]; if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { ibuf[ibufcount++] = ch;//from w w w .java 2 s.c o m if (ibufcount == ibuf.length) { ibufcount = 0; obufcount += base64Decode0(ibuf, obuf, obufcount); } } } if (obufcount == obuf.length) { return obuf; } byte[] ret = new byte[obufcount]; System.arraycopy(obuf, 0, ret, 0, obufcount); return ret; }
From source file:org.sakaiproject.content.impl.serialize.impl.test.ByteStorageConversionCheck.java
@Test public void test256Conversion() { byte[] bin = new byte[256]; char[] cin = new char[256]; byte[] bout = new byte[256]; {//from w ww. j a v a 2 s. co m int i = 0; for (byte bx = Byte.MIN_VALUE; bx <= Byte.MAX_VALUE && i < bin.length; bx++) { bin[i++] = bx; } } ByteStorageConversion.toChar(bin, 0, cin, 0, bin.length); ByteStorageConversion.toByte(cin, 0, bout, 0, cin.length); StringBuilder sb = new StringBuilder(); sb.append("\n"); for (int i = 0; i < bin.length; i++) { sb.append(" Byte " + bin[i] + ": Stored as int[" + (int) cin[i] + "] char[" + cin[i] + "]\n"); } log.info(sb.toString()); for (int i = 0; i < bin.length; i++) { Assert.assertEquals( "Internal Byte conversion failed at " + bin[i] + "=>" + (int) cin[i] + "=>" + bout[i], bin[i], bout[i]); } log.info("Internal Byte conversion test Passed Ok"); }
From source file:com.sdl.odata.renderer.json.util.JsonWriterUtilTest.java
@Test public void testWritePrimitiveValues() throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stream, JsonEncoding.UTF8); jsonGenerator.writeStartObject();//w w w . ja va 2 s . c om appendPrimitiveValue("MyString", "Some text", jsonGenerator); appendPrimitiveValue("MyByteProperty", Byte.MAX_VALUE, jsonGenerator); appendPrimitiveValue("MyShortProperty", (short) 1, jsonGenerator); appendPrimitiveValue("MyIntegerProperty", 2, jsonGenerator); appendPrimitiveValue("MyFloatProperty", 3.0f, jsonGenerator); appendPrimitiveValue("MyDoubleProperty", 4.0d, jsonGenerator); appendPrimitiveValue("MyLongProperty", (long) 5, jsonGenerator); appendPrimitiveValue("MyBooleanProperty", true, jsonGenerator); appendPrimitiveValue("MyUUIDProperty", UUID.fromString("23492a5b-c4f1-4a50-b7a5-d8ebd6067902"), jsonGenerator); appendPrimitiveValue("DecimalValueProperty", BigDecimal.valueOf(21), jsonGenerator); jsonGenerator.writeEndObject(); jsonGenerator.close(); assertEquals(prettyPrintJson(readContent(EXPECTED_PRIMITIVE_VALUES_PATH)), prettyPrintJson(stream.toString())); }
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 ww . j a va 2 s . co 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:Base64.java
/** * Decode the base64 data.//from www. ja v a 2s.com * @param data The base64 encoded data to be decoded * @param off The offset within the encoded data at which to start decoding * @param len The length of data to decode * @return The decoded data */ public static byte[] decode(char[] data, int off, int len) { char[] ibuf = new char[4]; int ibufcount = 0; byte[] obuf = new byte[(len >> 2) * 3 + 3]; int obufcount = 0; for (int i = off; i < off + len; i++) { char ch = data[i]; if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { ibuf[ibufcount++] = ch; if (ibufcount == ibuf.length) { ibufcount = 0; obufcount += decode0(ibuf, obuf, obufcount); } } } if (obufcount == obuf.length) { return obuf; } byte[] ret = new byte[obufcount]; System.arraycopy(obuf, 0, ret, 0, obufcount); return ret; }
From source file:org.joda.primitives.iterator.impl.TestArrayByteIterator.java
@Override public Iterator<Byte> makeFullIterator() { byte[] data = new byte[] { new Byte((byte) 2), new Byte((byte) -2), new Byte((byte) 38), new Byte((byte) 0), new Byte((byte) 126), new Byte((byte) 202), new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE) }; return new ArrayByteIterator(data); }