List of usage examples for java.math BigInteger ONE
BigInteger ONE
To view the source code for java.math BigInteger ONE.
Click Source Link
From source file:org.thymeleaf.util.EvaluationUtilTest.java
@Test public void convertToBooleanTest() { Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(null)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Boolean.TRUE)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Boolean.FALSE)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(BigDecimal.ZERO)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigDecimal.ONE)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigDecimal.TEN)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(BigInteger.ZERO)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigInteger.ONE)); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(BigInteger.TEN)); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Double.valueOf(0.0d))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Float.valueOf(0.0f))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(0.1d))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(0.1f))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(-0.1d))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(-0.1f))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(Double.MAX_VALUE))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(Float.MAX_VALUE))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Double.valueOf(Double.MIN_VALUE))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Float.valueOf(Float.MIN_VALUE))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(Character.valueOf((char) 0))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Character.valueOf('x'))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Character.valueOf('0'))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(Character.valueOf('1'))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("true")); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean("false")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("yes")); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean("no")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("on")); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean("off")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("sky")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean("high above")); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("true"))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(new LiteralValue("false"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("yes"))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(new LiteralValue("no"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("on"))); Assert.assertFalse(EvaluationUtil.evaluateAsBoolean(new LiteralValue("off"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("sky"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(new LiteralValue("high above"))); Assert.assertTrue(EvaluationUtil.evaluateAsBoolean(EvaluationUtil.class)); }
From source file:com.workday.autoparse.xml.demo.XmlParserTest.java
@Test public void testParse() throws UnknownElementException, ParseException, UnexpectedChildException { XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser(); InputStream in = getInputStreamOf("input.xml"); DemoModel model = (DemoModel) parser.parseStream(in); assertTrue(model.myBoxedBoolean);/*from w ww. ja v a2 s . c o m*/ assertTrue(model.myPrimitiveBoolean); assertEquals(new BigDecimal(0.5), model.myBigDecimal); assertEquals(BigInteger.ONE, model.myBigInteger); assertEquals(2, model.myPrimitiveByte); assertEquals(Byte.valueOf((byte) 4), model.myBoxedByte); assertEquals('a', model.myPrimitiveChar); assertEquals(Character.valueOf('b'), model.myBoxedChar); assertEquals(5.5, model.myPrimitiveDouble, DOUBLE_E); assertEquals(Double.valueOf(6.5), model.myBoxedDouble); assertEquals(7.5f, model.myPrimitiveFloat, FLOAT_E); assertEquals(Float.valueOf(8.5f), model.myBoxedFloat); assertEquals(9, model.myPrimitiveInt); assertEquals(Integer.valueOf(10), model.myBoxedInt); assertEquals(11, model.myPrimitiveLong); assertEquals(Long.valueOf(12), model.myBoxedLong); assertEquals(13, model.myPrimitiveShort); assertEquals(Short.valueOf((short) 15), model.myBoxedShort); assertEquals("Bob", model.myString); assertTrue(model.myChildModel != null); assertEquals("My_String_Value", model.myChildModel.myString); assertEquals(5, model.myChildModel.myInt); assertEquals(3, model.repeatedChildModels.size()); assertEquals("a", model.repeatedChildModels.get(0).value); assertEquals("I am some text.", model.repeatedChildModels.get(0).textContent); assertEquals("b", model.repeatedChildModels.get(1).value); assertNull(model.repeatedChildModels.get(1).textContent); assertEquals("c", model.repeatedChildModels.get(2).value); }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.writers.BugsWriterTest.java
/** * Build the items to write.//from w w w .j av a 2 s . co m * * @return items */ private List<BugBean> buildItems() { final Calendar cal = Calendar.getInstance(); final List<BugBean> items = new ArrayList<BugBean>(); final BugBean item1 = new BugBean(); item1.setId(BigInteger.ONE); item1.setProjectId(BigInteger.ONE); item1.setDescription("Description_1"); item1.setSummary("Summary_1"); item1.setDateSubmitted(new Timestamp(cal.getTimeInMillis())); item1.setLastUpdated(new Timestamp(cal.getTimeInMillis())); items.add(item1); return items; }
From source file:co.rsk.core.NetworkStateExporterTest.java
@Test public void testNoContracts() throws Exception { Repository repository = new RepositoryImpl(new TrieStoreImpl(new HashMapDB())); String address1String = "1000000000000000000000000000000000000000"; byte[] address1 = Hex.decode(address1String); repository.createAccount(address1);/* www. j a va 2 s . c o m*/ repository.addBalance(address1, BigInteger.ONE); repository.increaseNonce(address1); String address2String = "2000000000000000000000000000000000000000"; byte[] address2 = Hex.decode(address2String); repository.createAccount(address2); repository.addBalance(address2, BigInteger.TEN); repository.increaseNonce(address2); repository.increaseNonce(address2); byte[] remascSender = ZERO_BYTE_ARRAY; repository.createAccount(remascSender); repository.increaseNonce(remascSender); byte[] remascAddr = Hex.decode(PrecompiledContracts.REMASC_ADDR); repository.createAccount(remascAddr); repository.addBalance(remascAddr, BigInteger.TEN); repository.increaseNonce(remascAddr); Map result = writeAndReadJson(repository); Assert.assertEquals(3, result.keySet().size()); Map address1Value = (Map) result.get(address1String); Assert.assertEquals(2, address1Value.keySet().size()); Assert.assertEquals("1", address1Value.get("balance")); Assert.assertEquals("1", address1Value.get("nonce")); Map address2Value = (Map) result.get(address2String); Assert.assertEquals(2, address2Value.keySet().size()); Assert.assertEquals("10", address2Value.get("balance")); Assert.assertEquals("2", address2Value.get("nonce")); Map remascValue = (Map) result.get(PrecompiledContracts.REMASC_ADDR); Assert.assertEquals(2, remascValue.keySet().size()); Assert.assertEquals("10", remascValue.get("balance")); Assert.assertEquals("1", remascValue.get("nonce")); }
From source file:org.sinekartads.share.webscripts.sign.SkdsSignCallPreSignWS.java
@Override protected void processData(SignWizardDTO dto) throws AlfrescoException { DocumentDTO[] documents = dto.getDocuments(); int last = dto.getDocuments()[0].getSignatures().length - 1; SignatureDTO signature = dto.getDocuments()[0].getSignatures()[last]; Assert.isTrue(ArrayUtils.isNotEmpty(signature.getHexCertificateChain())); // Clone the chainSignature in order to update it without impacting on the DTO TsSelection tsSelection = TsSelection.valueOf(dto.getTsSelection()); SignatureDTO chainSignature = TemplateUtils.Instantiation.clone(signature); TimeStampRequestDTO timeStampRequest = chainSignature.getTimeStampRequest(); timeStampRequest.timestampDispositionToString(SignDisposition.TimeStamp.ENVELOPING); timeStampRequest.messageImprintAlgorithmToString(DigestAlgorithm.SHA256); timeStampRequest.nounceToString(BigInteger.ONE); // Update the nested timeStampRequest depending on the tsSelection switch (tsSelection) { case NONE: {//from w w w . j ava 2s.c o m timeStampRequest.setTsUrl(""); timeStampRequest.setTsUsername(""); timeStampRequest.setTsPassword(""); break; } case DEFAULT: { timeStampRequest.setTsUrl(conf.getTsaUrl()); timeStampRequest.setTsUsername(conf.getTsaUser()); timeStampRequest.setTsPassword(conf.getTsaPassword()); break; } default: { } } // Append the updated chainSignature to the documents' signatures, at the last position: // the server-tier webScripts and the signature client implementations will consider // this one as the signature to be applied for (DocumentDTO document : documents) { document.setSignatures((SignatureDTO[]) ArrayUtils.add(document.getSignatures(), chainSignature)); } // Execute the pre-sign to the documents. SkdsPreSignRequest prereq = new SkdsPreSignRequest(); prereq.documentsToBase64(documents); SkdsPreSignResponse dsiresp = postJsonRequest(prereq, SkdsPreSignResponse.class); documents = dsiresp.documentsFromBase64(); dto.setDocuments(documents); }
From source file:Bytes.java
/** * Convert the specified amount into a human readable (though slightly less accurate) * result. IE:/* w w w .j av a 2s. co m*/ * '4096 B' to '4 KB' * '5080 B' to '5 KB' even though it is really '4 KB + 984 B' */ public static String friendly(Bytes type, BigInteger value) { /** * Logic: * Loop from YB to B * If result = 0, continue * Else, round off * * NOTE: BigIntegers are not reusable, so not point in caching them outside the loop */ for (Bytes newType : reversed) { BigInteger newAmount = newType.convertFrom(value, type); if (newAmount.equals(BigInteger.ZERO)) continue; // Found the right one. Now to round off BigInteger unitBytes = Bytes.B.convertFrom(BigInteger.ONE, newType); BigInteger usedBytes = newAmount.multiply(unitBytes); BigInteger remainingBytes = Bytes.B.convertFrom(value, type).subtract(usedBytes); if (remainingBytes.equals(BigInteger.ZERO)) return String.format(friendlyFMT, newAmount.toString(), newType); if (remainingBytes.equals(value)) return String.format(friendlyFMT, newAmount.toString(), newType); BigInteger halfUnit = unitBytes.divide(TWO); if ((remainingBytes.subtract(halfUnit)).signum() < 0) return String.format(friendlyFMT, newAmount.toString(), newType); return String.format(friendlyFMT, (newAmount.add(BigInteger.ONE)).toString(), newType); } // Give up return String.format(friendlyFMT, value.toString(), type); }
From source file:com.offbynull.peernetic.common.identification.Id.java
/** * Generates a limit that's {@code 2^n-1}. Another way to think of it is, generates a limit that successively {@code n = (n << 1) | 1} * for {@code n} times -- making sure you have a limit that's value is all 1 bits. * <p/>/* www . j a va 2 s.c om*/ * Examples: * <ul> * <li>{@code n = 1, limit = 1 (1b)}<li/> * <li>{@code n = 2, limit = 3 (11b)}<li/> * <li>{@code n = 4, limit = 7 (111b)}<li/> * <li>{@code n = 8, limit = 15 (1111b)}<li/> * </ul> * @param exp exponent, such that the returned value is {@code 2^exp-1} * @return {@code 2^exp-1} as a byte array * @throws IllegalArgumentException if {@code exp <= 0} */ private static byte[] generatePowerOfTwoLimit(int exp) { Validate.inclusiveBetween(1, Integer.MAX_VALUE, exp); BigInteger val = BigInteger.ONE.shiftLeft(exp).subtract(BigInteger.ONE); // (1 << exp) - 1 return val.toByteArray(); }
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 www .jav a 2 s . 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:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsUserWriterTest.java
public StepExecution getStepExecution() { final Map<String, JobParameter> map = new HashMap<String, JobParameter>(); final JobParameters jobParams = new JobParameters(map); final JobExecution exec = MetaDataInstanceFactory.createJobExecution("testJob", 1L, 1L, jobParams); exec.getExecutionContext().put("mantis.loop.project_id", BigInteger.ONE); final StepExecution stepExecution = exec.createStepExecution("testStep"); return stepExecution; }
From source file:com.redhat.lightblue.metadata.types.BooleanTypeTest.java
@Test public void testCastBigInteger() { assertTrue(booleanType.cast(BigInteger.ONE) instanceof Boolean); }