List of usage examples for java.math BigInteger BigInteger
private BigInteger(long val)
From source file:MainClass.java
public void run() { try {//from w w w.jav a2 s .com ByteBuffer buffer = ByteBuffer.allocate(4); buffer.putInt(this.howMany); buffer.flip(); while (buffer.hasRemaining()) out.write(buffer); for (int i = 0; i < howMany; i++) { byte[] data = new BigInteger(Integer.toString(i)).toByteArray(); buffer = ByteBuffer.allocate(4 + data.length); buffer.putInt(data.length); buffer.put(data); buffer.flip(); while (buffer.hasRemaining()) out.write(buffer); } out.close(); System.err.println("Closed"); } catch (IOException ex) { System.err.println(ex); } }
From source file:edu.wisc.hr.demo.RandomBenefitStatementDao.java
@Override public BenefitStatements getBenefitStatements(String emplid) { if (emplIdToBenefitStatements.containsKey(emplid)) { return emplIdToBenefitStatements.get(emplid); }// w w w .j a v a 2 s . c o m int howManyBenefitStatements = random.nextInt(20); BenefitStatements benefitStatements = new BenefitStatements(); for (int i = 0; i < howManyBenefitStatements; i++) { BenefitStatement benefitStatement = new BenefitStatement(); int year = 2013 - i; String yearString = Integer.toString(year); benefitStatement.setDocId(new BigInteger(Integer.toString(random.nextInt()))); benefitStatement.setDocType("WhatsADocType?"); benefitStatement.setFullTitle("A Really Important Benefit Statement for ".concat(yearString)); benefitStatement.setName("Benefit Statement ".concat(yearString)); benefitStatement.setYear(new BigInteger(yearString)); benefitStatements.getBenefitStatements().add(benefitStatement); } this.emplIdToBenefitStatements.put(emplid, benefitStatements); return benefitStatements; }
From source file:edu.wisc.hr.demo.RandomSabbaticalStatementDao.java
@Override public SabbaticalReports getSabbaticalReports(String emplid) { if (this.emplIdToSabbaticalReports.containsKey(emplid)) { return emplIdToSabbaticalReports.get(emplid); }/*from ww w .j a v a 2 s . c o m*/ SabbaticalReports sabbaticalReports = new SabbaticalReports(); int howManySabbaticalReports = random.nextInt(5); for (int i = 0; i < howManySabbaticalReports; i++) { SabbaticalReport sabbaticalReport = new SabbaticalReport(); // TODO: make more realistic sabbatical reports sabbaticalReport.setFullTitle("What's a full title?"); sabbaticalReport.setName("What's a name?"); sabbaticalReport.setDocType("Type?"); sabbaticalReport.setYear(new BigInteger("2013")); String randomDocId = Integer.toString(random.nextInt(Integer.MAX_VALUE)); sabbaticalReport.setDocId(new BigInteger(randomDocId)); sabbaticalReports.getSabbaticalReports().add(sabbaticalReport); } emplIdToSabbaticalReports.put(emplid, sabbaticalReports); return sabbaticalReports; }
From source file:UInt64.java
/** * Create a UInt64 from a BigInteger//from w ww . j a va2 s . com * * @param value * Must be a valid BigInteger between MIN_VALUE–MAX_BIG_VALUE * @throws NumberFormatException * if value is not an integer between MIN_VALUE and MAX_BIG_VALUE */ public UInt64(BigInteger value) { /* if (null == value) { throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE })); } if (0 > value.compareTo(BigInteger.ZERO)) { throw new NumberFormatException(MessageFormat.format( _("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE })); } if (0 < value.compareTo(MAX_BIG_VALUE)) { throw new NumberFormatException(MessageFormat.format( _("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE })); } */ this.value = value; top = this.value.shiftRight(32).and(new BigInteger("4294967295")).longValue(); bottom = this.value.and(new BigInteger("4294967295")).longValue(); }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number object to parse/* ww w . ja v a2s .c o m*/ * @return parsed object * @throws ArithmeticException on overflow */ public static BigInteger toBigInteger(Number number) { /* Switch on class and convert to BigInteger */ String type = number.getClass().getSimpleName(); BigInteger parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = new BigInteger(by.toString()); break; case "Short": Short sh = (Short) number; parsed = new BigInteger(sh.toString()); break; case "Integer": Integer in = (Integer) number; parsed = new BigInteger(in.toString()); break; case "Long": Long lo = (Long) number; parsed = new BigInteger(lo.toString()); break; case "Float": Float fl = (Float) number; parsed = new BigInteger(fl.toString()); break; case "BigInteger": parsed = (BigInteger) number; break; case "BigDecimal": parsed = ((BigDecimal) number).toBigInteger(); break; case "Double": Double db = (Double) number; parsed = new BigInteger(db.toString()); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:Util.java
public static final BigDecimal[] interpLinear(BigDecimal[] x, BigDecimal[] y, BigDecimal[] xi) { if (x.length != y.length) { throw new IllegalArgumentException("X and Y must be the same length"); }// w w w. ja v a 2 s .c o m if (x.length == 1) { throw new IllegalArgumentException("X must contain more than one value"); } BigDecimal[] dx = new BigDecimal[x.length - 1]; BigDecimal[] dy = new BigDecimal[x.length - 1]; BigDecimal[] slope = new BigDecimal[x.length - 1]; BigDecimal[] intercept = new BigDecimal[x.length - 1]; // Calculate the line equation (i.e. slope and intercept) between each point BigInteger zero = new BigInteger("0"); BigDecimal minusOne = new BigDecimal(-1); for (int i = 0; i < x.length - 1; i++) { //dx[i] = x[i + 1] - x[i]; dx[i] = x[i + 1].subtract(x[i]); if (dx[i].equals(new BigDecimal(zero, dx[i].scale()))) { throw new IllegalArgumentException("X must be montotonic. A duplicate " + "x-value was found"); } if (dx[i].signum() < 0) { throw new IllegalArgumentException("X must be sorted"); } //dy[i] = y[i + 1] - y[i]; dy[i] = y[i + 1].subtract(y[i]); //slope[i] = dy[i] / dx[i]; slope[i] = dy[i].divide(dx[i]); //intercept[i] = y[i] - x[i] * slope[i]; intercept[i] = x[i].multiply(slope[i]).subtract(y[i]).multiply(minusOne); //intercept[i] = y[i].subtract(x[i]).multiply(slope[i]); } // Perform the interpolation here BigDecimal[] yi = new BigDecimal[xi.length]; for (int i = 0; i < xi.length; i++) { //if ((xi[i] > x[x.length - 1]) || (xi[i] < x[0])) { if (xi[i].compareTo(x[x.length - 1]) > 0 || xi[i].compareTo(x[0]) < 0) { yi[i] = null; // same as NaN } else { int loc = Arrays.binarySearch(x, xi[i]); if (loc < -1) { loc = -loc - 2; //yi[i] = slope[loc] * xi[i] + intercept[loc]; yi[i] = slope[loc].multiply(xi[i]).add(intercept[loc]); } else { yi[i] = y[loc]; } } } return yi; }
From source file:com.tasktop.c2c.server.internal.profile.crypto.OpenSSHPublicKeyReader.java
public SshPublicKey readPublicKey(String keySpec) { keySpec = keySpec.trim();// ww w . ja va2 s . c o m String[] parts = keySpec.split(" "); if (parts.length >= 2) { String algorithm = parts[0]; String base64Data = parts[1]; if (algorithm.equals("ssh-rsa")) { SshPublicKey sshPublicKey = new SshPublicKey(); sshPublicKey.setAlgorithm("RSA"); byte[] decodedData = Base64.decodeBase64(StringUtils.getBytesUtf8(base64Data)); Rfc4253Reader reader = new Rfc4253Reader(decodedData, 0); try { byte[] format = reader.readBytes(); byte[] exponent = reader.readBytes(); byte[] modulus = reader.readBytes(); if (Arrays.equals(FORMAT, format)) { BigInteger exp = new BigInteger(exponent); BigInteger mod = new BigInteger(modulus); RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(mod, exp); try { PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(rsaPublicKeySpec); sshPublicKey.setKeyData(publicKey.getEncoded()); return sshPublicKey; } catch (InvalidKeySpecException t) { getLogger().warn("Invalid key spec: " + t.getMessage(), t); } catch (NoSuchAlgorithmException t) { getLogger().warn("Invalid algorithm: " + t.getMessage(), t); } } } catch (IOException e) { // ignore } } } return null; }
From source file:hydrograph.ui.engine.util.FTPUtil.java
/** * Converts the String to {@link BigInteger} for widgets * /*from w w w . j a v a 2 s .c om*/ * @param propertyName * @return {@link BigInteger} */ public BigInteger getPortValue(String propertyName, String componentId, Map<String, Object> properties) { LOGGER.debug("Getting boolean Value for {}={}", new Object[] { propertyName, properties.get(propertyName) }); BigInteger bigInteger = null; String propertyValue = (String) properties.get(propertyName); if (StringUtils.isNotBlank(propertyValue) && StringUtils.isNumeric(propertyValue)) { bigInteger = new BigInteger(String.valueOf(propertyValue)); } else if (ParameterUtil.isParameter(propertyValue)) { ComponentXpath.INSTANCE.getXpathMap() .put((ComponentXpathConstants.COMPONENT_XPATH_BOOLEAN.value().replace("$id", componentId)) .replace(Constants.PARAM_PROPERTY_NAME, propertyName), new ComponentsAttributeAndValue(null, properties.get(propertyName).toString())); return null; } return bigInteger; }
From source file:org.glytoucan.api.soap.GlycoSequenceEndpointTest.java
@Test public void testSendAndReceive() { GlycoSequenceDetailRequest request = new GlycoSequenceDetailRequest(); request.setAccessionNumber("G00055MO"); Object result = new WebServiceTemplate(marshaller).marshalSendAndReceive("http://localhost:" + port + "/ws", request);/* w ww.j ava 2 s . c o m*/ assertNotNull(result); GlycoSequenceDetailResponse response = (GlycoSequenceDetailResponse) result; logger.debug(response); logger.debug(response.getDescription()); Assert.assertEquals(new BigInteger("0"), response.getResponseMessage().getErrorCode()); Assert.assertEquals("G00055MO", response.getAccessionNumber()); Assert.assertTrue(response.getDescription().contains("Gal(b1-4)GlcNAc(b1-")); }
From source file:it.geosolutions.opensdi.persistence.service.impl.TraceServiceTest.java
/** * Test for {@link TraceService#searchByRun(GeobatchRunInfo)} method *//* w w w .jav a 2 s.co m*/ @Test public void testSearchByRunInfo() { try { int traces = 10; TraceDto trace = null; String fileName = generateRandomString(); for (int i = 0; i < traces; i++) { trace = getTestTrace(fileName, 10); trace.setNr_rec_scartati(new BigInteger(i + "")); trace = traceService.saveTrace(trace); } List<TraceDto> list = traceService.searchByRun(getTestRunInfo(trace)); assertNotNull(list); assertTrue(!list.isEmpty()); assertTrue(list.size() == traces); } catch (Exception e) { e.printStackTrace(); fail(); } }