本文整理汇总了Java中java.util.Deque类的典型用法代码示例。如果您正苦于以下问题:Java Deque类的具体用法?Java Deque怎么用?Java Deque使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deque类属于java.util包,在下文中一共展示了Deque类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPrepare
import java.util.Deque; //导入依赖的package包/类
@Test(timeout = 1000)
public void testPrepare() throws IOException {
And and = new And();
Expression first = mock(Expression.class);
Expression second = mock(Expression.class);
Deque<Expression> children = new LinkedList<Expression>();
children.add(second);
children.add(first);
and.addChildren(children);
and.prepare();
verify(first).prepare();
verify(second).prepare();
verifyNoMoreInteractions(first);
verifyNoMoreInteractions(second);
}
示例2: doBuildResolvedResult
import java.util.Deque; //导入依赖的package包/类
private List<DependentBinariesResolvedResult> doBuildResolvedResult(final NativeBinarySpecInternal target, State state, Deque<NativeBinarySpecInternal> stack) {
if (stack.contains(target)) {
onCircularDependencies(state, stack, target);
}
List<DependentBinariesResolvedResult> result = resultsCache.getIfPresent(target);
if (result != null) {
return result;
}
stack.push(target);
result = Lists.newArrayList();
List<NativeBinarySpecInternal> dependents = state.getDependents(target);
for (NativeBinarySpecInternal dependent : dependents) {
List<DependentBinariesResolvedResult> children = doBuildResolvedResult(dependent, state, stack);
result.add(new DefaultDependentBinariesResolvedResult(dependent.getId(), dependent.getProjectScopedName(), dependent.isBuildable(), isTestSuite(dependent), children));
}
stack.pop();
resultsCache.put(target, result);
return result;
}
示例3: findNextLeafNode
import java.util.Deque; //导入依赖的package包/类
/**
* Depth first search, in left-to-right order, of the node tree, using
* an explicit stack, to find the next non-empty leaf node.
*/
@SuppressWarnings("unchecked")
protected final N findNextLeafNode(Deque<N> stack) {
N n = null;
while ((n = stack.pollFirst()) != null) {
if (n.getChildCount() == 0) {
if (n.count() > 0)
return n;
} else {
for (int i = n.getChildCount() - 1; i >= 0; i--)
stack.addFirst((N) n.getChild(i));
}
}
return null;
}
示例4: testSeqPref
import java.util.Deque; //导入依赖的package包/类
public void testSeqPref() throws Exception {
JavaIndexerWorker.TEST_DO_PREFETCH = false;
final LogHandler handler = new LogHandler();
handler.expect("Using sequential iterator"); //NOI18N
final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
log.setLevel(Level.FINE);
log.addHandler(handler);
try {
SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
assertTrue(handler.isFound());
final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
while (pf.hasNext()) {
final CompileTuple ct = pf.next();
assertNull(getCache(ct.jfo));
got.offer(ct);
pf.remove();
}
assertCollectionsEqual(files,got);
} finally {
log.removeHandler(handler);
}
}
示例5: extractDims
import java.util.Deque; //导入依赖的package包/类
/**
* Accumulates a flattened list of array dimensions specifiers with type annotations, and returns
* the base type.
* <p>
* <p>Given {@code int @A @B [][] @C []}, adds {@code [[@A, @B], [@C]]} to dims and returns {@code
* int}.
*/
private static Tree extractDims(Deque<List<AnnotationTree>> dims, Tree node) {
switch (node.getKind()) {
case ARRAY_TYPE:
return extractDims(dims, ((ArrayTypeTree) node).getType());
// TODO: 22-Jul-17 missing type
/* case ANNOTATED_TYPE:
AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree) node;
if (annotatedTypeTree.getUnderlyingType().getKind() != Tree.Kind.ARRAY_TYPE) {
return node;
}
node = extractDims(dims, annotatedTypeTree.getUnderlyingType());
dims.addFirst(ImmutableList.<AnnotationTree>copyOf(annotatedTypeTree.getAnnotations()));
return node;*/
default:
return node;
}
}
示例6: main
import java.util.Deque; //导入依赖的package包/类
/**
* Main method of the example. Creates three WriterTasks and a CleanerTask
*
* @param args
*/
public static void main(String[] args) {
// Creates the Event data structure
Deque<Event> deque = new ConcurrentLinkedDeque<>();
// Creates the three WriterTask and starts them
WriterTask writer = new WriterTask(deque);
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
Thread thread = new Thread(writer);
thread.start();
}
// Creates a cleaner task and starts them
CleanerTask cleaner = new CleanerTask(deque);
cleaner.start();
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:23,代码来源:Main.java
示例7: doLoad
import java.util.Deque; //导入依赖的package包/类
private Optional<SelectedSnapshot> doLoad(final Deque<SnapshotMetadata> metadatas) throws IOException {
SnapshotMetadata metadata = metadatas.removeFirst();
File file = toSnapshotFile(metadata);
LOG.debug("doLoad {}", file);
try {
Object data = deserialize(file);
LOG.debug("deserialized data: {}", data);
return Optional.of(new SelectedSnapshot(metadata, data));
} catch (IOException e) {
LOG.error("Error loading snapshot file {}, remaining attempts: {}", file, metadatas.size(), e);
if (metadatas.isEmpty()) {
throw e;
}
return doLoad(metadatas);
}
}
示例8: chooseDbSource
import java.util.Deque; //导入依赖的package包/类
public static File chooseDbSource(Shell shell, IPreferenceStore prefStore, boolean dir) {
String pathToDump = dir ? getDirPath(shell, prefStore) : getFilePath(shell, prefStore);
if (pathToDump == null) {
return null;
}
File dumpFile = new File(pathToDump);
Deque<File> dumpHistory = stringToDumpFileHistory(prefStore.getString(PREF.DB_STORE_FILES));
dumpHistory.addFirst(dumpFile);
while (dumpHistory.size() > MAX_FILES_HISTORY) {
dumpHistory.removeLast();
}
prefStore.setValue(PREF.DB_STORE_FILES, dumpFileHistoryToPreference(dumpHistory));
prefStore.setValue(PREF.LAST_OPENED_LOCATION,
dir ? dumpFile.getAbsolutePath() : dumpFile.getParent());
return dumpFile;
}
示例9: forEachRemaining
import java.util.Deque; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super T> consumer) {
if (curNode == null)
return;
if (tryAdvanceSpliterator == null) {
if (lastNodeSpliterator == null) {
Deque<Node<T>> stack = initStack();
Node<T> leaf;
while ((leaf = findNextLeafNode(stack)) != null) {
leaf.forEach(consumer);
}
curNode = null;
}
else
lastNodeSpliterator.forEachRemaining(consumer);
}
else
while(tryAdvance(consumer)) { }
}
示例10: rewriteHistory
import java.util.Deque; //导入依赖的package包/类
@Test
public void rewriteHistory() {
navigator.onCreate(activity, null);
navigator.goTo(screen);
assertThat(navigator.currentScreen()).isEqualTo(screen);
navigator.onDestroy(activity);
navigator.rewriteHistory(activity, new HistoryRewriter() {
@Override
public void rewriteHistory(Deque<Screen> history) {
history.pop();
}
});
assertThat(navigator.currentScreen()).isEqualTo(root);
}
示例11: navigate
import java.util.Deque; //导入依赖的package包/类
@Test
public void navigate() {
when(screen.shouldShowActionBar()).thenReturn(false);
when(screen2.shouldShowActionBar()).thenReturn(true);
navigator.onCreate(activity, null);
navigator.goTo(screen);
navigator.navigate(new HistoryRewriter() {
@Override
public void rewriteHistory(Deque<Screen> history) {
history.clear();
history.push(root);
history.push(screen2);
}
});
verify(screen).onHide(activity);
verify(screen2).onShow(activity);
assertThat(navigator.currentScreen()).isEqualTo(screen2);
}
示例12: toStyleProcessorOverThreshold
import java.util.Deque; //导入依赖的package包/类
@Test
public void toStyleProcessorOverThreshold() {
final Deque<Object> contextData = new ArrayDeque<>();
contextData.add(1); // Index
final SlaData data = new SlaData();
data.setDuration(13L); // Duration;
contextData.add(data);
final JiraSlaComputations slaComputations = new JiraSlaComputations();
final SlaConfiguration slaConfiguration0 = new SlaConfiguration();
slaConfiguration0.setThreshold(14);
final SlaConfiguration slaConfiguration1 = new SlaConfiguration();
slaConfiguration1.setThreshold(12);
slaComputations.setSlaConfigurations(Arrays.asList(slaConfiguration0, slaConfiguration1));
Assert.assertEquals("invalid", resource.toStyleProcessor(slaComputations, "normal", "invalid").getValue(contextData));
}
示例13: forEachRemaining
import java.util.Deque; //导入依赖的package包/类
@Override
public void forEachRemaining(T_CONS consumer) {
if (curNode == null)
return;
if (tryAdvanceSpliterator == null) {
if (lastNodeSpliterator == null) {
Deque<N> stack = initStack();
N leaf;
while ((leaf = findNextLeafNode(stack)) != null) {
leaf.forEach(consumer);
}
curNode = null;
}
else
lastNodeSpliterator.forEachRemaining(consumer);
}
else
while(tryAdvance(consumer)) { }
}
示例14: visitDepthFirst
import java.util.Deque; //导入依赖的package包/类
private void visitDepthFirst(AST ast) {
if ( ast == null ) {
return;
}
Deque<AST> stack = new ArrayDeque<AST>();
stack.addLast( ast );
while ( !stack.isEmpty() ) {
ast = stack.removeLast();
strategy.visit( ast );
if ( ast.getNextSibling() != null ) {
stack.addLast( ast.getNextSibling() );
}
if ( ast.getFirstChild() != null ) {
stack.addLast( ast.getFirstChild() );
}
}
}
示例15: floodIndices
import java.util.Deque; //导入依赖的package包/类
private Set<Coordinate> floodIndices(final Coordinate coordinate) {
final Set<Coordinate> flood = new LinkedHashSet<>();
final Color floodColor = getColor(coordinate);
final Deque<Coordinate> queue = new LinkedList<>();
queue.add(coordinate);
while (!queue.isEmpty()) {
final Coordinate location = queue.pop();
flood.add(location);
queue.addAll(getNeighbors(location).stream()
.filter(neighbor -> floodColor.equals(getColor(neighbor)) && !flood.contains(neighbor))
.collect(Collectors.toList()));
}
return flood;
}