List of usage examples for org.apache.commons.lang3.mutable MutableInt add
public void add(final Number operand)
From source file:demo.enumj.EnumeratorDemo.java
private static void demoOfSupplier(String pre) { final MutableInt it = new MutableInt(1); final Supplier<Optional<Integer>> supl = () -> { final int val = it.getValue(); if (val > 3) { return Optional.empty(); }/*w w w . j a va 2 s . c om*/ it.add(1); return Optional.of(val); }; final Enumerator<Integer> en = Enumerator.of(supl); printLn(Enumerator.of(supl), "Elements in supplied enumerator:", pre); }
From source file:enumj.AbstractEnumeratorTest.java
@Test public void testPeek() { System.out.println("peek"); final MutableInt x = new MutableInt(0); Reversible.peek(Enumerator.on(1, 2, 3, 4, 5), e -> x.add(e), false).forEach(y -> { });/*from w w w . j av a 2 s . c o m*/ assertEquals(1 + 2 + 3 + 4 + 5, x.intValue()); Enumerable.on(1, 2, 3, 4, 5).peek(e -> x.add(e)).forEach(y -> { }); assertEquals(2 * (1 + 2 + 3 + 4 + 5), x.intValue()); }
From source file:com.romeikat.datamessie.core.base.task.scheduling.IntervalTaskSchedulingThreadTest.java
private void run(final int taskExecutionInterval, final long taskExecutionDuration, final boolean allowOverlap, final boolean throwException) throws Exception { final MutableInt numberOfTaskExecutions = new MutableInt(0); final MutableInt numberOfTaskTriggerings = new MutableInt(0); final Task task = Mockito.spy(new FooTask() { @Override//from w ww . j av a 2s. co m public void execute(final TaskExecution taskExecution) throws Exception { if (throwException) { throw new Exception(); } numberOfTaskExecutions.add(1); Thread.sleep(taskExecutionDuration); } }); final String taskName = task.getName(); // Schedule task for multiple execution final MutableObject<LocalDateTime> startOfLatestCompletedTask = new MutableObject<LocalDateTime>(); final FooIntervalTaskSchedulingThread intervalTaskSchedulingThread = new FooIntervalTaskSchedulingThread( task, taskName, taskExecutionInterval, allowOverlap, taskManager) { @Override protected boolean shouldStopTaskExecution() { return numberOfTaskTriggerings.intValue() == NUMBER_OF_TASK_EXECUTIONS; } @Override protected void onAfterTriggeringTask(final TaskExecution latestTaskExecution) { startOfLatestCompletedTask.setValue(LocalDateTime.now()); numberOfTaskTriggerings.add(1); } @Override protected LocalDateTime getActualStartOfLatestCompletedTask() { return startOfLatestCompletedTask.getValue(); } }; intervalTaskSchedulingThread.start(); // Wait until all executions are finished final long additionalWaiting = TaskManager.DEFAULT_MANAGEMENT_INTERVAL + 1000; final long timePerTaskExecution = throwException ? taskExecutionInterval : taskExecutionInterval + taskExecutionDuration; final long waitUntilTaskExecutionShouldBeFinished = NUMBER_OF_TASK_EXECUTIONS * timePerTaskExecution + additionalWaiting; Thread.sleep(waitUntilTaskExecutionShouldBeFinished); // Check executions final int expectedNumberOfTaskTriggerings = NUMBER_OF_TASK_EXECUTIONS; assertEquals(expectedNumberOfTaskTriggerings, numberOfTaskTriggerings.intValue()); final int expectedNumbeOfTaskExecutions = throwException ? 0 : NUMBER_OF_TASK_EXECUTIONS; assertEquals(expectedNumbeOfTaskExecutions, numberOfTaskExecutions.intValue()); }
From source file:com.datatorrent.lib.io.fs.AbstractFSWriter.java
/** * This method rolls over to the next files. * @param fileName The file that you are rolling. * @throws IllegalArgumentException//from ww w .j a v a 2s. co m * @throws IOException * @throws ExecutionException */ private void rotate(String fileName) throws IllegalArgumentException, IOException, ExecutionException { counts.remove(fileName); streamsCache.invalidate(fileName); MutableInt mi = openPart.get(fileName); mi.add(1); LOG.debug("Part file index: {}", openPart); endOffsets.get(fileName).setValue(0L); }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This method serializes the given byte to the given byte buffer to the given offset, * the method also increments the offset appropriately. * @param val The value to serialize./*from ww w . jav a2s.com*/ * @param buffer The byte buffer to serialize to. * @param offset The offset in the buffer to serialize to and also to increment appropriately. */ public static void serializeByte(byte val, byte[] buffer, MutableInt offset) { buffer[offset.intValue()] = val; offset.add(Type.BYTE.getByteSize()); }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This method deserializes a byte from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized byte./*from w ww. j av a 2s.c o m*/ */ public static byte deserializeByte(byte[] buffer, MutableInt offset) { byte val = buffer[offset.intValue()]; offset.add(Type.BYTE.getByteSize()); return val; }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This method deserializes a boolean from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized boolean.//from w ww .ja va2 s . c o m */ public static boolean deserializeBoolean(byte[] buffer, MutableInt offset) { boolean val = buffer[offset.intValue()] != 0; offset.add(Type.BOOLEAN.getByteSize()); return val; }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This method serializes the given boolean to the given byte buffer to the given offset, * the method also increments the offset appropriately. * @param val The value to serialize./*w ww. j a v a 2 s . co m*/ * @param buffer The byte buffer to serialize to. * @param offset The offset in the buffer to serialize to and also to increment appropriately. */ public static void serializeBoolean(boolean val, byte[] buffer, MutableInt offset) { buffer[offset.intValue()] = (byte) (val ? 1 : 0); offset.add(Type.BOOLEAN.getByteSize()); }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This method deserializes a string from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized string./*from w w w.j a va 2 s . c om*/ */ public static String deserializeString(byte[] buffer, MutableInt offset) { int length = deserializeInt(buffer, offset); String val = new String(buffer, offset.intValue(), length); offset.add(length); return val; }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This method serializes the given short to the given byte buffer to the given offset, * the method also increments the offset appropriately. * @param val The value to serialize./*from w w w.j av a2 s . com*/ * @param buffer The byte buffer to serialize to. * @param offset The offset in the buffer to serialize to and also to increment appropriately. */ public static void serializeShort(short val, byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); buffer[0 + offsetInt] = (byte) ((val >> 8) & 0xFF); buffer[1 + offsetInt] = (byte) (val & 0xFF); offset.add(Type.SHORT.getByteSize()); }