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

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

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

Deque.size介绍

[英]Returns the number of elements in this deque.
[中]返回此数据块中的元素数。

代码示例

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

private void recordOpenCloseMethods()
{
  if ( RECORD_STATEMENTS_TRACES )
  {
    if ( statementOpenCloseCalls.size() > STATEMENT_TRACK_HISTORY_MAX_SIZE )
    {
      statementOpenCloseCalls.pop();
    }
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    statementOpenCloseCalls.add( Arrays.copyOfRange(stackTrace, 2, stackTrace.length) );
  }
}

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

/**
 * Can we send more requests to this node?
 *
 * @param node Node in question
 * @return true iff we have no requests still being sent to the given node
 */
public boolean canSendMore(String node) {
  Deque<NetworkClient.InFlightRequest> queue = requests.get(node);
  return queue == null || queue.isEmpty() ||
      (queue.peekFirst().send.completed() && queue.size() < this.maxInFlightRequestsPerConnection);
}

代码示例来源: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: 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: linkedin/parseq

private void loop() {
  //  Entering state:
  //  - _siblingActions is empty
  //  - _preOrderExecutionStack has one element
  //  - _inLoop is false
  _inLoop = true;
  try {
   do {
    _preOrderExecutionStack.pop().run();
    // currentAction could have submitted a few children actions, so we pop them out from
    // _siblingActions & push them into _preOrderExecutionStack, resulting in the desired
    // pre-order execution
    while (_siblingActions.size() > 0) {
     _preOrderExecutionStack.push(_siblingActions.pop());
    }
   } while (_preOrderExecutionStack.size() > 0);
  } finally {
   // maintain invariants
   _preOrderExecutionStack.clear();
   _siblingActions.clear();
   _inLoop = false;
  }
  //  Exiting state (even when exception is thrown):
  //  - _siblingActions is empty
  //  - _preOrderExecutionStack is empty
  //  - _inLoop is false
 }
}

代码示例来源:origin: org.junit.jupiter/junit-jupiter-api

