List of usage examples for java.math BigInteger BigInteger
private BigInteger(long val)
From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.MutualInformationBased.java
public MutualInformationBased(Finder aFinder) { super(aFinder); try {/*from w ww . java 2s.co m*/ Properties properties = new Properties(); BufferedInputStream stream = new BufferedInputStream( new FileInputStream("src/main/resources/index.properties")); properties.load(stream); stream.close(); FREQUENCY = new BigInteger(properties.getProperty("frequency")); } catch (Exception e) { FREQUENCY = new BigInteger("143782944956"); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.SharedSecretObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { String raw_b64;//from www .ja v a2 s.co m try { raw_b64 = obj.getString(RAW); } catch (JSONException e) { e.printStackTrace(); return; } byte[] ss = FastBase64.decode(raw_b64); if (from.secret != null && new BigInteger(from.secret).compareTo(new BigInteger(ss)) > 0) { //ignore the new key according to a time independent metric... return; } ContentValues values = new ContentValues(); values.put(Contact.SHARED_SECRET, ss); context.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), values, "_id=?", new String[] { String.valueOf(from.id) }); }
From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.FrequencyBased.java
/** * Calculates the weight for a split//from w w w.ja v a 2 s. c o m * @param split * @return */ private float calcRank(Split split) { BigInteger result = new BigInteger("1"); for (SplitElement elem : split.getSplits()) { result = result.multiply(this.freq(elem)); } return (float) Math.pow(result.doubleValue(), 1f / (double) split.getSplits().size()); }
From source file:org.glytoucan.api.soap.endpoint.GlycoSequenceEndpoint.java
/** * /*from w ww. j a v a 2 s . c o m*/ * Query entry using accession number. * * @param accessionNumber * @return */ @PayloadRoot(namespace = NAMESPACE_URI, localPart = "glycoSequenceDetailRequest") @ResponsePayload public GlycoSequenceDetailResponse queryEntry(@RequestPayload GlycoSequenceDetailRequest request) { Assert.notNull(request); Assert.notNull(request.getAccessionNumber()); SparqlEntity se = null; ResponseMessage rm = new ResponseMessage(); GlycoSequenceDetailResponse gsdr = new GlycoSequenceDetailResponse(); try { se = glycanProcedure.getDescription(request.getAccessionNumber()); } catch (InvalidException e) { // invalid data in se, return with errorcode. rm.setMessage("Invalid Accession Number"); rm.setErrorCode(new BigInteger("-100")); gsdr.setAccessionNumber(request.getAccessionNumber()); gsdr.setResponseMessage(rm); return gsdr; } rm.setMessage(se.getValue(GlycanProcedure.Description)); rm.setErrorCode(new BigInteger("0")); gsdr.setAccessionNumber(se.getValue(ResourceEntry.Identifier)); gsdr.setDescription(se.getValue(GlycanProcedure.Description)); gsdr.setIupac(se.getValue(GlycoSequence.Sequence)); gsdr.setMass(se.getValue(DerivatizedMass.MassLabel)); gsdr.setSequence(se.getValue(GlycoSequence.Sequence)); gsdr.setResponseMessage(rm); return gsdr; }
From source file:com.cyphermessenger.utils.Utils.java
public static long bytesToLong(byte[] b) { return new BigInteger(b).longValue(); }
From source file:dingwen.Command.java
public static void listShapesCmd(String command, ShapeCache shapeCache) { BigInteger id = null;//from www .ja v a 2s . c om if (NumberUtils.isParsable(command.substring(command.indexOf(" ") + 1))) { id = new BigInteger(command.substring(command.indexOf(" ") + 1)); } if (id == null) { Iterator it = shapeCache.getShapes().entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); System.out.println("shape " + pair.getKey() + " " + (Shape) pair.getValue()); } } else if (shapeCache.getShape(id) != null) { System.out.println("shape " + id + " " + shapeCache.getShape(id)); } else { System.out.println(CommonStatement.SHAPE_NOT_EXISTS); } }
From source file:net.onrc.openvirtex.util.OVXFlowManager.java
public Integer getFlowId(final byte[] srcMac, final byte[] dstMac) throws DroppedMessageException { final BigInteger dualMac = new BigInteger(ArrayUtils.addAll(srcMac, dstMac)); final Integer flowId = this.flowValues.inverse().get(dualMac); if (flowId != null && flowId != 0) { log.debug("virtual net = {}: retrieving flowId {} that is associated to {} {}", this.tenantId, flowId, MACAddress.valueOf(srcMac).toString(), MACAddress.valueOf(dstMac).toString()); return flowId; }//from w w w. jav a2s . co m throw new DroppedMessageException("virtual net = " + this.tenantId + ": unable to retrive the flowId associated to these mac addresses: " + MACAddress.valueOf(srcMac).toString() + "-" + MACAddress.valueOf(dstMac).toString() + ". Dropping message!"); }
From source file:edu.hku.sdb.upload.UploadHandler.java
public UploadHandler(MetaStore metaStore, String tableName, ServerConf serverConf) { searchEncrypt = SearchEncrypt.getInstance(); switch (serverConf.getType()) { case HIVE://w w w.j a va 2 s . c om dbName = ((JDBCServerConf) serverConf).getDatabaseName(); break; case ODPS: dbName = ((ODPSServerConf) serverConf).getProject(); break; default: LOG.error("Unsupported server type: " + serverConf.getType()); System.exit(-1); break; } DBMeta dbMeta = metaStore.getDB(dbName); n = new BigInteger(dbMeta.getN()); prime1 = new BigInteger(dbMeta.getPrime1()); prime2 = new BigInteger(dbMeta.getPrime2()); g = new BigInteger(dbMeta.getG()); totient = SDBEncrypt.evaluateTotient(prime1, prime2); List<ColumnMeta> colMetas = metaStore.getTbl(dbName, tableName).getCols(); for (int columnIndex = 0; columnIndex < colMetas.size(); columnIndex++) { ColumnMeta colMeta = colMetas.get(columnIndex); if (colMeta.getColName().equals(ColumnDefinition.ROW_ID_COLUMN_NAME) || colMeta.getColName().equals(ColumnDefinition.R_COLUMN_NAME) || colMeta.getColName().equals(ColumnDefinition.S_COLUMN_NAME)) { auxiliaryColMetas.add(colMeta); } else trueValueColMetas.add(colMeta); } }
From source file:au.com.ish.derbydump.derbydump.main.DumpTest.java
@Parameterized.Parameters(name = "{0}") public static Collection<Object[]> setupTestMatrix() throws Exception { List<Object[]> result = new ArrayList<Object[]>(); //testing numbers (BIGINT, DECIMAL, REAL, SMALLINT, INTEGER, DOUBLE) {/* w w w . j ava2 s .c o m*/ //standard set of numbers String[] columns = new String[] { "c1 BIGINT", "c2 DECIMAL(10,2)", "c3 REAL", "c4 SMALLINT", "c5 INTEGER", "c6 DOUBLE" }; Object[] row1 = new Object[] { new BigInteger("12"), new BigDecimal("12.12"), new Float("12.1"), Integer.valueOf(12), Integer.valueOf(24), Double.valueOf(12.12) }; String validOutput1 = "(12,12.12,12.1,12,24,12.12),"; Object[] row2 = new Object[] { new BigInteger("42"), new BigDecimal("42.12"), new Float("42.14"), Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42.14) }; String validOutput2 = "(42,42.12,42.14,42,64,42.14),"; Object[] row3 = new Object[] { new BigInteger("42"), new BigDecimal("42"), new Float("42"), Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42) }; String validOutput3 = "(42,42.00,42.0,42,64,42.0),"; Object[] row4 = new Object[] { new BigInteger("42"), new BigDecimal("42.1234"), new Float("42.1434"), Integer.valueOf(42), Integer.valueOf(64), Double.valueOf(42.1234) }; String validOutput4 = "(42,42.12,42.1434,42,64,42.1234),"; Object[] row5 = new Object[] { BigDecimal.ZERO, BigDecimal.ZERO, new Float("0"), Integer.valueOf(0), Integer.valueOf(0), Double.valueOf(0) }; String validOutput5 = "(0,0.00,0.0,0,0,0.0),"; //test nulls Object[] row6 = new Object[] { null, null, null, null, null, null }; String validOutput6 = "(NULL,NULL,NULL,NULL,NULL,NULL);"; Object[] values = new Object[] { row1, row2, row3, row4, row5, row6 }; String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3, validOutput4, validOutput5, validOutput6 }; result.add(new Object[] { "testNumbers", null, columns, values, validOutput, false, false }); } //testing strings { String[] columns = new String[] { "c1 VARCHAR(20)", "c2 VARCHAR(20)", "c3 VARCHAR(20)" }; //test normal characters Object[] row1 = new Object[] { "123", "abc", "" }; String validOutput1 = "('123','abc',''),"; //test nulls Object[] row2 = new Object[] { "%", null, "" }; String validOutput2 = "('%',NULL,''),"; //test quotes and tabs Object[] row3 = new Object[] { "'test'", "\"test\"", "\t" }; String validOutput3 = "('\\'test\\'','\"test\"','\\t'),"; //test new line chars Object[] row4 = new Object[] { "\n", "\r", "\n\r" }; String validOutput4 = "('\\n','\\r','\\n\\r');"; Object[] values = new Object[] { row1, row2, row3, row4 }; String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3, validOutput4 }; result.add(new Object[] { "testStrings", null, columns, values, validOutput, false, false }); } //testing dates { String[] columns = new String[] { "c1 TIMESTAMP", "c2 TIMESTAMP" }; // test standard dates Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.set(Calendar.YEAR, 2013); c.set(Calendar.MONTH, 5); c.set(Calendar.DAY_OF_MONTH, 6); c.set(Calendar.HOUR_OF_DAY, 11); c.set(Calendar.MINUTE, 10); c.set(Calendar.SECOND, 10); c.set(Calendar.MILLISECOND, 11); Calendar c2 = (Calendar) c.clone(); c2.add(Calendar.DATE, -5000); Object[] row1 = new Object[] { c.getTime(), c2.getTime() }; String validOutput1 = "('2013-06-06 11:10:10.011','1999-09-28 11:10:10.011'),"; Object[] row2 = new Object[] { "2012-07-07 08:54:33", "1999-09-09 10:04:10" }; String validOutput2 = "('2012-07-07 08:54:33.0','1999-09-09 10:04:10.0'),"; Object[] row3 = new Object[] { null, null }; String validOutput3 = "(NULL,NULL);"; Object[] values = new Object[] { row1, row2, row3 }; String[] validOutput = new String[] { validOutput1, validOutput2, validOutput3 }; result.add(new Object[] { "testDates", null, columns, values, validOutput, false, false }); } //testing CLOB { String[] columns = new String[] { "c1 CLOB" }; Object[] row1 = new Object[] { "<clob value here>" }; String validOutput1 = "('<clob value here>'),"; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testClob", null, columns, values, validOutput, false, false }); } //testing BLOB { String[] columns = new String[] { "c1 BLOB" }; Object[] row1 = new Object[] { getTestImage() }; Blob serialBlob = new SerialBlob(IOUtils.toByteArray(getTestImage())); String validOutput1 = "(" + Column.processBinaryData(serialBlob) + "),"; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testBlob", null, columns, values, validOutput, false, false }); } //testing skipping table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] row1 = new Object[] { "123" }; String validOutput1 = ""; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testSkip", null, columns, values, validOutput, true, false }); } //testing renaming table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] row1 = new Object[] { "123" }; String validOutput1 = "('123'),"; Object[] row2 = new Object[] { null }; String validOutput2 = "(NULL);"; Object[] values = new Object[] { row1, row2 }; String[] validOutput = new String[] { validOutput1, validOutput2 }; result.add(new Object[] { "testRename", "testRenameNew", columns, values, validOutput, false, false }); } //testing empty table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] values = new Object[] { new Object[] {} }; String[] validOutput = new String[] {}; result.add(new Object[] { "testEmptyTable", null, columns, values, validOutput, true, false }); } //testing truncate table { String[] columns = new String[] { "c1 VARCHAR(5)" }; Object[] values = new Object[] { new Object[] {} }; String[] validOutput = new String[] {}; result.add(new Object[] { "testTruncateTable", null, columns, values, validOutput, true, true }); } return result; }
From source file:com.redhat.lightblue.crud.validator.MinMaxCheckerTest.java
protected JsonNode mockFieldValue(JsonNode mock, int value) { if ((number instanceof Integer) || (number instanceof Byte) || (number instanceof Short) || (number instanceof Long)) { when(mock.asLong()).thenReturn(new Long(value)); } else if ((number instanceof Float) || (number instanceof Double)) { when(mock.asDouble()).thenReturn(new Double(value)); } else if (number instanceof BigInteger) { when(mock.bigIntegerValue()).thenReturn(new BigInteger(String.valueOf(value))); } else if (number instanceof BigDecimal) { when(mock.decimalValue()).thenReturn(new BigDecimal(value)); } else {/*from ww w . j ava 2 s . c om*/ throw new IllegalArgumentException("Not a supported Number type: " + number.getClass()); } return mock; }