java.util.Deque.isEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(221)

本文整理了Java中java.util.Deque.isEmpty()方法的一些代码示例,展示了Deque.isEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Deque.isEmpty()方法的具体详情如下:
包路径:java.util.Deque
类名称:Deque
方法名:isEmpty

Deque.isEmpty介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

@Override public List<Cookie> loadForRequest(HttpUrl url) {
  if (requestCookies.isEmpty()) return Collections.emptyList();
  return requestCookies.removeFirst();
 }
}

代码示例来源:origin: com.h2database/h2

public String getParsingCreateViewName() {
  if (viewNameStack.isEmpty()) {
    return null;
  }
  return viewNameStack.peek();
}

代码示例来源:origin: prestodb/presto

@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();
}

代码示例来源:origin: ehcache/ehcache3

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;
}

代码示例来源:origin: neo4j/neo4j

@Override
public void endBlock()
{
  if ( stateStack.isEmpty() )
  {
    throw new IllegalStateException( "Unbalanced blocks" );
  }
  stateStack.pop().endBlock();
}

代码示例来源:origin: google/guava

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();

代码示例来源:origin: lettuce-io/lettuce-core

@Override
public void complete(int depth) {
  if (counts.isEmpty()) {
    return;
  }
  if (depth == stack.size()) {
    if (stack.peek().size() == counts.peek()) {
      List<Object> pop = stack.pop();
      counts.pop();
      if (!stack.isEmpty()) {
        stack.peek().add(pop);
      }
    }
  }
}

代码示例来源:origin: skylot/jadx

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);
        }
      }
    }
  }
}

代码示例来源:origin: wildfly/wildfly

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;
}

代码示例来源:origin: prestodb/presto

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.
 }
}

代码示例来源:origin: querydsl/querydsl

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;
}

代码示例来源:origin: OryxProject/oryx

/**
 * @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;
 }
}

代码示例来源:origin: MovingBlocks/Terasology

@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;
}

代码示例来源:origin: prestodb/presto

@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());
  }
}

代码示例来源:origin: cucumber/cucumber-jvm

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;
      }
    }
  }
}

代码示例来源:origin: apache/incubator-druid

/**
 * 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);
 }
}

代码示例来源:origin: apache/hive

private void walkSubtree(Operator<?> root) {
 Deque<Operator<?>> deque = new LinkedList<>();
 deque.add(root);
 while (!deque.isEmpty()) {
  Operator<?> op = deque.pollLast();
  mark(op);
  if (op instanceof ReduceSinkOperator) {
   // Done with this branch
  } else {
   deque.addAll(op.getChildOperators());
  }
 }
}

代码示例来源:origin: apache/ignite

/** */
  private void changeServer() {
    if (!backups.isEmpty()) {
      backups.addLast(primary);

      primary = backups.removeFirst();

      try {
        ch.close();
      }
      catch (Exception ignored) {
      }

      ch = null;
    }
  }
}

代码示例来源:origin: apache/ignite

@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);

代码示例来源:origin: Alluxio/alluxio

/**
 * 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;
}

相关文章