Example usage for java.math BigInteger ONE

List of usage examples for java.math BigInteger ONE

Introduction

In this page you can find the example usage for java.math BigInteger ONE.

Prototype

BigInteger ONE

To view the source code for java.math BigInteger ONE.

Click Source Link

Document

The BigInteger constant one.

Usage

From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.writers.BugCustomFieldsWriterTest.java

/**
 * Build the items to write./*w ww.  ja v  a  2 s  . com*/
 *
 * @return items
 */
private List<BugBean> buildItems() {

    final List<BugBean> items = new ArrayList<BugBean>();

    final BugBean item1 = new BugBean();
    final BugCustomFieldValue val = new BugCustomFieldValue();
    val.setBugId(BigInteger.ONE);
    val.setFieldId(BigInteger.ONE);
    val.setFieldValue("value_1");

    item1.getCustomFields().add(val);
    items.add(item1);

    return items;
}

From source file:com.spotify.reaper.unit.service.SegmentRunnerTest.java

@Test
public void timeoutTest() throws InterruptedException, ReaperException, ExecutionException {
    final AppContext context = new AppContext();
    context.storage = new MemoryStorage();
    RepairUnit cf = context.storage/*from w  ww .j  ava2 s  .  com*/
            .addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper")));
    RepairRun run = context.storage.addRepairRun(
            new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL));
    context.storage.addRepairSegments(Collections.singleton(
            new RepairSegment.Builder(run.getId(), new RingRange(BigInteger.ONE, BigInteger.ZERO), cf.getId())),
            run.getId());
    final long segmentId = context.storage.getNextFreeSegment(run.getId()).get().getId();

    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final MutableObject<Future<?>> future = new MutableObject<>();

    context.jmxConnectionFactory = new JmxConnectionFactory() {
        @Override
        public JmxProxy connect(final Optional<RepairStatusHandler> handler, String host) {
            JmxProxy jmx = mock(JmxProxy.class);
            when(jmx.getClusterName()).thenReturn("reaper");
            when(jmx.isConnectionAlive()).thenReturn(true);
            when(jmx.tokenRangeToEndpoint(anyString(), any(RingRange.class)))
                    .thenReturn(Lists.newArrayList(""));
            when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), anyString(),
                    Matchers.<RepairParallelism>any(), Sets.newHashSet(anyString())))
                            .then(new Answer<Integer>() {
                                @Override
                                public Integer answer(InvocationOnMock invocation) {
                                    assertEquals(RepairSegment.State.NOT_STARTED,
                                            context.storage.getRepairSegment(segmentId).get().getState());
                                    future.setValue(executor.submit(new Thread() {
                                        @Override
                                        public void run() {
                                            handler.get().handle(1, ActiveRepairService.Status.STARTED,
                                                    "Repair command 1 has started");
                                            assertEquals(RepairSegment.State.RUNNING, context.storage
                                                    .getRepairSegment(segmentId).get().getState());
                                        }
                                    }));
                                    return 1;
                                }
                            });

            return jmx;
        }
    };
    RepairRunner rr = mock(RepairRunner.class);
    RepairUnit ru = mock(RepairUnit.class);
    SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 100, 0.5,
            RepairParallelism.PARALLEL, "reaper", ru, rr);
    sr.run();

    future.getValue().get();
    executor.shutdown();

    assertEquals(RepairSegment.State.NOT_STARTED, context.storage.getRepairSegment(segmentId).get().getState());
    assertEquals(1, context.storage.getRepairSegment(segmentId).get().getFailCount());
}

From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java

/**
 * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertProjectIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef)}.
 *///ww w  .  j  av a2  s.  c  o m
@Test
public void testInsertProjectIfNotExists() {
    final ObjectRef item = new ObjectRef(BigInteger.ONE, "item");
    final boolean result = dao.insertProjectIfNotExists(item);
    assertTrue(result);

    final List<ObjectRef> list = getJdbcTemplate().query("SELECT id, name FROM mantis_project_table",
            new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class));

    assertEquals(1, list.size());
    assertEquals(item, list.get(0));

    final boolean result2 = dao.insertProjectIfNotExists(item);
    assertTrue(result2);
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsVersionsWriterTest.java

