List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * @param dataTypeClass/*from w w w. j a v a 2 s .c o m*/ * @param untypedValue * @return */ public static Object toDataType(Class<?> dataTypeClass, Object untypedValue) { if ((dataTypeClass == null) || (untypedValue == null) || ClassUtils.isAssignable(untypedValue.getClass(), dataTypeClass)) { if (Date.class == dataTypeClass) { return DateUtils.truncate(untypedValue, Calendar.DATE); } return untypedValue; } Object v = null; String strUntypedValue = null; boolean isStringUntypedValue = untypedValue instanceof String; Number numUntypedValue = null; boolean isNumberUntypedValue = untypedValue instanceof Number; if (isStringUntypedValue) { strUntypedValue = (String) untypedValue; } if (isNumberUntypedValue) { numUntypedValue = (Number) untypedValue; } if (dataTypeClass == boolean.class || dataTypeClass == Boolean.class) { if (isNumberUntypedValue) { v = BooleanUtils.toBooleanObject(numUntypedValue.intValue()); } else if (isStringUntypedValue) { v = BooleanUtils.toBooleanObject(strUntypedValue); } } else if (dataTypeClass == Integer.class) { if (isNumberUntypedValue) { v = new Integer(numUntypedValue.intValue()); } else if (isStringUntypedValue) { v = NumberUtils.createInteger(strUntypedValue); } } else if (dataTypeClass == Double.class) { if (isNumberUntypedValue) { v = new Double(numUntypedValue.doubleValue()); } else if (isStringUntypedValue) { v = NumberUtils.createDouble(strUntypedValue); } } else if (dataTypeClass == Date.class) { if (isNumberUntypedValue) { v = DateUtils.truncate(new Date(numUntypedValue.longValue()), Calendar.DATE); } } else { v = ObjectUtils.toString(untypedValue); } return v; }
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleOr(final int opcode, final Number one, final Number two) { final Number number; if (opcode == IOR) { number = Integer.valueOf(one.intValue() | two.intValue()); } else {/* w w w. j av a 2s. com*/ number = Long.valueOf(one.longValue() | two.longValue()); } return NodeHelper.getInsnNodeFor(number); }
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleAnd(final int opcode, final Number one, final Number two) { final Number number; if (opcode == IAND) { number = Integer.valueOf(one.intValue() & two.intValue()); } else {/*from w w w .ja v a 2s . co m*/ number = Long.valueOf(one.longValue() & two.longValue()); } return NodeHelper.getInsnNodeFor(number); }
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleXOr(final int opcode, final Number one, final Number two) { final Number number; if (opcode == IXOR) { number = Integer.valueOf(one.intValue() ^ two.intValue()); } else {//from www . ja v a2s. c o m number = Long.valueOf(one.longValue() ^ two.longValue()); } return NodeHelper.getInsnNodeFor(number); }
From source file:net.sf.jasperreports.engine.data.JRAbstractTextDataSource.java
protected Object convertNumber(Number number, Class<?> valueClass) throws JRException { Number value = null;// w ww .j a v a 2 s . c om if (valueClass.equals(Byte.class)) { value = number.byteValue(); } else if (valueClass.equals(Short.class)) { value = number.shortValue(); } else if (valueClass.equals(Integer.class)) { value = number.intValue(); } else if (valueClass.equals(Long.class)) { value = number.longValue(); } else if (valueClass.equals(Float.class)) { value = number.floatValue(); } else if (valueClass.equals(Double.class)) { value = number.doubleValue(); } else if (valueClass.equals(BigInteger.class)) { value = BigInteger.valueOf(number.longValue()); } else if (valueClass.equals(BigDecimal.class)) { value = new BigDecimal(Double.toString(number.doubleValue())); } else { throw new JRException(EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE, new Object[] { valueClass.getName() }); } return value; }
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleShiftLeft(final int opcode, final Number one, final Number two) { final Number number; if (opcode == ISHL) { number = Integer.valueOf(one.intValue() << two.intValue()); } else {/*from ww w . ja v a2 s. c om*/ number = Long.valueOf(one.longValue() << two.longValue()); } return NodeHelper.getInsnNodeFor(number); }
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleArithmeticShiftRight(final int opcode, final Number one, final Number two) { final Number number; if (opcode == ISHR) { number = Integer.valueOf(one.intValue() >> two.intValue()); } else {//from ww w . ja v a 2 s . co m number = Long.valueOf(one.longValue() >> two.longValue()); } return NodeHelper.getInsnNodeFor(number); }
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleLogicalShiftRight(final int opcode, final Number one, final Number two) { final Number number; if (opcode == IUSHR) { number = Integer.valueOf(one.intValue() >>> two.intValue()); } else {/*from w ww . ja v a 2 s. co m*/ number = Long.valueOf(one.longValue() >>> two.longValue()); } return NodeHelper.getInsnNodeFor(number); }
From source file:org.rhq.enterprise.gui.common.servlet.ParameterizedServlet.java
/** * Parse a required long parameter.//from ww w .jav a 2 s . c om * * @param request the servlet request * @param paramName the parameter name * * @return the value of the parsed parameter * * @throws IllegalArgumentException if the parameter didn't exist */ protected long parseRequiredLongParameter(HttpServletRequest request, String paramName) { long value; String param = request.getParameter(paramName); if (null != param) { Number n = NumberUtil.stringAsNumber(param); if (n.equals(NumberUtil.NaN)) { throw invalidParamErr(paramName, param); } else { value = n.longValue(); } } else { throw requiredParamErr(paramName); } return value; }
From source file:org.polymap.core.runtime.recordstore.lucene.NumericValueCoder.java
public Query searchQuery(QueryExpression exp) { // EQUALS/*from w w w .j a v a 2 s. c om*/ if (exp instanceof QueryExpression.Equal) { Equal equalExp = (QueryExpression.Equal) exp; if (equalExp.value instanceof Number) { String key = equalExp.key; Number value = (Number) equalExp.value; if (equalExp.value instanceof Integer) { return NumericRangeQuery.newIntRange(key, value.intValue(), value.intValue(), true, true); } else if (equalExp.value instanceof Long) { return NumericRangeQuery.newLongRange(key, value.longValue(), value.longValue(), true, true); } else if (equalExp.value instanceof Float) { return NumericRangeQuery.newFloatRange(key, value.floatValue(), value.floatValue(), true, true); } else if (equalExp.value instanceof Double) { return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), value.doubleValue(), true, true); } else { throw new RuntimeException("Unknown Number type: " + value.getClass()); } } } // GREATER else if (exp instanceof QueryExpression.Greater) { Greater greaterExp = (QueryExpression.Greater) exp; if (greaterExp.value instanceof Number) { String key = greaterExp.key; Number value = (Number) greaterExp.value; if (greaterExp.value instanceof Integer) { return NumericRangeQuery.newIntRange(key, value.intValue(), null, false, false); } else if (greaterExp.value instanceof Long) { return NumericRangeQuery.newLongRange(key, value.longValue(), null, false, false); } else if (greaterExp.value instanceof Float) { return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, false, false); } else if (greaterExp.value instanceof Double) { return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, false, false); } else { throw new RuntimeException("Unknown Number type: " + value.getClass()); } } } // GREATER OR EQUAL else if (exp instanceof QueryExpression.GreaterOrEqual) { GreaterOrEqual greaterExp = (QueryExpression.GreaterOrEqual) exp; if (greaterExp.value instanceof Number) { String key = greaterExp.key; Number value = (Number) greaterExp.value; if (greaterExp.value instanceof Integer) { return NumericRangeQuery.newIntRange(key, value.intValue(), null, true, false); } else if (greaterExp.value instanceof Long) { return NumericRangeQuery.newLongRange(key, value.longValue(), null, true, false); } else if (greaterExp.value instanceof Float) { return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, true, false); } else if (greaterExp.value instanceof Double) { return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, true, false); } else { throw new RuntimeException("Unknown Number type: " + value.getClass()); } } } // LESS else if (exp instanceof QueryExpression.Less) { Less lessExp = (QueryExpression.Less) exp; if (lessExp.value instanceof Number) { String key = lessExp.key; Number value = (Number) lessExp.value; if (lessExp.value instanceof Integer) { return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, false); } else if (lessExp.value instanceof Long) { return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, false); } else if (lessExp.value instanceof Float) { return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, false); } else if (lessExp.value instanceof Double) { return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, false); } else { throw new RuntimeException("Unknown Number type: " + value.getClass()); } } } // LESS or equal else if (exp instanceof QueryExpression.LessOrEqual) { LessOrEqual lessExp = (QueryExpression.LessOrEqual) exp; if (lessExp.value instanceof Number) { String key = lessExp.key; Number value = (Number) lessExp.value; if (lessExp.value instanceof Integer) { return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, true); } else if (lessExp.value instanceof Long) { return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, true); } else if (lessExp.value instanceof Float) { return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, true); } else if (lessExp.value instanceof Double) { return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, true); } else { throw new RuntimeException("Unknown Number type: " + value.getClass()); } } } // MATCHES else if (exp instanceof QueryExpression.Match) { Match matchExp = (Match) exp; if (matchExp.value instanceof Number) { throw new UnsupportedOperationException("MATCHES not supported for Number values."); } } return null; }