List of usage examples for java.math BigInteger valueOf
private static BigInteger valueOf(int val[])
From source file:it.gualtierotesta.gdocx.GTc.java
/** * Set table cell grid span//from ww w .j a va 2s . c o m * * @param lSpan grid span value * @return the same GTc instance */ @Nonnull public GTc gridspan(final long lSpan) { Validate.isTrue(0L < lSpan, "Grid span value not valid"); final TcPrInner.GridSpan gridSpan = FACTORY.createTcPrInnerGridSpan(); gridSpan.setVal(BigInteger.valueOf(lSpan)); tcPr.setGridSpan(gridSpan); return this; }
From source file:PalidromeArray.java
public PalidromeArray(BigInteger[] array) { this.totalLength = BigInteger.valueOf(array.length); this.halfLength = totalLength.divide(TWO); if (MathUtil.isOdd(totalLength)) { isEven = false;//from w ww . j av a2s .c o m halfLength = halfLength.add(BigInteger.ONE); } this.array = new ConcurrentHashMap<BigInteger, BigInteger>(); BigInteger index = BigInteger.ZERO; for (BigInteger bi : array) { this.array.put(index, bi); index = index.add(BigInteger.ONE); } }
From source file:org.gridobservatory.greencomputing.dao.MachineDao.java
@Override public Machine findById(BigInteger id) { return this.getJdbcTemplate().queryForObject( "select machine_id, room_id, motherboard_id, middleware_id, date_created, date_retired from machine where machine_id = ?", new Object[] { id }, new RowMapper<Machine>() { @Override/*from www . j ava2 s. c o m*/ public Machine mapRow(ResultSet rs, int rowNum) throws SQLException { int i = 1; Machine machine = new Machine(); machine.setMachineID(rs.getBigDecimal(i++).toBigIntegerExact()); machine.setRoom(new Room()); machine.getRoom().setRoomID(rs.getBigDecimal(i++).toBigIntegerExact()); machine.setMotherboard(new Motherboard()); machine.getMotherboard().setMotherboardID(rs.getBigDecimal(i++).toBigIntegerExact()); machine.setMiddleware(new Middleware()); machine.getMiddleware().setMiddlewareID(rs.getBigDecimal(i++).toBigIntegerExact()); machine.setDateCreated(BigInteger.valueOf(rs.getTimestamp(i++).getTime())); return machine; } }); }
From source file:org.btc4j.ws.impl.BtcDaemonServicePortImpl.java
private BtcWsException btcWsException(Throwable t) { LOG.severe(String.valueOf(t)); BtcFault fault = new BtcFault(); if (t instanceof BtcException) { BtcException e = (BtcException) t; fault.setCode(BigInteger.valueOf(e.getCode())); fault.setMessage(e.getMessage()); } else {//from w w w . ja v a 2 s.c o m fault.setCode(BigInteger.valueOf(BTC4JWS_ERROR_CODE)); fault.setMessage(BTC4JWS_ERROR_MESSAGE + ": " + t.getMessage()); } return new BtcWsException(t.getMessage(), fault, t); }
From source file:com.kixeye.chassis.transport.shared.JettyConnectorRegistry.java
/** * Register to listen to HTTPS./* ww w. j a v a 2 s .c o m*/ * * @param server * @param address * @throws Exception */ public static void registerHttpsConnector(Server server, InetSocketAddress address, boolean selfSigned, boolean mutualSsl, String keyStorePath, String keyStoreData, String keyStorePassword, String keyManagerPassword, String trustStorePath, String trustStoreData, String trustStorePassword, String[] excludedCipherSuites) throws Exception { // SSL Context Factory SslContextFactory sslContextFactory = new SslContextFactory(); if (selfSigned) { char[] passwordChars = UUID.randomUUID().toString().toCharArray(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, passwordChars); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(1024); KeyPair keyPair = keyPairGenerator.generateKeyPair(); X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator(); v3CertGen.setSerialNumber(BigInteger.valueOf(new SecureRandom().nextInt()).abs()); v3CertGen.setIssuerDN(new X509Principal("CN=" + "kixeye.com" + ", OU=None, O=None L=None, C=None")); v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30)); v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365 * 10))); v3CertGen.setSubjectDN(new X509Principal("CN=" + "kixeye.com" + ", OU=None, O=None L=None, C=None")); v3CertGen.setPublicKey(keyPair.getPublic()); v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption"); X509Certificate privateKeyCertificate = v3CertGen.generateX509Certificate(keyPair.getPrivate()); keyStore.setKeyEntry("selfSigned", keyPair.getPrivate(), passwordChars, new java.security.cert.Certificate[] { privateKeyCertificate }); ByteArrayOutputStream keyStoreBaos = new ByteArrayOutputStream(); keyStore.store(keyStoreBaos, passwordChars); keyStoreData = new String(Hex.encode(keyStoreBaos.toByteArray()), Charsets.UTF_8); keyStorePassword = new String(passwordChars); keyManagerPassword = keyStorePassword; sslContextFactory.setTrustAll(true); } KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); if (StringUtils.isNotBlank(keyStoreData)) { keyStore.load(new ByteArrayInputStream(Hex.decode(keyStoreData)), keyStorePassword.toCharArray()); } else if (StringUtils.isNotBlank(keyStorePath)) { try (InputStream inputStream = new DefaultResourceLoader().getResource(keyStorePath).getInputStream()) { keyStore.load(inputStream, keyStorePassword.toCharArray()); } } sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyStorePassword(keyStorePassword); if (StringUtils.isBlank(keyManagerPassword)) { keyManagerPassword = keyStorePassword; } sslContextFactory.setKeyManagerPassword(keyManagerPassword); KeyStore trustStore = null; if (StringUtils.isNotBlank(trustStoreData)) { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(new ByteArrayInputStream(Hex.decode(trustStoreData)), trustStorePassword.toCharArray()); } else if (StringUtils.isNotBlank(trustStorePath)) { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); try (InputStream inputStream = new DefaultResourceLoader().getResource(trustStorePath) .getInputStream()) { trustStore.load(inputStream, trustStorePassword.toCharArray()); } } if (trustStore != null) { sslContextFactory.setTrustStore(trustStore); sslContextFactory.setTrustStorePassword(trustStorePassword); } sslContextFactory.setNeedClientAuth(mutualSsl); sslContextFactory.setExcludeCipherSuites(excludedCipherSuites); // SSL Connector ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory()); connector.setHost(address.getHostName()); connector.setPort(address.getPort()); server.addConnector(connector); }
From source file:com.spotify.hdfs2cass.cassandra.utils.CassandraPartitioner.java
@Override public int getPartition(AvroKey<ByteBuffer> key, AvroValue<Mutation> value, int numReducers) { if (distributeRandomly) { return reducers.get(random.nextInt(reducers.size())); }/*from w w w .ja va2s .c om*/ final Token token = partitioner.getToken(key.datum()); BigInteger bigIntToken; if (token instanceof BigIntegerToken) { bigIntToken = ((BigIntegerToken) token).token.abs(); } else if (token instanceof LongToken) { bigIntToken = BigInteger.valueOf(((LongToken) token).token).add(MURMUR3_SCALE); } else { throw new RuntimeException( "Invalid partitioner Token type. Only BigIntegerToken and LongToken supported"); } return reducers.get(bigIntToken.divide(rangePerReducer).intValue()); }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.v4.TermDeserializer.java
@Override protected Term doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final Term term = new Term(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { term.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { term.setType(jp.nextTextValue()); } else if ("BaseTerm".equals(jp.getCurrentName())) { term.setBaseTerm(jp.nextTextValue()); } else if ("DefaultValue".equals(jp.getCurrentName())) { term.setDefaultValue(jp.nextTextValue()); } else if ("Nullable".equals(jp.getCurrentName())) { term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("MaxLength".equals(jp.getCurrentName())) { term.setMaxLength(jp.nextTextValue()); } else if ("Precision".equals(jp.getCurrentName())) { term.setPrecision(BigInteger.valueOf(jp.nextLongValue(0L))); } else if ("Scale".equals(jp.getCurrentName())) { term.setScale(BigInteger.valueOf(jp.nextLongValue(0L))); } else if ("SRID".equals(jp.getCurrentName())) { term.setSrid(jp.nextTextValue()); } else if ("AppliesTo".equals(jp.getCurrentName())) { for (String split : StringUtils.split(jp.nextTextValue())) { term.getAppliesTo().add(CSDLElement.valueOf(split)); }/*from ww w. j a v a 2 s . c o m*/ } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); term.setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return term; }
From source file:co.rsk.remasc.RemascStorageProviderTest.java
@Test public void setSaveRetrieveAndGetRewardBalance() throws IOException { String accountAddress = randomAddress(); Repository repository = new RepositoryImplForTesting(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); provider.setRewardBalance(BigInteger.valueOf(255)); provider.save();/*w w w. j a v a 2 s . c om*/ RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress); Assert.assertEquals(BigInteger.valueOf(255), newProvider.getRewardBalance()); }
From source file:org.tsm.concharto.dao.IntegrationTestUserTagDao.java
@Test public void tagCounts() throws ParseException { String tag1 = "tag1"; String tag2 = "tag2"; userTagDao.save(new UserTag(tag1)); userTagDao.save(new UserTag(tag1)); userTagDao.save(new UserTag(tag2)); UserTag userTag = new UserTag(tag2); userTagDao.save(userTag);//from w ww . j ava2 s . c o m //now modify the create date to be older than 20 days ago //it should not show up in the results Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -21); userTag.setCreated(cal.getTime()); userTagDao.saveOrUpdate(userTag); List<TagCloudEntry> tagCloudEntries = userTagDao.getTagCounts(20); //results are in alphabetic order assertEquals(BigInteger.valueOf(2), tagCloudEntries.get(0).getCount()); assertEquals(BigInteger.valueOf(1), tagCloudEntries.get(1).getCount()); assertEquals(4, userTagDao.findAll(50).size()); assertEquals(2, userTagDao.getTagCounts(TimeRangeFormat.parse("2000-2009")).size()); //just trolling for exceptions here assertEquals(0, userTagDao.getTagCountsByEventBeginDate(TimeRangeFormat.parse("2000-2009")).size()); }
From source file:de.decoit.visa.net.IPNetwork.java
/** * Construct a new network object. The provided address must match the * address notation of the specified IP version. * * @param pNetworkAddress String notation of the network IP address, must be * valid for the provided IP version * @param pSubnetMaskLength Bit length of the subnet mask used for this * network/*from w ww. j ava2 s . c o m*/ * @param pVersion Version of the Internet Protocol which will be used for * this network */ public IPNetwork(String pNetworkAddress, int pSubnetMaskLength, IPVersion pVersion) { int deviceMaskLength = pVersion.getAddressBitCount() - pSubnetMaskLength; if (deviceMaskLength >= 0 && deviceMaskLength <= pVersion.getAddressBitCount()) { // Calculate maximum number of device addresses in this network maxIPAddressCount = BigInteger.valueOf(2).pow(deviceMaskLength); // Subtract network and broadcast addresses maxIPAddressCount.subtract(BigInteger.valueOf(2)); } else { throw new IllegalArgumentException("Invalid subnet mask length provided"); } addressesInUse = new HashMap<>(); version = pVersion; subnetMask = pSubnetMaskLength; networkAddress = new IPAddress(pNetworkAddress, version); nextAddressMask = incrAddressMask(networkAddress.toBigIntBitmask(), BigInteger.ONE); lastAddressMask = incrAddressMask(networkAddress.toBigIntBitmask(), maxIPAddressCount); }