Java Code Examples for java.math.BigInteger

The following are top voted examples for showing how to use java.math.BigInteger. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: nuls   File: SM2.java   Source Code and License 7 votes vote down vote up
public void sm2Verify(byte md[], ECPoint userKey, BigInteger r, BigInteger s, SM2Result sm2Result) {
    sm2Result.R = null;
    BigInteger e = new BigInteger(1, md);
    BigInteger t = r.add(s).mod(ecc_n);
    if (t.equals(BigInteger.ZERO)) {
        return;
    } else {
        ECPoint x1y1 = ecc_point_g.multiply(sm2Result.s);
        System.out.println("X0: " + x1y1.getX().toBigInteger().toString(16));
        System.out.println("Y0: " + x1y1.getY().toBigInteger().toString(16));
        System.out.println("");

        x1y1 = x1y1.add(userKey.multiply(t));
        System.out.println("X1: " + x1y1.getX().toBigInteger().toString(16));
        System.out.println("Y1: " + x1y1.getY().toBigInteger().toString(16));
        System.out.println("");
        sm2Result.R = e.add(x1y1.getX().toBigInteger()).mod(ecc_n);
        System.out.println("R: " + sm2Result.R.toString(16));
        return;
    }
}
 
Example 2
Project: datatree-adapters   File: JsonBson.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
	if (clazz == BigDecimal.class) {
		return (Codec<T>) bigDecimalCodec;
	}
	if (clazz == BigInteger.class) {
		return (Codec<T>) bigIntegerCodec;
	}
	if (clazz == InetAddress.class || clazz == Inet4Address.class || clazz == Inet6Address.class) {
		return (Codec<T>) inetAddressCodec;
	}
	if (clazz.isArray()) {
		return (Codec<T>) arrayCodec;
	}
	return null;
}
 
Example 3
Project: Cryptocurrency-Java-Wrappers   File: Etherscan.java   Source Code and License 6 votes vote down vote up
/**
 * Experimental. Returns the value from a storage position at a given address
 * @param address Address
 * @param position Storage position
 * @return Value from storage position
 */
public String getStorageAt(String address, BigInteger position) {

	HttpGet get = new HttpGet(PUBLIC_URL + "?module=proxy&action=eth_getStorageAt&address=" + address + "&position=" + "0x" + position.toString(16) + "&tag=latest" + "&apikey=" + API_KEY);
	String response = null;

	try(CloseableHttpResponse httpResponse = httpClient.execute(get)) {
		HttpEntity httpEntity = httpResponse.getEntity();
		response = EntityUtils.toString(httpEntity);
		EntityUtils.consume(httpEntity);
	} catch (IOException e) {
		e.printStackTrace();
	}

	@SuppressWarnings("rawtypes")
	ArrayList<CustomNameValuePair<String, CustomNameValuePair>> a = Utility.evaluateExpression(response);

	for(int j = 0; j < a.size(); j++)
		if(a.get(j).getName().toString().equals("result"))
			return a.get(j).getValue().toString();

	return null;  // Null should not be expected when API is functional

}
 
Example 4
Project: BiglyBT   File: DSASigner.java   Source Code and License 5 votes vote down vote up
private BigInteger calculateE(BigInteger n, byte[] message)
{
    if (n.bitLength() >= message.length * 8)
    {
        return new BigInteger(1, message);
    }
    else
    {
        byte[] trunc = new byte[n.bitLength() / 8];

        System.arraycopy(message, 0, trunc, 0, trunc.length);

        return new BigInteger(1, trunc);
    }
}
 
Example 5
Project: openjdk-systemtest   File: TestSuite016.java   Source Code and License 5 votes vote down vote up
public void testItem_0798()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 0, new MathContext("precision=1 roundingMode=UNNECESSARY"));
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
 
Example 6
Project: AppCoins-ethereumj   File: ByzantiumConfig.java   Source Code and License 5 votes vote down vote up
public ByzantiumConfig(BlockchainConfig parent) {
    super(parent);
    constants = new ConstantsAdapter(super.getConstants()) {
        private final BigInteger BLOCK_REWARD = new BigInteger("3000000000000000000");

        @Override
        public BigInteger getBLOCK_REWARD() {
            return BLOCK_REWARD;
        }
    };
}
 
