/** * Adds a single input split * * @param split The input split to add */ public void addInputSplit(LocatableInputSplitWithCount split) { int localCount = split.getLocalCount(); if (minLocalCount == -1) { // first split to add this.minLocalCount = localCount; this.elementCycleCount = 1; this.splits.offerFirst(split); } else if (localCount < minLocalCount) { // split with new min local count this.nextMinLocalCount = this.minLocalCount; this.minLocalCount = localCount; // all other splits have more local host than this one this.elementCycleCount = 1; splits.offerFirst(split); } else if (localCount == minLocalCount ) { this.elementCycleCount++; this.splits.offerFirst(split); } else { if (localCount < nextMinLocalCount) { nextMinLocalCount = localCount; } splits.offerLast(split); } }
@Test public void testParseOptsMultiPuts() { Queue<String> opts = new LinkedList<>(); String cmdName = "sequentialWrite"; opts.offer("--multiPut=10"); opts.offer(cmdName); opts.offer("64"); PerformanceEvaluation.TestOptions options = null; try { options = PerformanceEvaluation.parseOpts(opts); fail("should fail"); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } ((LinkedList<String>) opts).offerFirst("--multiPut=10"); ((LinkedList<String>) opts).offerFirst("--autoFlush=true"); options = PerformanceEvaluation.parseOpts(opts); assertNotNull(options); assertNotNull(options.getCmdName()); assertEquals(cmdName, options.getCmdName()); assertTrue(options.getMultiPut() == 10); }
@Test public void testParseOptsConnCount() { Queue<String> opts = new LinkedList<>(); String cmdName = "sequentialWrite"; opts.offer("--oneCon=true"); opts.offer("--connCount=10"); opts.offer(cmdName); opts.offer("64"); PerformanceEvaluation.TestOptions options = null; try { options = PerformanceEvaluation.parseOpts(opts); fail("should fail"); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } ((LinkedList<String>) opts).offerFirst("--connCount=10"); options = PerformanceEvaluation.parseOpts(opts); assertNotNull(options); assertNotNull(options.getCmdName()); assertEquals(cmdName, options.getCmdName()); assertTrue(options.getConnCount() == 10); } }
@Override public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { return queue.offerFirst(e); }
@Override public boolean offerFirst(E e) { return queue.offerFirst(e); }
@Override public boolean offerFirst(Object paramObject) { if (_directAccess) { return super.offerFirst(paramObject); } if (isDelayLoad()) { load(); } return super.offerFirst(paramObject); }
@Override public boolean offerFirst(Object paramObject) { if (_directAccess) { return super.offerFirst(paramObject); } if (isDelayLoad()) { load(); } return super.offerFirst(paramObject); }
@Override public boolean offerFirst(E element) { validateCapacityAndPollFirstIfNeeded(); return super.offerFirst(element); }
@Override public boolean offerFirst(Object paramObject) { if (_directAccess) { return super.offerFirst(paramObject); } if (isDelayLoad()) { load(); } return super.offerFirst(paramObject); }
@Override public boolean offerFirst( E e ) { if( size() >= maxElements ) { return false; } return super.offerFirst( e ); }
@Override public boolean offerFirst(Object paramObject) { if (_directAccess) { return super.offerFirst(paramObject); } if (isDelayLoad()) { load(); } return super.offerFirst(paramObject); }
@Override public boolean offerFirst(T t) { lock.lock(); try { boolean ret = super.offerFirst(t); notifyIfNotEmpty(); return ret; } finally { lock.unlock(); } }
public class StreamHistory<T> { private final int numberOfElementsToRemember; private LinkedList<T> queue = new LinkedList<T>(); // queue will store at most numberOfElementsToRemember public StreamHistory(int numberOfElementsToRemember) { this.numberOfElementsToRemember = numberOfElementsToRemember; } public StreamHistory save(T curElem) { if (queue.size() == numberOfElementsToRemember) { queue.pollLast(); // remove last to keep only requested number of elements } queue.offerFirst(curElem); return this; } public LinkedList<T> getLastElements() { return queue; // or return immutable copy or immutable view on the queue. Depends on what you want. } }
/** * Adds a single input split * * @param split The input split to add */ public void addInputSplit(LocatableInputSplitWithCount split) { int localCount = split.getLocalCount(); if (minLocalCount == -1) { // first split to add this.minLocalCount = localCount; this.elementCycleCount = 1; this.splits.offerFirst(split); } else if (localCount < minLocalCount) { // split with new min local count this.nextMinLocalCount = this.minLocalCount; this.minLocalCount = localCount; // all other splits have more local host than this one this.elementCycleCount = 1; splits.offerFirst(split); } else if (localCount == minLocalCount ) { this.elementCycleCount++; this.splits.offerFirst(split); } else { if (localCount < nextMinLocalCount) { nextMinLocalCount = localCount; } splits.offerLast(split); } }
offerFirst(curElem);
offerFirst(curElem); return this;
@Impure @Override @NonFrozenRecipient public boolean offerFirst(@Captured E element) { return super.offerFirst(element); }
@Test public void testParseOptsMultiPuts() { Queue<String> opts = new LinkedList<>(); String cmdName = "sequentialWrite"; opts.offer("--multiPut=10"); opts.offer(cmdName); opts.offer("64"); PerformanceEvaluation.TestOptions options = null; try { options = PerformanceEvaluation.parseOpts(opts); fail("should fail"); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } ((LinkedList<String>) opts).offerFirst("--multiPut=10"); ((LinkedList<String>) opts).offerFirst("--autoFlush=true"); options = PerformanceEvaluation.parseOpts(opts); assertNotNull(options); assertNotNull(options.getCmdName()); assertEquals(cmdName, options.getCmdName()); assertTrue(options.getMultiPut() == 10); }
trajectory.offerFirst(csh);
@Test public void testParseOptsConnCount() { Queue<String> opts = new LinkedList<>(); String cmdName = "sequentialWrite"; opts.offer("--oneCon=true"); opts.offer("--connCount=10"); opts.offer(cmdName); opts.offer("64"); PerformanceEvaluation.TestOptions options = null; try { options = PerformanceEvaluation.parseOpts(opts); fail("should fail"); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } ((LinkedList<String>) opts).offerFirst("--connCount=10"); options = PerformanceEvaluation.parseOpts(opts); assertNotNull(options); assertNotNull(options.getCmdName()); assertEquals(cmdName, options.getCmdName()); assertTrue(options.getConnCount() == 10); } }