List of usage examples for java.math BigInteger ZERO
BigInteger ZERO
To view the source code for java.math BigInteger ZERO.
Click Source Link
From source file:org.openestate.io.is24_xml.Is24XmlUtils.java
public static String printZahl20(BigInteger value) { if (value == null || value.compareTo(BigInteger.ZERO) != 1) throw new IllegalArgumentException("Can't print integer value '" + value + "'!"); String val = DatatypeConverter.printInteger(value); if (val.length() > 20) throw new IllegalArgumentException( "Can't print integer value '" + value + "'! The value exceeds maximal length of 20 digits."); return val; }
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
/** * This is the most complex rewriting part, since all columns need to do keyUpdate * after two tables join together.// w w w. j a v a 2 s . c om * * @param tblRefs * @param selList * @param whereClause * @throws RewriteException */ protected void rewriteTableRefs(List<TableRef> tblRefs, SelectionList selList, Expr whereClause) throws RewriteException { LOG.debug("Rewriting table list"); // First of all, initialize the auxiliary columns RowID, R, S of the selection // list, since we possibly need them for the later computation. // In the optimization phase, we will delete all those useless auxiliary columns. SelectionItem leftRowID = new SelectionItem(); SelectionItem leftR = new SelectionItem(); SelectionItem leftS = new SelectionItem(); leftRowID.setAlias(ColumnDefinition.ROW_ID_COLUMN_NAME); leftR.setAlias(ColumnDefinition.R_COLUMN_NAME); leftS.setAlias(ColumnDefinition.S_COLUMN_NAME); // To record the set of table names we have visited. Set<String> visitedTbl = new HashSet<>(); boolean isFirstOne = true; for (TableRef tblRef : tblRefs) { if (tblRef instanceof InLineViewRef) { // Perform rewrite for inline view first. rewriteInLineViewRef((InLineViewRef) tblRef); } // Do if it is the first table. if (isFirstOne) { if (tblRef instanceof BaseTableRef) { String tblName = tblRef.getTblName(); SdbColumnKey rowIDColKey = getTableColumnKey(tblName, ColumnDefinition.ROW_ID_COLUMN_NAME); FieldLiteral rowID = new FieldLiteral(tblName, ColumnDefinition.ROW_ID_COLUMN_NAME, Type.INT, true, rowIDColKey); leftRowID.setExpr(rowID); SdbColumnKey rColKey = getTableColumnKey(tblName, ColumnDefinition.R_COLUMN_NAME); FieldLiteral r = new FieldLiteral(tblName, ColumnDefinition.R_COLUMN_NAME, Type.INT, true, rColKey); leftR.setExpr(r); SdbColumnKey sColKey = getTableColumnKey(tblName, ColumnDefinition.S_COLUMN_NAME); FieldLiteral s = new FieldLiteral(tblName, ColumnDefinition.S_COLUMN_NAME, Type.INT, true, sColKey); leftS.setExpr(s); if (!tblRef.getAlias().equals("")) { // Should use the alias in the final rewritten query. rowID.setTbl(tblRef.getAlias()); r.setTbl(tblRef.getAlias()); s.setTbl(tblRef.getAlias()); // Check if alias has been used. if (aliasTblMap.containsKey(tblRef.getAlias())) { RewriteException e = new RewriteException("Repeated alias!"); LOG.error("Please use another alias for table " + tblName, e); throw e; } aliasTblMap.put(tblRef.getAlias(), tblName); visitedTbl.add(tblRef.getAlias()); } else { visitedTbl.add(tblName); } } // Is is an inline view. else { // The rewrite has been performed. SelectionList inLineSelList = ((SelectStmt) ((InLineViewRef) tblRef).getQueryStmt()) .getSelectList(); FieldLiteral inlineRowID = new FieldLiteral(tblRef.getAlias(), ColumnDefinition.ROW_ID_COLUMN_NAME, Type.INT); FieldLiteral inlineR = new FieldLiteral(tblRef.getAlias(), ColumnDefinition.R_COLUMN_NAME, Type.INT); FieldLiteral inlineS = new FieldLiteral(tblRef.getAlias(), ColumnDefinition.S_COLUMN_NAME, Type.INT); // Get column keys for rowID, R and S inlineRowID.setSdbColKey(inLineSelList.getRowID().getExpr().getSdbColKey()); inlineR.setSdbColKey(inLineSelList.getAuxiliaryR().getExpr().getSdbColKey()); inlineS.setSdbColKey(inLineSelList.getAuxiliaryS().getExpr().getSdbColKey()); leftRowID = new SelectionItem(inlineRowID, ColumnDefinition.ROW_ID_COLUMN_NAME); leftR = new SelectionItem(inlineR, ColumnDefinition.R_COLUMN_NAME); leftS = new SelectionItem(inlineS, ColumnDefinition.S_COLUMN_NAME); visitedTbl.add(tblRef.getAlias()); } isFirstOne = false; } // It is a join table. else { boolean isInlineView = false; Expr onClause = tblRef.getOnClause(); assert (onClause != null); SelectionItem rightRowID = new SelectionItem(); SelectionItem rightS = new SelectionItem(); if (tblRef instanceof BaseTableRef) { String tblName = tblRef.getTblName(); SdbColumnKey rowIDColKey = getTableColumnKey(tblName, ColumnDefinition.ROW_ID_COLUMN_NAME); FieldLiteral rowID = new FieldLiteral(tblName, ColumnDefinition.ROW_ID_COLUMN_NAME, Type.INT, true, rowIDColKey); rightRowID.setExpr(rowID); SdbColumnKey sColKey = getTableColumnKey(tblName, ColumnDefinition.S_COLUMN_NAME); FieldLiteral s = new FieldLiteral(tblName, ColumnDefinition.S_COLUMN_NAME, Type.INT, true, sColKey); rightS.setExpr(s); if (!tblRef.getAlias().equals("")) { // Should use the alias in the final rewritten query. rowID.setTbl(tblRef.getAlias()); s.setTbl(tblRef.getAlias()); // Check if alias has been used. if (aliasTblMap.containsKey(tblRef.getAlias())) { RewriteException e = new RewriteException("Repeated alias!"); LOG.error("Please use another alias for table " + tblName, e); throw e; } aliasTblMap.put(tblRef.getAlias(), tblName); } } // It is an inline view. else { isInlineView = true; SelectionList inLineSelList = ((SelectStmt) ((InLineViewRef) tblRef).getQueryStmt()) .getSelectList(); FieldLiteral inlineRowID = new FieldLiteral(tblRef.getAlias(), ColumnDefinition.ROW_ID_COLUMN_NAME, Type.INT); // FieldLiteral inlineR = new FieldLiteral(tblRef.getAlias(), // ColumnDefinition.R_COLUMN_NAME, DataType.INT); FieldLiteral inlineS = new FieldLiteral(tblRef.getAlias(), ColumnDefinition.S_COLUMN_NAME, Type.INT); // Get column keys for rowID, R and S inlineRowID.setSdbColKey(inLineSelList.getRowID().getExpr().getSdbColKey()); // inlineR.setSdbColKey(inLineSelList.getAuxiliaryR().getExpr() // .getSdbColKey()); inlineS.setSdbColKey(inLineSelList.getAuxiliaryS().getExpr().getSdbColKey()); rightRowID = new SelectionItem(inlineRowID, ColumnDefinition.ROW_ID_COLUMN_NAME); rightS = new SelectionItem(inlineS, ColumnDefinition.S_COLUMN_NAME); } // Property of Column Key <m, 0>: all values in the Column A has the same // item key m. That means if two values a1, a2 are equal, then their // encrypted // value E(a1) and E(a2) are equal as well. BigInteger targetM = SDBEncrypt.generatePositiveRand(prime1, prime2); BigInteger targetX = BigInteger.ZERO; // Perform Key updates on the join columns if (onClause != null) { rewriteJoinPred(onClause, leftS, rightS, targetM, targetX); } else { RewriteException e = new UnSupportedException("Join clause has no onClause"); LOG.error("There is unsupported join clause!", e); throw e; } // Do transform for all sensitive columns in the selection list for (SelectionItem selItem : selList.getItemList()) { if (selItem.involveEncrytedCol()) { Expr originExpr = selItem.getExpr(); Expr rewrittenExpr = buildCartesianExpr(originExpr, leftS, rightS, visitedTbl); rewrittenExpr.setReferredByList(originExpr.getReferredByList()); if (selItem.getAlias().equals("")) { if (originExpr instanceof FieldLiteral) { selItem.setAlias(((FieldLiteral) originExpr).getName()); } else { RewriteException e = new UnSupportedException( "Only column can be " + "without alias in the selection list"); LOG.error("There is unsupported selection item!", e); throw e; } } selItem.setExpr(rewrittenExpr); } } // The row column key should be equal for across all tables. assert (leftRowID.getExpr().getSdbColKey().getM() .equals(rightRowID.getExpr().getSdbColKey().getM())); // Update the auxiliary columns // The row id is homomorphic additive Expr newRowID = new SdbArithmeticExpr(SdbOperator.SDB_ADDROWID); newRowID.addChild(leftRowID.getExpr()); newRowID.addChild(rightRowID.getExpr()); newRowID.addChild(new BigIntLiteral(n)); BigInteger m = leftRowID.getExpr().getSdbColKey().getM(); BigInteger x = leftRowID.getExpr().getSdbColKey().getX() .add(rightRowID.getExpr().getSdbColKey().getX()); newRowID.setSdbColKey(new SdbColumnKey(m, x)); Expr newR = buildCartesianExpr(leftR.getExpr(), leftS, rightS, visitedTbl); Expr newS = buildCartesianExpr(leftS.getExpr(), leftS, rightS, visitedTbl); leftRowID.setExpr(newRowID); leftR.setExpr(newR); leftS.setExpr(newS); if (isInlineView) { visitedTbl.add(tblRef.getAlias()); } else { if (tblRef.getAlias().equals("")) visitedTbl.add(tblRef.getTblName()); else visitedTbl.add(tblRef.getAlias()); } } } selList.setAuxiliaryR(leftR); selList.setAuxiliaryS(leftS); selList.setRowID(leftRowID); }
From source file:com.amazonaws.kinesis.agg.AggRecord.java
/** * Calculate a new explicit hash key based on the input partition key (following * the algorithm from the original KPL). * /*from w ww . j av a 2 s .c om*/ * @param partitionKey * The partition key to seed the new explicit hash key with * @return An explicit hash key based on the input partition key generated using * an algorithm from the original KPL. */ private String createExplicitHashKey(final String partitionKey) { BigInteger hashKey = BigInteger.ZERO; this.md5.reset(); byte[] pkDigest = this.md5.digest(partitionKey.getBytes(StandardCharsets.UTF_8)); for (int i = 0; i < this.md5.getDigestLength(); i++) { BigInteger p = new BigInteger(String.valueOf((int) pkDigest[i] & 0xFF)); // convert // to // unsigned // integer BigInteger shifted = p.shiftLeft((16 - i - 1) * 8); hashKey = hashKey.add(shifted); } return hashKey.toString(10); }
From source file:cc.redberry.core.number.Complex.java
@Override public Complex add(BigInteger bg) { NumberUtils.checkNotNull(bg);/*from ww w .j ava 2s . c o m*/ return bg.equals(BigInteger.ZERO) ? this : new Complex(real.add(bg), imaginary); }
From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaBuilder.java
private void generateCollectionElement(ExplicitGroup all, String name, String description, DataType type, boolean required) { name = hyphenize(name);/* w w w .j a va 2s . co m*/ BigInteger minOccurs = required ? BigInteger.ONE : BigInteger.ZERO; String collectionName = hyphenize(NameUtils.singularize(name)); LocalComplexType collectionComplexType = generateCollectionComplexType(collectionName, description, type); TopLevelElement collectionElement = new TopLevelElement(); collectionElement.setName(name); collectionElement.setMinOccurs(minOccurs); collectionElement.setMaxOccurs("1"); collectionElement.setAnnotation(createDocAnnotation(description)); all.getParticle().add(objectFactory.createElement(collectionElement)); collectionElement.setComplexType(collectionComplexType); }
From source file:org.apache.cassandra.cql.jdbc.HandleObjects.java
public static final ByteBuffer makeBytes(Object object, int baseType, int scaleOrLength) throws SQLException { Class<? extends Object> objectClass = object.getClass(); boolean isCollection = (Collection.class.isAssignableFrom(objectClass)); int targetSqlType = isCollection ? Types.OTHER : baseType; // Type check first switch (targetSqlType) { case Types.TINYINT: // Only Numeric classes, Strings and Booleans are supported for transformation to TINYINT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "TINYINT"); break;//from w w w . j a v a 2 s. c o m case Types.SMALLINT: // Only Numeric classes, Strings and Booleans are supported for transformation to SMALLINT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "SMALLINT"); break; case Types.INTEGER: // Only Numeric classes, Strings and Booleans are supported for transformation to INTEGER if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "INTEGER"); break; case Types.BIGINT: // Only Numeric classes, Strings and Booleans are supported for transformation to BIGINT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "BIGINT"); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: // Only Numeric classes Strings and Booleans are supported for transformation to REAL,FLOAT,DOUBLE,DECIMAL if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "the floating point types"); break; case Types.NUMERIC: //NB This as a special case variation for Cassandra!! NUMERIC is transformed to java BigInteger (varint CQL type) // // Only Numeric classes Strings and Booleans are supported for transformation to NUMERIC if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "NUMERIC"); break; case Types.BIT: // Only Numeric classes Strings and Booleans are supported for transformation to BIT if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "BIT"); break; case Types.BOOLEAN: // Only Numeric classes Strings and Booleans are supported for transformation to BOOLEAN if (!(objectClass == String.class || objectClass == Boolean.class || Number.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "BOOLEAN"); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: if (!objectClass.isAssignableFrom(String.class)) throw makeBadMapping(objectClass, "String", "the various VARCHAR types"); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (!(objectClass.isAssignableFrom(ByteBuffer.class) || objectClass.getSimpleName().equals("byte[]"))) throw makeBadMapping(objectClass, "ByteBuffer or byte[]", "the BINARY Types"); break; case Types.DATE: if (!(objectClass == String.class || objectClass == java.util.Date.class || objectClass == Date.class || objectClass == Timestamp.class)) throw makeBadMapping(objectClass, "String, Date(java and sql) or Timestamp types", "DATE"); break; case Types.TIME: if (!(objectClass == String.class || objectClass == java.util.Date.class || objectClass == Time.class || objectClass == Timestamp.class)) throw makeBadMapping(objectClass, "String, Date (java), Time or Timestamp types", "TIME"); break; case Types.TIMESTAMP: if (!(objectClass == String.class || objectClass == java.util.Date.class || objectClass == Date.class || objectClass == Timestamp.class)) throw makeBadMapping(objectClass, "String, Date(java and sql) or Timestamp types", "TIMESTAMP"); break; case Types.DATALINK: if (objectClass != URL.class) throw makeBadMapping(objectClass, "a URL type", "DATALINK"); break; case Types.JAVA_OBJECT: break; case Types.OTHER: // Only Collection classes for transformation to OTHER if (!(List.class.isAssignableFrom(object.getClass()) || Set.class.isAssignableFrom(object.getClass()) || Map.class.isAssignableFrom(object.getClass()))) throw makeBadMapping(objectClass, STR_BOOL_NUMERIC, "OTHER"); break; case Types.ROWID: if (objectClass != RowId.class) throw makeBadMapping(objectClass, "a RowId type", "ROWID"); break; default: throw new SQLNonTransientException("Unsupported transformation to Jdbc Type: " + targetSqlType); } // see if we can map to an supported Type switch (targetSqlType) { case Types.BIT: BigInteger bitvalue = objectToBITorTINYINTorSMALLINTorNUMERIC(objectClass, object); assert bitvalue != null; return JdbcInteger.instance.decompose((bitvalue == BigInteger.ZERO) ? BigInteger.ZERO : BigInteger.ONE); case Types.TINYINT: case Types.SMALLINT: case Types.NUMERIC: BigInteger varint = objectToBITorTINYINTorSMALLINTorNUMERIC(objectClass, object); assert varint != null; return JdbcInteger.instance.decompose(varint); case Types.INTEGER: Integer value = objectToINTEGER(objectClass, object); assert value != null; return JdbcInt32.instance.decompose(value); case Types.BIGINT: Long longvalue = objectToBIGINT(objectClass, object); assert longvalue != null; return JdbcLong.instance.decompose(longvalue); case Types.BOOLEAN: Boolean bool = objectToBOOLEAN(objectClass, object); assert bool != null; return JdbcBoolean.instance.decompose(bool); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: return ByteBufferUtil.bytes((String) object); case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (objectClass.isAssignableFrom(ByteBuffer.class)) { return ((ByteBuffer) object); } else if (objectClass.getSimpleName().equals("byte[]")) { return ByteBuffer.wrap((byte[]) object); } else return null; // this should not happen case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Long millis = objectToDATEorTIMEorTIMESTAMP(objectClass, object); assert millis != null; return JdbcLong.instance.decompose(millis); case Types.DATALINK: String urlAsString = ((URL) object).toExternalForm(); return JdbcUTF8.instance.decompose(urlAsString); case Types.JAVA_OBJECT: return javaObject(object); case Types.OTHER: if (List.class.isAssignableFrom(objectClass)) { return handleAsList(objectClass, object); } else if (Set.class.isAssignableFrom(objectClass)) { return handleAsSet(objectClass, object); } else if (Map.class.isAssignableFrom(objectClass)) { return handleAsMap(objectClass, object); } else return null; case Types.ROWID: byte[] bytes = ((RowId) object).getBytes(); return ByteBuffer.wrap(bytes); default: LOG.warn("Unhandled JDBC type: " + targetSqlType); return null; } }
From source file:cc.redberry.core.number.Complex.java
@Override public Complex subtract(BigInteger bg) { NumberUtils.checkNotNull(bg);/*w w w .j a v a 2 s .c om*/ return bg.equals(BigInteger.ZERO) ? this : new Complex(real.subtract(bg), imaginary); }
From source file:org.multibit.utils.CSMiscUtils.java
public static BigInteger calcMigrationFeeSatoshis(BitcoinController bitcoinController, Wallet wallet) { BigInteger migrationFee = null; Address sendAddressObject;/*from w ww. j av a 2 s. c o m*/ try { /* We allow calculation of the migration fee even if there is no send address specified, so we could generate an address from utxo, or just use a dummy address. TODO: Get transc */ String address = null; NetworkParameters params = bitcoinController.getModel().getNetworkParameters(); if (params.getId().equals(NetworkParameters.ID_MAINNET)) { address = "1LLBoY7gp4B9WUtBdgJQLyNVS7doskFQcn"; //production } else { address = "mzc55AvWnAmk48UfN74ktw4pxkiKfscNgU"; //testnet3 } // TODO: Instead of this dummy address, use a parameter sendAddressObject = new Address(bitcoinController.getModel().getNetworkParameters(), address); SendRequest sendRequest = SendRequest.emptyWallet(sendAddressObject); sendRequest.ensureMinRequiredFee = true; sendRequest.fee = BigInteger.ZERO; wallet.completeTx(sendRequest, false); migrationFee = sendRequest.fee; } catch (Exception ex) { } return migrationFee; }
From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaBuilder.java
private LocalComplexType generateCollectionComplexType(String name, final String description, final DataType type) { final LocalComplexType collectionComplexType = new LocalComplexType(); final ExplicitGroup sequence = new ExplicitGroup(); collectionComplexType.setSequence(sequence); final TopLevelElement collectionItemElement = new TopLevelElement(); collectionItemElement.setName(name); collectionItemElement.setMinOccurs(BigInteger.ZERO); collectionItemElement.setMaxOccurs(SchemaConstants.UNBOUNDED); final DataType genericType = getFirstGenericType(type); genericType.getQualifier().accept(new AbstractDataQualifierVisitor() { @Override//w w w . j ava 2 s . c om public void onPojo() { collectionItemElement.setComplexType(newLocalComplexTypeWithBase(genericType, description)); } @Override protected void defaultOperation() { collectionItemElement.setComplexType(generateComplexValueType(genericType)); } }); sequence.getParticle().add(objectFactory.createElement(collectionItemElement)); return collectionComplexType; }
From source file:org.ethereum.rpc.Web3Impl.java
private String sendTransaction(CallArguments args, Account account) throws Exception { String s = null;/*from w w w .j a v a2 s .c o m*/ try { if (account == null) throw new JsonRpcInvalidParamException("From address private key could not be found in this node"); String toAddress = args.to != null ? Hex.toHexString(StringHexToByteArray(args.to)) : null; BigInteger value = args.value != null ? TypeConverter.StringNumberAsBigInt(args.value) : BigInteger.ZERO; BigInteger gasPrice = args.gasPrice != null ? TypeConverter.StringNumberAsBigInt(args.gasPrice) : BigInteger.ZERO; BigInteger gasLimit = args.gas != null ? TypeConverter.StringNumberAsBigInt(args.gas) : BigInteger.valueOf(GasCost.TRANSACTION_DEFAULT); if (args.data != null && args.data.startsWith("0x")) args.data = args.data.substring(2); PendingState pendingState = worldManager.getPendingState(); synchronized (pendingState) { BigInteger accountNonce = args.nonce != null ? TypeConverter.StringNumberAsBigInt(args.nonce) : (pendingState.getRepository().getNonce(account.getAddress())); Transaction tx = Transaction.create(toAddress, value, accountNonce, gasPrice, gasLimit, args.data); tx.sign(account.getEcKey().getPrivKeyBytes()); eth.submitTransaction(tx); s = TypeConverter.toJsonHex(tx.getHash()); } return s; } finally { if (logger.isDebugEnabled()) logger.debug("eth_sendTransaction({}): {}", args, s); } }