Example 7
Project: guava-mock   File: BigIntegerMathTest.java   Source Code and License 5 votes vote down vote up
@GwtIncompatible // TODO
@AndroidIncompatible // slow
public void testDivNonZeroExact() {
  boolean isAndroid = System.getProperties().getProperty("java.runtime.name").contains("Android");
  for (BigInteger p : NONZERO_BIGINTEGER_CANDIDATES) {
    for (BigInteger q : NONZERO_BIGINTEGER_CANDIDATES) {
      if (isAndroid && p.equals(BAD_FOR_ANDROID_P) && q.equals(BAD_FOR_ANDROID_Q)) {
        // https://code.google.com/p/android/issues/detail?id=196555
        continue;
      }
      if (isAndroid && p.equals(BAD_FOR_GINGERBREAD_P) && q.equals(BAD_FOR_GINGERBREAD_Q)) {
        // Works fine under Marshmallow, so I haven't filed a bug.
        continue;
      }

      boolean dividesEvenly = p.remainder(q).equals(ZERO);

      try {
        BigInteger quotient = BigIntegerMath.divide(p, q, UNNECESSARY);
        BigInteger undone = quotient.multiply(q);
        if (!p.equals(undone)) {
          failFormat("expected %s.multiply(%s) = %s; got %s", quotient, q, p, undone);
        }
        assertTrue(dividesEvenly);
      } catch (ArithmeticException e) {
        assertFalse(dividesEvenly);
      }
    }
  }
}
 
Example 8
Project: AppCoins-ethereumj   File: EthashAlgoSlow.java   Source Code and License 5 votes vote down vote up
/**
 * This the slower miner version which uses only cache thus taking much less memory than
 * regular {@link #mine} method
 */
public long mineLight(long fullSize, final byte[][] cache, byte[] blockHeaderTruncHash, long difficulty) {
    BigInteger target = valueOf(2).pow(256).divide(valueOf(difficulty));
    long nonce = new Random().nextLong();
    while(!Thread.currentThread().isInterrupted()) {
        nonce++;
        Pair<byte[], byte[]> pair = hashimotoLight(fullSize, cache, blockHeaderTruncHash, longToBytes(nonce));
        BigInteger h = new BigInteger(1, pair.getRight() /* ?? */);
        if (h.compareTo(target) < 0) break;
    }
    return nonce;
}
 
Example 9
Project: xitk   File: EmulatorP11Slot.java   Source Code and License 5 votes vote down vote up
@Override
protected P11Identity generateRSAKeypair0(int keysize, BigInteger publicExponent,
        String label, P11NewKeyControl control) throws P11TokenException {
    KeyPair keypair;
    try {
        keypair = KeyUtil.generateRSAKeypair(keysize, publicExponent, random);
    } catch (NoSuchAlgorithmException | NoSuchProviderException
            | InvalidAlgorithmParameterException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    }
    return saveP11Entity(keypair, label);
}
 
Example 10
Project: SoftUni   File: p05_PascalTriangle.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    /*
    Plot Pascal triangle of given size
     */
    // take the size of the triangle (max 100)
    int triangleSize = Integer.parseInt(input.nextLine());
    // Make jagged array for the triangle of type BigInteger
    BigInteger[][] pascTriangle = new BigInteger[triangleSize][];
    // Create the first element of the triangle
    pascTriangle[0] = new BigInteger[] {BigInteger.ONE};
    for (int row = 1; row < triangleSize; row++) {
        // create next row with length +1
        pascTriangle[row] = new BigInteger[row + 1];
        // for current row create first element = 1
        pascTriangle[row][0] = BigInteger.ONE;
        // find the middle of the row
        int middle = (pascTriangle[row].length - 1) /2;
        // loop to the end of the current row
        for (int col = 1; col < pascTriangle[row].length; col++) {
            // if the index is less or equal to the middle index
            if (col <= middle){
                // sum the above row members and save result at current possition
                pascTriangle[row][col] = (pascTriangle[row - 1][col - 1]).add(pascTriangle[row - 1][col]);
            } else {
                // else, copy forward previous members
                // "row - col" is in fact "(length - 1) - col" or "(last index) - current iteration"
                pascTriangle[row][col] = pascTriangle[row][row  - col];
            }
        }
    }
    // print the triangle
    for (int row = 0; row < pascTriangle.length; row++) {
        for (int col = 0; col < pascTriangle[row].length; col++) {
            System.out.print(pascTriangle[row][col] + " ");
        }
        System.out.println();
    }
}
 
Example 11
Project: GcmForMojo   File: DialogActivity.java   Source Code and License 5 votes vote down vote up
public static String getMD5(String val) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(val.getBytes("UTF-8"));
    byte[] magnitude = digest.digest();
    BigInteger bi = new BigInteger(1, magnitude);
    return String.format("%0" + (magnitude.length << 1) + "x", bi);
}
 
Example 12
Project: jackson-dataformat-velocypack   File: VPackSerializeDeserializeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void toBigNumbers() throws IOException {
	final VPackBuilder builder = new VPackBuilder();
	{
		builder.add(ValueType.OBJECT);
		builder.add("bi", BigInteger.valueOf(2));
		builder.add("bd", BigDecimal.valueOf(3.75));
		builder.close();
	}
	final VPackSlice vpack = builder.slice();
	final TestEntityBigNumber entity = mapper.readValue(vpack.getBuffer(), TestEntityBigNumber.class);
	assertThat(entity, is(notNullValue()));
	assertThat(entity.bi, is(BigInteger.valueOf(2)));
	assertThat(entity.bd, is(BigDecimal.valueOf(3.75)));
}
 
