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.thymeleaf.util.EvaluationUtilTest.java
@Test public void convertToBooleanTest() { Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(null)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Boolean.TRUE)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Boolean.FALSE)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(BigDecimal.ZERO)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigDecimal.ONE)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigDecimal.TEN)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(BigInteger.ZERO)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigInteger.ONE)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigInteger.TEN)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Double.valueOf(0.0d))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Float.valueOf(0.0f))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(0.1d))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(0.1f))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(-0.1d))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(-0.1f))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(Double.MAX_VALUE))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(Float.MAX_VALUE))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(Double.MIN_VALUE))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(Float.MIN_VALUE))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Character.valueOf((char) 0))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Character.valueOf('x'))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Character.valueOf('0'))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Character.valueOf('1'))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("true")); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean("false")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("yes")); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean("no")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("on")); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean("off")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("sky")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("high above")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("true"))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(new LiteralValue("false"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("yes"))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(new LiteralValue("no"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("on"))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(new LiteralValue("off"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("sky"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("high above"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(EvaluationUtil.class)); }
From source file:com.amazon.carbonado.repo.jdbc.LoggingPreparedStatement.java
private void logStatement() { String statement = mSQL;//from ww w . j a v a2 s . c o m Object[] params; BigInteger setParams; if ((params = mParams) != null && (setParams = mSetParams) != BigInteger.ZERO) { int length = setParams.bitLength(); StringBuilder b = new StringBuilder(statement.length() + length * 10); b.append(statement); b.append(" -- "); boolean any = false; for (int i = 0; i < length; i++) { if (setParams.testBit(i)) { if (any) { b.append(", ["); } else { b.append('['); any = true; } b.append(i); b.append("]="); b.append(params[i]); } } statement = b.toString(); } mLog.debug(statement); }
From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java
public KmerRangePartition[] getHistogramPartitions(KmerHistogramRecord[] records, long samples) { KmerRangePartition[] partitions = new KmerRangePartition[this.numPartitions]; // calc 4^kmerSize String As = ""; String Ts = ""; for (int i = 0; i < this.kmerSize; i++) { As += "A"; Ts += "T"; }//from www. j a v a2 s . c om long partitionWidth = samples / this.numPartitions; long partitionWidthRemain = partitionWidth; int partitionIdx = 0; int recordIdx = 0; long curRecordRemain = records[0].getFrequency(); BigInteger nextPartitionBegin = BigInteger.ZERO; while (partitionIdx < this.numPartitions) { long diff = partitionWidthRemain - curRecordRemain; if (diff > 0) { partitionWidthRemain -= curRecordRemain; recordIdx++; if (recordIdx < records.length) { curRecordRemain = records[recordIdx].getFrequency(); } else { break; } } else if (diff == 0) { BigInteger partitionBegin = nextPartitionBegin; BigInteger partitionEnd = null; if (partitionIdx == this.numPartitions - 1) { partitionEnd = SequenceHelper.convertToBigInteger(Ts); } else { partitionEnd = SequenceHelper .convertToBigInteger((records[recordIdx].getKmer() + Ts).substring(0, this.kmerSize)); } BigInteger partitionSize = partitionEnd.subtract(partitionBegin); partitions[partitionIdx] = new KmerRangePartition(this.kmerSize, this.numPartitions, partitionIdx, partitionSize, partitionBegin, partitionEnd); nextPartitionBegin = partitionEnd.add(BigInteger.ONE); partitionIdx++; recordIdx++; if (recordIdx < records.length) { curRecordRemain = records[recordIdx].getFrequency(); } else { break; } partitionWidthRemain = partitionWidth; } else { // in between BigInteger partitionBegin = nextPartitionBegin; BigInteger partitionEnd = null; if (partitionIdx == this.numPartitions - 1) { partitionEnd = SequenceHelper.convertToBigInteger(Ts); } else { BigInteger recordBegin = SequenceHelper .convertToBigInteger((records[recordIdx].getKmer() + As).substring(0, this.kmerSize)); BigInteger recordEnd = SequenceHelper .convertToBigInteger((records[recordIdx].getKmer() + Ts).substring(0, this.kmerSize)); BigInteger recordWidth = recordEnd.subtract(recordBegin); BigInteger curWidth = recordWidth.multiply(BigInteger.valueOf(partitionWidthRemain)) .divide(BigInteger.valueOf(records[recordIdx].getFrequency())); BigInteger bigger = null; if (recordBegin.compareTo(partitionBegin) > 0) { bigger = recordBegin; } else { bigger = partitionBegin; } partitionEnd = bigger.add(curWidth); } BigInteger partitionSize = partitionEnd.subtract(partitionBegin); partitions[partitionIdx] = new KmerRangePartition(this.kmerSize, this.numPartitions, partitionIdx, partitionSize, partitionBegin, partitionEnd); nextPartitionBegin = partitionEnd.add(BigInteger.ONE); partitionIdx++; curRecordRemain -= partitionWidthRemain; partitionWidthRemain = partitionWidth; } } return partitions; }
From source file:Main.java
public static byte[] decodeBase58(String input) { if (input == null) { return null; }/*from w w w . ja v a 2 s .c om*/ input = input.trim(); if (input.length() == 0) { return new byte[0]; } BigInteger resultNum = BigInteger.ZERO; int nLeadingZeros = 0; while (nLeadingZeros < input.length() && input.charAt(nLeadingZeros) == BASE58[0]) { nLeadingZeros++; } long acc = 0; int nDigits = 0; int p = nLeadingZeros; while (p < input.length()) { int v = BASE58_VALUES[input.charAt(p) & 0xff]; if (v >= 0) { acc *= 58; acc += v; nDigits++; if (nDigits == BASE58_CHUNK_DIGITS) { resultNum = resultNum.multiply(BASE58_CHUNK_MOD).add(BigInteger.valueOf(acc)); acc = 0; nDigits = 0; } p++; } else { break; } } if (nDigits > 0) { long mul = 58; while (--nDigits > 0) { mul *= 58; } resultNum = resultNum.multiply(BigInteger.valueOf(mul)).add(BigInteger.valueOf(acc)); } final int BASE58_SPACE = -2; while (p < input.length() && BASE58_VALUES[input.charAt(p) & 0xff] == BASE58_SPACE) { p++; } if (p < input.length()) { return null; } byte[] plainNumber = resultNum.toByteArray(); int plainNumbersOffs = plainNumber[0] == 0 ? 1 : 0; byte[] result = new byte[nLeadingZeros + plainNumber.length - plainNumbersOffs]; System.arraycopy(plainNumber, plainNumbersOffs, result, nLeadingZeros, plainNumber.length - plainNumbersOffs); return result; }
From source file:org.btc4j.ws.BtcDaemonServiceTest.java
@Test public void getConnectionCount() throws BtcWsException { System.out.println("BtcDaemonServiceTest.getConnectionCount"); BigInteger connections = BTCWS_SVC.getConnectionCount(); assertTrue(connections.compareTo(BigInteger.ZERO) >= 0); }
From source file:edu.hku.sdb.udf.util.UDFHandler.java
/** * (1) value less than halfN means that a > b, return true * (2) value greater or equal to halfN means that a < b, return false * @param value// w ww .j a v a 2 s. co m * @param halfN * @return */ public static boolean greatThan(BigInteger value, BigInteger halfN) { if (value.equals(BigInteger.ZERO)) return false; int result = value.compareTo(halfN); if (result < 0) return true; else return false; }
From source file:Bytes.java
/** * Convert the specified amount into a human readable (though slightly less accurate) * result. IE:// www.ja v a2 s.com * '4096 B' to '4 KB' * '5080 B' to '5 KB' even though it is really '4 KB + 984 B' */ public static String friendly(Bytes type, BigInteger value) { /** * Logic: * Loop from YB to B * If result = 0, continue * Else, round off * * NOTE: BigIntegers are not reusable, so not point in caching them outside the loop */ for (Bytes newType : reversed) { BigInteger newAmount = newType.convertFrom(value, type); if (newAmount.equals(BigInteger.ZERO)) continue; // Found the right one. Now to round off BigInteger unitBytes = Bytes.B.convertFrom(BigInteger.ONE, newType); BigInteger usedBytes = newAmount.multiply(unitBytes); BigInteger remainingBytes = Bytes.B.convertFrom(value, type).subtract(usedBytes); if (remainingBytes.equals(BigInteger.ZERO)) return String.format(friendlyFMT, newAmount.toString(), newType); if (remainingBytes.equals(value)) return String.format(friendlyFMT, newAmount.toString(), newType); BigInteger halfUnit = unitBytes.divide(TWO); if ((remainingBytes.subtract(halfUnit)).signum() < 0) return String.format(friendlyFMT, newAmount.toString(), newType); return String.format(friendlyFMT, (newAmount.add(BigInteger.ONE)).toString(), newType); } // Give up return String.format(friendlyFMT, value.toString(), type); }
From source file:org.openhim.mediator.denormalization.ATNAAuditingActor.java
protected String generateForPIXRequest(ATNAAudit audit) throws JAXBException { AuditMessage res = new AuditMessage(); EventIdentificationType eid = new EventIdentificationType(); eid.setEventID(ATNAUtil.buildCodedValueType("DCM", "110112", "Query")); eid.setEventActionCode("E"); eid.setEventDateTime(ATNAUtil.newXMLGregorianCalendar()); eid.getEventTypeCode().add(ATNAUtil.buildCodedValueType("IHE Transactions", "ITI-9", "PIX Query")); eid.setEventOutcomeIndicator(audit.getOutcome() ? BigInteger.ZERO : new BigInteger("4")); res.setEventIdentification(eid);/* w w w .j av a 2 s . c o m*/ res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant( config.getProperty("pix.sendingFacility") + "|" + config.getProperty("pix.sendingApplication"), ATNAUtil.getProcessID(), true, ATNAUtil.getHostIP(), (short) 2, "DCM", "110153", "Source")); res.getActiveParticipant() .add(ATNAUtil.buildActiveParticipant( config.getProperty("pix.receivingFacility") + "|" + config.getProperty("pix.receivingApplication"), "2100", false, config.getProperty("pix.manager.host"), (short) 1, "DCM", "110152", "Destination")); res.getAuditSourceIdentification().add(ATNAUtil.buildAuditSource("openhim")); // Max of 1 patient is allowed Identifier id = audit.getParticipantIdentifiers().get(0); if (id != null) { res.getParticipantObjectIdentification().add(ATNAUtil.buildParticipantObjectIdentificationType( id.toCX(), (short) 1, (short) 1, "RFC-3881", "2", "PatientNumber", null)); } res.getParticipantObjectIdentification() .add(ATNAUtil.buildParticipantObjectIdentificationType(UUID.randomUUID().toString(), (short) 2, (short) 24, "IHE Transactions", "ITI-9", "PIX Query", audit.getMessage(), new ATNAUtil.ParticipantObjectDetail("MSH-10", audit.getUniqueId().getBytes()))); return ATNAUtil.marshallATNAObject(res); }
From source file:org.apache.streams.moreover.MoreoverClient.java
/** * get limit ArticlesAfter sequenceId.// w w w .j a v a2 s .c o m * @param sequenceId sequenceId * @param limit limit * @return MoreoverResult * @throws IOException IOException */ public MoreoverResult getArticlesAfter(String sequenceId, int limit) throws IOException { String urlString = String.format(BASE_URL, this.apiKey, limit, sequenceId); logger.debug("Making call to {}", urlString); long start = System.nanoTime(); MoreoverResult result = new MoreoverResult(id, getArticles(new URL(urlString)), start, System.nanoTime()); if (!result.getMaxSequencedId().equals(BigInteger.ZERO)) { this.lastSequenceId = result.getMaxSequencedId(); logger.debug("Maximum sequence from last call {}", this.lastSequenceId); } else { logger.debug("No maximum sequence returned in last call {}", this.lastSequenceId); } return result; }
From source file:org.limewire.mojito.util.DHTSizeEstimator.java
/** * Clears the history and sets everything to * its initial state./*from w w w.j av a2s .c o m*/ */ public synchronized void clear() { estimatedSize = BigInteger.ZERO; localEstimateTime = 0L; updateEstimatedSizeTime = 0L; localSizeHistory.clear(); remoteSizeHistory.clear(); }