Example usage for java.math BigInteger valueOf

List of usage examples for java.math BigInteger valueOf

Introduction

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

Prototype

private static BigInteger valueOf(int val[]) 

Source Link

Document

Returns a BigInteger with the given two's complement representation.

Usage

From source file:com.coupa.api.impl.DefaultRepository.java

public T findById(long id) {
    return client.get(getResourceUri(BigInteger.valueOf(id)), resourceClass);
}

From source file:com.google.nigori.common.DSATest.java

@Test
public void paramGValid() {
    assertTrue(NigoriConstants.DSA_G.compareTo(BigInteger.valueOf(2)) >= 0);
    assertTrue(NigoriConstants.DSA_G.modPow(NigoriConstants.DSA_Q, NigoriConstants.DSA_P)
            .compareTo(BigInteger.valueOf(1)) == 0);
}

From source file:automenta.climatenet.ImportKML.java

public static String getSerial(String layer, int serial) {
    return (Base64.getEncoder().encodeToString(
            BigInteger.valueOf(serial).add(BigInteger.valueOf(layer.hashCode()).shiftRight(32)).toByteArray()));
}

From source file:org.spring.cache.CachingWithGeodeIntegrationTest.java

@Test
public void aCacheMisses() {
    assertThat(mathService.factorial(BigInteger.valueOf(0)), is(equalTo(BigInteger.ONE)));
    assertThat(mathService.wasCacheMiss(), is(true));
    assertThat(mathService.factorial(BigInteger.valueOf(1)), is(equalTo(BigInteger.ONE)));
    assertThat(mathService.wasCacheMiss(), is(true));
    assertThat(mathService.factorial(BigInteger.valueOf(2)), is(equalTo(MathService.TWO)));
    assertThat(mathService.wasCacheMiss(), is(true));
    assertThat(mathService.factorial(BigInteger.valueOf(4)), is(equalTo(BigInteger.valueOf(24))));
    assertThat(mathService.wasCacheMiss(), is(true));
    assertThat(mathService.factorial(BigInteger.valueOf(8)), is(equalTo(BigInteger.valueOf(40320))));
    assertThat(mathService.wasCacheMiss(), is(true));
}

From source file:MainClass.java

public static X509Certificate[] buildChain() throws Exception {
    KeyPair pair = generateRSAKeyPair();
    PKCS10CertificationRequest request = generateRequest(pair);

    KeyPair rootPair = generateRSAKeyPair();
    X509Certificate rootCert = generateV1Certificate(rootPair);

    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

    certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    certGen.setIssuerDN(rootCert.getSubjectX500Principal());
    certGen.setNotBefore(new Date(System.currentTimeMillis()));
    certGen.setNotAfter(new Date(System.currentTimeMillis() + 10000));
    certGen.setSubjectDN(request.getCertificationRequestInfo().getSubject());
    certGen.setPublicKey(request.getPublicKey("BC"));
    certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");

    certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false,
            new AuthorityKeyIdentifierStructure(rootCert));

    certGen.addExtension(X509Extensions.SubjectKeyIdentifier,

            false, new SubjectKeyIdentifierStructure(request.getPublicKey("BC")));

    certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(false));

    certGen.addExtension(X509Extensions.KeyUsage, true,
            new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));

    certGen.addExtension(X509Extensions.ExtendedKeyUsage, true,
            new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth));

    ASN1Set attributes = request.getCertificationRequestInfo().getAttributes();

    for (int i = 0; i != attributes.size(); i++) {
        Attribute attr = Attribute.getInstance(attributes.getObjectAt(i));

        if (attr.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) {
            X509Extensions extensions = X509Extensions.getInstance(attr.getAttrValues().getObjectAt(0));

            Enumeration e = extensions.oids();
            while (e.hasMoreElements()) {
                DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
                X509Extension ext = extensions.getExtension(oid);

                certGen.addExtension(oid, ext.isCritical(), ext.getValue().getOctets());
            }//from w  w w  .j  a  va 2  s .c  o m
        }
    }
    X509Certificate issuedCert = certGen.generateX509Certificate(rootPair.getPrivate());

    return new X509Certificate[] { issuedCert, rootCert };
}

From source file:csv2docxconverter.DocumentGenerator.java

