List of usage examples for java.math BigInteger valueOf
private static BigInteger valueOf(int val[])
From source file:co.rsk.blockchain.utils.BlockGenerator.java
public static Block createChildBlock(Block parent, List<Transaction> txs, List<BlockHeader> uncles, long difficulty, BigInteger minGasPrice) { if (txs == null) txs = new ArrayList<>(); if (uncles == null) uncles = new ArrayList<>(); Bloom logBloom = new Bloom(); byte[] bidiff = BigInteger.valueOf(difficulty).toByteArray(); byte[] unclesListHash = HashUtil.sha3(BlockHeader.getUnclesEncodedEx(uncles)); BlockHeader newHeader = new BlockHeader(parent.getHash(), unclesListHash, parent.getCoinbase(), ByteUtils.clone(new Bloom().getData()), new byte[] { 1 }, parent.getNumber() + 1, parent.getGasLimit(), 0, parent.getTimestamp() + ++count, new byte[] {}, new byte[] {}, new byte[] {}, new byte[] {}, (minGasPrice != null) ? minGasPrice.toByteArray() : null, CollectionUtils.size(uncles)); if (difficulty == 0) newHeader.setDifficulty(newHeader.calcDifficulty(parent.getHeader()).toByteArray()); else/*from w ww .j a v a 2 s.c o m*/ newHeader.setDifficulty(BigInteger.valueOf(difficulty).toByteArray()); newHeader.setTransactionsRoot(Block.getTxTrie(txs).getHash()); newHeader.setStateRoot(parent.getStateRoot()); Block newBlock = new Block(newHeader, txs, uncles); return newBlock; }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
public BigInteger updateSwitch(BigInteger dummy) throws MgmtException { updateSwitchUnconditionally(); return BigInteger.valueOf(0); }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Convert any Number object to the specified type for this * <i>Converter</i>.//from w ww . j av a 2 s. com * <p> * This method handles conversion to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The Number to convert. * * @return The converted value. */ private Number toNumber(Class sourceType, Class targetType, Number value) { // Correct Number type already if (targetType.equals(value.getClass())) { return value; } // Byte if (targetType.equals(Byte.class)) { long longValue = value.longValue(); if (longValue > Byte.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Byte.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Byte(value.byteValue()); } // Short if (targetType.equals(Short.class)) { long longValue = value.longValue(); if (longValue > Short.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Short.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Short(value.shortValue()); } // Integer if (targetType.equals(Integer.class)) { long longValue = value.longValue(); if (longValue > Integer.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Integer.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Integer(value.intValue()); } // Long if (targetType.equals(Long.class)) { return new Long(value.longValue()); } // Float if (targetType.equals(Float.class)) { if (value.doubleValue() > Float.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } return new Float(value.floatValue()); } // Double if (targetType.equals(Double.class)) { return new Double(value.doubleValue()); } // BigDecimal if (targetType.equals(BigDecimal.class)) { if (value instanceof Float || value instanceof Double) { return new BigDecimal(value.toString()); } else if (value instanceof BigInteger) { return new BigDecimal((BigInteger) value); } else { return BigDecimal.valueOf(value.longValue()); } } // BigInteger if (targetType.equals(BigInteger.class)) { if (value instanceof BigDecimal) { return ((BigDecimal) value).toBigInteger(); } else { return BigInteger.valueOf(value.longValue()); } } String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'"; throw new ConversionException(msg); }
From source file:com.itelis.worker.dev.template.service.JRXmlDataSource.java
protected Object convertNumber(Number number, Class valueClass) throws JRException { Number value = null;/*from ww w .jav a2s. com*/ if (valueClass.equals(Byte.class)) { value = new Byte(number.byteValue()); } else if (valueClass.equals(Short.class)) { value = new Short(number.shortValue()); } else if (valueClass.equals(Integer.class)) { value = new Integer(number.intValue()); } else if (valueClass.equals(Long.class)) { value = new Long(number.longValue()); } else if (valueClass.equals(Float.class)) { value = new Float(number.floatValue()); } else if (valueClass.equals(Double.class)) { value = new Double(number.doubleValue()); } else if (valueClass.equals(BigInteger.class)) { value = BigInteger.valueOf(number.longValue()); } else if (valueClass.equals(BigDecimal.class)) { value = new BigDecimal(Double.toString(number.doubleValue())); } else { throw new JRException("Unknown number class " + valueClass.getName()); } return value; }
From source file:com.aqnote.shared.cryptology.cert.gen.CertGenerator.java
private X509Certificate createRootCaCert(X500Name idn, KeyPair keyPair) throws Exception { PublicKey pubKey = keyPair.getPublic(); PrivateKey privKey = keyPair.getPrivate(); BigInteger sno = BigInteger.valueOf(1); Date nb = new Date(System.currentTimeMillis() - ONE_DAY); Date na = new Date(nb.getTime() + TWENTY_YEAR); X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(idn, sno, nb, na, idn, pubKey); addSubjectKID(certBuilder, pubKey);// w w w .j a v a 2 s. com addAuthorityKID(certBuilder, pubKey); addCRLDistributionPoints(certBuilder); addAuthorityInfoAccess(certBuilder); certBuilder.addExtension(Extension.basicConstraints, true, new BasicConstraints(Boolean.TRUE)); X509Certificate certificate = signCert(certBuilder, privKey); certificate.checkValidity(new Date()); certificate.verify(pubKey); setPKCS9Info(certificate); return certificate; }
From source file:com.wisemapping.exporter.FreemindExporter.java
private void addFontNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) { final String fontStyle = mindmapTopic.getFontStyle(); if (fontStyle != null && fontStyle.length() != 0) { final Font font = objectFactory.createFont(); final String[] part = fontStyle.split(";", 6); int countParts = part.length; boolean fontNodeNeeded = false; if (!fontStyle.endsWith(FreemindConstant.EMPTY_FONT_STYLE)) { int idx = 0; // Font name if (idx < countParts && part[idx].length() != 0) { font.setNAME(part[idx]); fontNodeNeeded = true;//from w ww. ja va2 s . c om } idx++; // Font size if (idx < countParts && part[idx].length() != 0) { final String size = part[idx]; if (size != null && !size.isEmpty()) { int wiseSize = Integer.parseInt(size); Integer freeSize = wiseToFreeFontSize.get(wiseSize); if (freeSize != null) { font.setSIZE(BigInteger.valueOf(freeSize)); fontNodeNeeded = true; } } } idx++; // Font Color if (idx < countParts && part[idx].length() != 0) { freemindNode.setCOLOR(this.rgbToHex(part[idx])); } idx++; // Font Styles if (idx < countParts && part[idx].length() != 0) { font.setBOLD(Boolean.TRUE.toString()); fontNodeNeeded = true; } idx++; if (idx < countParts && part[idx].length() != 0) { font.setITALIC(Boolean.TRUE.toString()); fontNodeNeeded = true; } if (fontNodeNeeded) { // font size should be set if freemind node has font properties note if (font.getSIZE() == null) { font.setSIZE(BigInteger.valueOf(wiseToFreeFontSize.get(8))); } freemindNode.getArrowlinkOrCloudOrEdge().add(font); } } } }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
public BigInteger setPublicKey(String publicKey) throws MgmtException { HashMap map = new HashMap(); map.put(ConfigPropertyNames.PROP_ADMIN_PUBKEY, publicKey); setCellProperties(map);//from www .ja v a 2 s . c om return BigInteger.valueOf(0); }
From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java
/** * Allocate a number of a given type and value. * @param type destination class//w ww .j a v a2 s .co m * @param value double * @return Number */ protected Number allocateNumber(Class type, double value) { type = TypeUtils.wrapPrimitive(type); if (type == Byte.class) { return new Byte((byte) value); } if (type == Short.class) { return new Short((short) value); } if (type == Integer.class) { return new Integer((int) value); } if (type == Long.class) { return new Long((long) value); } if (type == Float.class) { return new Float((float) value); } if (type == Double.class) { return new Double(value); } if (type == BigInteger.class) { return BigInteger.valueOf((long) value); } if (type == BigDecimal.class) { return new BigDecimal(value); } String classname = type.getName(); Class initialValueType = null; if ("java.util.concurrent.atomic.AtomicInteger".equals(classname)) { initialValueType = int.class; } if ("java.util.concurrent.atomic.AtomicLong".equals(classname)) { initialValueType = long.class; } if (initialValueType != null) { try { return (Number) type.getConstructor(new Class[] { initialValueType }) .newInstance(new Object[] { allocateNumber(initialValueType, value) }); } catch (Exception e) { throw new JXPathTypeConversionException(classname, e); } } return null; }
From source file:com.bosscs.spark.commons.utils.Utils.java
/** * Cast number type.// w w w . j av a2 s. c o m * * @param object the object * @param clazz the clazz * @return object */ public static Object castNumberType(Object object, Class clazz) { if (Number.class.isAssignableFrom(clazz)) { // AtomicInteger, AtomicLong, BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short if (Double.class.isAssignableFrom(clazz)) { return ((Number) object).doubleValue(); } else if (Long.class.isAssignableFrom(clazz)) { return ((Number) object).longValue(); } else if (Float.class.isAssignableFrom(clazz)) { return ((Number) object).floatValue(); } else if (Integer.class.isAssignableFrom(clazz)) { return ((Number) object).intValue(); } else if (Short.class.isAssignableFrom(clazz)) { return ((Number) object).shortValue(); } else if (Byte.class.isAssignableFrom(clazz)) { return ((Number) object).byteValue(); } else if (BigInteger.class.isAssignableFrom(clazz)) { return BigInteger.valueOf(((Number) object).longValue()); } else if (BigDecimal.class.isAssignableFrom(clazz)) { return BigDecimal.valueOf(((Number) object).longValue()); } else if (AtomicLong.class.isAssignableFrom(clazz)) { return new AtomicLong(((Number) object).longValue()); } else if (AtomicInteger.class.isAssignableFrom(clazz)) { return new AtomicInteger(((Number) object).intValue()); } } throw new ClassCastException("it is not a Number Type" + object.getClass() + "|" + clazz); }
From source file:info.estebanluengo.alfrescoAPI.AlfrescoAPI.java
/** * Creates a new Document in the folder with the name, content, and mimeType. * /* ww w .j av a2 s. co m*/ * @param session a Session object that is connected with the server * @param folder a Folder object where the new document will be created * @param fileName a String that contain the file name * @param content a byte array that contain the document * @param mimeType a String that represent the mime type of the document * * @return a Document object that represent the document that has just been created * @throws CmisContentAlreadyExistsException if the document to be created exists in the same folder */ public static Document createDocument(Session session, Folder folder, String fileName, byte[] content, String mimeType) throws CmisContentAlreadyExistsException { logger.debug("createDocument called for document name:" + fileName); Map<String, Object> docProps = new HashMap<>(); docProps.put(PropertyIds.NAME, fileName); docProps.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value()); docProps.put(PropertyIds.CREATION_DATE, new Date()); ByteArrayInputStream in = new ByteArrayInputStream(content); ContentStream contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(content.length), mimeType, in); ObjectId documentId = session.createDocument(docProps, session.createObjectId((String) folder.getPropertyValue(PropertyIds.OBJECT_ID)), contentStream, null, null, null, null); logger.debug("Document created with id:" + documentId.getId()); Document document = (Document) session.getObject(documentId); return document; }