List of usage examples for java.lang Long byteValue
public byte byteValue()
From source file:Main.java
public static void main(String[] args) { Long longObject = new Long("1234567"); byte b = longObject.byteValue(); System.out.println("byte:" + b); }
From source file:Main.java
public static void main(String[] args) { Long lObj = new Long("10"); byte b = lObj.byteValue(); System.out.println(b);//ww w. j av a 2 s . co m short s = lObj.shortValue(); System.out.println(s); int i = lObj.intValue(); System.out.println(i); float f = lObj.floatValue(); System.out.println(f); double d = lObj.doubleValue(); System.out.println(d); }
From source file:org.apache.hadoop.hive.ql.udf.UDFToByte.java
public Byte evaluate(Long i) { if (i == null) { return null; } else {/*ww w. j a v a 2 s. c o m*/ return Byte.valueOf(i.byteValue()); } }
From source file:com.wizecommerce.hecuba.JSONResultSet.java
public Byte getByte(String fieldName) { final Long value = (Long) decoder.get(fieldName); return (value == null) ? null : value.byteValue(); }
From source file:com.linkedin.urls.HostNormalizer.java
/** * This covers cases like://ww w. j a va 2 s.c o m * Hexadecimal: 0x1283983 * Decimal: 12839273 * Octal: 037362273110 * Dotted Decimal: 192.168.1.1 * Dotted Hexadecimal: 0xfe.0x83.0x18.0x1 * Dotted Octal: 0301.00.046.00 * Dotted Mixed: 0x38.168.077.1 * * if ipv4 was found, _bytes is set to the byte representation of the ipv4 address */ private byte[] tryDecodeHostToIPv4(String host) { String[] parts = CharUtils.splitByDot(host); int numParts = parts.length; if (numParts != 4 && numParts != 1) { return null; } byte[] bytes = new byte[16]; //An ipv4 mapped ipv6 bytes will have the 11th and 12th byte as 0xff bytes[10] = (byte) 0xff; bytes[11] = (byte) 0xff; for (int i = 0; i < parts.length; i++) { String parsedNum; int base; if (parts[i].startsWith("0x")) { //hex parsedNum = parts[i].substring(2); base = 16; } else if (parts[i].startsWith("0")) { //octal parsedNum = parts[i].substring(1); base = 8; } else { //decimal parsedNum = parts[i]; base = 10; } Long section; try { section = parsedNum.isEmpty() ? 0 : Long.parseLong(parsedNum, base); } catch (NumberFormatException e) { return null; } if (numParts == 4 && section > MAX_IPV4_PART || //This would look like 288.1.2.4 numParts == 1 && section > MAX_NUMERIC_DOMAIN_VALUE || //This would look like 4294967299 section < MIN_IP_PART) { return null; } //bytes 13->16 is where the ipv4 address of an ipv4-mapped-ipv6-address is stored. if (numParts == 4) { bytes[IPV4_MAPPED_IPV6_START_OFFSET + i] = section.byteValue(); } else { //numParts == 1 int index = IPV4_MAPPED_IPV6_START_OFFSET; bytes[index++] = (byte) ((section >> 24) & 0xFF); bytes[index++] = (byte) ((section >> 16) & 0xFF); bytes[index++] = (byte) ((section >> 8) & 0xFF); bytes[index] = (byte) (section & 0xFF); return bytes; } } return bytes; }
From source file:com.intuit.tank.vm.settings.AgentConfigCpTest.java
/** * Run the Long getConnectionTimeout() method test. * //from ww w . j a v a2s . c om * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testGetConnectionTimeout_1() throws Exception { AgentConfig fixture = new AgentConfig(new HierarchicalConfiguration()); fixture.setResultsTypeMap(new HashMap()); Long result = fixture.getConnectionTimeout(); assertNotNull(result); assertEquals("40000", result.toString()); assertEquals((byte) 64, result.byteValue()); assertEquals((short) -25536, result.shortValue()); assertEquals(40000, result.intValue()); assertEquals(40000L, result.longValue()); assertEquals(40000.0f, result.floatValue(), 1.0f); assertEquals(40000.0, result.doubleValue(), 1.0); }
From source file:cz.lbenda.dataman.db.RowDesc.java
@SuppressWarnings({ "unchecked", "RedundantCast" }) private <T> T repairClassOfValue(ColumnDesc column, T value) { if (value == null) { return null; }//from w ww . j av a 2 s . c o m if (column.getDataType().getJavaClass().equals(value.getClass())) { return value; } if (column.getDataType() == ColumnType.TIME) { if (value instanceof LocalTime) { return (T) (Object) java.sql.Time.valueOf((LocalTime) value); } } else if (column.getDataType() == ColumnType.DATE) { if (value instanceof LocalDate) { return (T) (Object) java.sql.Date.valueOf((LocalDate) value); } } else if (column.getDataType() == ColumnType.TIMESTAMP) { if (value instanceof LocalDateTime) { return (T) (Object) java.sql.Timestamp.valueOf((LocalDateTime) value); } } else { Long val; if (value instanceof Long) { val = (Long) value; } else if (value instanceof Integer) { val = ((Integer) value).longValue(); } else if (value instanceof Short) { val = ((Short) value).longValue(); } else if (value instanceof Byte) { val = ((Byte) value).longValue(); } else { return value; } if (column.getDataType() == ColumnType.INTEGER) { return (T) (Object) val.intValue(); } if (column.getDataType() == ColumnType.BYTE) { return (T) (Object) val.byteValue(); } if (column.getDataType() == ColumnType.SHORT) { return (T) (Object) val.shortValue(); } } return value; }
From source file:ca.oson.json.Oson.java
private <E> String byte2Json(FieldData objectDTO) { if (objectDTO == null || objectDTO.json2Java) { return null; }// w ww . j a va 2s. c om Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; if (returnType != null && value != null && (returnType == byte.class || returnType == Byte.class)) { Byte valueToProcess = null; String valueToReturn = null; if (returnType == byte.class) { valueToProcess = Byte.valueOf((byte) value); } else { valueToProcess = (Byte) value; } if (valueToProcess != null) { try { Function function = objectDTO.getSerializer(); if (function != null) { try { if (function instanceof DataMapper2JsonFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); return ((DataMapper2JsonFunction) function).apply(classData); } else if (function instanceof Byte2JsonFunction) { return ((Byte2JsonFunction) function).apply(valueToProcess); } else { Object returnedValue = null; if (function instanceof FieldData2JsonFunction) { FieldData2JsonFunction f = (FieldData2JsonFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else { returnedValue = function.apply(value); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (returnedValue instanceof Byte) { valueToProcess = (Byte) returnedValue; } else { objectDTO.valueToProcess = returnedValue; return object2String(objectDTO); } } } catch (Exception e) { } } if (valueToProcess != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min.byteValue() > valueToProcess) { valueToProcess = min.byteValue(); } if (max != null && max.byteValue() < valueToProcess) { valueToProcess = max.byteValue(); } Integer precision = objectDTO.getPrecision(); if (precision != null) { valueToProcess = (Byte) NumberUtil.setPrecision(valueToProcess, precision, getRoundingMode()); } return NumberUtil.toPlainString(valueToProcess); } } catch (Exception ex) { //ex.printStackTrace(); } } } return byte2JsonDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E> Byte json2Byte(FieldData objectDTO) { if (objectDTO == null || !objectDTO.json2Java) { return null; }// ww w . ja v a2 s.c o m Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; if (value != null && value.toString().trim().length() > 0) { String valueToProcess = value.toString().trim(); Byte valueToReturn = null; try { Function function = objectDTO.getDeserializer(); if (function != null) { try { Object returnedValue = null; if (function instanceof Json2DataMapperFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); returnedValue = ((Json2DataMapperFunction) function).apply(classData); } else if (function instanceof Json2FieldDataFunction) { Json2FieldDataFunction f = (Json2FieldDataFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else if (function instanceof Json2ByteFunction) { return ((Json2ByteFunction) function).apply(valueToProcess); } else { returnedValue = function.apply(valueToProcess); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (Number.class.isAssignableFrom(returnedValue.getClass()) || returnedValue.getClass().isPrimitive()) { if (returnedValue instanceof Byte) { valueToReturn = (Byte) returnedValue; } else if (returnedValue instanceof String) { valueToReturn = Byte .parseByte(NumberUtil.removeTrailingDecimalZeros(returnedValue)); } else if (returnedValue instanceof Integer) { valueToReturn = ((Integer) returnedValue).byteValue(); } else if (returnedValue instanceof Long) { valueToReturn = ((Long) returnedValue).byteValue(); } else if (returnedValue instanceof Short) { valueToReturn = ((Short) returnedValue).byteValue(); } else if (returnedValue instanceof Double) { valueToReturn = ((Double) returnedValue).byteValue(); } else if (returnedValue instanceof Float) { valueToReturn = ((Float) returnedValue).byteValue(); } else if (returnedValue instanceof BigInteger) { valueToReturn = ((BigInteger) returnedValue).byteValue(); } else if (returnedValue instanceof BigDecimal) { valueToReturn = ((BigDecimal) returnedValue).byteValue(); } else if (returnedValue instanceof AtomicInteger) { valueToReturn = ((AtomicInteger) returnedValue).byteValue(); } else if (returnedValue instanceof AtomicLong) { valueToReturn = ((AtomicLong) returnedValue).byteValue(); } else { valueToReturn = ((Number) returnedValue).byteValue(); } } else if (returnedValue instanceof Character) { char c = (Character) returnedValue; valueToReturn = (byte) c; } else if (returnedValue instanceof Boolean) { if ((Boolean) returnedValue) valueToReturn = 1; else valueToReturn = 0; } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = ((Integer) ((Enum) returnedValue).ordinal()).byteValue(); } else if (Date.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = (byte) ((Date) returnedValue).getTime(); } else { valueToReturn = Byte.parseByte(NumberUtil.removeTrailingDecimalZeros(returnedValue)); } return valueToReturn; } catch (Exception e) { e.printStackTrace(); } } else { long longValue = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(valueToProcess)); if (longValue > Byte.MAX_VALUE) { valueToReturn = Byte.MAX_VALUE; } else { valueToReturn = (byte) longValue; } // valueToReturn = Byte.parseByte(valueToProcess); } if (valueToReturn != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min.byteValue() > valueToReturn) { return min.byteValue(); } if (max != null && max.byteValue() < valueToReturn) { valueToReturn = max.byteValue(); } return valueToReturn; } } catch (Exception ex) { //ex.printStackTrace(); } } return json2ByteDefault(objectDTO); }
From source file:ca.oson.json.Oson.java
private <E> Byte json2ByteDefault(FieldData objectDTO) { Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; boolean required = objectDTO.required(); Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); boolean json2Java = objectDTO.json2Java; if (returnType == byte.class || getDefaultType() == JSON_INCLUDE.DEFAULT || required) { Byte defaultValue = (Byte) objectDTO.getDefaultValue(); if (defaultValue != null) { if (min != null && min.byteValue() > defaultValue) { return min.byteValue(); }//from w w w .ja v a2 s . c om return defaultValue; } if (min != null && min.byteValue() > DefaultValue.dbyte) { return min.byteValue(); } return DefaultValue.dbyte; } return null; }