本文整理汇总了Java中org.apache.commons.lang3.mutable.MutableLong类的典型用法代码示例。如果您正苦于以下问题:Java MutableLong类的具体用法?Java MutableLong怎么用?Java MutableLong使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MutableLong类属于org.apache.commons.lang3.mutable包,在下文中一共展示了MutableLong类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPercentPoint
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
/**
* Get the value which %percent% of the values are less than. This works
* just like median (where median represents the 50% point). A typical
* desire is to see the 90% point - the value that 90% of the data points
* are below, the remaining 10% are above.
*
* @param percent
* number representing the wished percent (between <code>0</code>
* and <code>1.0</code>)
* @return the value which %percent% of the values are less than
*/
public T getPercentPoint(double percent) {
if (count <= 0) {
return ZERO;
}
if (percent >= 1.0) {
return getMax();
}
// use Math.round () instead of simple (long) to provide correct value rounding
long target = Math.round (count * percent);
try {
for (Entry<T, MutableLong> val : valuesMap.entrySet()) {
target -= val.getValue().longValue();
if (target <= 0){
return val.getKey();
}
}
} catch (ConcurrentModificationException ignored) {
// ignored. May happen occasionally, but no harm done if so.
}
return ZERO; // TODO should this be getMin()?
}
示例2: count
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Override
public <STREAM extends WindowedStream<Tuple.WindowedTuple<Long>>> STREAM count(Option... opts)
{
Function.MapFunction<T, Tuple<Long>> kVMap = new Function.MapFunction<T, Tuple<Long>>()
{
@Override
public Tuple<Long> f(T input)
{
if (input instanceof Tuple.TimestampedTuple) {
return new Tuple.TimestampedTuple<>(((Tuple.TimestampedTuple)input).getTimestamp(), 1L);
} else {
return new Tuple.TimestampedTuple<>(System.currentTimeMillis(), 1L);
}
}
};
WindowedStream<Tuple<Long>> innerstream = map(kVMap);
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = createWindowedOperator(new SumLong());
return innerstream.addOperator(windowedOperator, windowedOperator.input, windowedOperator.output, opts);
}
示例3: bucketAccessed
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
void bucketAccessed(long bucketId)
{
long now = System.currentTimeMillis();
if (accessedBucketIds.add(bucketId) || now - lastUpdateAccessTime > updateAccessTimeInterval) {
synchronized (bucketLastAccess) {
for (long id : accessedBucketIds) {
MutableLong lastAccessTime = bucketLastAccess.get(id);
if (lastAccessTime != null) {
lastAccessTime.setValue(now);
} else {
bucketLastAccess.put(id, new MutableLong(now));
}
}
}
accessedBucketIds.clear();
lastUpdateAccessTime = now;
}
}
示例4: testSimpleRemoveEmpty
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Test
public void testSimpleRemoveEmpty()
{
WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();
wqqm.setup(null);
wqqm.beginWindow(0);
QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
Query queryD = qb == null ? null : qb.getQuery();
Assert.assertEquals("The queries must match.", null, queryD);
qb = wqqm.dequeue();
queryD = qb == null ? null : qb.getQuery();
Assert.assertEquals("The queries must match.", null, queryD);
wqqm.endWindow();
wqqm.teardown();
}
示例5: testSimpleAddOneRemove
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Test
public void testSimpleAddOneRemove()
{
WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();
wqqm.setup(null);
wqqm.beginWindow(0);
Query query = new MockQuery("1");
wqqm.enqueue(query, null, new MutableLong(1L));
Query queryD = wqqm.dequeue().getQuery();
QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
Query queryD1 = qb == null ? null : qb.getQuery();
wqqm.endWindow();
wqqm.teardown();
Assert.assertEquals("The queries must match.", query, queryD);
Assert.assertEquals("The queries must match.", null, queryD1);
}
示例6: run
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Override
public void run()
{
int numLoops = totalTuples / batchSize;
for (int loopCounter = 0, tupleCounter = 0; loopCounter < numLoops; loopCounter++, tupleCounter++) {
for (int batchCounter = 0; batchCounter < batchSize; batchCounter++, tupleCounter++) {
queueManager.enqueue(new MockQuery(tupleCounter + ""), null, new MutableLong(1L));
if (rand.nextDouble() < waitMillisProb) {
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
}
}
}
示例7: createDefaultWindowedOperator
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
private WindowedOperatorImpl<Long, MutableLong, Long> createDefaultWindowedOperator()
{
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = new WindowedOperatorImpl<>();
if (useSpillable) {
sccImpl = new SpillableComplexComponentImpl(testMeta.timeStore);
// TODO: We don't yet support Spillable data structures for window state storage because SpillableMapImpl does not yet support iterating over all keys.
windowStateStorage = new InMemoryWindowedStorage<>();
SpillableWindowedPlainStorage<MutableLong> pds = new SpillableWindowedPlainStorage<>();
pds.setSpillableComplexComponent(sccImpl);
plainDataStorage = pds;
SpillableWindowedPlainStorage<Long> prs = new SpillableWindowedPlainStorage<>();
prs.setSpillableComplexComponent(sccImpl);
plainRetractionStorage = prs;
windowedOperator.addComponent("SpillableComplexComponent", sccImpl);
} else {
windowStateStorage = new InMemoryWindowedStorage<>();
plainDataStorage = new InMemoryWindowedStorage<>();
plainRetractionStorage = new InMemoryWindowedStorage<>();
}
windowedOperator.setDataStorage(plainDataStorage);
windowedOperator.setRetractionStorage(plainRetractionStorage);
windowedOperator.setWindowStateStorage(windowStateStorage);
windowedOperator.setAccumulation(new SumAccumulation());
return windowedOperator;
}
示例8: testValidation
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Test
public void testValidation() throws Exception
{
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = new WindowedOperatorImpl<>();
verifyValidationFailure(windowedOperator, "nothing is configured");
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
verifyValidationFailure(windowedOperator, "data storage is not set");
windowedOperator.setDataStorage(new InMemoryWindowedStorage<MutableLong>());
verifyValidationFailure(windowedOperator, "accumulation is not set");
windowedOperator.setAccumulation(new SumAccumulation());
windowedOperator.validate();
windowedOperator.setTriggerOption(new TriggerOption().accumulatingAndRetractingFiredPanes());
verifyValidationFailure(windowedOperator, "retracting storage is not set for ACCUMULATING_AND_RETRACTING");
windowedOperator.setRetractionStorage(new InMemoryWindowedStorage<Long>());
windowedOperator.validate();
windowedOperator.setTriggerOption(new TriggerOption().discardingFiredPanes().firingOnlyUpdatedPanes());
verifyValidationFailure(windowedOperator, "DISCARDING is not valid for option firingOnlyUpdatedPanes");
windowedOperator.setTriggerOption(new TriggerOption().accumulatingFiredPanes().firingOnlyUpdatedPanes());
windowedOperator.setRetractionStorage(null);
verifyValidationFailure(windowedOperator, "retracting storage is not set for option firingOnlyUpdatedPanes");
}
示例9: testSlidingWindowAssignment
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Test
public void testSlidingWindowAssignment()
{
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = createDefaultWindowedOperator();
windowedOperator.setWindowOption(new WindowOption.SlidingTimeWindows(Duration.millis(1000), Duration.millis(200)));
windowedOperator.setup(testMeta.operatorContext);
Tuple.WindowedTuple<Long> windowedValue = windowedOperator.getWindowedValue(new Tuple.TimestampedTuple<>(BASE + 1600L, 2L));
Collection<? extends Window> windows = windowedValue.getWindows();
Window[] winArray = windows.toArray(new Window[]{});
Assert.assertEquals(5, winArray.length);
Assert.assertEquals(BASE + 800, winArray[0].getBeginTimestamp());
Assert.assertEquals(1000, winArray[0].getDurationMillis());
Assert.assertEquals(BASE + 1000, winArray[1].getBeginTimestamp());
Assert.assertEquals(1000, winArray[1].getDurationMillis());
Assert.assertEquals(BASE + 1200, winArray[2].getBeginTimestamp());
Assert.assertEquals(1000, winArray[2].getDurationMillis());
Assert.assertEquals(BASE + 1400, winArray[3].getBeginTimestamp());
Assert.assertEquals(1000, winArray[3].getDurationMillis());
Assert.assertEquals(BASE + 1600, winArray[4].getBeginTimestamp());
Assert.assertEquals(1000, winArray[4].getDurationMillis());
windowedOperator.teardown();
}
示例10: testKeyedAccumulation
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Test
public void testKeyedAccumulation()
{
KeyedWindowedOperatorImpl<String, Long, MutableLong, Long> windowedOperator = createDefaultKeyedWindowedOperator(false);
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.millis(1000)));
windowedOperator.setup(testMeta.operatorContext);
windowedOperator.beginWindow(1);
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 100L, new KeyValPair<>("a", 2L)));
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 200L, new KeyValPair<>("a", 3L)));
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 300L, new KeyValPair<>("b", 4L)));
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 150L, new KeyValPair<>("b", 5L)));
windowedOperator.endWindow();
Assert.assertEquals(1, keyedDataStorage.size());
Assert.assertEquals(5L, keyedDataStorage.get(new Window.TimeWindow(BASE, 1000), "a").longValue());
Assert.assertEquals(9L, keyedDataStorage.get(new Window.TimeWindow(BASE, 1000), "b").longValue());
windowedOperator.teardown();
}
示例11: populateDAG
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Override
public void populateDAG(DAG dag, Configuration configuration)
{
WordGenerator inputOperator = new WordGenerator();
KeyedWindowedOperatorImpl<String, Long, MutableLong, Long> windowedOperator = new KeyedWindowedOperatorImpl<>();
Accumulation<Long, MutableLong, Long> sum = new SumAccumulation();
windowedOperator.setAccumulation(sum);
windowedOperator.setDataStorage(new InMemoryWindowedKeyedStorage<String, MutableLong>());
windowedOperator.setRetractionStorage(new InMemoryWindowedKeyedStorage<String, Long>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(1)));
windowedOperator.setTriggerOption(TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.millis(1000)).accumulatingAndRetractingFiredPanes());
//windowedOperator.setAllowedLateness(Duration.millis(14000));
ConsoleOutputOperator outputOperator = new ConsoleOutputOperator();
dag.addOperator("inputOperator", inputOperator);
dag.addOperator("windowedOperator", windowedOperator);
dag.addOperator("outputOperator", outputOperator);
dag.addStream("input_windowed", inputOperator.output, windowedOperator.input);
dag.addStream("windowed_output", windowedOperator.output, outputOperator.input);
}
示例12: populateDAG
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Override
public void populateDAG(DAG dag, Configuration configuration)
{
RandomNumberPairGenerator inputOperator = new RandomNumberPairGenerator();
WindowedOperatorImpl<MutablePair<Double, Double>, MutablePair<MutableLong, MutableLong>, Double> windowedOperator = new WindowedOperatorImpl<>();
Accumulation<MutablePair<Double, Double>, MutablePair<MutableLong, MutableLong>, Double> piAccumulation = new PiAccumulation();
windowedOperator.setAccumulation(piAccumulation);
windowedOperator.setDataStorage(new InMemoryWindowedStorage<MutablePair<MutableLong, MutableLong>>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.GlobalWindow());
windowedOperator.setTriggerOption(TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.millis(1000)).accumulatingFiredPanes());
ConsoleOutputOperator outputOperator = new ConsoleOutputOperator();
dag.addOperator("inputOperator", inputOperator);
dag.addOperator("windowedOperator", windowedOperator);
dag.addOperator("outputOperator", outputOperator);
dag.addStream("input_windowed", inputOperator.output, windowedOperator.input);
dag.addStream("windowed_output", windowedOperator.output, outputOperator.input);
}
示例13: SumTest
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
@Test
public void SumTest()
{
SumInt si = new SumInt();
SumLong sl = new SumLong();
SumFloat sf = new SumFloat();
SumDouble sd = new SumDouble();
Assert.assertEquals(new MutableInt(10), si.accumulate(si.defaultAccumulatedValue(), 10));
Assert.assertEquals(new MutableInt(11), si.accumulate(new MutableInt(1), 10));
Assert.assertEquals(new MutableInt(22), si.merge(new MutableInt(1), new MutableInt(21)));
Assert.assertEquals(new MutableLong(10L), sl.accumulate(sl.defaultAccumulatedValue(), 10L));
Assert.assertEquals(new MutableLong(22L), sl.accumulate(new MutableLong(2L), 20L));
Assert.assertEquals(new MutableLong(41L), sl.merge(new MutableLong(32L), new MutableLong(9L)));
Assert.assertEquals(new MutableFloat(9.0F), sf.accumulate(sf.defaultAccumulatedValue(), 9.0F));
Assert.assertEquals(new MutableFloat(22.5F), sf.accumulate(new MutableFloat(2.5F), 20F));
Assert.assertEquals(new MutableFloat(41.0F), sf.merge(new MutableFloat(33.1F), new MutableFloat(7.9F)));
Assert.assertEquals(new MutableDouble(9.0), sd.accumulate(sd.defaultAccumulatedValue(), 9.0));
Assert.assertEquals(new MutableDouble(22.5), sd.accumulate(new MutableDouble(2.5), 20.0));
Assert.assertEquals(new MutableDouble(41.0), sd.merge(new MutableDouble(33.1), new MutableDouble(7.9)));
}
示例14: compute_gauss_mask_0
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
/**
* Compute gauss mask 0.
*
* @param num
* the num
* @param sigma
* the sigma
* @return the double[]
*/
/*
* num ist eigentlich pointer - aufrufende Funkion nimmt an, dass num geändert
* wird. Übergebe es deswegen als MutableDouble aus CommonsLang
*/
public double[] compute_gauss_mask_0(MutableLong num, double sigma) {
int i, n;
double limit;
double[] h;
limit = LinesUtil.MASK_SIZE(LinesUtil.MAX_SIZE_MASK_0, sigma); /* Error < 0.001 on each side */
n = (int) limit;
h = new double[2 * n + 1];
for (i = -n + 1; i <= n - 1; i++)
h[n + i] = phi0(-i + 0.5, sigma) - phi0(-i - 0.5, sigma);
h[0] = 1.0 - phi0(n - 0.5, sigma);
h[2 * n] = phi0(-n + 0.5, sigma);
num.setValue(n);
return h;
}
示例15: compute_gauss_mask_1
import org.apache.commons.lang3.mutable.MutableLong; //导入依赖的package包/类
/**
* Compute gauss mask 1.
*
* @param num
* the num
* @param sigma
* the sigma
* @return the double[]
*/
/*
* num ist eigentlich pointer - aufrufende Funkion nimmt an, dass num geändert
* wird. Übergebe es deswegen als MutableDouble aus CommonsLang
*/
public double[] compute_gauss_mask_1(MutableLong num, double sigma) {
int i, n;
double limit;
double[] h;
limit = LinesUtil.MASK_SIZE(LinesUtil.MAX_SIZE_MASK_1, sigma); /* Error < 0.001 on each side */
n = (int) limit;
h = new double[2 * n + 1];
for (i = -n + 1; i <= n - 1; i++)
h[n + i] = phi1(-i + 0.5, sigma) - phi1(-i - 0.5, sigma);
h[0] = -phi1(n - 0.5, sigma);
h[2 * n] = phi1(-n + 0.5, sigma);
num.setValue(n);
return h;
}