Example usage for org.apache.commons.lang3.mutable MutableLong add

List of usage examples for org.apache.commons.lang3.mutable MutableLong add

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableLong add.

Prototype

public void add(final Number operand) 

Source Link

Document

Adds a value to the value of this instance.

Usage

From source file:org.apache.gobblin.writer.ThrottleWriterTest.java

public void testThrottleBytes() throws IOException {
    DataWriter<Void> writer = mock(DataWriter.class);
    final MutableLong mockBytes = new MutableLong();
    when(writer.bytesWritten()).thenAnswer(new Answer<Long>() {
        @Override/*from ww w.  j a va 2  s  .  c  o m*/
        public Long answer(InvocationOnMock invocation) throws Throwable {
            mockBytes.add(1L); //Delta bytes
            return mockBytes.getValue();
        }
    });

    int parallelism = 2;
    int bps = 2;
    DataWriter<Void> throttleWriter = setup(writer, parallelism, bps, ThrottleType.Bytes);

    int count = 0;
    long duration = 10L;
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(TimeUnit.SECONDS) <= duration) {
        throttleWriter.writeEnvelope(null);
        count++;
    }

    int expected = (int) (bps * duration);
    Assert.assertTrue(count <= expected + bps * 2);
    Assert.assertTrue(count >= expected - bps * 2);
}

From source file:org.apache.jorphan.math.StatCalculator.java

private void updateValueCount(T actualValue, long sampleCount) {
    MutableLong count = valuesMap.get(actualValue);
    if (count != null) {
        count.add(sampleCount);
    } else {//from   ww w  .j  a v  a 2 s  . c o  m
        // insert new value
        valuesMap.put(actualValue, new MutableLong(sampleCount));
    }
}

From source file:org.javersion.util.PersistentHashSetTest.java

@Test
public void split_till_the_end() {
    PersistentHashSet<Integer> ints = new PersistentHashSet<Integer>().conjAll(integers());
    List<Spliterator<Integer>> spliterators = new ArrayList<>();
    spliterators.add(ints.spliterator());
    int size = 0;
    while (size != spliterators.size()) {
        size = spliterators.size();/*from  w ww.  ja va2  s .  c o m*/
        for (int i = size - 1; i >= 0; i--) {
            Spliterator<Integer> spliterator = spliterators.get(i);
            Spliterator<Integer> split = spliterator.trySplit();
            if (split != null) {
                spliterators.add(split);
            }
        }
    }
    final MutableLong sum = new MutableLong(0);
    for (Spliterator<Integer> spliterator : spliterators) {
        while (spliterator.tryAdvance(i -> sum.add(i)))
            ;
    }
    Assertions.assertThat(sum.longValue()).isEqualTo(ints.stream().map(Long::new).reduce(Long::sum).get());
}