Example 13
Project: AppCoins-ethereumj   File: PrecompiledContracts.java   Source Code and License 5 votes vote down vote up
@Override
public Pair<Boolean, byte[]> execute(byte[] data) {

    if (data == null)
        return Pair.of(true, EMPTY_BYTE_ARRAY);

    int baseLen = parseLen(data, 0);
    int expLen  = parseLen(data, 1);
    int modLen  = parseLen(data, 2);

    BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
    BigInteger exp  = parseArg(data, addSafely(ARGS_OFFSET, baseLen), expLen);
    BigInteger mod  = parseArg(data, addSafely(addSafely(ARGS_OFFSET, baseLen), expLen), modLen);

    // check if modulus is zero
    if (isZero(mod))
        return Pair.of(true, EMPTY_BYTE_ARRAY);

    byte[] res = stripLeadingZeroes(base.modPow(exp, mod).toByteArray());

    // adjust result to the same length as the modulus has
    if (res.length < modLen) {

        byte[] adjRes = new byte[modLen];
        System.arraycopy(res, 0, adjRes, modLen - res.length, res.length);

        return Pair.of(true, adjRes);

    } else {
        return Pair.of(true, res);
    }
}
 
Example 14
Project: toshi-headless-client   File: RLP.java   Source Code and License 5 votes vote down vote up
public static BigInteger decodeBigInteger(byte[] data, int index) {

        final int length = calculateLength(data, index);
        byte[] valueBytes = new byte[length];
        System.arraycopy(data, index, valueBytes, 0, length);
        return new BigInteger(1, valueBytes);
    }
 
Example 15
Project: AppCoins-ethereumj   File: Utils.java   Source Code and License 5 votes vote down vote up
/**
 * @param number should be in form '0x34fabd34....'
 *
 * @return String
 */
public static BigInteger unifiedNumericToBigInteger(String number) {

  boolean match = Pattern.matches("0[xX][0-9a-fA-F]+", number);
  if (!match) {
    return (new BigInteger(number));
  } else {
    number = number.substring(2);
    number = number.length() % 2 != 0 ? "0".concat(number) : number;
    byte[] numberBytes = Hex.decode(number);
    return (new BigInteger(1, numberBytes));
  }
}
 
Example 16
Project: ipack   File: RSACoreEngine.java   Source Code and License 5 votes vote down vote up
public BigInteger convertInput(
    byte[]  in,
    int     inOff,
    int     inLen)
{
    if (inLen > (getInputBlockSize() + 1))
    {
        throw new DataLengthException("input too large for RSA cipher.");
    }
    else if (inLen == (getInputBlockSize() + 1) && !forEncryption)
    {
        throw new DataLengthException("input too large for RSA cipher.");
    }

    byte[]  block;

    if (inOff != 0 || inLen != in.length)
    {
        block = new byte[inLen];

        System.arraycopy(in, inOff, block, 0, inLen);
    }
    else
    {
        block = in;
    }

    BigInteger res = new BigInteger(1, block);
    if (res.compareTo(key.getModulus()) >= 0)
    {
        throw new DataLengthException("input too large for RSA cipher.");
    }

    return res;
}
 
Example 17
Project: neo-java   File: ECCurve.java   Source Code and License 5 votes vote down vote up
private ECCurve(final BigInteger Q, final BigInteger A, final BigInteger B, final BigInteger N, final byte[] G) {
	this.Q = Q;
	this.A = new ECFieldElement(A, this);
	this.B = new ECFieldElement(B, this);
	this.N = N;
	Infinity = new ECPoint(new byte[1], null, null, this);
	this.G = ECPoint.DecodePoint(G, this);
}
 
Example 18
Project: jdk8u-jdk   File: JsseJce.java   Source Code and License 5 votes vote down vote up
static int getRSAKeyLength(PublicKey key) {
    BigInteger modulus;
    if (key instanceof RSAPublicKey) {
        modulus = ((RSAPublicKey)key).getModulus();
    } else {
        RSAPublicKeySpec spec = getRSAPublicKeySpec(key);
        modulus = spec.getModulus();
    }
    return modulus.bitLength();
}
 
Example 19
Project: openNaEF   File: IpAddress.java   Source Code and License 5 votes vote down vote up
public static void checkCanonicalSubnetAddressRange(IpAddress lowerBound, IpAddress upperBound) {
    BigInteger size = getRangeSize(lowerBound, upperBound);
    boolean isPowersOfTwo = size.bitCount() == 1;
    if (! isPowersOfTwo) {
        throw new ValueException("サイズが2の冪になっていません.");
    }
    if (! lowerBound.toBigInteger().mod(size).equals(BigInteger.ZERO)) {
        throw new ValueException("始点アドレス(ネットワーク アドレス)がサイズの倍数になっていません.");
    }
}
 
