Refine search
@Test public void iteratorModificationPoll() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(2); queue.addAll(asList(4, 5)); Iterator<Integer> iterator = queue.iterator(); assertThat(iterator.hasNext()).isTrue(); Integer element = iterator.next(); assertThat(element).isEqualTo(4); queue.poll(); exception.expect(ConcurrentModificationException.class); iterator.next(); }
/** * delete all file * * @param directory */ public static void deleteAllFile(String directory) { List<File> fileList = new ArrayList<File>(); File directoryFile = new File(directory); Queue<File> queue = new ConcurrentLinkedQueue<File>(); queue.add(directoryFile); while (!queue.isEmpty()) { File file = queue.poll(); if (file.isDirectory()) { File[] fileArray = file.listFiles(); if (fileArray != null) { queue.addAll(Arrays.asList(fileArray)); } } fileList.add(file); } for (int i = fileList.size() - 1; i >= 0; i--) { fileList.get(i).delete(); } }
protected void updateAllocation(ScoreDirector scoreDirector, Allocation originalAllocation) { Queue<Allocation> uncheckedSuccessorQueue = new ArrayDeque<>(); uncheckedSuccessorQueue.addAll(originalAllocation.getSuccessorAllocationList()); while (!uncheckedSuccessorQueue.isEmpty()) { Allocation allocation = uncheckedSuccessorQueue.remove(); boolean updated = updatePredecessorsDoneDate(scoreDirector, allocation); if (updated) { uncheckedSuccessorQueue.addAll(allocation.getSuccessorAllocationList()); } } }
@Test public void poll() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(2); assertThat(queue.size()).isEqualTo(0); queue.add(1); assertThat(queue.size()).isEqualTo(1); queue.add(2); assertThat(queue.size()).isEqualTo(2); queue.addAll(asList(3, 4, 5)); assertThat(queue.size()).isEqualTo(2); Integer peek = queue.peek(); assertThat(peek).isEqualTo(4); assertThat(queue.size()).isEqualTo(2); Integer poll = queue.poll(); assertThat(poll).isEqualTo(4); assertThat(queue.size()).isEqualTo(1); Integer secondPoll = queue.poll(); assertThat(secondPoll).isEqualTo(5); assertThat(queue.size()).isEqualTo(0); Integer emptyPoll = queue.poll(); assertThat(emptyPoll).isNull(); assertThat(queue.size()).isEqualTo(0); queue.add(1); assertThat(queue.size()).isEqualTo(1); }
/** * is has file from directory * * @param directory * @param fileSuffix * @return boolean */ public static boolean isHasFile(String directory, String fileSuffix) { boolean result = false; File directoryFile = new File(directory); Queue<File> queue = new ConcurrentLinkedQueue<File>(); queue.add(directoryFile); while (!queue.isEmpty()) { File file = queue.poll(); if (file.isDirectory()) { File[] fileArray = file.listFiles(); if (fileArray != null) { queue.addAll(Arrays.asList(fileArray)); } } else if (file.isFile()) { if (file.getName().toLowerCase().endsWith(fileSuffix.toLowerCase())) { result = true; break; } } } return result; }
public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> aClazz) { //Check class hierarchy for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; } } //Check interfaces (breadth first) Queue<Class<?>> q = new LinkedList<Class<?>>(); q.add(clazz); while (!q.isEmpty()) { Class<?> c = q.remove(); if (c != null) { if (c.isInterface()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; } } else { q.add(c.getSuperclass()); } q.addAll(Arrays.asList(c.getInterfaces())); } } return null; } }
/** * Registers the type variables for the given type and all of its superclasses and superinterfaces. */ protected void registerAllTypeVariables(Type classType) { Queue<Type> typesToRegister = new LinkedList<Type>(); Set<Type> registeredTypes = new HashSet<Type>(); typesToRegister.add(classType); while (!typesToRegister.isEmpty()) { Type typeToRegister = typesToRegister.poll(); if (typeToRegister == null || registeredTypes.contains(typeToRegister)) { continue; } registerTypeVariablesOn(typeToRegister); registeredTypes.add(typeToRegister); Class<?> rawType = extractRawTypeOf(typeToRegister); typesToRegister.add(rawType.getGenericSuperclass()); typesToRegister.addAll(Arrays.asList(rawType.getGenericInterfaces())); } }
public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> aClazz) { //Check class hierarchy for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; } } //Check interfaces (breadth first) Queue<Class<?>> q = new LinkedList<Class<?>>(); q.add(clazz); while (!q.isEmpty()) { Class<?> c = q.remove(); if (c != null) { if (c.isInterface()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; } } else { q.add(c.getSuperclass()); } q.addAll(Arrays.asList(c.getInterfaces())); } } return null; } }
List<Map<String, List<T>>> result) throws Exception { nfaState.getCompletedMatches().addAll(potentialMatches); nfaState.getCompletedMatches().poll(); List<Map<String, List<EventId>>> matchedResult = sharedBufferAccessor.extractPatterns(earliestMatch.getPreviousBufferEntry(), earliestMatch.getVersion());
/** * Helper method to traverse star-tree using BFS and write nodes into the data buffer. */ private static void writeNodes(PinotDataBuffer dataBuffer, long offset, TreeNode rootNode) { Queue<TreeNode> queue = new LinkedList<>(); queue.add(rootNode); int currentNodeId = 0; while (!queue.isEmpty()) { TreeNode node = queue.remove(); if (node._children == null) { offset = writeNode(dataBuffer, offset, node, INVALID_ID, INVALID_ID); } else { // Sort all children nodes based on dimension value List<TreeNode> sortedChildren = new ArrayList<>(node._children.values()); sortedChildren.sort((o1, o2) -> Integer.compare(o1._dimensionValue, o2._dimensionValue)); int firstChildId = currentNodeId + queue.size() + 1; int lastChildId = firstChildId + sortedChildren.size() - 1; offset = writeNode(dataBuffer, offset, node, firstChildId, lastChildId); queue.addAll(sortedChildren); } currentNodeId++; } }
final int doAnalysis(GraphView gv, InteractionFlowHandler ifh, Map<N, A> inFlow, Map<N, A> outFlow) { assert gv != null; assert ifh != null; ifh = Options.v().interactive_mode() ? ifh : InteractionFlowHandler.NONE; final List<Entry<N, A>> universe = Orderer.INSTANCE.newUniverse(graph, gv, entryInitialFlow(), isForward()); initFlow(universe, inFlow, outFlow); Queue<Entry<N, A>> q = PriorityQueue.of(universe, true); // Perform fixed point flow analysis for (int numComputations = 0;; numComputations++) { Entry<N, A> e = q.poll(); if (e == null) { return numComputations; } meetFlows(e); // Compute beforeFlow and store it. ifh.handleFlowIn(this, e.data); boolean hasChanged = flowThrough(e); ifh.handleFlowOut(this, e.data); // Update queue appropriately if (hasChanged) { q.addAll(Arrays.asList(e.out)); } } }
protected Set<SSAValue> markUsed() { Set<SSAValue> used = new HashSet<SSAValue>(aValues.size() / 2); Queue<SSAValue> q = new UniqueQueue<>(); q.addAll(aValues); while (!q.isEmpty()) { SSAValue v = q.poll(); if (v.used) { used.add(v); { SSAValue p = v.parent; if (p != null) { if (!p.used) { p.used = true; q.add(p); } } } if (v.otherParents != null) { for (SSAValue p : v.otherParents) { if (!p.used) { p.used = true; q.add(p); } } } } } return used; }
private void getNodes(RadixTreeNode<T> parent, ArrayList<T> keys, int limit) { Queue<RadixTreeNode<T>> queue = new LinkedList<RadixTreeNode<T>>(); queue.addAll(parent.getChildern()); while (!queue.isEmpty()) { RadixTreeNode<T> node = queue.remove(); if (node.isReal() == true) { keys.add(node.getValue()); } if (keys.size() == limit) { break; } queue.addAll(node.getChildern()); } }
@Test public void zeroQueueOperations() { Queue<Integer> q = Queues.<Integer>empty().get(); List<Integer> vals = Arrays.asList(1, 2, 3); assertThat(q.add(1)).as("add").isFalse(); assertThat(q.addAll(vals)).as("addAll").isFalse(); assertThat(q.offer(1)).as("offer").isFalse(); assertThat(q.peek()).as("peek").isNull(); assertThat(q.poll()).as("poll").isNull(); assertThat(q.contains(1)).as("contains").isFalse(); assertThat(q.iterator()).as("iterator").isEmpty(); assertThatExceptionOfType(NoSuchElementException.class) .as("element") .isThrownBy(q::element); assertThatExceptionOfType(NoSuchElementException.class) .as("remove") .isThrownBy(q::remove); assertThat(q.remove(1)).as("remove").isFalse(); assertThat(q.containsAll(vals)).as("containsAll").isFalse(); assertThat(q.retainAll(vals)).as("retainAll").isFalse(); assertThat(q.removeAll(vals)).as("removeAll").isFalse(); assertThatCode(q::clear).as("clear").doesNotThrowAnyException(); assertThat(q) .hasSize(0) .isEmpty(); assertThat(q.toArray()).as("toArray").isEmpty(); assertThat(q.toArray(new Integer[0])).as("toArray(empty)").isEmpty(); Integer[] array = new Integer[]{-1, -2, -3}; assertThat(q.toArray(array)).as("toArray(pre-filled)").containsExactly(null, -2, -3); }
Queue<File> queue = new ConcurrentLinkedQueue<File>(); queue.add(sourceDirectoryFile); while (!queue.isEmpty()) { File file = queue.poll(); boolean result = false; if (!file.isHidden() || includeHidden) { File[] fileArray = file.listFiles(); if (fileArray != null) { queue.addAll(Arrays.asList(fileArray));
/** * Helper method to process the filter tree and get a map from column to a list of predicates applied to it. */ private Map<String, List<Predicate>> getPredicatesMap(@Nonnull FilterQueryTree rootFilterNode) { Map<String, List<Predicate>> predicatesMap = new HashMap<>(); Queue<FilterQueryTree> queue = new LinkedList<>(); queue.add(rootFilterNode); while (!queue.isEmpty()) { FilterQueryTree filterNode = queue.remove(); List<FilterQueryTree> children = filterNode.getChildren(); if (children == null) { String columnName = filterNode.getColumn(); Predicate predicate = Predicate.newPredicate(filterNode); predicatesMap.computeIfAbsent(columnName, k -> new ArrayList<>()).add(predicate); } else { queue.addAll(children); } } return predicatesMap; }