List of usage examples for java.math BigInteger signum
int signum
To view the source code for java.math BigInteger signum.
Click Source Link
From source file:piuk.blockchain.android.ui.SendCoinsFragment.java
private void updateView() { String address = getToAddress(); if (receivingAddressView.getText().toString().trim().length() == 0 || address != null) { receivingAddressErrorView.setVisibility(View.GONE); } else {// w w w. ja va 2 s . c o m receivingAddressErrorView.setVisibility(View.VISIBLE); } final BigInteger amount = amountView.getAmount(); final boolean validAmount = amount != null && amount.signum() > 0; receivingAddressView.setEnabled(state == State.INPUT); amountView.setEnabled(state == State.INPUT); viewGo.setEnabled(state == State.INPUT && address != null && validAmount); if (state == State.INPUT) viewGo.setText(R.string.send_coins_fragment_button_send); else if (state == State.SENDING) viewGo.setText(R.string.send_coins_sending_msg); else if (state == State.SENT) viewGo.setText(R.string.send_coins_sent_msg); viewCancel.setEnabled(state != State.SENDING); viewCancel.setText(state != State.SENT ? R.string.button_cancel : R.string.send_coins_fragment_button_back); }
From source file:devcoin.wallet.ui.SendCoinsFragment.java
private void validateAmounts(final boolean popups) { isValidAmounts = false;/*from www . j a v a 2 s . c o m*/ final BigInteger amount = amountCalculatorLink.getAmount(); if (amount == null) { // empty amount if (popups) popupMessage(amountCalculatorLink.activeView(), getString(R.string.send_coins_fragment_amount_empty)); } else if (amount.signum() > 0) { final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); // TODO subscribe to wallet changes final BigInteger availableAfterAmount = available.subtract(amount); final boolean enoughFundsForAmount = availableAfterAmount.signum() >= 0; if (enoughFundsForAmount) { // everything fine isValidAmounts = true; } else { // not enough funds for amount if (popups) popupAvailable(amountCalculatorLink.activeView(), available, pending); } } else { // invalid amount if (popups) popupMessage(amountCalculatorLink.activeView(), getString(R.string.send_coins_fragment_amount_error)); } updateView(); }
From source file:de.schildbach.litecoinwallet.ui.SendCoinsFragment.java
private void validateAmounts(final boolean popups) { isValidAmounts = false;/*from w ww . j a va2 s .c om*/ final BigInteger amount = amountCalculatorLink.getAmount(); if (amount == null) { // empty amount if (popups) popupMessage(amountCalculatorLink.activeView(), getString(R.string.send_coins_fragment_amount_empty)); } else if (amount.signum() > 0) { final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED); final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE); final BigInteger pending = estimated.subtract(available); // TODO subscribe to litecoinwallet changes final BigInteger availableAfterAmount = available.subtract(amount); final boolean enoughFundsForAmount = availableAfterAmount.signum() >= 0; if (enoughFundsForAmount) { // everything fine isValidAmounts = true; } else { // not enough funds for amount if (popups) popupAvailable(amountCalculatorLink.activeView(), available, pending); } } else { // invalid amount if (popups) popupMessage(amountCalculatorLink.activeView(), getString(R.string.send_coins_fragment_amount_error)); } updateView(); }
From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java
private boolean isAmountValid() { final BigInteger amount = paymentIntent.mayEditAmount() ? amountCalculatorLink.getAmount() : paymentIntent.getAmount(); return amount != null && amount.signum() > 0; }
From source file:net.pms.util.Rational.java
/** * Used internally to generate a rational string representation from two * {@link BigInteger}s./*ww w . j a v a 2 s . c o m*/ * * @param numerator the numerator. * @param denominator the denominator. * @return The rational string representation. */ @Nonnull protected static String generateRationalString(@Nonnull BigInteger numerator, @Nonnull BigInteger denominator) { if (denominator.signum() == 0) { if (numerator.signum() == 0) { return "NaN"; } return numerator.signum() > 0 ? "\u221e" : "-\u221e"; } if (BigInteger.ONE.equals(denominator)) { return numerator.toString(); } return numerator.toString() + "/" + denominator.toString(); }
From source file:net.pms.util.Rational.java
/** * Used internally to generate a hexadecimal rational string representation * from two {@link BigInteger}s.//from w w w .ja va2s. co m * * @param numerator the numerator. * @param denominator the denominator. * @return The hexadecimal rational string representation. */ @Nonnull protected static String generateRationalHexString(@Nonnull BigInteger numerator, @Nonnull BigInteger denominator) { if (denominator.signum() == 0) { if (numerator.signum() == 0) { return "NaN"; } return numerator.signum() > 0 ? "\u221e" : "-\u221e"; } if (BigInteger.ONE.equals(denominator)) { return numerator.toString(16); } return numerator.toString(16) + "/" + denominator.toString(16); }
From source file:net.pms.util.Rational.java
/** * Used internally to generate a decimal string representation from two * {@link BigInteger}s. The decimal representation is limited to 20 * decimals.//from w w w. j a v a 2 s .com * * @param numerator the numerator. * @param denominator the denominator. * @param decimalFormat the {@link DecimalFormat} instance to use for * formatting. * @return The string representation. */ protected static String generateDecimalString(@Nonnull BigInteger numerator, @Nonnull BigInteger denominator, @Nonnull DecimalFormat decimalFormat) { if (denominator.signum() == 0) { if (numerator.signum() == 0) { return "NaN"; } return numerator.signum() > 0 ? "\u221e" : "-\u221e"; } if (BigInteger.ONE.equals(denominator)) { return numerator.toString(); } BigDecimal decimalValue = new BigDecimal(numerator).divide(new BigDecimal(denominator), 20, RoundingMode.HALF_EVEN); return decimalFormat.format(decimalValue); }
From source file:hashengineering.digitalcoin.wallet.ui.SendCoinsFragment.java
private void popupAvailable(@Nonnull final View anchor, @Nonnull final BigInteger available, @Nonnull final BigInteger pending) { dismissPopup();/*from w w w . j a va 2s. c o m*/ final CurrencyTextView viewAvailable = (CurrencyTextView) popupAvailableView .findViewById(R.id.send_coins_popup_available_amount); viewAvailable.setPrefix(Constants.CURRENCY_CODE_BITCOIN); viewAvailable.setAmount(available); final TextView viewPending = (TextView) popupAvailableView .findViewById(R.id.send_coins_popup_available_pending); viewPending.setVisibility(pending.signum() > 0 ? View.VISIBLE : View.GONE); viewPending.setText(getString(R.string.send_coins_fragment_pending, GenericUtils.formatValue(pending, Constants.BTC_MAX_PRECISION))); popup(anchor, popupAvailableView); }
From source file:net.pms.util.Rational.java
/** * Calculates the least common multiple for two {@link BigInteger}s using the formula * {@code u * v / gcd(u, v)} where {@code gcd} is the greatest common divisor for the two. * * @param u the first number./* w w w . j av a 2 s . c om*/ * @param v the second number. * @return The LCM, always 1 or greater. */ @Nullable public static BigInteger calculateLeastCommonMultiple(@Nullable BigInteger u, @Nullable BigInteger v) { if (u == null || v == null) { return null; } if (u.signum() == 0 && v.signum() == 0) { return BigInteger.ONE; } u = u.abs(); v = v.abs(); if (u.signum() == 0) { return v; } if (v.signum() == 0) { return u; } return u.divide(calculateGreatestCommonDivisor(u, v)).multiply(v); }
From source file:net.pms.util.Rational.java
/** * Returns an instance with the given {@code numerator} and * {@code denominator}.//from w ww. jav a2 s . c om * * @param numerator the numerator. * @param denominator the denominator. * @return An instance that represents the value of {@code numerator}/ * {@code denominator}. */ @Nullable public static Rational valueOf(@Nullable BigInteger numerator, @Nullable BigInteger denominator) { if (numerator == null || denominator == null) { return null; } if (numerator.signum() == 0 && denominator.signum() == 0) { return NaN; } if (denominator.signum() == 0) { return numerator.signum() > 0 ? POSITIVE_INFINITY : NEGATIVE_INFINITY; } if (numerator.signum() == 0) { return ZERO; } if (numerator.equals(denominator)) { return ONE; } if (denominator.signum() < 0) { numerator = numerator.negate(); denominator = denominator.negate(); } BigInteger reducedNumerator; BigInteger reducedDenominator; BigInteger greatestCommonDivisor = calculateGreatestCommonDivisor(numerator, denominator); if (BigInteger.ONE.equals(greatestCommonDivisor)) { reducedNumerator = numerator; reducedDenominator = denominator; } else { reducedNumerator = numerator.divide(greatestCommonDivisor); reducedDenominator = denominator.divide(greatestCommonDivisor); } return new Rational(numerator, denominator, greatestCommonDivisor, reducedNumerator, reducedDenominator); }