Deque<String> actualDeque = new ArrayDeque<>(actualLines);
main: while (!expectedDeque.isEmpty()) {
  String expectedLine = expectedDeque.pop();
  int expectedLineNumber = expectedLines.size() - expectedDeque.size(); // 1-based line number
  if (actualDeque.isEmpty()) {
    fail(expectedLines, actualLines, "expected line #%d:`%s` not found - actual lines depleted",
      expectedLineNumber, snippet(expectedLine));
    actualDeque.pop();
    continue; // main
    if (expectedDeque.isEmpty()) {
      int actualRemaining = actualDeque.size();
        actualDeque.pop();
if (!actualDeque.isEmpty()) {
  fail(expectedLines, actualLines, "more actual lines than expected: %d", actualDeque.size());

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

@Override
public String readAttribute(final HttpServerExchange exchange) {
  Deque<String> res = exchange.getPathParameters().get(parameter);
  if(res == null) {
    return null;
  }else if(res.isEmpty()) {
    return "";
  } else if(res.size() ==1) {
    return res.getFirst();
  } else {
    StringBuilder sb = new StringBuilder("[");
    int i = 0;
    for(String s : res) {
      sb.append(s);
      if(++i != res.size()) {
        sb.append(", ");
      }
    }
    sb.append("]");
    return sb.toString();
  }
}

代码示例来源:origin: spotify/helios

public synchronized void exited() {
 running = false;
 exits.add(clock.now().getMillis() - startMillis);
 while (exits.size() > restartCount) {
  exits.pop();
 }
}

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

create().equals(new ArrayDeque<>(ImmutableList.of("foo")));
create().hashCode();
create().isEmpty();
create().iterator();
create().remove("foo");
create().removeAll(ImmutableList.of("foo"));
create().retainAll(ImmutableList.of("foo"));
create().size();
create().toArray();
create().toArray(new String[] {"foo"});
create().removeLastOccurrence("e");
create().push("e");
create().pop();
create().descendingIterator();

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

@Override
public String readAttribute(final HttpServerExchange exchange) {
  Deque<String> res = exchange.getQueryParameters().get(parameter);
  if(res == null) {
    return null;
  }else if(res.isEmpty()) {
    return "";
  } else if(res.size() ==1) {
    return res.getFirst();
  } else {
    StringBuilder sb = new StringBuilder("[");
    int i = 0;
    for(String s : res) {
      sb.append(s);
      if(++i != res.size()) {
        sb.append(", ");
      }
    }
    sb.append("]");
    return sb.toString();
  }
}

代码示例来源:origin: changmingxie/tcc-transaction

public void cleanAfterCompletion(Transaction transaction) {
  if (isTransactionActive() && transaction != null) {
    Transaction currentTransaction = getCurrentTransaction();
    if (currentTransaction == transaction) {
      CURRENT.get().pop();
      if (CURRENT.get().size() == 0) {
        CURRENT.remove();
      }
    } else {
      throw new SystemException("Illegal transaction when clean after completion");
    }
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

private static void printServerError(String msg,
    Deque<ComponentInfo> attributes, boolean widthError,
    PrintStream errorStream) {
  StringBuilder err = new StringBuilder();
  err.append("Vaadin DEBUG\n");
  StringBuilder indent = new StringBuilder();
  ComponentInfo ci;
  if (attributes != null) {
    while (attributes.size() > LAYERS_SHOWN) {
      attributes.pop();
    }
    while (!attributes.isEmpty()) {
      ci = attributes.pop();
      showComponent(ci.component, ci.info, err, indent, widthError);
    }
  }
  err.append("Layout problem detected: ");
  err.append(msg);
  err.append("\n");
  err.append(
      "Relative sizes were replaced by undefined sizes, components may not render as expected.\n");
  errorStream.println(err);
}

代码示例来源:origin: Atmosphere/atmosphere

/**
 * Return the next {@link java.io.File} object or {@code null} if no more files are
 * available.
 * 
 * @see #getFile()
 */
public File next() throws IOException {
  if (stack.isEmpty()) {
    current = null;
    return null;
  } else {
    current = stack.removeLast();
    if (current.isDirectory()) {
      if (stack.size() < rootCount) {
        rootCount = stack.size();
      }
      addReverse(current.listFiles());
      return next();
    } else {
      return current;
    }
  }
}

代码示例来源:origin: looly/hutool

/**
 * 切取部分数据<br>
 * 切取后的栈将减少这些元素
 * 
 * @param <T> 集合元素类型
 * @param surplusAlaDatas 原数据
 * @param partSize 每部分数据的长度
 * @return 切取出的数据或null
 */
public static <T> List<T> popPart(Deque<T> surplusAlaDatas, int partSize) {
  if (isEmpty(surplusAlaDatas)) {
    return null;
  }
  final List<T> currentAlaDatas = new ArrayList<>();
  int size = surplusAlaDatas.size();
  // 切割
  if (size > partSize) {
    for (int i = 0; i < partSize; i++) {
      currentAlaDatas.add(surplusAlaDatas.pop());
    }
  } else {
    for (int i = 0; i < size; i++) {
      currentAlaDatas.add(surplusAlaDatas.pop());
    }
  }
  return currentAlaDatas;
}

代码示例来源:origin: opensourceBIM/BIMserver

while (!stack.isEmpty()) {
  if (stack.size() > MAX_STACK_SIZE) {
    dumpEndQuery();
    throw new BimserverDatabaseException("Query stack size > 10000, probably a bug, please report");
    stack.pop();
    continue;

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

private void doBulkLoad(LoadIncrementalHFiles loadHFiles, Table table,
  Deque<LoadQueueItem> queue, RegionLocator locator, int maxRetries) throws IOException {
 int count = 0;
 Pair<byte[][], byte[][]> startEndKeys;
 while (!queue.isEmpty()) {
  // need to reload split keys each iteration.
  startEndKeys = locator.getStartEndKeys();
  if (count != 0) {
   LOG.warn("Error occurred while replicating HFiles, retry attempt " + count + " with "
     + queue.size() + " files still remaining to replicate.");
  }
  if (maxRetries != 0 && count >= maxRetries) {
   throw new IOException("Retry attempted " + count
     + " times without completing, bailing out.");
  }
  count++;
  // Try bulk load
  loadHFiles.loadHFileQueue(table, connection, queue, startEndKeys);
 }
}

代码示例来源:origin: looly/hutool

/**
 * 切取部分数据<br>
 * 切取后的栈将减少这些元素
 * 
 * @param <T> 集合元素类型
 * @param surplusAlaDatas 原数据
 * @param partSize 每部分数据的长度
 * @return 切取出的数据或null
 */
public static <T> List<T> popPart(Deque<T> surplusAlaDatas, int partSize) {
  if (isEmpty(surplusAlaDatas)) {
    return null;
  }
  final List<T> currentAlaDatas = new ArrayList<>();
  int size = surplusAlaDatas.size();
  // 切割
  if (size > partSize) {
    for (int i = 0; i < partSize; i++) {
      currentAlaDatas.add(surplusAlaDatas.pop());
    }
  } else {
    for (int i = 0; i < size; i++) {
      currentAlaDatas.add(surplusAlaDatas.pop());
    }
  }
  return currentAlaDatas;
}

代码示例来源:origin: SonarSource/sonar-java

private void checkSymbol(Symbol symbol) {
 if (!atLeastOneReference.isEmpty()) {
  int level = referenceInstance(symbol);
  if (level >= 0) {
   for (int i = 0; i < level; i++) {
    atLeastOneReference.pop();
   }
   while (atLeastOneReference.size() != outerClasses.size()) {
    atLeastOneReference.push(Boolean.TRUE);
   }
  }
 }
}

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

@Override
public void run() {
  synchronized (runnerMonitor) {
    boolean mayContinue = true;
    int itemsAtStart = taskQueue.size();
    int processedItems = 0;
    while (mayContinue) {
      processNextTask();
      processedItems++;
      // Continue processing if there is no rescheduling involved and there are events in the queue, or if yielding failed
      mayContinue = (processedItems < itemsAtStart && !taskQueue.isEmpty()) || !yield();
    }
  }
}

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

if (path.contains(name)) {
 StringBuilder message = new StringBuilder("Module Inclusion Cycle: ");
 if (path.size() == 1) {
  message.append(name).append(" includes itself directly.");
 } else {
  String current = null;
  String includer = name;
  for (int i = 0; path.size() > 0; i++) {
   current = includer;
   includer = path.pop();
   message.append("\n").append(i).append(". ")
     .append(current).append(" included by ").append(includer);
 path.push(name);
 collectIncludesRecursively(includedModule, result, path);
 path.pop();

相关文章