List of usage examples for java.math BigInteger compareTo
public int compareTo(BigInteger val)
From source file:com.google.uzaygezen.core.ranges.BigIntegerRange.java
public BigIntegerRange(BigInteger start, BigInteger end) { Preconditions.checkArgument(end.compareTo(start) > 0 & start.signum() >= 0, "start must be nonnegative and less than end."); this.start = start; this.end = end; }
From source file:org.dbrain.data.jackson.serializers.JsonBigIntegerSerializer.java
@Override public void serialize(BigInteger value, JsonGenerator jgen, SerializerProvider provider) throws IOException { if (value != null) { if (value.compareTo(MIN_VALUE) >= 0 && value.compareTo(MAX_VALUE) <= 0) { jgen.writeNumber(value);//from ww w . j a v a 2 s. co m } else { jgen.writeString(value.toString()); } } else { jgen.writeNull(); } }
From source file:com.ephesoft.dcma.tablefinder.share.TableExtractionResultModifierUtility.java
/** * This method gets the rectangle coordinates for the new merged row value. * /*from w ww.ja va2 s . c o m*/ * @param coordinatesList {@link Row} * @param currentRow {@link Row} */ public static void setMergedRowCoordinates(final Row previousRow, final Row currentRow) { LOGGER.trace("Entering method to merge coordinates of multiline column row."); if (null == previousRow || null == currentRow) { LOGGER.error("PreviousRow or currentRow is null. Coordinates of row could not be set."); } else { BigInteger minX0 = BigInteger.ZERO; BigInteger minY0 = BigInteger.ZERO; BigInteger maxX1 = BigInteger.ZERO; BigInteger maxY1 = BigInteger.ZERO; final Coordinates previousRowCoordinates = previousRow.getRowCoordinates(); final Coordinates currentRowCoordinates = currentRow.getRowCoordinates(); if (null == previousRowCoordinates || null == currentRowCoordinates) { LOGGER.error( "previousRowCoordinates or currentRowCoordinates are null. Coordinates of row could not be set."); } else { final BigInteger previousRowX0 = previousRowCoordinates.getX0(); final BigInteger previousRowY0 = previousRowCoordinates.getY0(); final BigInteger previousRowX1 = previousRowCoordinates.getX1(); final BigInteger previousRowY1 = previousRowCoordinates.getY1(); final BigInteger currentRowX0 = currentRowCoordinates.getX0(); final BigInteger currentRowY0 = currentRowCoordinates.getY0(); final BigInteger currentRowX1 = currentRowCoordinates.getX1(); final BigInteger currentRowY1 = currentRowCoordinates.getY1(); if (previousRowX0.compareTo(currentRowX0) < 0) { minX0 = previousRowX0; } else { minX0 = currentRowX0; } if (previousRowY0.compareTo(currentRowY0) < 0) { minY0 = previousRowY0; } else { minY0 = currentRowY0; } if (previousRowX1.compareTo(currentRowX1) > 0) { maxX1 = previousRowX1; } else { maxX1 = currentRowX1; } if (previousRowY1.compareTo(currentRowY1) > 0) { maxY1 = previousRowY1; } else { maxY1 = currentRowY1; } final Coordinates coordinates = new Coordinates(); coordinates.setX0(minX0); coordinates.setX1(maxX1); coordinates.setY0(minY0); coordinates.setY1(maxY1); previousRow.setRowCoordinates(coordinates); LOGGER.debug("Coordinates of row could are set: (X0, Y0, X1, Y1) are (", minX0, minY0, maxX1, maxY1, ")."); } } LOGGER.trace("Exiting method to merge coordinates of multiline column row."); }
From source file:dao.ParametrDao.java
public boolean hasCats(Long paramId) throws Exception { String sql = "select count(*) from param_category_link where parametr_id=:paramId"; Query query = getCurrentSession().createSQLQuery(sql); query.setParameter("paramId", paramId); BigInteger res = (BigInteger) query.uniqueResult(); //throw new Exception("res="+res); return res.compareTo(BigInteger.valueOf(0)) > 0; }
From source file:org.cesecore.certificates.ca.internal.SernoGeneratorRandom.java
protected boolean checkSernoValidity(final BigInteger serno) { if ((serno.compareTo(lowest) >= 0) && (serno.compareTo(highest) <= 0)) { return true; }/*from w ww . j a va2s.co m*/ return false; }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.databasecomponents.ModifyListenerForDBComp.java
/** * The Function will compare bigInteger values * @param value1//from ww w . ja v a 2s . c o m * @param value2 * @return */ private int compareBigIntegerValue(String value1, String value2) { BigInteger int1 = BigInteger.valueOf(Long.parseLong(value1)); BigInteger int2 = BigInteger.valueOf(Long.parseLong(value2)); return int1.compareTo(int2); }
From source file:com.swdouglass.joid.DiffieHellman.java
/** * Creates a DiffieHellman instance./* w ww .j a v a 2 s .c o m*/ * * @param mod the modulus to use. If null, use {@link #DEFAULT_MODULUS}. * @param gen the generator to use. If null, use * {@link #DEFAULT_GENERATOR}. */ public DiffieHellman(BigInteger mod, BigInteger gen) { modulus = (mod != null ? mod : DiffieHellman.DEFAULT_MODULUS); generator = (gen != null ? gen : DiffieHellman.DEFAULT_GENERATOR); int bits = modulus.bitLength(); BigInteger max = modulus.subtract(BigInteger.ONE); while (true) { BigInteger pkey = new BigInteger(bits, random); if (pkey.compareTo(max) >= 0) { //too large continue; } else if (pkey.compareTo(BigInteger.ONE) <= 0) {//too small continue; } privateKey = pkey; publicKey = generator.modPow(privateKey, modulus); break; } }
From source file:net.bither.rawprivatekey.RawPrivateKeyBinaryFragment.java
private boolean checkValue(byte[] data) { BigInteger value = new BigInteger(1, data); if (value.compareTo(BigInteger.ZERO) == 0 || value.compareTo(ECKey.CURVE.getN()) == 0) { return false; }/*w w w .jav a 2 s . c o m*/ return true; }
From source file:org.trnltk.numeral.DigitsToTextConverter.java
private String convertNaturalNumberToWords(BigInteger naturalNumber) { Validate.isTrue(naturalNumber.compareTo(ZERO) >= 0); Validate.isTrue(naturalNumber.compareTo(MAX_NATURAL_NUMBER_SUPPORTED) <= 0, "Given number " + naturalNumber + " is larger than maximum supported natural number " + MAX_NATURAL_NUMBER_SUPPORTED); StringBuilder result = new StringBuilder(); if (naturalNumber.compareTo(BigInteger.TEN) < 0) { result.append(NUMERAL_SYMBOL_NAMES.get(naturalNumber.intValue())); } else if (naturalNumber.compareTo(ONE_HUNDRED) < 0) { final BigInteger tensDigit = naturalNumber.divide(TEN); final BigInteger onesDigit = naturalNumber.mod(TEN); final String strTensDigit = TENS_MULTIPLES_NAMES.get(tensDigit.intValue()); final String strOnesDigit = onesDigit.compareTo(ZERO) > 0 ? convertNaturalNumberToWords(onesDigit) : StringUtils.EMPTY;/*from w w w .j av a2 s .c o m*/ result.append(strTensDigit).append(" ").append(strOnesDigit); } else if (naturalNumber.compareTo(ONE_THOUSAND) < 0) { final BigInteger hundredsDigit = naturalNumber.divide(ONE_HUNDRED); final BigInteger rest = naturalNumber.mod(ONE_HUNDRED); final String strHundredsDigit; if (hundredsDigit.equals(ZERO)) { strHundredsDigit = StringUtils.EMPTY; } else if (hundredsDigit.equals(ONE)) { strHundredsDigit = StringUtils.EMPTY; } else { strHundredsDigit = convertNaturalNumberToWords(hundredsDigit); } final String restStr = rest.compareTo(ZERO) > 0 ? convertNaturalNumberToWords(rest) : StringUtils.EMPTY; result.append(strHundredsDigit).append(" ").append(HUNDRED_NAME).append(" ").append(restStr); } else { int mostSignificantGroupBase = this.findMostSignificantGroupBase(naturalNumber); for (int i = mostSignificantGroupBase / 3; i > 0; i--) { int groupNumber = this.getNthGroupNumber(naturalNumber, i); //noinspection StatementWithEmptyBody if (groupNumber == 0) { // don't write 'sifir milyon' } else if (groupNumber == 1 && i == 1) { // don't write 'bir bin', but write 'bir milyon'(below) result.append(" ").append(THOUSAND_NAME); } else { final String strGroupNumber = this.convertNaturalNumberToWords(BigInteger.valueOf(groupNumber)); result.append(" ").append(strGroupNumber).append(" ").append(THOUSAND_POWER_NAMES.get(i)); } result = new StringBuilder(result.toString().trim()); } final BigInteger lastGroupNumber = naturalNumber.mod(ONE_THOUSAND); if (lastGroupNumber.compareTo(ZERO) > 0) result.append(" ").append(convertNaturalNumberToWords(lastGroupNumber)); } return result.toString().trim(); }
From source file:org.blackbananacoin.incubator.extsupernode.SuperNodeApiTester.java
public void mineBlock(Block b) { Stopwatch stopwatch = Stopwatch.createStarted(); BigInteger target = Difficulty.getTarget(b.getDifficultyTarget()); log.debug("[Mine] target=0x{}", target.toString(16)); int count = 0; for (Integer nonce : nonceTrySet) { b.setNonce(nonce);/*from w w w . j a v a2 s.com*/ b.computeHash(); BigInteger hashAsInteger = new Hash(b.getHash()).toBigInteger(); count++; if (hashAsInteger.compareTo(target) <= 0) { log.debug("[Mine End] count={}, nonce=0x{}", count, Integer.toHexString(nonce)); log.debug("[Mine End] hashInteger=0x{}", hashAsInteger.toString(16)); break; } } statsMs.addValue(stopwatch.elapsed(TimeUnit.MILLISECONDS)); statsCount.addValue(count); log.debug("Mine Block with time {} and hash {}", stopwatch, b.getHash()); }