@Test
public void test() throws Exception {
    final Operation op = sequenceOf(
            insertInto("mantis_project_table").columns("id", "name").values(1, "project_1").build(),

            insertInto("mantis_project_version_table").columns("id", "version", "project_id")
                    .values(1, "old_version_1", 1).build());

    lauchOperation(op);/*from www.  j av  a 2  s .  co  m*/

    projectVersionsWriter.write(buildItems());

    final List<ProjectVersionData> results = getJdbcTemplate().query(
            "SELECT id, version as name, project_id" + " FROM mantis_project_version_table"
                    + " WHERE project_id = 1",
            new BeanPropertyRowMapper<ProjectVersionData>(ProjectVersionData.class));

    assertEquals(2, results.size());

    for (final ProjectVersionData item : results) {
        assertEquals(BigInteger.ONE, item.getProject_id());
        if (item.getId() == BigInteger.ONE) {
            assertEquals("new_version_1", item.getName());
        } else {
            assertEquals(BigInteger.valueOf(2), item.getId());
            assertEquals("new_version_2", item.getName());
        }
    }
}

From source file:co.rsk.remasc.RemascStorageProviderTest.java

@Test
public void setAndGetBurnedBalance() {
    String accountAddress = randomAddress();
    Repository repository = new RepositoryImpl();

    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);

    provider.setBurnedBalance(BigInteger.ONE);

    Assert.assertEquals(BigInteger.ONE, provider.getBurnedBalance());
}

From source file:Ternary.java

public Ternary(BigInteger toConvert) {
    this();//from w w w  .j  a  v a  2 s .c om
    int position = 0;
    BigInteger remaining = toConvert;
    BigInteger rounded, left;
    while (!remaining.equals(BigInteger.ZERO)) {
        rounded = ((new BigDecimal(remaining)).divide(bdThree, 0, BigDecimal.ROUND_HALF_UP)).toBigInteger();
        left = remaining.subtract(rounded.multiply(biThree));
        if (left.equals(BigInteger.ONE))
            setTrit(position++, Trit.POSITIVE);
        else if (left.equals(BigInteger.ZERO))
            setTrit(position++, Trit.NEUTRAL);
        else
            setTrit(position++, Trit.NEGATIVE);
        remaining = rounded;
    }
}

From source file:edu.utah.further.core.api.math.ArithmeticUtil.java

/**
 * Compute the factorial of a {@link BigInteger}. Allows computing big numbers.
 *
 * @param n//w  w  w  .  java 2 s .  c om
 * @return
 */
public static BigInteger factorial(final int n) {
    BigInteger fact = BigInteger.ONE;
    for (int i = n; i > 1; i--) {
        fact = fact.multiply(new BigInteger(Integer.toString(i)));
    }
    return fact;
}

From source file:org.openestate.io.examples.CasaItWritingExample.java

/**
 * Create a {@link Realestate} with some example data.
 *
 * @return/* ww  w .  j a  va 2  s .  com*/
 * created example object
 */
