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:com.flexive.core.storage.genericSQL.GenericTreeStorageSpreaded.java
protected long _reorganizeSpace(Connection con, SequencerEngine seq, FxTreeMode sourceMode, FxTreeMode destMode, long nodeId, boolean includeNodeId, BigInteger overrideSpacing, BigInteger overrideLeft, FxTreeNodeInfo insertParent, int insertPosition, BigInteger insertSpace, BigInteger insertBoundaries[], int depthDelta, Long destinationNode, boolean createMode, boolean createKeepIds, boolean disableSpaceOptimization) throws FxTreeException { long firstCreatedNodeId = -1; FxTreeNodeInfoSpreaded nodeInfo;/*w ww.ja v a 2s .co m*/ try { nodeInfo = (FxTreeNodeInfoSpreaded) getTreeNodeInfo(con, sourceMode, nodeId); } catch (Exception e) { return -1; } if (!nodeInfo.isSpaceOptimizable() && !disableSpaceOptimization) { // The Root node and cant be optimize any more ... so all we can do is fail :-/ // This should never really happen if (nodeId == ROOT_NODE) { return -1; } //System.out.println("### UP we go, depthDelta=" + depthDelta); return _reorganizeSpace(con, seq, sourceMode, destMode, nodeInfo.getParentId(), includeNodeId, overrideSpacing, overrideLeft, insertParent, insertPosition, insertSpace, insertBoundaries, depthDelta, destinationNode, createMode, createKeepIds, false); } BigInteger spacing = nodeInfo.getDefaultSpacing(); if (overrideSpacing != null && (overrideSpacing.compareTo(spacing) < 0 || overrideLeft != null)) { // override spacing unless it is greater OR overrideLeft is specified (in that case we // have to use the spacing for valid tree ranges) spacing = overrideSpacing; } else { if (spacing.compareTo(GO_UP) < 0 && !createMode && !disableSpaceOptimization) { return _reorganizeSpace(con, seq, sourceMode, destMode, nodeInfo.getParentId(), includeNodeId, overrideSpacing, overrideLeft, insertParent, insertPosition, insertSpace, insertBoundaries, depthDelta, destinationNode, createMode, createKeepIds, false); } } if (insertBoundaries != null && insertPosition == -1) { insertPosition = 0; // insertPosition cannot be negative } Statement stmt = null; PreparedStatement ps = null; ResultSet rs; BigInteger left = overrideLeft == null ? nodeInfo.getLeft() : overrideLeft; BigInteger right = null; String includeNode = includeNodeId ? "=" : ""; long counter = 0; long newId = -1; try { final long start = System.currentTimeMillis(); String createProps = createMode ? ",PARENT,REF,NAME,TEMPLATE" : ""; String sql = " SELECT ID," + StorageManager.getIfFunction( // compute total child count only when the node has children "CHILDCOUNT = 0", "0", "(SELECT COUNT(*) FROM " + getTable(sourceMode) + " WHERE LFT > NODE.LFT AND RGT < NODE.RGT)") + // 3 4 5 6 ", CHILDCOUNT, LFT AS LFTORD,RGT,DEPTH" + createProps + " FROM (SELECT ID,CHILDCOUNT,LFT,RGT,DEPTH" + createProps + " FROM " + getTable(sourceMode) + " WHERE " + "LFT>" + includeNode + nodeInfo.getLeft() + " AND LFT<" + includeNode + nodeInfo.getRight() + ") NODE " + "ORDER BY LFTORD ASC"; stmt = con.createStatement(); rs = stmt.executeQuery(sql); if (createMode) { // 1 2 3 4 5 6 7 8 ps = con.prepareStatement( "INSERT INTO " + getTable(destMode) + " (ID,PARENT,DEPTH,DIRTY,REF,TEMPLATE,LFT,RGT," + //9 10 11 "CHILDCOUNT,NAME,MODIFIED_AT) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"); } else { ps = con.prepareStatement("UPDATE " + getTable(sourceMode) + " SET LFT=?,RGT=?,DEPTH=? WHERE ID=?"); } long id; int total_childs; int direct_childs; BigInteger nextLeft; int lastDepth = nodeInfo.getDepth() + (includeNodeId ? 0 : 1); int depth; BigInteger _rgt; BigInteger _lft; Long ref = null; String data = null; String name = ""; Stack<Long> currentParent = null; if (createMode) { currentParent = new Stack<Long>(); currentParent.push(destinationNode); } //System.out.println("Spacing:"+SPACING); while (rs.next()) { //System.out.println("------------------"); id = rs.getLong(1); total_childs = rs.getInt(2); direct_childs = rs.getInt(3); _lft = getNodeBounds(rs, 4); _rgt = getNodeBounds(rs, 5); depth = rs.getInt(6); if (createMode) { // Reading these properties is slow, only do it when needed ref = rs.getLong(8); if (rs.wasNull()) ref = null; name = rs.getString(9); data = rs.getString(10); if (rs.wasNull()) data = null; } left = left.add(spacing).add(BigInteger.ONE); // Handle depth differences if (lastDepth - depth > 0) { BigInteger depthDifference = spacing.add(BigInteger.ONE); left = left.add(depthDifference.multiply(BigInteger.valueOf(lastDepth - depth))); } if (createMode) { if (lastDepth < depth) { currentParent.push(newId); } else if (lastDepth > depth) { for (int p = 0; p < (lastDepth - depth); p++) currentParent.pop(); } } right = left.add(spacing).add(BigInteger.ONE); // add child space if needed if (total_childs > 0) { BigInteger childSpace = spacing.multiply(BigInteger.valueOf(total_childs * 2)); childSpace = childSpace.add(BigInteger.valueOf((total_childs * 2) - 1)); right = right.add(childSpace); nextLeft = left; } else { nextLeft = right; } if (insertBoundaries != null) { // insert gap at requested position // If we're past the gap, keep adding the insert space to left/right because the added // space is never "injected" into the loop, i.e. without adding it the left/right boundaries of // nodes after the gap would be too far to the left. if (_lft.compareTo(insertBoundaries[0]) > 0) { left = left.add(insertSpace); } if (_rgt.compareTo(insertBoundaries[0]) > 0) { right = right.add(insertSpace); } } // sanity checks if (left.compareTo(right) >= 0) { throw new FxTreeException(LOG, "ex.tree.reorganize.failed", counter, left, right, "left greater than right"); } if (insertParent != null && right.compareTo((BigInteger) insertParent.getRight()) > 0) { throw new FxTreeException(LOG, "ex.tree.reorganize.failed", counter, left, right, "wrote past parent node bounds"); } // Update the node if (createMode) { newId = createKeepIds ? id : seq.getId(destMode.getSequencer()); if (firstCreatedNodeId == -1) firstCreatedNodeId = newId; // Create the main entry ps.setLong(1, newId); ps.setLong(2, currentParent.peek()); ps.setLong(3, depth + depthDelta); ps.setBoolean(4, destMode != FxTreeMode.Live); //only flag non-live tree's dirty if (ref == null) { ps.setNull(5, java.sql.Types.NUMERIC); } else { ps.setLong(5, ref); } if (data == null) { ps.setNull(6, java.sql.Types.VARCHAR); } else { ps.setString(6, data); } // System.out.println("=> id:"+newId+" left:"+left+" right:"+right); setNodeBounds(ps, 7, left); setNodeBounds(ps, 8, right); ps.setInt(9, direct_childs); ps.setString(10, name); ps.setLong(11, System.currentTimeMillis()); ps.addBatch(); } else { setNodeBounds(ps, 1, left); setNodeBounds(ps, 2, right); ps.setInt(3, depth + depthDelta); ps.setLong(4, id); ps.addBatch(); // ps.executeBatch(); // ps.clearBatch(); } // Prepare variables for the next node left = nextLeft; lastDepth = depth; counter++; // Execute batch every 10000 items to avoid out of memory if (counter % 10000 == 0) { ps.executeBatch(); ps.clearBatch(); } } rs.close(); stmt.close(); stmt = null; ps.executeBatch(); if (LOG.isDebugEnabled()) { final long time = System.currentTimeMillis() - start; LOG.debug("Tree reorganization of " + counter + " items completed in " + time + " ms (spaceLen=" + spacing + ")"); } return firstCreatedNodeId; } catch (FxApplicationException e) { throw e instanceof FxTreeException ? (FxTreeException) e : new FxTreeException(e); } catch (SQLException e) { String next = ""; if (e.getNextException() != null) next = " next:" + e.getNextException().getMessage(); if (StorageManager.isDuplicateKeyViolation(e)) throw new FxTreeException(LOG, e, "ex.tree.reorganize.duplicateKey"); throw new FxTreeException(LOG, e, "ex.tree.reorganize.failed", counter, left, right, e.getMessage() + next); } catch (Exception e) { throw new FxTreeException(e); } finally { try { if (stmt != null) stmt.close(); } catch (Throwable t) { /*ignore*/} try { if (ps != null) ps.close(); } catch (Throwable t) { /*ignore*/} } }
From source file:groovy.ui.GroovyMain.java
/** * Process a script against a single input file. * * @param s script to execute.//w ww . j av a2s .co m * @param reader input file. * @param pw output sink. */ private void processReader(Script s, BufferedReader reader, PrintWriter pw) throws IOException { String line; String lineCountName = "count"; s.setProperty(lineCountName, BigInteger.ZERO); String autoSplitName = "split"; s.setProperty("out", pw); try { InvokerHelper.invokeMethod(s, "begin", null); } catch (MissingMethodException mme) { // ignore the missing method exception // as it means no begin() method is present } while ((line = reader.readLine()) != null) { s.setProperty("line", line); s.setProperty(lineCountName, ((BigInteger) s.getProperty(lineCountName)).add(BigInteger.ONE)); if (autoSplit) { s.setProperty(autoSplitName, line.split(splitPattern)); } Object o = s.run(); if (autoOutput && o != null) { pw.println(o); } } try { InvokerHelper.invokeMethod(s, "end", null); } catch (MissingMethodException mme) { // ignore the missing method exception // as it means no end() method is present } }
From source file:net.pms.util.Rational.java
/** * Returns a {@link Rational} whose value is {@code (this * value)}. * * @param value the value to be multiplied by this {@link Rational}. * @return The multiplication result.// w ww .j a v a2 s . c om */ @Nullable public Rational multiply(@Nullable BigInteger value) { if (value == null) { return null; } if (isNaN()) { return NaN; } if (isInfinite()) { if (value.signum() == 0) { return NaN; // Infinity by zero } return numerator.signum() == value.signum() ? POSITIVE_INFINITY : NEGATIVE_INFINITY; } if (value.signum() == 0) { return ZERO; } if (BigInteger.ONE.equals(value.abs())) { return value.signum() < 0 ? negate() : this; } return valueOf(reducedNumerator.multiply(value), reducedDenominator); }
From source file:test.integ.be.fedict.trust.util.TestUtils.java
public static X509CRL generateCrl(PrivateKey issuerPrivateKey, X509Certificate issuerCertificate, DateTime thisUpdate, DateTime nextUpdate, List<String> deltaCrlUris, boolean deltaCrl, List<RevokedCertificate> revokedCertificates, String signatureAlgorithm) throws InvalidKeyException, CRLException, IllegalStateException, NoSuchAlgorithmException, SignatureException, CertificateParsingException { X509V2CRLGenerator crlGenerator = new X509V2CRLGenerator(); crlGenerator.setThisUpdate(thisUpdate.toDate()); crlGenerator.setNextUpdate(nextUpdate.toDate()); crlGenerator.setSignatureAlgorithm(signatureAlgorithm); crlGenerator.setIssuerDN(issuerCertificate.getSubjectX500Principal()); for (RevokedCertificate revokedCertificate : revokedCertificates) { crlGenerator.addCRLEntry(revokedCertificate.serialNumber, revokedCertificate.revocationDate.toDate(), CRLReason.privilegeWithdrawn); }/*from www . j a v a2s. c om*/ crlGenerator.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(issuerCertificate)); crlGenerator.addExtension(X509Extensions.CRLNumber, false, new CRLNumber(BigInteger.ONE)); if (null != deltaCrlUris && !deltaCrlUris.isEmpty()) { DistributionPoint[] deltaCrlDps = new DistributionPoint[deltaCrlUris.size()]; for (int i = 0; i < deltaCrlUris.size(); i++) { deltaCrlDps[i] = getDistributionPoint(deltaCrlUris.get(i)); } CRLDistPoint crlDistPoint = new CRLDistPoint(deltaCrlDps); crlGenerator.addExtension(X509Extensions.FreshestCRL, false, crlDistPoint); } if (deltaCrl) { crlGenerator.addExtension(X509Extensions.DeltaCRLIndicator, true, new CRLNumber(BigInteger.ONE)); } return crlGenerator.generate(issuerPrivateKey); }
From source file:com.ibm.soatf.component.soap.builder.SampleXmlUtil.java
private String formatDecimal(String start, SchemaType sType) { BigDecimal result = new BigDecimal(start); XmlDecimal xmlD;//from w w w. ja v a 2 s . co m xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); BigDecimal min = xmlD != null ? xmlD.getBigDecimalValue() : null; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); BigDecimal max = xmlD != null ? xmlD.getBigDecimalValue() : null; boolean minInclusive = true, maxInclusive = true; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (xmlD != null) { BigDecimal minExcl = xmlD.getBigDecimalValue(); if (min == null || min.compareTo(minExcl) < 0) { min = minExcl; minInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (xmlD != null) { BigDecimal maxExcl = xmlD.getBigDecimalValue(); if (max == null || max.compareTo(maxExcl) > 0) { max = maxExcl; maxInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_TOTAL_DIGITS); int totalDigits = -1; if (xmlD != null) { totalDigits = xmlD.getBigDecimalValue().intValue(); StringBuilder sb = new StringBuilder(totalDigits); for (int i = 0; i < totalDigits; i++) sb.append('9'); BigDecimal digitsLimit = new BigDecimal(sb.toString()); if (max != null && max.compareTo(digitsLimit) > 0) { max = digitsLimit; maxInclusive = true; } digitsLimit = digitsLimit.negate(); if (min != null && min.compareTo(digitsLimit) < 0) { min = digitsLimit; minInclusive = true; } } int sigMin = min == null ? 1 : result.compareTo(min); int sigMax = max == null ? -1 : result.compareTo(max); boolean minOk = sigMin > 0 || sigMin == 0 && minInclusive; boolean maxOk = sigMax < 0 || sigMax == 0 && maxInclusive; // Compute the minimum increment xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_FRACTION_DIGITS); int fractionDigits = -1; BigDecimal increment; if (xmlD == null) increment = new BigDecimal(1); else { fractionDigits = xmlD.getBigDecimalValue().intValue(); if (fractionDigits > 0) { StringBuilder sb = new StringBuilder("0."); for (int i = 1; i < fractionDigits; i++) sb.append('0'); sb.append('1'); increment = new BigDecimal(sb.toString()); } else increment = new BigDecimal(1); } if (minOk && maxOk) { // OK } else if (minOk && !maxOk) { // TOO BIG if (maxInclusive) result = max; else result = max.subtract(increment); } else if (!minOk && maxOk) { // TOO SMALL if (minInclusive) result = min; else result = min.add(increment); } else { // MIN > MAX!! } // We have the number // Adjust the scale according to the totalDigits and fractionDigits int digits = 0; BigDecimal ONE = new BigDecimal(BigInteger.ONE); for (BigDecimal n = result; n.abs().compareTo(ONE) >= 0; digits++) n = n.movePointLeft(1); if (fractionDigits > 0) if (totalDigits >= 0) result.setScale(Math.max(fractionDigits, totalDigits - digits)); else result.setScale(fractionDigits); else if (fractionDigits == 0) result.setScale(0); return result.toString(); }
From source file:com.centeractive.ws.builder.soap.SampleXmlUtil.java
private String formatDecimal(String start, SchemaType sType) { BigDecimal result = new BigDecimal(start); XmlDecimal xmlD;/*from w w w.j ava 2 s . c o m*/ xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); BigDecimal min = xmlD != null ? xmlD.getBigDecimalValue() : null; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); BigDecimal max = xmlD != null ? xmlD.getBigDecimalValue() : null; boolean minInclusive = true, maxInclusive = true; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (xmlD != null) { BigDecimal minExcl = xmlD.getBigDecimalValue(); if (min == null || min.compareTo(minExcl) < 0) { min = minExcl; minInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (xmlD != null) { BigDecimal maxExcl = xmlD.getBigDecimalValue(); if (max == null || max.compareTo(maxExcl) > 0) { max = maxExcl; maxInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_TOTAL_DIGITS); int totalDigits = -1; if (xmlD != null) { totalDigits = xmlD.getBigDecimalValue().intValue(); StringBuffer sb = new StringBuffer(totalDigits); for (int i = 0; i < totalDigits; i++) sb.append('9'); BigDecimal digitsLimit = new BigDecimal(sb.toString()); if (max != null && max.compareTo(digitsLimit) > 0) { max = digitsLimit; maxInclusive = true; } digitsLimit = digitsLimit.negate(); if (min != null && min.compareTo(digitsLimit) < 0) { min = digitsLimit; minInclusive = true; } } int sigMin = min == null ? 1 : result.compareTo(min); int sigMax = max == null ? -1 : result.compareTo(max); boolean minOk = sigMin > 0 || sigMin == 0 && minInclusive; boolean maxOk = sigMax < 0 || sigMax == 0 && maxInclusive; // Compute the minimum increment xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_FRACTION_DIGITS); int fractionDigits = -1; BigDecimal increment; if (xmlD == null) increment = new BigDecimal(1); else { fractionDigits = xmlD.getBigDecimalValue().intValue(); if (fractionDigits > 0) { StringBuffer sb = new StringBuffer("0."); for (int i = 1; i < fractionDigits; i++) sb.append('0'); sb.append('1'); increment = new BigDecimal(sb.toString()); } else increment = new BigDecimal(1); } if (minOk && maxOk) { // OK } else if (minOk && !maxOk) { // TOO BIG if (maxInclusive) result = max; else result = max.subtract(increment); } else if (!minOk && maxOk) { // TOO SMALL if (minInclusive) result = min; else result = min.add(increment); } else { // MIN > MAX!! } // We have the number // Adjust the scale according to the totalDigits and fractionDigits int digits = 0; BigDecimal ONE = new BigDecimal(BigInteger.ONE); for (BigDecimal n = result; n.abs().compareTo(ONE) >= 0; digits++) n = n.movePointLeft(1); if (fractionDigits > 0) if (totalDigits >= 0) result.setScale(Math.max(fractionDigits, totalDigits - digits)); else result.setScale(fractionDigits); else if (fractionDigits == 0) result.setScale(0); return result.toString(); }
From source file:org.apache.juddi.samples.JuddiAdminService.java
void autoMagic123() throws Exception { //1 > 2 >3 >1 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList(); Transport transport = clerkManager.getTransport("default"); String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")) .getAuthInfo();// ww w. ja v a 2s . c o m JUDDIApiPortType juddiApiService = transport.getJUDDIApiService(); System.out.println("fetching..."); ReplicationConfiguration replicationNodes = null; try { replicationNodes = juddiApiService.getReplicationNodes(authtoken); } catch (Exception ex) { System.out.println("Error getting replication config"); ex.printStackTrace(); replicationNodes = new ReplicationConfiguration(); } if (replicationNodes.getCommunicationGraph() == null) { replicationNodes.setCommunicationGraph(new CommunicationGraph()); } Operator op = new Operator(); op.setOperatorNodeID("uddi:juddi.apache.org:node1"); op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("bob", "en")); op.getContact().get(0).setUseType("admin"); replicationNodes.getOperator().clear(); replicationNodes.getOperator().add(op); op = new Operator(); op.setOperatorNodeID("uddi:another.juddi.apache.org:node2"); op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2") .getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("mary", "en")); op.getContact().get(0).setUseType("admin"); replicationNodes.getOperator().add(op); op = new Operator(); op.setOperatorNodeID("uddi:yet.another.juddi.apache.org:node3"); op.setSoapReplicationURL(clerkManager.getClientConfig() .getUDDINode("uddi:yet.another.juddi.apache.org:node3").getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("mary", "en")); op.getContact().get(0).setUseType("admin"); replicationNodes.getOperator().add(op); replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2"); replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1"); replicationNodes.getCommunicationGraph().getNode().add("uddi:yet.another.juddi.apache.org:node3"); replicationNodes.setSerialNumber(0L); replicationNodes.setTimeOfConfigurationUpdate(""); replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE); replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE); if (replicationNodes.getRegistryContact().getContact() == null) { replicationNodes.getRegistryContact().setContact(new Contact()); replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null)); } JAXB.marshal(replicationNodes, System.out); juddiApiService.setReplicationNodes(authtoken, replicationNodes); transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2"); authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo(); juddiApiService = transport.getJUDDIApiService(); juddiApiService.setReplicationNodes(authtoken, replicationNodes); transport = clerkManager.getTransport("uddi:yet.another.juddi.apache.org:node3"); authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo(); juddiApiService = transport.getJUDDIApiService(); juddiApiService.setReplicationNodes(authtoken, replicationNodes); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.RecursiveCluster.java
private Set<BigInteger> createIdSet(String filter) { Set<BigInteger> result; if (StringUtils.isEmpty(filter)) { result = Sets.newHashSet(BigInteger.valueOf(-1L), BigInteger.ONE); } else {/*from www . jav a 2 s .c o m*/ result = Sets.newHashSet(); String[] idStrings = filter.split(","); for (String idString : idStrings) { result.add(new BigInteger(idString)); } } return result; }
From source file:edu.hku.sdb.rewrite.SdbSchemeRewriter.java
/** * Rewrite a normal join predicate.//from ww w. j a v a 2 s . c o m * * @param normalBinPred * @param leftS * @param rightS * @param targetM * @param targetX * @throws RewriteException */ protected void rewriteNorBinJoinPred(NormalBinPredicate normalBinPred, SelectionItem leftS, SelectionItem rightS, BigInteger targetM, BigInteger targetX) throws RewriteException { LOG.debug("Rewriting join predicate for " + normalBinPred.toSql()); if (!normalBinPred.involveEncrytedCol()) return; if (normalBinPred.getOp() != BinaryPredicate.BinOperator.EQ) { UnSupportedException e = new UnSupportedException( "Can not support condition" + " " + normalBinPred.getOp() + " in join clause!"); LOG.error("There is unsupported join condition!", e); throw e; } Expr leftExpr = normalBinPred.getLeftExpr(); Expr rightExpr = normalBinPred.getRightExpr(); if (!(leftExpr instanceof FieldLiteral && rightExpr instanceof FieldLiteral)) { UnSupportedException e = new UnSupportedException("Can not support " + "non-column join attributes!"); LOG.error("There is unsupported join condition!", e); throw e; } FieldLiteral leftField = (FieldLiteral) leftExpr; FieldLiteral rightField = (FieldLiteral) rightExpr; if (!leftField.getType().equals(Type.INT) || !rightField.getType().equals(Type.INT)) { UnSupportedException e = new UnSupportedException("Can not support " + "non-integer join attributes!"); LOG.error("There is unsupported join condition!", e); throw e; } // EE mode if (leftField.involveEncrytedCol() && rightField.involveEncrytedCol()) { SdbColumnKey leftSColKey = leftS.getExpr().getSdbColKey(); // The auxiliary update values p, q for the left field BigInteger[] pqLeft = SDBEncrypt.keyUpdateClient(leftExpr.getSdbColKey().getM(), targetM, leftSColKey.getM(), leftExpr.getSdbColKey().getX(), targetX, leftSColKey.getX(), prime1, prime2); // The auxiliary update values p, q for the right field BigInteger[] pqRight = SDBEncrypt.keyUpdateClient(rightExpr.getSdbColKey().getM(), targetM, rightS.getExpr().getSdbColKey().getM(), rightExpr.getSdbColKey().getX(), targetX, rightS.getExpr().getSdbColKey().getX(), prime1, prime2); // The order must be:(field, auxiliaryS, p, q, n) Expr leftKeyUp = buildSdbKeyUpdateExpr(leftExpr, leftS.getExpr(), new BigIntLiteral(pqLeft[0]), new BigIntLiteral(pqLeft[1]), new BigIntLiteral(n), targetM, targetX); Expr rightKeyUp = buildSdbKeyUpdateExpr(rightExpr, rightS.getExpr(), new BigIntLiteral(pqRight[0]), new BigIntLiteral(pqRight[1]), new BigIntLiteral(n), targetM, targetX); // Replace the original predicate normalBinPred.setLeftExpr(leftKeyUp); normalBinPred.setRightExpr(rightKeyUp); } else { if (leftField.involveEncrytedCol()) { SdbColumnKey leftSColKey = leftS.getExpr().getSdbColKey(); // The auxiliary update values p, q for the left field BigInteger[] pqLeft = SDBEncrypt.keyUpdateClient(leftExpr.getSdbColKey().getM(), targetM, leftSColKey.getM(), leftExpr.getSdbColKey().getX(), targetX, leftSColKey.getX(), prime1, prime2); // The auxiliary update values p, q for the right field BigInteger[] pqRight = SDBEncrypt.keyUpdateClient(BigInteger.ONE, targetM, rightS.getExpr().getSdbColKey().getM(), BigInteger.ZERO, targetX, rightS.getExpr().getSdbColKey().getX(), prime1, prime2); // The order must be:(field, auxiliaryS, p, q, n) Expr leftKeyUp = buildSdbKeyUpdateExpr(leftExpr, leftS.getExpr(), new BigIntLiteral(pqLeft[0]), new BigIntLiteral(pqLeft[1]), new BigIntLiteral(n), targetM, targetX); Expr rightKeyUp = buildSdbKeyUpdateExpr(rightExpr, rightS.getExpr(), new BigIntLiteral(pqRight[0]), new BigIntLiteral(pqRight[1]), new BigIntLiteral(n), targetM, targetX); // Replace the original predicate normalBinPred.setLeftExpr(leftKeyUp); normalBinPred.setRightExpr(rightKeyUp); } else { SdbColumnKey leftSColKey = leftS.getExpr().getSdbColKey(); // The auxiliary update values p, q for the left field BigInteger[] pqLeft = SDBEncrypt.keyUpdateClient(BigInteger.ONE, targetM, leftSColKey.getM(), BigInteger.ZERO, targetX, leftSColKey.getX(), prime1, prime2); // The auxiliary update values p, q for the right field BigInteger[] pqRight = SDBEncrypt.keyUpdateClient(rightExpr.getSdbColKey().getM(), targetM, rightS.getExpr().getSdbColKey().getM(), rightExpr.getSdbColKey().getX(), targetX, rightS.getExpr().getSdbColKey().getX(), prime1, prime2); // The order must be:(field, auxiliaryS, p, q, n) Expr leftKeyUp = buildSdbKeyUpdateExpr(leftExpr, leftS.getExpr(), new BigIntLiteral(pqLeft[0]), new BigIntLiteral(pqLeft[1]), new BigIntLiteral(n), targetM, targetX); Expr rightKeyUp = buildSdbKeyUpdateExpr(rightExpr, rightS.getExpr(), new BigIntLiteral(pqRight[0]), new BigIntLiteral(pqRight[1]), new BigIntLiteral(n), targetM, targetX); // Replace the original predicate normalBinPred.setLeftExpr(leftKeyUp); normalBinPred.setRightExpr(rightKeyUp); } } }
From source file:com.ng.mats.psa.mt.paga.data.JSONObject.java
/** * Increment a property of a JSONObject. If there is no such property, * create one with a value of 1. If there is such a property, and if it is * an Integer, Long, Double, or Float, then add one to it. * // w w w . j av a2s . c om * @param key * A key string. * @return this. * @throws JSONException * If there is already a property with this name that is not an * Integer, Long, Double, or Float. */ public JSONObject increment(String key) throws JSONException { Object value = this.opt(key); if (value == null) { this.put(key, 1); } else if (value instanceof BigInteger) { this.put(key, ((BigInteger) value).add(BigInteger.ONE)); } else if (value instanceof BigDecimal) { this.put(key, ((BigDecimal) value).add(BigDecimal.ONE)); } else if (value instanceof Integer) { this.put(key, (Integer) value + 1); } else if (value instanceof Long) { this.put(key, (Long) value + 1); } else if (value instanceof Double) { this.put(key, (Double) value + 1); } else if (value instanceof Float) { this.put(key, (Float) value + 1); } else { throw new JSONException("Unable to increment [" + quote(key) + "]."); } return this; }