List of usage examples for java.math BigInteger valueOf
private static BigInteger valueOf(int val[])
From source file:com.healthcit.cacure.dao.FormElementDao.java
/** * @return Next Ord Number in ordered entities. */// w w w. j a va 2s. c o m @Transactional(propagation = Propagation.SUPPORTS) public Integer calculateNextOrdNumber(Long formId) { String sql = "select max(ord +1) from form_element where form_id = :formId"; Query query = em.createNativeQuery(sql); query.setParameter("formId", formId); BigInteger o = (BigInteger) query.getSingleResult(); if (o == null) { o = BigInteger.valueOf(1l); } return o == null ? null : Integer.valueOf(o.intValue()); }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
public BigInteger delCell(Byte cellId) throws MgmtException { logger.info("MC: delCell cell ID = " + cellId); MultiCellIntf api = MultiCellIntf.Proxy.getMultiCellAPI(); if (api == null) { logger.severe("failed to grab multicellAPI"); return BigInteger.valueOf(-1); }// w w w . j av a2 s . com try { api.removeCell(cellId); return BigInteger.valueOf(0); } catch (IOException ioe) { logger.log(Level.SEVERE, "failed to delete cell from the hive", ioe); throw new MgmtException("Internal error while deleting the cell " + "from the hive"); } catch (MultiCellException mue) { logger.log(Level.SEVERE, "failed to delete cell from the hive", mue); throw new MgmtException(mue.getMessage()); } catch (ManagedServiceException mse) { logger.log(Level.SEVERE, "failed to delete cell from the hive", mse); throw new MgmtException("Internal error while deleting the cell " + "from the hive"); } }
From source file:co.rsk.blockchain.utils.BlockGenerator.java
public static Block createEmptyGenesisBlock() { Bloom logBloom = new Bloom(); Block original = BlockGenerator.getGenesisBlock(); return new Block(original.getParentHash(), // parent hash EMPTY_LIST_HASH, // uncle hash original.getCoinbase(), // coinbase logBloom.getData(), // logs bloom original.getDifficulty(), // difficulty 0, original.getGasLimit(), original.getGasUsed(), original.getTimestamp() + ++count, EMPTY_BYTE_ARRAY, // extraData EMPTY_BYTE_ARRAY, // mixHash BigInteger.ZERO.toByteArray(), // provisory nonce EMPTY_TRIE_HASH, // receipts root EMPTY_TRIE_HASH, // transaction receipts EMPTY_TRIE_HASH, // state root null, // transaction list null, // uncle list BigInteger.valueOf(RskSystemProperties.RSKCONFIG.minerMinGasPrice()).toByteArray()); }
From source file:net.ripe.rpki.commons.validation.X509ResourceCertificateBottomUpValidatorTest.java
private X509CrlBuilder getRootCRL() { X509CrlBuilder builder = new X509CrlBuilder(); builder.withIssuerDN(ROOT_CERTIFICATE_NAME); builder.withThisUpdateTime(VALIDITY_PERIOD.getNotValidBefore().plusDays(1)); builder.withNextUpdateTime(new DateTime().plusMonths(1)); builder.withNumber(BigInteger.valueOf(1)); builder.withAuthorityKeyIdentifier(ROOT_KEY_PAIR.getPublic()); builder.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER); return builder; }
From source file:com.example.util.FileUtils.java
/** * Returns a human-readable version of the file size, where the input represents a specific number of bytes. * <p>//from w w w. ja va2 s . c o m * If the size is over 1GB, the size is returned as the number of whole GB, i.e. the size is rounded down to the * nearest GB boundary. * </p> * <p> * Similarly for the 1MB and 1KB boundaries. * </p> * * @param size * the number of bytes * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes) * @see <a href="https://issues.apache.org/jira/browse/IO-226">IO-226 - should the rounding be changed?</a> */ // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed? public static String byteCountToDisplaySize(long size) { return byteCountToDisplaySize(BigInteger.valueOf(size)); }
From source file:com.sourcesense.opencmis.server.TypeManager.java
/** * CMIS getTypesChildren.// ww w . j a v a 2 s. c om */ public TypeDefinitionList getTypesChildren(CallContext context, String typeId, boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount) { TypeDefinitionListImpl result = new TypeDefinitionListImpl(); result.setList(new ArrayList<TypeDefinition>()); result.setHasMoreItems(false); result.setNumItems(BigInteger.valueOf(0)); int skip = (skipCount == null ? 0 : skipCount.intValue()); if (skip < 0) { skip = 0; } int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue()); if (max < 1) { return result; } if (typeId == null) { if (skip < 1) { result.getList().add(copyTypeDefintion(fTypes.get(FOLDER_TYPE_ID).getTypeDefinition())); max--; } if ((skip < 2) && (max > 0)) { result.getList().add(copyTypeDefintion(fTypes.get(DOCUMENT_TYPE_ID).getTypeDefinition())); max--; } result.setHasMoreItems((result.getList().size() + skip) < 2); result.setNumItems(BigInteger.valueOf(2)); } else { TypeDefinitionContainer tc = fTypes.get(typeId); if ((tc == null) || (tc.getChildren() == null)) { return result; } for (TypeDefinitionContainer child : tc.getChildren()) { if (skip > 0) { skip--; continue; } result.getList().add(copyTypeDefintion(child.getTypeDefinition())); max--; if (max == 0) { break; } } result.setHasMoreItems((result.getList().size() + skip) < tc.getChildren().size()); result.setNumItems(BigInteger.valueOf(tc.getChildren().size())); } if (!includePropertyDefinitions) { for (TypeDefinition type : result.getList()) { type.getPropertyDefinitions().clear(); } } return result; }
From source file:org.opendaylight.ovsdb.plugin.ConfigurationService.java
/** * Create a Port Attached to a Bridge/*w w w . j a v a2 s. c o m*/ * Ex. ovs-vsctl add-port br0 vif0 * @param node Node serving this configuration service * @param bridgeIdentifier String representation of a Bridge Domain * @param portIdentifier String representation of a user defined Port Name */ @Override public Status addPort(Node node, String bridgeIdentifier, String portIdentifier, Map<ConfigConstants, Object> configs) { try { if (connectionService == null) { logger.error("Couldn't refer to the ConnectionService"); return new Status(StatusCode.NOSERVICE); } Connection connection = this.getConnection(node); if (connection == null) { return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available"); } if (connection != null) { Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName()); String newBridge = "new_bridge"; String newInterface = "new_interface"; String newPort = "new_port"; if (brTable != null) { Operation addBrMutRequest = null; String brUuid = null; for (String uuid : brTable.keySet()) { Bridge bridge = (Bridge) brTable.get(uuid); if (bridge.getName().contains(bridgeIdentifier)) { brUuid = uuid; } } UUID brUuidPair = new UUID(newPort); Mutation bm = new Mutation("ports", Mutator.INSERT, brUuidPair); List<Mutation> mutations = new ArrayList<Mutation>(); mutations.add(bm); UUID uuid = new UUID(brUuid); Condition condition = new Condition("_uuid", Function.EQUALS, uuid); List<Condition> where = new ArrayList<Condition>(); where.add(condition); addBrMutRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations); OvsDBMap<String, String> options = null; String type = null; OvsDBSet<BigInteger> tags = null; if (configs != null) { type = (String) configs.get(ConfigConstants.TYPE); Map<String, String> customConfigs = (Map<String, String>) configs .get(ConfigConstants.CUSTOM); if (customConfigs != null) { options = new OvsDBMap<String, String>(); for (String customConfig : customConfigs.keySet()) { options.put(customConfig, customConfigs.get(customConfig)); } } } Interface interfaceRow = new Interface(); interfaceRow.setName(portIdentifier); if (type != null) { if (type.equalsIgnoreCase(OvsdbType.PortType.TUNNEL.name())) { interfaceRow.setType((String) configs.get(ConfigConstants.TUNNEL_TYPE)); if (options == null) options = new OvsDBMap<String, String>(); options.put("remote_ip", (String) configs.get(ConfigConstants.DEST_IP)); } else if (type.equalsIgnoreCase(OvsdbType.PortType.VLAN.name())) { tags = new OvsDBSet<BigInteger>(); tags.add(BigInteger .valueOf(Integer.parseInt((String) configs.get(ConfigConstants.VLAN)))); } else if (type.equalsIgnoreCase(OvsdbType.PortType.PATCH.name())) { interfaceRow.setType(type.toLowerCase()); } } if (options != null) { interfaceRow.setOptions(options); } InsertOperation addIntfRequest = new InsertOperation(Interface.NAME.getName(), newInterface, interfaceRow); Port portRow = new Port(); portRow.setName(portIdentifier); if (tags != null) portRow.setTag(tags); OvsDBSet<UUID> interfaces = new OvsDBSet<UUID>(); UUID interfaceid = new UUID(newInterface); interfaces.add(interfaceid); portRow.setInterfaces(interfaces); InsertOperation addPortRequest = new InsertOperation(Port.NAME.getName(), newPort, portRow); TransactBuilder transaction = new TransactBuilder(); transaction.addOperations(new ArrayList<Operation>( Arrays.asList(addBrMutRequest, addPortRequest, addIntfRequest))); ListenableFuture<List<OperationResult>> transResponse = connection.getRpc() .transact(transaction); List<OperationResult> tr = transResponse.get(); List<Operation> requests = transaction.getRequests(); Status status = new Status(StatusCode.SUCCESS); for (int i = 0; i < tr.size(); i++) { if (i < requests.size()) requests.get(i).setResult(tr.get(i)); if (tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) { OperationResult result = tr.get(i); status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails()); } } if (tr.size() > requests.size()) { OperationResult result = tr.get(tr.size() - 1); logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier, result.getError(), result.getDetails()); status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails()); } return status; } return new Status(StatusCode.INTERNALERROR); } } catch (Exception e) { logger.error("Error in addPort()", e); } return new Status(StatusCode.INTERNALERROR); }
From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java
private BigInteger step3ComputeUpperBound(final BigInteger s, final BigInteger modulus, final BigInteger upperIntervalBound) { BigInteger upperBound = upperIntervalBound.multiply(s); upperBound = upperBound.subtract(BigInteger.valueOf(2).multiply(bigB)); // ceil//from w ww . j av a 2 s .co m BigInteger[] tmp = upperBound.divideAndRemainder(modulus); if (BigInteger.ZERO.compareTo(tmp[1]) != 0) { upperBound = BigInteger.ONE.add(tmp[0]); } else { upperBound = tmp[0]; } return upperBound; }
From source file:net.ripe.rpki.commons.validation.X509ResourceCertificateBottomUpValidatorTest.java
private X509CrlBuilder getChildCRL() { X509CrlBuilder builder = new X509CrlBuilder(); builder.withIssuerDN(FIRST_CHILD_CERTIFICATE_NAME); builder.withThisUpdateTime(VALIDITY_PERIOD.getNotValidBefore().plusDays(1)); builder.withNextUpdateTime(new DateTime().plusMonths(1)); builder.withNumber(BigInteger.valueOf(1)); builder.withAuthorityKeyIdentifier(FIRST_CHILD_KEY_PAIR.getPublic()); builder.withSignatureProvider(DEFAULT_SIGNATURE_PROVIDER); return builder; }
From source file:jp.aegif.nemaki.cmis.aspect.impl.CompileServiceImpl.java
@Override public ObjectList compileChangeDataList(CallContext context, String repositoryId, List<Change> changes, Holder<String> changeLogToken, Boolean includeProperties, String filter, Boolean includePolicyIds, Boolean includeAcl) {//ww w .j av a 2 s. co m ObjectListImpl results = new ObjectListImpl(); results.setObjects(new ArrayList<ObjectData>()); Map<String, Content> cachedContents = new HashMap<String, Content>(); if (changes != null && CollectionUtils.isNotEmpty(changes)) { for (Change change : changes) { // Retrieve the content(using caches) String objectId = change.getId(); Content content = new Content(); if (cachedContents.containsKey(objectId)) { content = cachedContents.get(objectId); } else { content = contentService.getContent(repositoryId, objectId); cachedContents.put(objectId, content); } // Compile a change object data depending on its type results.getObjects() .add(compileChangeObjectData(repositoryId, change, content, includePolicyIds, includeAcl)); } } results.setNumItems(BigInteger.valueOf(results.getObjects().size())); String latestInRepository = repositoryService.getRepositoryInfo(repositoryId).getLatestChangeLogToken(); String latestInResults = changeLogToken.getValue(); if (latestInResults != null && latestInResults.equals(latestInRepository)) { results.setHasMoreItems(false); } else { results.setHasMoreItems(true); } return results; }