protected static Realestate createRealestate() {
    // create an example real estate
    Realestate obj = FACTORY.createContainerRealestateitemsRealestate();
    obj.setAction(BigInteger.ONE);
    obj.setAgencycode(0);
    obj.setBathrooms(BigInteger.valueOf(RandomUtils.nextLong(1, 5)));
    obj.setCondition(BigInteger.ONE);
    obj.setContracttype(BigInteger.ONE);
    obj.setFloor(BigInteger.valueOf(RandomUtils.nextLong(1, 5)));
    obj.setHasbalcony(RandomUtils.nextInt(0, 2) == 1);
    obj.setHasterrace(RandomUtils.nextInt(0, 2) == 1);
    obj.setHeatingtype(BigInteger.ONE);
    obj.setHousetypology(BigInteger.ONE);
    obj.setOccupationstate(BigInteger.ONE);
    obj.setRealestatetype(BigInteger.ONE);
    obj.setReference(RandomStringUtils.randomAlphanumeric(5));
    obj.setReferenceID(RandomUtils.nextInt(1, 1000));
    obj.setRooms(BigInteger.valueOf(RandomUtils.nextLong(1, 10)));
    obj.setSize(BigInteger.valueOf(RandomUtils.nextLong(50, 5000)));

    obj.setAddress(FACTORY.createContainerRealestateitemsRealestateAddress());
    obj.getAddress().setCity("Berlin");
    obj.getAddress().setNumber("123");
    obj.getAddress().setStreet("example street");
    obj.getAddress().setZip("12345");
    obj.getAddress().setZone("Berlin");

    obj.setBox(FACTORY.createContainerRealestateitemsRealestateBox());
    obj.getBox().setSize(BigInteger.valueOf(RandomUtils.nextLong(50, 1000)));
    obj.getBox().setType(BigInteger.ONE);

    obj.setBuilding(FACTORY.createContainerRealestateitemsRealestateBuilding());
    obj.getBuilding().setAge(BigInteger.valueOf(RandomUtils.nextLong(5, 50)));
    obj.getBuilding().setExpenses(BigDecimal.valueOf(RandomUtils.nextDouble(1000, 1000000)));
    obj.getBuilding().setHaslift(RandomUtils.nextInt(0, 2) == 1);
    obj.getBuilding().setTotalfloors(BigInteger.valueOf(RandomUtils.nextLong(1, 5)));
    obj.getBuilding().setUnits(BigInteger.ONE);

    obj.setConfiguration(FACTORY.createContainerRealestateitemsRealestateConfiguration());
    obj.getConfiguration().setIsaddressvisibleonsite(RandomUtils.nextInt(0, 2) == 1);
    obj.getConfiguration().setIsmapvisible(RandomUtils.nextInt(0, 2) == 1);
    obj.getConfiguration().setIsrealestatevisibleonmap(RandomUtils.nextInt(0, 2) == 1);

    obj.setDescription(FACTORY.createContainerRealestateitemsRealestateDescription());
    obj.getDescription().setValue("a nice little description for the object");

    obj.setGarden(FACTORY.createContainerRealestateitemsRealestateGarden());
    obj.getGarden().setSize(BigInteger.valueOf(RandomUtils.nextLong(10, 100)));
    obj.getGarden().setType(BigInteger.ONE);

    obj.setGooglemapcoordinate(FACTORY.createContainerRealestateitemsRealestateGooglemapcoordinate());
    obj.getGooglemapcoordinate().setLatitude(BigDecimal.valueOf(RandomUtils.nextDouble(0, 90)));
    obj.getGooglemapcoordinate().setLatitudemapcenter(BigDecimal.valueOf(RandomUtils.nextDouble(0, 90)));
    obj.getGooglemapcoordinate().setLongitude(BigDecimal.valueOf(RandomUtils.nextDouble(0, 90)));
    obj.getGooglemapcoordinate().setLongitudemapcenter(BigDecimal.valueOf(RandomUtils.nextDouble(0, 90)));
    obj.getGooglemapcoordinate().setMapzoom(10);

    obj.setImages(FACTORY.createContainerRealestateitemsRealestateImages());
    obj.getImages().getAdvertismentimage().add(createAdvertismentimage());
    obj.getImages().getAdvertismentimage().add(createAdvertismentimage());
    obj.getImages().getAdvertismentimage().add(createAdvertismentimage());

    obj.setPrice(FACTORY.createContainerRealestateitemsRealestatePrice());
    obj.getPrice().setMax(BigDecimal.valueOf(RandomUtils.nextDouble(1000, 1000000)));
    obj.getPrice().setMin(BigDecimal.valueOf(RandomUtils.nextDouble(1000, 1000000)));
    obj.getPrice().setValue(BigDecimal.valueOf(RandomUtils.nextDouble(1000, 1000000)));

    return obj;
}