Example 20
Project: AppCoins-ethereumj   File: TransactionInfo.java   Source Code and License 5 votes vote down vote up
public TransactionInfo(byte[] rlp) {
    RLPList params = RLP.decode2(rlp);
    RLPList txInfo = (RLPList) params.get(0);
    RLPList receiptRLP = (RLPList) txInfo.get(0);
    RLPItem blockHashRLP  = (RLPItem) txInfo.get(1);
    RLPItem indexRLP = (RLPItem) txInfo.get(2);

    receipt = new TransactionReceipt(receiptRLP.getRLPData());
    blockHash = blockHashRLP.getRLPData();
    if (indexRLP.getRLPData() == null)
        index = 0;
    else
        index = new BigInteger(1, indexRLP.getRLPData()).intValue();
}
 
Example 21
Project: AppCoins-ethereumj   File: DataWord.java   Source Code and License 5 votes vote down vote up
public void addmod(cm.aptoide.pt.ethereum.ethereumj.vm.DataWord word1,
    cm.aptoide.pt.ethereum.ethereumj.vm.DataWord word2) {
  if (word2.isZero()) {
    this.data = new byte[32];
    return;
  }

  BigInteger result = value().add(word1.value())
      .mod(word2.value());
  this.data = ByteUtil.copyToArray(result.and(MAX_VALUE));
}
 
Example 22
Project: Nird2   File: Sec1KeyParser.java   Source Code and License 5 votes vote down vote up
@Override
public PrivateKey parsePrivateKey(byte[] encodedKey)
		throws GeneralSecurityException {
	long now = System.currentTimeMillis();
	if (encodedKey.length != privateKeyBytes)
		throw new GeneralSecurityException();
	BigInteger d = new BigInteger(1, encodedKey); // Positive signum
	// Verify that the private value is < n
	if (d.compareTo(params.getN()) >= 0)
		throw new GeneralSecurityException();
	// Construct a private key from the private value and the params
	ECPrivateKeyParameters k = new ECPrivateKeyParameters(d, params);
	PrivateKey p = new Sec1PrivateKey(k, keyBits);
	long duration = System.currentTimeMillis() - now;
	if (LOG.isLoggable(INFO))
		LOG.info("Parsing private key took " + duration + " ms");
	return p;
}
 
Example 23
Project: apfloat   File: AprationalTest.java   Source Code and License 5 votes vote down vote up
public static void testBigIntegerConstructor()
{
    Aprational a = new Aprational(BigInteger.valueOf(5));
    assertEquals("5 radix", 10, a.radix());
    assertEquals("5 String", "5", a.toString());
    a = new Aprational(BigInteger.valueOf(11), 12);
    assertEquals("11 radix", 12, a.radix());
    assertEquals("11 String", "b", a.toString());
}
 
Example 24
Project: zxbangban   File: MD5Util.java   Source Code and License 5 votes vote down vote up
public static String EncryptedByMD5(String arg) {
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(arg.getBytes());
        return new BigInteger(1,md5.digest()).toString(16);
    }catch (Exception e){
        e.printStackTrace();
        throw new IllegalArgumentException("MD5加密失败!");
    }
}
 
Example 25
Project: dble   File: ItemFuncWeekday.java   Source Code and License 5 votes vote down vote up
@Override
public BigInteger valInt() {
    MySQLTime ltime = new MySQLTime();

    if (getArg0Date(ltime, MyTime.TIME_NO_ZERO_DATE))
        return BigInteger.ZERO;

    return BigInteger.valueOf(MyTime.calcWeekday(MyTime.calcDaynr(ltime.getYear(), ltime.getMonth(), ltime.getDay()), false));
}
 
Example 26
Project: chvote-protocol-poc   File: SecretVoterData.java   Source Code and License 5 votes vote down vote up
public SecretVoterData(BigInteger x, BigInteger y, byte[] f, byte[][] rc) {
    this.x = x;
    this.y = y;
    this.f = Arrays.copyOf(f, f.length);
    this.rc = new byte[rc.length][];
    for (int i = 0; i < rc.length; i++) {
        this.rc[i] = Arrays.copyOf(rc[i], rc[i].length);
    }
}
 
