splits.offerLast(split);
/** * 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); } }
@Override public boolean offer(E e) { if (size() >= _capacity) { _linkedList.removeFirst(); } _linkedList.offerLast(e); return true; }
@Override public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { return queue.offerLast(e); }
@Override public boolean offerLast(E e) { return queue.offerLast(e); }
private void initStackAndSet() { objectStack = new LinkedList<T>(); objectsSet = new HashSet<T>(); objectStack.offerLast(firstObject); objectsSet.add(firstObject); // there is no need for using firstObject pointer anymore firstObject = null; }
@Override public boolean offerLast(T t) { lock.lock(); try { boolean ret = super.offerLast(t); notifyIfNotEmpty(); return ret; } finally { lock.unlock(); } }
@Override public boolean offerLast( E e ) { if( size() >= maxElements ) { return false; } return super.offerLast( e ); }
@Override public boolean offerLast(E element) { validateCapacityAndPollFirstIfNeeded(); return super.offerLast(element); }
public class RingGroupPrint { public static void printSquare(int min,int max){ LinkedList<Integer> list = new LinkedList<Integer>(); for (int a=min; a<=max; a++) { list.add(a); } for (int i= 0, amount = max-min +1; i<amount; i++ ){ for (Integer val: list) { System.out.print(val); } list.offerLast(list.pollFirst()); System.out.println(); } } public static void main(String[] args) { printSquare(1, 5); } }
@Impure @Override @NonFrozenRecipient public boolean offerLast(@Captured E element) { return super.offerLast(element); }
@Override public void addCost(long userId, int cost) { if (userId == context.joinedUserId.peek()) { if (cost < context.preRoundCost) { RoomContext.logger.info("{}(id:{})想加注{}。 但是小于之前{}的注码,失败!", context.usersInRoom.get(userId).getUser().getUsername(), userId, cost, context.preRoundCost); return; } context.usersInRoom.get(userId).addThisGameCost(cost); RoomContext.logger.info("{}(id:{})加注{}。",context.usersInRoom.get(userId).getUser().getUsername(), userId, cost); context.gameCosted += cost; context.preRoundCost = cost; Long pollId = context.joinedUserId.pollFirst(); context.joinedUserId.offerLast(pollId); } else { RoomContext.logger.info("{}(id:{})想加注{}, 但是还没轮到他说话。",context.usersInRoom.get(userId).getUser().getUsername(), userId, cost); } }
private void handleBricklayerRequest() { BricklayerRequest bricklayerRequest = bricklayerRequests.poll(); if (bricklayerRequest != null && bricklayerRequest.isRequestAlive()) { IManageableBricklayer bricklayer = joblessBricklayers.removeObjectNextTo(bricklayerRequest.getPosition()); if (bricklayer != null) { if (!bricklayer.setBricklayerJob(bricklayerRequest.building, bricklayerRequest.bricklayerTargetPos, bricklayerRequest.direction)) { bricklayerRequests.add(bricklayerRequest); } } else if (!bricklayerRequest.isCreationRequested()) { // if the creation hasn't been requested yet => request it. createNewToolUser(bricklayerRequest); bricklayerRequest.setCreationRequested(); bricklayerRequests.offerLast(bricklayerRequest); } else { // no bricklayer available and creation already requested => nothing to do. bricklayerRequests.offerLast(bricklayerRequest); } } }
private void handleWorkerRequest() { WorkerRequest workerRequest = workerRequests.poll(); if (workerRequest != null) { IManageableWorker worker = joblessWorkers.removeObjectNextTo(workerRequest.getPosition(), currentWorker -> currentWorker.getMovableType() == workerRequest.movableType); if (worker != null && worker.isAlive()) { worker.setWorkerJob(workerRequest.building); } else { if (!workerRequest.creationRequested) { workerRequest.creationRequested = true; createNewToolUser(workerRequest); } workerRequests.offerLast(workerRequest); } } }
@Override public boolean visitEnter(TreeNodeResult<String> node) { String id = node.getObject(); int count = node.getAttCount(); TARGET object = converter.convert(id); TreeNodeResult<TARGET> newNode = new TreeNodeResult<TARGET>( object, count); TreeNodeResult<TARGET> parent = stack.peekLast(); if (parent == null) { // le premier noeud, donc le root a retourner plus tard tree = newNode; } else { parent.add(newNode); } stack.offerLast(newNode); return true; }
@Override public boolean visitEnter(WikittyQueryResultTreeNode<String> node) { String id = node.getObject(); int count = node.getAttCount(); TARGET object = converter.convert(id); WikittyQueryResultTreeNode<TARGET> newNode = new WikittyQueryResultTreeNode<TARGET>( object, count); WikittyQueryResultTreeNode<TARGET> parent = stack.peekLast(); if (parent == null) { // le premier noeud, donc le root a retourner plus tard tree = newNode; } else { parent.add(newNode); } stack.offerLast(newNode); return true; }