@Override public List<Cookie> loadForRequest(HttpUrl url) { if (requestCookies.isEmpty()) return Collections.emptyList(); return requestCookies.removeFirst(); } }
@Override public boolean hasNext() { if (geometriesDeque.isEmpty()) { return false; } while (geometriesDeque.peek() instanceof OGCConcreteGeometryCollection) { OGCGeometryCollection collection = (OGCGeometryCollection) geometriesDeque.pop(); for (int i = 0; i < collection.numGeometries(); i++) { geometriesDeque.push(collection.geometryN(i)); } } return !geometriesDeque.isEmpty(); }
private static boolean recursiveDelete(File file) { Deque<File> toDelete = new ArrayDeque<>(); toDelete.push(file); while (!toDelete.isEmpty()) { File target = toDelete.pop(); File[] contents = target.listFiles(); if (contents == null || contents.length == 0) { if (target.exists() && !target.delete()) { return false; } } else { toDelete.push(target); for (File f : contents) { toDelete.push(f); } } } return true; }
public void testHoldsLockOnAllOperations() { create().element(); create().offer("foo"); create().peek(); create().poll(); create().remove(); create().add("foo"); create().addAll(ImmutableList.of("foo")); create().clear(); create().equals(new ArrayDeque<>(ImmutableList.of("foo"))); create().hashCode(); create().isEmpty(); create().iterator(); create().remove("foo"); create().offerFirst("e"); create().offerLast("e"); create().removeFirst(); create().removeLast(); create().pollFirst(); create().removeFirstOccurrence("e"); create().removeLastOccurrence("e"); create().push("e"); create().pop(); create().descendingIterator();
private static void placePhi(MethodNode mth, int regNum, LiveVarAnalysis la) { List<BlockNode> blocks = mth.getBasicBlocks(); int blocksCount = blocks.size(); BitSet hasPhi = new BitSet(blocksCount); BitSet processed = new BitSet(blocksCount); Deque<BlockNode> workList = new LinkedList<>(); BitSet assignBlocks = la.getAssignBlocks(regNum); for (int id = assignBlocks.nextSetBit(0); id >= 0; id = assignBlocks.nextSetBit(id + 1)) { processed.set(id); workList.add(blocks.get(id)); } while (!workList.isEmpty()) { BlockNode block = workList.pop(); BitSet domFrontier = block.getDomFrontier(); for (int id = domFrontier.nextSetBit(0); id >= 0; id = domFrontier.nextSetBit(id + 1)) { if (!hasPhi.get(id) && la.isLive(id, regNum)) { BlockNode df = blocks.get(id); addPhi(mth, df, regNum); hasPhi.set(id); if (!processed.get(id)) { processed.set(id); workList.add(df); } } } } }
private static Map<File, Long> doScan(File file) { final Map<File, Long> results = new HashMap<File, Long>(); final Deque<File> toScan = new ArrayDeque<File>(); toScan.add(file); while (!toScan.isEmpty()) { File next = toScan.pop(); if (next.isDirectory()) { results.put(next, next.lastModified()); File[] list = next.listFiles(); if (list != null) { for (File f : list) { toScan.push(new File(f.getAbsolutePath())); } } } } return results; }
private void promoteCalls() { if (runningAsyncCalls.size() >= maxRequests) return; // Already running max capacity. if (readyAsyncCalls.isEmpty()) return; // No ready calls to promote. for (Iterator<AsyncCall> i = readyAsyncCalls.iterator(); i.hasNext(); ) { AsyncCall call = i.next(); if (runningCallsForHost(call) < maxRequestsPerHost) { i.remove(); runningAsyncCalls.add(call); executorService().execute(call); } if (runningAsyncCalls.size() >= maxRequests) return; // Reached max capacity. } }
public static Set<Class<?>> getImplementedInterfaces(Class<?> cl) { Set<Class<?>> interfaces = new HashSet<Class<?>>(); Deque<Class<?>> classes = new ArrayDeque<Class<?>>(); classes.add(cl); while (!classes.isEmpty()) { Class<?> c = classes.pop(); interfaces.addAll(Arrays.asList(c.getInterfaces())); if (c.getSuperclass() != null) { classes.add(c.getSuperclass()); } classes.addAll(Arrays.asList(c.getInterfaces())); } return interfaces; }
/** * @param closeable object to close at shutdown * @return {@code true} iff this is the first object to be registered * @throws IllegalStateException if already shutting down */ public boolean addCloseable(Closeable closeable) { Objects.requireNonNull(closeable); Preconditions.checkState(!triggered, "Can't add closeable %s; already shutting down", closeable); synchronized (closeAtShutdown) { boolean wasFirst = closeAtShutdown.isEmpty(); closeAtShutdown.push(closeable); return wasFirst; } }
@Override public Activity startActivity(String activityName) { if (Thread.currentThread() != mainThread) { return OFF_THREAD_ACTIVITY; } ActivityInfo newActivity = new ActivityInfo(activityName).initialize(); if (!activityStack.isEmpty()) { ActivityInfo currentActivity = activityStack.peek(); currentActivity.ownTime += newActivity.startTime - ((currentActivity.resumeTime > 0) ? currentActivity.resumeTime : currentActivity.startTime); currentActivity.ownMem += (currentActivity.startMem - newActivity.startMem > 0) ? currentActivity.startMem - newActivity.startMem : 0; } activityStack.push(newActivity); return activityInstance; }
@Override protected LocatedFileStatus computeNext() { while (true) { while (remoteIterator.hasNext()) { LocatedFileStatus status = getLocatedFileStatus(remoteIterator); // Ignore hidden files and directories. Hive ignores files starting with _ and . as well. String fileName = status.getPath().getName(); if (fileName.startsWith("_") || fileName.startsWith(".")) { continue; } if (status.isDirectory()) { switch (nestedDirectoryPolicy) { case IGNORED: continue; case RECURSE: paths.add(status.getPath()); continue; case FAIL: throw new NestedDirectoryNotAllowedException(); } } return status; } if (paths.isEmpty()) { return endOfData(); } remoteIterator = getLocatedFileStatusRemoteIterator(paths.removeFirst()); } }
private void moveToNext() { if (nextBlank && !this.iterators.isEmpty()) { if (!iterators.peek().hasNext()) { iterators.removeFirst(); moveToNext(); } else { final Object next = iterators.peekFirst().next(); if (next instanceof Iterator) { push((Iterator<?>) next); moveToNext(); } else { this.next = (T) next; nextBlank = false; } } } }
/** * Submit a fetch task if remainingBytes is smaller than prefetchTriggerBytes. */ private void fetchIfNeeded(long remainingBytes) { if ((fetchFutures.isEmpty() || fetchFutures.peekLast().isDone()) && remainingBytes <= prefetchConfig.getPrefetchTriggerBytes()) { Future<Void> fetchFuture = fetchExecutor.submit(() -> { fetch(); return null; }); fetchFutures.add(fetchFuture); } }
/** */ private void changeServer() { if (!backups.isEmpty()) { backups.addLast(primary); primary = backups.removeFirst(); try { ch.close(); } catch (Exception ignored) { } ch = null; } } }
@Override public void run() { Deque<IgniteBiTuple<Integer, Path>> queue = new ArrayDeque<>(); queue.add(F.t(0, dir)); U.awaitQuiet(barrier); while (!queue.isEmpty()) { IgniteBiTuple<Integer, Path> t = queue.pollFirst(); int curDepth = t.getKey(); Path curPath = t.getValue(); if (curDepth <= depth) { int newDepth = curDepth + 1; // Create directories. for (int i = 0; i < entryCnt; i++) { Path subDir = new Path(curPath, "dir-" + newDepth + "-" + i); try { if (fs.mkdirs(subDir)) queue.addLast(F.t(newDepth, subDir)); } catch (IOException e) { err.compareAndSet(null, e); } } } } } }, THREAD_CNT);
/** * Sorts a given set of payloads topologically based on the DAG. This method requires all the * payloads to be in the DAG. * * @param payloads the set of input payloads * @return the payloads after topological sort */ public List<T> sortTopologically(Set<T> payloads) { List<T> result = new ArrayList<>(); Set<T> input = new HashSet<>(payloads); Deque<DirectedAcyclicGraphNode<T>> toVisit = new ArrayDeque<>(mRoots); while (!toVisit.isEmpty()) { DirectedAcyclicGraphNode<T> visit = toVisit.removeFirst(); T payload = visit.getPayload(); if (input.remove(payload)) { result.add(visit.getPayload()); } toVisit.addAll(visit.getChildren()); } Preconditions.checkState(input.isEmpty(), "Not all the given payloads are in the DAG: ", input); return result; }