Example 27
Project: allure-java   File: AllureTestNg.java   Source Code and License 5 votes vote down vote up
protected String getHistoryId(final ITestNGMethod method, final List<Parameter> parameters) {
    final MessageDigest digest = getMessageDigest();
    final String testClassName = method.getTestClass().getName();
    final String methodName = method.getMethodName();
    digest.update(testClassName.getBytes(UTF_8));
    digest.update(methodName.getBytes(UTF_8));
    parameters.stream()
            .sorted(comparing(Parameter::getName).thenComparing(Parameter::getValue))
            .forEachOrdered(parameter -> {
                digest.update(parameter.getName().getBytes(UTF_8));
                digest.update(parameter.getValue().getBytes(UTF_8));
            });
    final byte[] bytes = digest.digest();
    return new BigInteger(1, bytes).toString(16);
}
 
Example 28
Project: rskj   File: MinimumGasPriceCalculatorTest.java   Source Code and License 5 votes vote down vote up
@Test
public void mgpOnRage() {
    MinimumGasPriceCalculator mgpCalculator = new MinimumGasPriceCalculator();

    BigInteger prev = BigInteger.valueOf(1000L);
    BigInteger target = BigInteger.valueOf(995L);

    BigInteger mgp = mgpCalculator.calculate(prev, target);

    Assert.assertTrue(target.compareTo(mgp) == 0);
}
 
Example 29
Project: ipack   File: DSAPublicKeyParameters.java   Source Code and License 5 votes vote down vote up
public DSAPublicKeyParameters(
    BigInteger      y,
    DSAParameters   params)
{
    super(false, params);

    this.y = y;
}
 
Example 30
Project: quilt   File: LiquidityPointTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testEqualsHashCode() throws Exception {
  final LiquidityPoint liquidityPoint1 =
      LiquidityPoint.builder()
          .inputAmount(BigInteger.ZERO)
          .outputAmount(BigInteger.ONE)
          .build();

  final LiquidityPoint liquidityPoint2 =
      LiquidityPoint.builder()
          .inputAmount(BigInteger.ZERO)
          .outputAmount(BigInteger.ONE)
          .build();

  assertTrue(liquidityPoint1.equals(liquidityPoint2));
  assertTrue(liquidityPoint2.equals(liquidityPoint1));
  assertTrue(liquidityPoint1.hashCode() == liquidityPoint2.hashCode());

  {
    final LiquidityPoint liquidityPoint3 =
        LiquidityPoint.builder()
            .inputAmount(BigInteger.TEN)
            .outputAmount(BigInteger.TEN)
            .build();

    assertFalse(liquidityPoint1.equals(liquidityPoint3));
    assertFalse(liquidityPoint3.equals(liquidityPoint1));
    assertFalse(liquidityPoint1.hashCode() == liquidityPoint3.hashCode());
  }

}
 
Example 31
Project: openjdk-systemtest   File: TestSuite027.java   Source Code and License 4 votes vote down vote up
public void testItem_0113()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), new MathContext("precision=2147483647 roundingMode=HALF_UP"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 32
Project: openjdk-jdk10   File: Decode.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    check(new String(""+Long.MIN_VALUE), Long.MIN_VALUE);
    check(new String(""+Long.MAX_VALUE), Long.MAX_VALUE);

    check("10",   10L);
    check("0x10", 16L);
    check("0X10", 16L);
    check("010",  8L);
    check("#10",  16L);

    check("+10",   10L);
    check("+0x10", 16L);
    check("+0X10", 16L);
    check("+010",  8L);
    check("+#10",  16L);

    check("-10",   -10L);
    check("-0x10", -16L);
    check("-0X10", -16L);
    check("-010",  -8L);
    check("-#10",  -16L);

    check(Long.toString(Long.MIN_VALUE), Long.MIN_VALUE);
    check(Long.toString(Long.MAX_VALUE), Long.MAX_VALUE);

    checkFailure("0x-10",   "Long.decode allows negative sign in wrong position.");
    checkFailure("0x+10",   "Long.decode allows positive sign in wrong position.");

    checkFailure("+",       "Raw plus sign allowed.");
    checkFailure("-",       "Raw minus sign allowed.");

    checkFailure(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE).toString(),
                 "Out of range");
    checkFailure(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE).toString(),
                 "Out of range");

    checkFailure("", "Empty String");

    try {
        Long.decode(null);
        throw new RuntimeException("Long.decode(null) expected to throw NPE");
    } catch (NullPointerException npe) {/* Okay */}
}
 
Example 33
Project: openjdk-systemtest   File: TestSuite052.java   Source Code and License 4 votes vote down vote up
public void testItem_0225()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 34
Project: dble   File: FieldReal.java   Source Code and License 4 votes vote down vote up
@Override
public BigInteger valInt() {
    return isNull() ? BigInteger.ZERO : valReal().toBigInteger();
}
 
Example 35
Project: spring-boot-vue-simple-sample   File: NonZeroInt.java   Source Code and License 4 votes vote down vote up
public BigInteger getValue() {
    return value;
}
 
