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

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

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

Deque.push介绍

[英]Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

This method is equivalent to #addFirst.
[中]如果可以在不违反容量限制的情况下立即将元素推送到该deque表示的堆栈上(换句话说,在该deque的开头),则在成功时返回true,如果当前没有可用空间,则抛出IllegalStateException。
此方法相当于#addFirst。

代码示例

代码示例来源:origin: graphql-java/graphql-java

boolean examiningType(String typeName) {
  if (examinedTypes.contains(typeName)) {
    return true;
  }
  examinedTypes.add(typeName);
  currentTypes.push(typeName);
  return false;
}

代码示例来源:origin: yahoo/squidb

private void setTransactionSuccessful() {
  nestedSuccessStack.pop();
  nestedSuccessStack.push(true);
}

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

/**
 * Store un-initialized variables in a temporary stack for future use.
 */
private void storePrevScopeUninitializedVariableData() {
  final ScopeData scopeData = scopeStack.peek();
  final Deque<DetailAST> prevScopeUninitializedVariableData =
      new ArrayDeque<>();
  scopeData.uninitializedVariables.forEach(prevScopeUninitializedVariableData::push);
  prevScopeUninitializedVariables.push(prevScopeUninitializedVariableData);
}

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

final String name = nameIterator.hasNext() ? nameIterator.next() : null;
final String name2 = inferAlias(exprList, node);
names.add(Util.first(name, name2));
} else {
 final Frame frame = stack.pop();
 final RelDataType rowType =
   RexUtil.createStructType(cluster.getTypeFactory(), exprList,
     names, SqlValidatorUtil.F_SUGGESTER);
 stack.push(
   new Frame(frame.rel,
     ImmutableList.of(Pair.of(frame.right.get(0).left, rowType))));

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

@Override
public void visitNode(Tree tree) {
 if (tree.is(Tree.Kind.TRY_STATEMENT)) {
  withinTry.push((TryStatementTree) tree);
  toReport.push(new ArrayList<>());
 } else if (withinStandardTryWithFinally() && ((NewClassTree) tree).symbolType().isSubtypeOf("java.lang.AutoCloseable")) {
  toReport.peek().add(tree);
 }
}

代码示例来源: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: com.h2database/h2

/**
 * Stores name of currently parsed view in a stack so it can be determined
 * during {@code prepare()}.
 *
 * @param parsingView
 *            {@code true} to store one more name, {@code false} to remove it
 *            from stack
 * @param viewName
 *            name of the view
 */
public void setParsingCreateView(boolean parsingView, String viewName) {
  // It can be recursive, thus implemented as counter.
  this.parsingView += parsingView ? 1 : -1;
  assert this.parsingView >= 0;
  if (parsingView) {
    viewNameStack.push(viewName);
  } else {
    assert viewName.equals(viewNameStack.peek());
    viewNameStack.pop();
  }
}
public String getParsingCreateViewName() {

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

public void testHoldsLockOnAllOperations() {
 create().element();
 create().offer("foo");
 create().peek();
 create().poll();
 create().remove();
 create().equals(new ArrayDeque<>(ImmutableList.of("foo")));
 create().hashCode();
 create().isEmpty();
 create().iterator();
 create().remove("foo");
 create().removeFirstOccurrence("e");
 create().removeLastOccurrence("e");
 create().push("e");
 create().pop();
 create().descendingIterator();

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

private StringBuilder dump(StringBuilder sb) {
 Deque<ASTNode> stack = new ArrayDeque<ASTNode>();
 stack.push(this);
 int tabLength = 0;
 while (!stack.isEmpty()) {
  ASTNode next = stack.peek();
  if (!next.visited) {
   sb.append(StringUtils.repeat(" ", tabLength * 3));
   sb.append(next.toString());
   sb.append("\n");
   if (next.children != null) {
    for (int i = next.children.size() - 1 ; i >= 0 ; i--) {
     stack.push((ASTNode)next.children.get(i));
    }
   }
   tabLength++;
   next.visited = true;
  } else {
   tabLength--;
   next.visited = false;
   stack.pop();
  }
 }
 return sb;
}

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

@Override
  public void multi(int count) {

    if (!initialized) {
      output = OutputFactory.newList(Math.max(1, count));
      initialized = true;
    }

    List<Object> a = OutputFactory.newList(count);
    output.add(a);
    stack.push(output);
    output = a;
    this.depth++;
  }
}

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

final String name = nameIterator.hasNext() ? nameIterator.next() : null;
final String name2 = inferAlias(exprList, node);
names.add(Util.first(name, name2));
} else {
 final Frame frame = stack.pop();
 final RelDataType rowType =
     RexUtil.createStructType(cluster.getTypeFactory(), exprList,
         names, SqlValidatorUtil.F_SUGGESTER);
 stack.push(
     new Frame(frame.rel,
         ImmutableList.of(Pair.of(frame.right.get(0).left, rowType))));

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

private void unsetTransactionSuccessful() {
  nestedSuccessStack.pop();
  nestedSuccessStack.push(false);
}

代码示例来源:origin: btraceio/btrace

Boolean val = simulatedStack.peek();
  val = val != null ? val : Boolean.FALSE;
  simulatedStack.push(val);
  if (val) return;
  break;
  simulatedStack.push(vals[vals.length - 1]);
  simulatedStack.addAll(Arrays.asList(vals));
  if (vals[1]) {
  simulatedStack.push(vals[vals.length - 1]);
  simulatedStack.addAll(Arrays.asList(vals));
  if (vals[2]) {
  simulatedStack.push(vals[vals.length - 2]);
  simulatedStack.push(vals[vals.length - 1]);
  simulatedStack.addAll(Arrays.asList(vals));
  if (vals[1] && vals[2]) {
  simulatedStack.push(vals[vals.length - 2]);
  simulatedStack.push(vals[vals.length - 1]);
  simulatedStack.addAll(Arrays.asList(vals));
  break;
  simulatedStack.push(vals[1]);
  simulatedStack.push(vals[0]);
  break;
case Opcodes.DCONST_0:

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

@Override
public void visitToken(DetailAST ast) {
  final AbstractExpressionHandler handler = handlerFactory.getHandler(this, ast,
    handlers.peek());
  handlers.push(handler);
  handler.checkIndentation();
}

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

if (!configStack.isEmpty()) {
  final DefaultConfiguration top =
    configStack.peek();
  top.addChild(conf);
configStack.push(conf);
  configStack.peek();
top.addAttribute(name, value);
final DefaultConfiguration top = configStack.peek();
top.addMessage(key, value);

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

@Override
  public void multi(int count) {

    if (!initialized) {
      output = OutputFactory.newList(count);
      initialized = true;
    }

    if (stack.isEmpty()) {
      stack.push(output);
    } else {
      stack.push(OutputFactory.newList(count));

    }
    counts.push(count);
  }
}

相关文章