List of usage examples for java.math BigInteger ONE
BigInteger ONE
To view the source code for java.math BigInteger ONE.
Click Source Link
From source file:net.pms.util.Rational.java
/** * Converts this {@link Rational} to a {@link BigDecimal}. This may involve * rounding. The conversion is limited to 100 decimals and uses * {@link RoundingMode#HALF_EVEN}.//from w ww . j a va 2s . c o m * <p> * For explicit control over the conversion, use one of the overloaded * methods. * * @return This {@link Rational} converted to a {@link BigDecimal}. * @throws ArithmeticException If this is {@code NaN} or infinite. * * @see #bigDecimalValue(MathContext) * @see #bigDecimalValue(RoundingMode) * @see #bigDecimalValue(int, RoundingMode) */ @Nonnull public BigDecimal bigDecimalValue() { if (isNaN()) { throw new ArithmeticException("Impossible to express NaN as BigDecimal"); } if (isInfinite()) { throw new ArithmeticException("Impossible to express infinity as BigDecimal"); } if (BigInteger.ONE.equals(reducedDenominator)) { return new BigDecimal(reducedNumerator); } return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), 100, RoundingMode.HALF_EVEN); }
From source file:net.pms.util.Rational.java
/** * Converts this {@link Rational} to a {@link BigDecimal}. This may involve * rounding. The conversion is limited to 100 decimals and uses * {@code roundingMode}./*w w w . j a v a2 s.co m*/ * * @param roundingMode the {@link RoundingMode} to apply. * @return This {@link Rational} converted to a {@link BigDecimal}. * @throws ArithmeticException If this is {@code NaN} or infinite or if * {@code roundingMode} is {@link RoundingMode#UNNECESSARY} and * the specified scale is insufficient to represent the result * of the division exactly. * * @see #bigDecimalValue() * @see #bigDecimalValue(MathContext) * @see #bigDecimalValue(int, RoundingMode) */ @Nonnull public BigDecimal bigDecimalValue(RoundingMode roundingMode) { if (isNaN()) { throw new ArithmeticException("Impossible to express NaN as BigDecimal"); } if (isInfinite()) { throw new ArithmeticException("Impossible to express infinity as BigDecimal"); } if (BigInteger.ONE.equals(reducedDenominator)) { return new BigDecimal(reducedNumerator); } return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), 100, roundingMode); }
From source file:org.nd4j.linalg.util.BigDecimalMath.java
/** * The hyperbolic sine.//from w ww . ja v a 2 s. c o m * * @param x the argument. * @return the sinh(x) = (exp(x)-exp(-x))/2 . */ static public BigDecimal sinh(final BigDecimal x) { if (x.compareTo(BigDecimal.ZERO) < 0) { return sinh(x.negate()).negate(); } else if (x.compareTo(BigDecimal.ZERO) == 0) { return BigDecimal.ZERO; } else { if (x.doubleValue() > 2.4) { /* Move closer to zero with sinh(2x)= 2*sinh(x)*cosh(x). */ BigDecimal two = new BigDecimal(2); BigDecimal xhalf = x.divide(two); BigDecimal resul = sinh(xhalf).multiply(cosh(xhalf)).multiply(two); /* The error in the result is set by the error in x itself. * The first derivative of sinh(x) is cosh(x), so the absolute error * in the result is cosh(x)*errx, and the relative error is coth(x)*errx = errx/tanh(x) */ double eps = Math.tanh(x.doubleValue()); MathContext mc = new MathContext(err2prec(0.5 * x.ulp().doubleValue() / eps)); return resul.round(mc); } else { BigDecimal xhighpr = scalePrec(x, 2); /* Simple Taylor expansion, sum_{i=0..infinity} x^(2i+1)/(2i+1)! */ BigDecimal resul = xhighpr; /* x^i */ BigDecimal xpowi = xhighpr; /* 2i+1 factorial */ BigInteger ifac = BigInteger.ONE; /* The error in the result is set by the error in x itself. */ double xUlpDbl = x.ulp().doubleValue(); /* The error in the result is set by the error in x itself. * We need at most k terms to squeeze x^(2k+1)/(2k+1)! below this value. * x^(2k+1) < x.ulp; (2k+1)*log10(x) < -x.precision; 2k*log10(x)< -x.precision; * 2k*(-log10(x)) > x.precision; 2k*log10(1/x) > x.precision */ int k = (int) (x.precision() / Math.log10(1.0 / xhighpr.doubleValue())) / 2; MathContext mcTay = new MathContext(err2prec(x.doubleValue(), xUlpDbl / k)); for (int i = 1;; i++) { /* TBD: at which precision will 2*i or 2*i+1 overflow? */ ifac = ifac.multiply(new BigInteger("" + (2 * i))); ifac = ifac.multiply(new BigInteger("" + (2 * i + 1))); xpowi = xpowi.multiply(xhighpr).multiply(xhighpr); BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay); resul = resul.add(corr); if (corr.abs().doubleValue() < 0.5 * xUlpDbl) { break; } } /* The error in the result is set by the error in x itself. */ MathContext mc = new MathContext(x.precision()); return resul.round(mc); } } }
From source file:net.pms.util.Rational.java
/** * Converts this {@link Rational} to a {@link BigDecimal}. This may involve * rounding./*from w w w .j a v a 2 s .c om*/ * <p> * Use {@code scale == 0} and * {@code roundingMode == RoundingMode.UNNECESSARY} to achieve absolute * precision. This will throw an {@link ArithmeticException} if the exact * quotient cannot be represented (because it has a non-terminating decimal * expansion). * * @param scale the scale of the {@link BigDecimal} quotient to be returned. * @param roundingMode the {@link RoundingMode} to apply. * @return This {@link Rational} converted to a {@link BigDecimal}. * @throws ArithmeticException If this is {@code NaN} or infinite or if * {@code roundingMode} is {@link RoundingMode#UNNECESSARY} and * the specified scale is insufficient to represent the result * of the division exactly. * * @see #bigDecimalValue() * @see #bigDecimalValue(MathContext) * @see #bigDecimalValue(RoundingMode) */ @Nonnull public BigDecimal bigDecimalValue(int scale, RoundingMode roundingMode) { if (isNaN()) { throw new ArithmeticException("Impossible to express NaN as BigDecimal"); } if (isInfinite()) { throw new ArithmeticException("Impossible to express infinity as BigDecimal"); } if (BigInteger.ONE.equals(reducedDenominator)) { return new BigDecimal(reducedNumerator); } return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), scale, roundingMode); }
From source file:org.apache.pig.test.TestBuiltin.java
@Test public void testAVGFinal() throws Exception { String[] avgTypes = { "AVGFinal", "DoubleAvgFinal", "LongAvgFinal", "IntAvgFinal", "FloatAvgFinal", "BigDecimalAvgFinal", "BigIntegerAvgFinal" }; String[] avgIntermediateTypes = { "AVGIntermediate", "DoubleAvgIntermediate", "LongAvgIntermediate", "IntAvgIntermediate", "FloatAvgIntermediate", "BigDecimalAvgIntermediate", "BigIntegerAvgIntermediate" }; for (int k = 0; k < avgTypes.length; k++) { EvalFunc<?> avg = evalFuncMap.get(avgTypes[k]); Tuple tup = inputMap.get(getInputType(avgTypes[k])); // To test AVGFinal, AVGIntermediate should first be called and // the output of AVGIntermediate should be supplied as input to // AVGFinal. To simulate this, we will call Intermediate twice // on the above tuple and collect the outputs and pass it to // Final. // get the right "Intermediate" EvalFunc EvalFunc<?> avgIntermediate = evalFuncMap.get(avgIntermediateTypes[k]); // The tuple we got above has a bag with input // values. Input to the Intermediate.exec() however comes // from the map which would put each value and a count of // 1 in a tuple and send it down. So lets create a bag with // tuples that have two fields - the value and a count 1. // The input has 10 values - lets put the first five of them // in the input to the first call of AVGIntermediate and the // remaining five in the second call. DataBag bg = (DataBag) tup.get(0); DataBag bg1 = bagFactory.newDefaultBag(); DataBag bg2 = bagFactory.newDefaultBag(); int i = 0; for (Tuple t : bg) { Tuple newTuple = tupleFactory.newTuple(2); newTuple.set(0, t.get(0));/* ww w . j a va2s . c om*/ if (t.get(0) == null) { if (getInputType(avgTypes[k]) == "BigDecimal") { newTuple.set(1, BigDecimal.ZERO); } else if (getInputType(avgTypes[k]) == "BigInteger") { newTuple.set(1, BigInteger.ZERO); } else { newTuple.set(1, new Long(0)); } } else { if (getInputType(avgTypes[k]) == "BigDecimal") { newTuple.set(1, BigDecimal.ONE); } else if (getInputType(avgTypes[k]) == "BigInteger") { newTuple.set(1, BigInteger.ONE); } else { newTuple.set(1, new Long(1)); } } if (i < 5) { bg1.add(newTuple); } else { bg2.add(newTuple); } i++; } Tuple intermediateInput1 = tupleFactory.newTuple(); intermediateInput1.append(bg1); Object output1 = avgIntermediate.exec(intermediateInput1); Tuple intermediateInput2 = tupleFactory.newTuple(); intermediateInput2.append(bg2); Object output2 = avgIntermediate.exec(intermediateInput2); DataBag bag = Util.createBag(new Tuple[] { (Tuple) output1, (Tuple) output2 }); Tuple finalTuple = TupleFactory.getInstance().newTuple(1); finalTuple.set(0, bag); Object output = avg.exec(finalTuple); String msg = "[Testing " + avgTypes[k] + " on input type: " + getInputType(avgTypes[k]) + " ( (output) " + output + " == " + getExpected(avgTypes[k]) + " (expected) )]"; if (getInputType(avgTypes[k]) == "BigDecimal" || getInputType(avgTypes[k]) == "BigInteger") { assertEquals(msg, ((BigDecimal) getExpected(avgTypes[k])).toPlainString(), ((BigDecimal) output).toPlainString()); } else { assertEquals(msg, (Double) getExpected(avgTypes[k]), (Double) output, 0.00001); } } }
From source file:net.pms.util.Rational.java
/** * Converts this {@link Rational} to a {@link BigDecimal} using the given * {@link MathContext}. This may involve rounding. * <p>//from ww w .ja v a2s. com * * @param mathContext the {@link MathContext} to use. * @return This {@link Rational} converted to a {@link BigDecimal}. * @throws ArithmeticException If this is {@code NaN} or infinite or if the * result is inexact but the rounding mode is * {@code UNNECESSARY} or {@code mathContext.precision == 0} and * the quotient has a non-terminating decimal expansion. * * @see #bigDecimalValue() * @see #bigDecimalValue(RoundingMode) * @see #bigDecimalValue(int, RoundingMode) */ @Nonnull public BigDecimal bigDecimalValue(MathContext mathContext) { if (isNaN()) { throw new NumberFormatException("Impossible to express NaN as BigDecimal"); } if (isInfinite()) { throw new NumberFormatException("Impossible to express infinity as BigDecimal"); } if (BigInteger.ONE.equals(reducedDenominator)) { return new BigDecimal(reducedNumerator); } return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), mathContext); }
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
/** * Rewrite subtraction for EE mode. Assume columns are from the same table. * * @param leftExpr/* w w w. j a va 2 s. c o m*/ * @param rightExpr * @param S * @return */ protected Expr rewriteSubtractEE(Expr leftExpr, Expr rightExpr, Expr S) throws UnSupportedException { LOG.debug("Rewriting EE mode subtraction"); assert (leftExpr.involveEncrytedCol() && rightExpr.involveEncrytedCol()); BigInteger inverseM = rightExpr.getSdbColKey().getM().multiply(n.subtract(BigInteger.ONE)).mod(n); SdbColumnKey colKey = new SdbColumnKey(inverseM, rightExpr.getSdbColKey().getX()); rightExpr.setSdbColKey(colKey); return rewriteAddEE(leftExpr, rightExpr, S); }
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
/** * Rewrite subtraction for EP mode. Assume columns are from the same table. * * @param leftExpr//from w ww. j a v a2 s . c o m * @param rightExpr * @param S * @return */ protected Expr rewriteSubtractEP(Expr leftExpr, Expr rightExpr, Expr S) throws UnSupportedException { LOG.debug("Rewriting EP mode subtraction"); // only one involves encrypted column assert (leftExpr.involveEncrytedCol() ^ rightExpr.involveEncrytedCol()); BigInteger targetM = SDBEncrypt.generatePositiveRand(prime1, prime2); BigInteger targetX = SDBEncrypt.generatePositiveRand(prime1, prime2); // We need to inverse the value of the right expression if (leftExpr.involveEncrytedCol()) { // P is the right expression. Inverse P. rightExpr = keyUpdateInversedPlainCol(rightExpr, S, targetM, targetX); BigInteger[] pq = SDBEncrypt.keyUpdateClient(leftExpr.getSdbColKey().getM(), targetM, S.getSdbColKey().getM(), leftExpr.getSdbColKey().getX(), targetX, S.getSdbColKey().getX(), prime1, prime2); leftExpr = buildSdbKeyUpdateExpr(leftExpr, S, new BigIntLiteral(pq[0]), new BigIntLiteral(pq[1]), new BigIntLiteral(n), targetM, targetX); } else { // P is the left expression. leftExpr = keyUpdatePlainCol(leftExpr, S, targetM, targetX); // Inverse E expression. BigInteger inverseM = rightExpr.getSdbColKey().getM().multiply(n.subtract(BigInteger.ONE)).mod(n); BigInteger[] pq = SDBEncrypt.keyUpdateClient(inverseM, targetM, S.getSdbColKey().getM(), rightExpr.getSdbColKey().getX(), targetX, S.getSdbColKey().getX(), prime1, prime2); rightExpr = buildSdbKeyUpdateExpr(rightExpr, S, new BigIntLiteral(pq[0]), new BigIntLiteral(pq[1]), new BigIntLiteral(n), targetM, targetX); } return rewriteAddEE(leftExpr, rightExpr, S); }
From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast.java
@SuppressWarnings({ "unchecked", "deprecation" }) private Object convertWithSchema(Object obj, ResourceFieldSchema fs) throws IOException { Object result = null;/*w ww . j av a2s. c o m*/ if (fs == null) { return obj; } if (obj == null) { // handle DataType.NULL return null; } switch (fs.getType()) { case DataType.BAG: if (obj instanceof DataBag) { DataBag db = (DataBag) obj; // Get inner schema of a bag if (fs.getSchema() != null) { ResourceFieldSchema tupleFs = fs.getSchema().getFields()[0]; Iterator<Tuple> iter = db.iterator(); while (iter.hasNext()) { Tuple t = iter.next(); convertWithSchema(t, tupleFs); } } result = db; } else if (obj instanceof DataByteArray) { if (null != caster) { result = caster.bytesToBag(((DataByteArray) obj).get(), fs); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "bag."; throw new ExecException(msg, errCode, PigException.INPUT); } } else { throw new ExecException("Cannot cast " + obj + " to bag.", 1120, PigException.INPUT); } break; case DataType.TUPLE: if (obj instanceof Tuple) { try { Tuple t = (Tuple) obj; ResourceSchema innerSchema = fs.getSchema(); if (innerSchema == null) return t; if (innerSchema.getFields().length != t.size()) return null; int i = 0; for (ResourceFieldSchema fieldSchema : innerSchema.getFields()) { Object field = convertWithSchema(t.get(i), fieldSchema); t.set(i, field); i++; } result = t; } catch (Exception e) { throw new ExecException("Cannot convert " + obj + " to " + fs); } } else if (obj instanceof DataByteArray) { if (null != caster) { result = caster.bytesToTuple(((DataByteArray) obj).get(), fs); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "tuple."; throw new ExecException(msg, errCode, PigException.INPUT); } } else { throw new ExecException("Cannot cast " + obj + " to tuple.", 1120, PigException.INPUT); } break; case DataType.MAP: if (obj instanceof Map) { if (fs != null && fs.getSchema() != null) { ResourceFieldSchema innerFieldSchema = fs.getSchema().getFields()[0]; Map m = (Map) obj; for (Object entry : m.entrySet()) { Object newValue = convertWithSchema(((Map.Entry) entry).getValue(), innerFieldSchema); m.put(((Map.Entry) entry).getKey(), newValue); } result = m; } else result = obj; } else if (obj instanceof DataByteArray) { if (null != caster) { result = caster.bytesToMap(((DataByteArray) obj).get(), fs); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "tuple."; throw new ExecException(msg, errCode, PigException.INPUT); } } else { throw new ExecException("Cannot cast " + obj + " to map.", 1120, PigException.INPUT); } break; case DataType.BOOLEAN: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToBoolean(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "int."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: result = obj; break; case DataType.INTEGER: result = Boolean.valueOf(((Integer) obj).intValue() != 0); ; break; case DataType.DOUBLE: result = Boolean.valueOf(((Double) obj).doubleValue() != 0.0D); break; case DataType.LONG: result = Boolean.valueOf(((Long) obj).longValue() != 0L); break; case DataType.FLOAT: result = Boolean.valueOf(((Float) obj).floatValue() != 0.0F); break; case DataType.CHARARRAY: result = CastUtils.stringToBoolean((String) obj); break; case DataType.BIGINTEGER: result = Boolean.valueOf(!BigInteger.ZERO.equals((BigInteger) obj)); break; case DataType.BIGDECIMAL: result = Boolean.valueOf(!BigDecimal.ZERO.equals((BigDecimal) obj)); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.INTEGER: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToInteger(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "int."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { result = Integer.valueOf(1); } else { result = Integer.valueOf(0); } break; case DataType.INTEGER: result = obj; break; case DataType.DOUBLE: result = Integer.valueOf(((Double) obj).intValue()); break; case DataType.LONG: result = Integer.valueOf(((Long) obj).intValue()); break; case DataType.FLOAT: result = Integer.valueOf(((Float) obj).intValue()); break; case DataType.DATETIME: result = Integer.valueOf(Long.valueOf(((DateTime) obj).getMillis()).intValue()); break; case DataType.CHARARRAY: result = CastUtils.stringToInteger((String) obj); break; case DataType.BIGINTEGER: result = Integer.valueOf(((BigInteger) obj).intValue()); break; case DataType.BIGDECIMAL: result = Integer.valueOf(((BigDecimal) obj).intValue()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.DOUBLE: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToDouble(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "double."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { result = new Double(1); } else { result = new Double(1); } break; case DataType.INTEGER: result = new Double(((Integer) obj).doubleValue()); break; case DataType.DOUBLE: result = (Double) obj; break; case DataType.LONG: result = new Double(((Long) obj).doubleValue()); break; case DataType.FLOAT: result = new Double(((Float) obj).doubleValue()); break; case DataType.DATETIME: result = new Double(Long.valueOf(((DateTime) obj).getMillis()).doubleValue()); break; case DataType.CHARARRAY: result = CastUtils.stringToDouble((String) obj); break; case DataType.BIGINTEGER: result = Double.valueOf(((BigInteger) obj).doubleValue()); break; case DataType.BIGDECIMAL: result = Double.valueOf(((BigDecimal) obj).doubleValue()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.LONG: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToLong(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "long."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { result = Long.valueOf(1); } else { result = Long.valueOf(0); } break; case DataType.INTEGER: result = Long.valueOf(((Integer) obj).longValue()); break; case DataType.DOUBLE: result = Long.valueOf(((Double) obj).longValue()); break; case DataType.LONG: result = (Long) obj; break; case DataType.FLOAT: result = Long.valueOf(((Float) obj).longValue()); break; case DataType.DATETIME: result = Long.valueOf(((DateTime) obj).getMillis()); break; case DataType.CHARARRAY: result = CastUtils.stringToLong((String) obj); break; case DataType.BIGINTEGER: result = Long.valueOf(((BigInteger) obj).longValue()); break; case DataType.BIGDECIMAL: result = Long.valueOf(((BigDecimal) obj).longValue()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.FLOAT: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToFloat(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "float."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { result = new Float(1); } else { result = new Float(0); } break; case DataType.INTEGER: result = new Float(((Integer) obj).floatValue()); break; case DataType.DOUBLE: result = new Float(((Double) obj).floatValue()); break; case DataType.LONG: result = new Float(((Long) obj).floatValue()); break; case DataType.FLOAT: result = obj; break; case DataType.DATETIME: result = new Float(Long.valueOf(((DateTime) obj).getMillis()).floatValue()); break; case DataType.CHARARRAY: result = CastUtils.stringToFloat((String) obj); break; case DataType.BIGINTEGER: result = Float.valueOf(((BigInteger) obj).floatValue()); break; case DataType.BIGDECIMAL: result = Float.valueOf(((BigDecimal) obj).floatValue()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.DATETIME: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToDateTime(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "datetime."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.INTEGER: result = new DateTime(((Integer) obj).longValue()); break; case DataType.DOUBLE: result = new DateTime(((Double) obj).longValue()); break; case DataType.LONG: result = new DateTime(((Long) obj).longValue()); break; case DataType.FLOAT: result = new DateTime(((Float) obj).longValue()); break; case DataType.DATETIME: result = (DateTime) obj; break; case DataType.CHARARRAY: result = ToDate.extractDateTime((String) obj); break; case DataType.BIGINTEGER: result = new DateTime(((BigInteger) obj).longValue()); break; case DataType.BIGDECIMAL: result = new DateTime(((BigDecimal) obj).longValue()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.CHARARRAY: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToCharArray(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "float."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { //result = "1"; result = Boolean.TRUE.toString(); } else { //result = "0"; result = Boolean.FALSE.toString(); } break; case DataType.INTEGER: result = ((Integer) obj).toString(); break; case DataType.DOUBLE: result = ((Double) obj).toString(); break; case DataType.LONG: result = ((Long) obj).toString(); break; case DataType.FLOAT: result = ((Float) obj).toString(); break; case DataType.DATETIME: result = ((DateTime) obj).toString(); break; case DataType.CHARARRAY: result = obj; break; case DataType.BIGINTEGER: result = ((BigInteger) obj).toString(); break; case DataType.BIGDECIMAL: result = ((BigDecimal) obj).toString(); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } break; case DataType.BIGINTEGER: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToBigInteger(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "BigInteger."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { result = BigInteger.ONE; } else { result = BigInteger.ZERO; } break; case DataType.INTEGER: result = BigInteger.valueOf(((Integer) obj).longValue()); break; case DataType.DOUBLE: result = BigInteger.valueOf(((Double) obj).longValue()); break; case DataType.LONG: result = BigInteger.valueOf(((Long) obj).longValue()); break; case DataType.FLOAT: result = BigInteger.valueOf(((Float) obj).longValue()); break; case DataType.CHARARRAY: result = new BigInteger((String) obj); break; case DataType.BIGINTEGER: result = (BigInteger) obj; break; case DataType.BIGDECIMAL: result = ((BigDecimal) obj).toBigInteger(); break; case DataType.DATETIME: result = BigInteger.valueOf(((DateTime) obj).getMillis()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } case DataType.BIGDECIMAL: switch (DataType.findType(obj)) { case DataType.BYTEARRAY: if (null != caster) { result = caster.bytesToBigDecimal(((DataByteArray) obj).get()); } else { int errCode = 1075; String msg = unknownByteArrayErrorMessage + "BigDecimal."; throw new ExecException(msg, errCode, PigException.INPUT); } break; case DataType.BOOLEAN: if ((Boolean) obj) { result = BigDecimal.ONE; } else { result = BigDecimal.ZERO; } break; case DataType.INTEGER: result = BigDecimal.valueOf(((Integer) obj).longValue()); break; case DataType.DOUBLE: result = BigDecimal.valueOf(((Double) obj).doubleValue()); break; case DataType.LONG: result = BigDecimal.valueOf(((Long) obj).longValue()); break; case DataType.FLOAT: result = BigDecimal.valueOf(((Float) obj).doubleValue()); break; case DataType.CHARARRAY: result = new BigDecimal((String) obj); break; case DataType.BIGINTEGER: result = new BigDecimal((BigInteger) obj); break; case DataType.BIGDECIMAL: result = (BigDecimal) obj; break; case DataType.DATETIME: result = BigDecimal.valueOf(((DateTime) obj).getMillis()); break; default: throw new ExecException("Cannot convert " + obj + " to " + fs, 1120, PigException.INPUT); } default: throw new ExecException("Don't know how to convert " + obj + " to " + fs, 1120, PigException.INPUT); } return result; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.AbstractCswSource.java
private GetRecordsType createSubscriptionGetRecordsRequest() { GetRecordsType getRecordsType = new GetRecordsType(); getRecordsType.setVersion(cswVersion); getRecordsType.setService(CswConstants.CSW); getRecordsType.setResultType(ResultType.RESULTS); getRecordsType.setStartPosition(BigInteger.ONE); getRecordsType.setMaxRecords(BigInteger.TEN); getRecordsType.setOutputFormat(MediaType.APPLICATION_XML); getRecordsType.setOutputSchema("urn:catalog:metacard"); getRecordsType.getResponseHandler().add(SystemBaseUrl.constructUrl("csw/subscription/event", true)); QueryType queryType = new QueryType(); queryType.setElementSetName(createElementSetName(ElementSetType.FULL)); ObjectFactory objectFactory = new ObjectFactory(); getRecordsType.setAbstractQuery(objectFactory.createQuery(queryType)); return getRecordsType; }