Example 36
Project: gwt-jackson-apt   File: DeserializerInstanceBuilderTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testArrayMapTypeField() throws Exception {
    addFieldTest("abstractMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            AbstractMapJsonDeserializer.class, StringKeyDeserializer.class, ArrayJsonDeserializer.class, StringJsonDeserializer.class,
            ArrayCreator.class, String.class, String.class), result));

    addFieldTest("enumMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.class), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            EnumMapJsonDeserializer.class, EnumKeyDeserializer.class, AnEnum.class, ArrayJsonDeserializer.class, IntegerJsonDeserializer.class,
            ArrayCreator.class, Integer.class, Integer.class), result));

    addFieldTest("hashMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            HashMapJsonDeserializer.class, BaseNumberKeyDeserializer.IntegerKeyDeserializer.class, ArrayJsonDeserializer.class, DoubleJsonDeserializer.class,
            ArrayCreator.class, Double.class, Double.class), result));

    addFieldTest("identityHashMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            IdentityHashMapJsonDeserializer.class, BaseNumberKeyDeserializer.LongKeyDeserializer.class, ArrayJsonDeserializer.class, DateJsonDeserializer.class,
            ArrayCreator.class, Date.class, Date.class), result));

    addFieldTest("linkedHashMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.newInstance($T.class), ($T<$T>) $T[]::new))",
            LinkedHashMapJsonDeserializer.class, BaseNumberKeyDeserializer.DoubleKeyDeserializer.class, ArrayJsonDeserializer.class, EnumJsonDeserializer.class, AnEnum.class,
            ArrayCreator.class, AnEnum.class, AnEnum.class), result));

    addFieldTest("mapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            MapJsonDeserializer.class, BaseNumberKeyDeserializer.ShortKeyDeserializer.class, ArrayJsonDeserializer.class, SqlTimeJsonDeserializer.class,
            ArrayCreator.class, Time.class, Time.class), result));

    addFieldTest("sortedMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            SortedMapJsonDeserializer.class, StringKeyDeserializer.class, ArrayJsonDeserializer.class, ShortJsonDeserializer.class,
            ArrayCreator.class, Short.class, Short.class), result));

    addFieldTest("treeMapArray", result -> assertEquals(buildTestString(
            "$T.newInstance($T.getInstance(), $T.newInstance($T.getInstance(), ($T<$T>) $T[]::new))",
            TreeMapJsonDeserializer.class, StringKeyDeserializer.class, ArrayJsonDeserializer.class, BigIntegerJsonDeserializer.class,
            ArrayCreator.class, BigInteger.class, BigInteger.class), result));

    runTests();
}
 
Example 37
Project: openjdk-systemtest   File: TestSuite055.java   Source Code and License 4 votes vote down vote up
public void testItem_0622()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 38
Project: rskj   File: Transaction.java   Source Code and License 4 votes vote down vote up
public BigInteger getGasPriceAsInteger() {
    return (this.getGasPrice() == null) ? null : BigIntegers.fromUnsignedByteArray(this.getGasPrice());
}
 
Example 39
Project: talchain   File: TransactionExecutionSummary.java   Source Code and License 4 votes vote down vote up
public BigInteger getGasLimit() {
    if (!parsed) rlpParse();
    return gasLimit;
}
 
Example 40
Project: openjdk-systemtest   File: TestSuite023.java   Source Code and License 4 votes vote down vote up
public void testItem_0505()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 41
Project: dble   File: ItemFuncSecond.java   Source Code and License 4 votes vote down vote up
@Override
public BigInteger valInt() {
    MySQLTime ltime = new MySQLTime();
    return getArg0Time(ltime) ? BigInteger.ZERO : BigInteger.valueOf(ltime.getSecond());
}
 
Example 42
Project: openjdk-systemtest   File: TestSuite008.java   Source Code and License 4 votes vote down vote up
public void testItem_0604()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 0, new MathContext("precision=2147483647 roundingMode=DOWN"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 43
Project: bitcoin-bruteforce   File: Calc.java   Source Code and License 4 votes vote down vote up
public static String getAddressFromPrivateKey(BigInteger privateKey) {
    return getAddressFromPrivateKey(Base58.encode(privateKey.toByteArray()));
}
 
Example 44
Project: paillier   File: PaillierAlgorithm.java   Source Code and License 4 votes vote down vote up
protected BigInteger getG() {
	return G;
}
 
Example 45
Project: openjdk-systemtest   File: TestSuite006.java   Source Code and License 4 votes vote down vote up
public void testItem_0809()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), -2147483648, new MathContext("precision=2147483647 roundingMode=HALF_UP"));
  Assert.assertEquals("3.2E+2147483649", rc_BigDecimal.toString());
}
 
Example 46
Project: chvote-protocol-poc   File: ShuffleProof.java   Source Code and License 4 votes vote down vote up
public List<BigInteger> getT_4() {
    return ImmutableList.copyOf(t_4);
}
 