From source file:com.redhat.lightblue.metadata.types.StringTypeTest.java

@Test
public void testCompareEqual() {
    assertEquals(stringType.compare((Object) BigInteger.ONE, (Object) BigInteger.ONE), 0);
}

From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java

public KmerRangePartition[] getHistogramPartitions(KmerHistogramRecord[] records, long samples) {
    KmerRangePartition[] partitions = new KmerRangePartition[this.numPartitions];

    // calc 4^kmerSize
    String As = "";
    String Ts = "";
    for (int i = 0; i < this.kmerSize; i++) {
        As += "A";
        Ts += "T";
    }/*from   w  ww.  j ava 2s .c om*/

    long partitionWidth = samples / this.numPartitions;
    long partitionWidthRemain = partitionWidth;
    int partitionIdx = 0;
    int recordIdx = 0;
    long curRecordRemain = records[0].getFrequency();
    BigInteger nextPartitionBegin = BigInteger.ZERO;
    while (partitionIdx < this.numPartitions) {
        long diff = partitionWidthRemain - curRecordRemain;
        if (diff > 0) {
            partitionWidthRemain -= curRecordRemain;
            recordIdx++;
            if (recordIdx < records.length) {
                curRecordRemain = records[recordIdx].getFrequency();
            } else {
                break;
            }
        } else if (diff == 0) {
            BigInteger partitionBegin = nextPartitionBegin;
            BigInteger partitionEnd = null;
            if (partitionIdx == this.numPartitions - 1) {
                partitionEnd = SequenceHelper.convertToBigInteger(Ts);
            } else {
                partitionEnd = SequenceHelper
                        .convertToBigInteger((records[recordIdx].getKmer() + Ts).substring(0, this.kmerSize));
            }
            BigInteger partitionSize = partitionEnd.subtract(partitionBegin);
            partitions[partitionIdx] = new KmerRangePartition(this.kmerSize, this.numPartitions, partitionIdx,
                    partitionSize, partitionBegin, partitionEnd);

            nextPartitionBegin = partitionEnd.add(BigInteger.ONE);
            partitionIdx++;
            recordIdx++;
            if (recordIdx < records.length) {
                curRecordRemain = records[recordIdx].getFrequency();
            } else {
                break;
            }
            partitionWidthRemain = partitionWidth;
        } else {
            // in between
            BigInteger partitionBegin = nextPartitionBegin;
            BigInteger partitionEnd = null;
            if (partitionIdx == this.numPartitions - 1) {
                partitionEnd = SequenceHelper.convertToBigInteger(Ts);
            } else {
                BigInteger recordBegin = SequenceHelper
                        .convertToBigInteger((records[recordIdx].getKmer() + As).substring(0, this.kmerSize));
                BigInteger recordEnd = SequenceHelper
                        .convertToBigInteger((records[recordIdx].getKmer() + Ts).substring(0, this.kmerSize));
                BigInteger recordWidth = recordEnd.subtract(recordBegin);
                BigInteger curWidth = recordWidth.multiply(BigInteger.valueOf(partitionWidthRemain))
                        .divide(BigInteger.valueOf(records[recordIdx].getFrequency()));

                BigInteger bigger = null;
                if (recordBegin.compareTo(partitionBegin) > 0) {
                    bigger = recordBegin;
                } else {
                    bigger = partitionBegin;
                }

                partitionEnd = bigger.add(curWidth);
            }
            BigInteger partitionSize = partitionEnd.subtract(partitionBegin);
            partitions[partitionIdx] = new KmerRangePartition(this.kmerSize, this.numPartitions, partitionIdx,
                    partitionSize, partitionBegin, partitionEnd);

            nextPartitionBegin = partitionEnd.add(BigInteger.ONE);
            partitionIdx++;
            curRecordRemain -= partitionWidthRemain;
            partitionWidthRemain = partitionWidth;
        }
    }

    return partitions;
}