/**
* Generate DocX element from list of the rows containing account information
 * @param columnNames a list of columns for data parsing
 * @param contents list of data rows for parsing
 * @return an XWPFDocument representing a DocX file
*//*from  w w  w. ja  v  a 2s . c  om*/
public XWPFDocument generateDocx(String[] columnNames, List contents) {
    XWPFDocument document = new XWPFDocument();

    // create title
    XWPFParagraph title = document.createParagraph();
    title.setAlignment(ParagraphAlignment.CENTER);
    XWPFRun titleRun = title.createRun();
    titleRun.setText("G SUITE created accounts");
    titleRun.setFontSize(18);

    for (int k = 0; k < contents.size(); k++) {
        List tableContent = (List) contents.get(k);

        // create title
        title = document.createParagraph();
        title.setAlignment(ParagraphAlignment.CENTER);
        titleRun = title.createRun();
        titleRun.setText("Table " + (k + 1));
        titleRun.setFontSize(18);

        // create account table
        XWPFTable table = document.createTable();
        // set "justified" alignment
        table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(10000));

        //create header for table
        setHeader(table, columnNames);

        // if account list is empty
        if (tableContent == null || tableContent.size() == 0) {
            // add empty row to the table
            XWPFTableRow emptyRow = table.createRow();
        } else {
            String[] headerRow = null;
            // create rows in table
            for (int i = 0; i < tableContent.size(); i++) {
                if (i == 0) {
                    headerRow = (String[]) tableContent.get(i);
                    continue;
                }
                String[] csvRow = (String[]) tableContent.get(i);

                XWPFTableRow row = table.createRow();
                //create cells in a row
                for (int j = 0; j < columnNames.length; j++) {
                    int number = getColumnNumber(columnNames[j], headerRow);

                    XWPFTableCell cell = row.getCell(j);
                    if (cell != null) {
                        XWPFRun run = setBodyCell(cell);
                        if (number >= 0 && number < csvRow.length) {
                            run.setText(csvRow[number]);
                        }
                    }
                }
            }
        }
    }

    return document;
}

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 * @param number the number to convert//from w  ww.  java2s  .c  o m
 * @param targetClass the target class to convert to
 * @return the converted number
 * @throws IllegalArgumentException if the target class is not supported
 * (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte
 * @see java.lang.Short
 * @see java.lang.Integer
 * @see java.lang.Long
 * @see java.math.BigInteger
 * @see java.lang.Float
 * @see java.lang.Double
 * @see java.math.BigDecimal
 */
public static Number convertNumberToTargetClass(Number number, Class targetClass)
        throws IllegalArgumentException {

    if (targetClass.isInstance(number)) {
        return number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Byte(number.byteValue());
    } else if (targetClass.equals(Short.class)) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Short(number.shortValue());
    } else if (targetClass.equals(Integer.class)) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Integer(number.intValue());
    } else if (targetClass.equals(Long.class)) {
        return new Long(number.longValue());
    } else if (targetClass.equals(Float.class)) {
        return new Float(number.floatValue());
    } else if (targetClass.equals(Double.class)) {
        return new Double(number.doubleValue());
    } else if (targetClass.equals(BigInteger.class)) {
        return BigInteger.valueOf(number.longValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return new BigDecimal(number.toString());
    } else {
        throw new IllegalArgumentException("Could not convert number [" + number + "] of type ["
                + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]");
    }
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperBigInteger.java

/**
 * Builds a new {@link ColumnMapperBigDecimal} using the specified max number of digits.
 *
 * @param digits The max number of digits. If {@code null}, the {@link #DEFAULT_DIGITS} will be used.
 *//*from   w  w w. j  a v  a2 s  .co m*/
@JsonCreator
public ColumnMapperBigInteger(@JsonProperty("digits") Integer digits) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance }, new AbstractType[] {});

    if (digits != null && digits <= 0) {
        throw new IllegalArgumentException("Positive digits required");
    }

    this.digits = digits == null ? DEFAULT_DIGITS : digits;
    complement = BigInteger.valueOf(10).pow(this.digits).subtract(BigInteger.valueOf(1));
    BigInteger maxValue = complement.multiply(BigInteger.valueOf(2));
    hexDigits = encode(maxValue).length();
}

From source file:com.msopentech.odatajclient.engine.data.metadata.edm.v4.TypeDefinitionDeserializer.java

@Override
protected TypeDefinition doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final TypeDefinition typeDefinition = new TypeDefinition();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                typeDefinition.setName(jp.nextTextValue());
            } else if ("UnderlyingType".equals(jp.getCurrentName())) {
                typeDefinition.setUnderlyingType(jp.nextTextValue());
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                typeDefinition.setMaxLength(jp.nextTextValue());
            } else if ("Unicode".equals(jp.getCurrentName())) {
                typeDefinition.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Precision".equals(jp.getCurrentName())) {
                typeDefinition.setPrecision(BigInteger.valueOf(jp.nextLongValue(0L)));
            } else if ("Scale".equals(jp.getCurrentName())) {
                typeDefinition.setScale(BigInteger.valueOf(jp.nextLongValue(0L)));
            } else if ("SRID".equals(jp.getCurrentName())) {
                typeDefinition.setSrid(jp.nextTextValue());
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();//from   ww  w  .  j a  va2s  .c o m
                typeDefinition.getAnnotations().add(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return typeDefinition;
}

From source file:org.osmsurround.ae.osm.OsmConvertService.java

public OsmNode amenityToNode(Amenity amenity) {
    OsmNode node = of.createOsmNode();//  www .  j a v  a 2s.  c  o m
    node.setId(BigInteger.valueOf(amenity.getNodeId()));
    node.setLat((float) amenity.getLat());
    node.setLon((float) amenity.getLon());

    node.getTag().clear();
    setNodeTags(node, amenity.getKeyValues());

    return node;
}