Example 47
Project: gwt-jackson-apt   File: DeserializerInstanceBuilderTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testCollectionArrayTypeField() throws Exception {
    addFieldTest("arrayAbstractCollection", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, AbstractCollectionJsonDeserializer.class, StringJsonDeserializer.class,
            ArrayCreator.class, AbstractCollection.class, String.class, AbstractCollection.class), result));

    addFieldTest("arrayAbstractList", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, AbstractListJsonDeserializer.class, IntegerJsonDeserializer.class,
            ArrayCreator.class, AbstractList.class, Integer.class, AbstractList.class), result));

    addFieldTest("arrayAbstractSequentialList", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, AbstractSequentialListJsonDeserializer.class, DoubleJsonDeserializer.class,
            ArrayCreator.class, AbstractSequentialList.class, Double.class, AbstractSequentialList.class), result));

    addFieldTest("arrayAbstractSet", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.newInstance($T.class)), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, AbstractSetJsonDeserializer.class, EnumJsonDeserializer.class, AnEnum.class,
            ArrayCreator.class, AbstractSet.class, AnEnum.class, AbstractSet.class), result));

    addFieldTest("arrayArrayList", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, ArrayListJsonDeserializer.class, DateJsonDeserializer.class,
            ArrayCreator.class, ArrayList.class, Date.class, ArrayList.class), result));

    addFieldTest("arrayCollection", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, CollectionJsonDeserializer.class, FloatJsonDeserializer.class,
            ArrayCreator.class, Collection.class, Float.class, Collection.class), result));

    addFieldTest("arrayHashSet", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, HashSetJsonDeserializer.class, VoidJsonDeserializer.class,
            ArrayCreator.class, HashSet.class, Void.class, HashSet.class), result));

    addFieldTest("arrayIterable", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, IterableJsonDeserializer.class, ShortJsonDeserializer.class,
            ArrayCreator.class, Iterable.class, Short.class, Iterable.class), result));

    addFieldTest("arrayLinkedList", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, LinkedListJsonDeserializer.class, SqlDateJsonDeserializer.class,
            ArrayCreator.class, LinkedList.class, java.sql.Date.class, LinkedList.class), result));

    addFieldTest("longArrayList", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, ListJsonDeserializer.class, LongJsonDeserializer.class,
            ArrayCreator.class, List.class, Long.class, List.class), result));

    addFieldTest("arrayQueue", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, QueueJsonDeserializer.class, BooleanJsonDeserializer.class,
            ArrayCreator.class, Queue.class, Boolean.class, Queue.class), result));

    addFieldTest("arrayStack", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, StackJsonDeserializer.class, CharacterJsonDeserializer.class,
            ArrayCreator.class, Stack.class, Character.class, Stack.class), result));

    addFieldTest("arrayTreeSet", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, TreeSetJsonDeserializer.class, BigIntegerJsonDeserializer.class,
            ArrayCreator.class, TreeSet.class, BigInteger.class, TreeSet.class), result));

    addFieldTest("arrayVector", result -> assertEquals(buildTestString(
            "$T.newInstance($T.newInstance($T.getInstance()), ($T<$T<$T>>) $T[]::new)",
            ArrayJsonDeserializer.class, VectorJsonDeserializer.class, SqlTimeJsonDeserializer.class,
            ArrayCreator.class, Vector.class, Time.class, Vector.class), result));

    runTests();
}
 
Example 48
Project: openjdk-systemtest   File: TestSuite013.java   Source Code and License 4 votes vote down vote up
public void testItem_0359()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), new MathContext("precision=1 roundingMode=HALF_UP"));
  Assert.assertEquals("3E+1", rc_BigDecimal.toString());
}
 
Example 49
Project: openjdk-systemtest   File: TestSuite029.java   Source Code and License 4 votes vote down vote up
public void testItem_0374()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), -2147483648);
  Assert.assertEquals("3.2E+2147483649", rc_BigDecimal.toString());
}
 
Example 50
Project: rskj   File: SiblingPaymentCalculator.java   Source Code and License 4 votes vote down vote up
public BigInteger getPublishersSurplus() {
    return publishersSurplus;
}
 
Example 51
Project: boohee_v5.6   File: Draft_10.java   Source Code and License 4 votes vote down vote up
public Framedata translateSingleFrame(ByteBuffer buffer) throws IncompleteException, InvalidDataException {
    int maxpacketsize = buffer.remaining();
    int realpacketsize = 2;
    if (maxpacketsize < 2) {
        throw new IncompleteException(2);
    }
    byte b1 = buffer.get();
    boolean FIN = (b1 >> 8) != 0;
    byte rsv = (byte) ((b1 & 127) >> 4);
    if (rsv != (byte) 0) {
        throw new InvalidFrameException("bad rsv " + rsv);
    }
    byte b2 = buffer.get();
    boolean MASK = (b2 & -128) != 0;
    int payloadlength = (byte) (b2 & 127);
    Opcode optcode = toOpcode((byte) (b1 & 15));
    if (FIN || !(optcode == Opcode.PING || optcode == Opcode.PONG || optcode == Opcode.CLOSING)) {
        int i;
        if (payloadlength < (byte) 0 || payloadlength > (byte) 125) {
            if (optcode == Opcode.PING || optcode == Opcode.PONG || optcode == Opcode.CLOSING) {
                throw new InvalidFrameException("more than 125 octets");
            } else if (payloadlength == 126) {
                realpacketsize = 2 + 2;
                if (maxpacketsize < realpacketsize) {
                    throw new IncompleteException(realpacketsize);
                }
                byte[] sizebytes = new byte[3];
                sizebytes[1] = buffer.get();
                sizebytes[2] = buffer.get();
                payloadlength = new BigInteger(sizebytes).intValue();
            } else {
                realpacketsize = 2 + 8;
                if (maxpacketsize < realpacketsize) {
                    throw new IncompleteException(realpacketsize);
                }
                byte[] bytes = new byte[8];
                for (i = 0; i < 8; i++) {
                    bytes[i] = buffer.get();
                }
                long length = new BigInteger(bytes).longValue();
                if (length > 2147483647L) {
                    throw new LimitExedeedException("Payloadsize is to big...");
                }
                payloadlength = (int) length;
            }
        }
        realpacketsize = (realpacketsize + (MASK ? 4 : 0)) + payloadlength;
        if (maxpacketsize < realpacketsize) {
            throw new IncompleteException(realpacketsize);
        }
        FrameBuilder frame;
        ByteBuffer payload = ByteBuffer.allocate(checkAlloc(payloadlength));
        if (MASK) {
            byte[] maskskey = new byte[4];
            buffer.get(maskskey);
            for (i = 0; i < payloadlength; i++) {
                payload.put((byte) (buffer.get() ^ maskskey[i % 4]));
            }
        } else {
            payload.put(buffer.array(), buffer.position(), payload.limit());
            buffer.position(buffer.position() + payload.limit());
        }
        if (optcode == Opcode.CLOSING) {
            frame = new CloseFrameBuilder();
        } else {
            frame = new FramedataImpl1();
            frame.setFin(FIN);
            frame.setOptcode(optcode);
        }
        payload.flip();
        frame.setPayload(payload);
        return frame;
    }
    throw new InvalidFrameException("control frames may no be fragmented");
}
 
Example 52
Project: openjdk-systemtest   File: TestSuite010.java   Source Code and License 4 votes vote down vote up
public void testItem_0351()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 2147483647, new MathContext("precision=1 roundingMode=HALF_UP"));
  Assert.assertEquals("3E-2147483646", rc_BigDecimal.toString());
}
 
Example 53
Project: openjdk-jdk10   File: DOMKeyValue.java   Source Code and License 4 votes vote down vote up
private static BigInteger bigInt(String s) {
    return new BigInteger(s, 16);
}
 
Example 54
Project: openjdk-systemtest   File: TestSuite034.java   Source Code and License 4 votes vote down vote up
public void testItem_0667()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), new MathContext("precision=1 roundingMode=FLOOR"));
  Assert.assertEquals("3E+1", rc_BigDecimal.toString());
}
 
Example 55
Project: openjdk-systemtest   File: TestSuite043.java   Source Code and License 4 votes vote down vote up
public void testItem_0817()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 0);
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 56
Project: openjdk-systemtest   File: TestSuite059.java   Source Code and License 4 votes vote down vote up
public void testItem_0996()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 2147483647);
  Assert.assertEquals("3.2E-2147483646", rc_BigDecimal.toString());
}
 
Example 57
Project: quorum   File: HumanStandardToken.java   Source Code and License 4 votes vote down vote up
public RemoteCall<BigInteger> balanceOf(String _owner) {
    Function function = new Function("balanceOf",
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_owner)),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
 
Example 58
Project: openjdk-systemtest   File: TestSuite004.java   Source Code and License 4 votes vote down vote up
public void testItem_0936()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 2147483647);
  Assert.assertEquals("3.2E-2147483646", rc_BigDecimal.toString());
}
 
Example 59
Project: openjdk-systemtest   File: TestSuite059.java   Source Code and License 4 votes vote down vote up
public void testItem_0974()
{
  rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"));
  Assert.assertEquals("32", rc_BigDecimal.toString());
}
 
Example 60
Project: ipack   File: ECCurve.java   Source Code and License 4 votes vote down vote up
public ECPoint createPoint(BigInteger x, BigInteger y, boolean withCompression)
{
    return new ECPoint.F2m(this, fromBigInteger(x), fromBigInteger(y), withCompression);
}