本文整理汇总了Java中java.util.Deque.addFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Deque.addFirst方法的具体用法?Java Deque.addFirst怎么用?Java Deque.addFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Deque
的用法示例。
在下文中一共展示了Deque.addFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: getPath
import java.util.Deque; //导入方法依赖的package包/类
@Override
public final String getPath() {
FileNaming fileNaming = getFileName();
Deque<String> stack = new ArrayDeque<String>();
while (fileNaming != null) {
stack.addFirst(fileNaming.getName());
fileNaming = fileNaming.getParent();
}
String rootName = stack.removeFirst();
if (BaseUtilities.isWindows()) {
rootName = rootName.replace(File.separatorChar, '/');
if(rootName.startsWith("//")) { //NOI18N
// UNC root like //computer/sharedFolder
rootName += "/"; //NOI18N
}
}
StringBuilder path = new StringBuilder();
path.append(rootName);
while (!stack.isEmpty()) {
path.append(stack.removeFirst());
if (!stack.isEmpty()) {
path.append('/'); //NOI18N
}
}
return path.toString();
}
示例3: visitName
import java.util.Deque; //导入方法依赖的package包/类
/**
* Helper method for import declarations, names, and qualified names.
*/
private void visitName(Tree node) {
Deque<Name> stack = new ArrayDeque<>();
for (; node instanceof MemberSelectTree; node = ((MemberSelectTree) node).getExpression()) {
stack.addFirst(((MemberSelectTree) node).getIdentifier());
}
stack.addFirst(((IdentifierTree) node).getName());
boolean first = true;
for (Name name : stack) {
if (!first) {
token(".");
}
token(name.toString());
first = false;
}
}
示例4: readEffectiveConfig
import java.util.Deque; //导入方法依赖的package包/类
private static Map<String, Object> readEffectiveConfig(Path filePath){
Map<String, Object> config = getConfigParametersFromFile(filePath);
Deque<Map<String, Object>> configs = new ArrayDeque<>();
configs.add(config);
while (config.get(INHERIT) != null) {
String inherit = String.valueOf(config.get(INHERIT));
filePath = filePath.getParent().resolve(inherit);
config = getConfigParametersFromFile(filePath);
if (!config.isEmpty()) {
configs.addFirst(config);
}
}
Map<String, Object> effectiveConfig = configs.pollFirst();
while (!configs.isEmpty()) {
overwriteInnerProperties(effectiveConfig, configs.pollFirst());
}
effectiveConfig.remove(INHERIT);
return effectiveConfig;
}
示例5: flatten
import java.util.Deque; //导入方法依赖的package包/类
private synchronized void flatten(final boolean flattenNested) {
// We use iterative traversal as recursion may exceed the stack size limit.
final char[] chars = new char[length];
int pos = length;
// Strings are most often composed by appending to the end, which causes ConsStrings
// to be very unbalanced, with mostly single string elements on the right and a long
// linear list on the left. Traversing from right to left helps to keep the stack small
// in this scenario.
final Deque<CharSequence> stack = new ArrayDeque<>();
stack.addFirst(left);
CharSequence cs = right;
do {
if (cs instanceof ConsString) {
final ConsString cons = (ConsString) cs;
// Count the times a cons-string is traversed as part of other cons-strings being flattened.
// If it crosses a threshold we flatten the nested cons-string internally.
if (cons.state == STATE_FLATTENED || (flattenNested && ++cons.state >= STATE_THRESHOLD)) {
cs = cons.flattened(false);
} else {
stack.addFirst(cons.left);
cs = cons.right;
}
} else {
final String str = (String) cs;
pos -= str.length();
str.getChars(0, str.length(), chars, pos);
cs = stack.isEmpty() ? null : stack.pollFirst();
}
} while (cs != null);
left = new String(chars);
right = "";
state = STATE_FLATTENED;
}
示例6: createPathForRoot
import java.util.Deque; //导入方法依赖的package包/类
private static Deque<FileObject> createPathForRoot(@NonNull FileObject root) {
final Deque<FileObject> result = new ArrayDeque<>();
while (root != null) {
result.addFirst(root);
root = root.getParent();
}
return result;
}
示例7: testAddFirstOrigin
import java.util.Deque; //导入方法依赖的package包/类
@Test
public void testAddFirstOrigin() {
Deque<Integer> queue = new ArrayDeque<Integer>();
queue.addFirst(1);
queue.addFirst(2);
queue.addFirst(3);
assertThat(queue).containsExactly(3, 2, 1);
}
示例8: add
import java.util.Deque; //导入方法依赖的package包/类
/**
* Add the given request to the queue for the connection it was directed to
*/
public void add(NetworkClient.InFlightRequest request) {
String destination = request.destination;
Deque<NetworkClient.InFlightRequest> reqs = this.requests.get(destination);
if (reqs == null) {
reqs = new ArrayDeque<>();
this.requests.put(destination, reqs);
}
reqs.addFirst(request);
}
示例9: testUnshift
import java.util.Deque; //导入方法依赖的package包/类
@Test
public void testUnshift() throws ScriptException {
final Deque<Object> l = getListAdapter();
l.addFirst(0);
assertEquals(l.getFirst(), 0);
assertEquals(l.getLast(), 4);
assertEquals(l.size(), 5);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:AddAndRemoveOnListAdapterOutsideOfJavaScriptContextTest.java
示例10: initStack
import java.util.Deque; //导入方法依赖的package包/类
/**
* Initiate a stack containing, in left-to-right order, the child nodes
* covered by this spliterator
*/
@SuppressWarnings("unchecked")
protected final Deque<N> initStack() {
// Bias size to the case where leaf nodes are close to this node
// 8 is the minimum initial capacity for the ArrayDeque implementation
Deque<N> stack = new ArrayDeque<>(8);
for (int i = curNode.getChildCount() - 1; i >= curChildIndex; i--)
stack.addFirst((N) curNode.getChild(i));
return stack;
}
示例11: release
import java.util.Deque; //导入方法依赖的package包/类
private void release(DateFormat format, Locale locale)
{
synchronized( mutex )
{
Deque<DateFormat> sp = getSubpool(locale);
if( sp.size() >= poolSizePerLocale )
{
sp.addFirst(format);
}
}
}
示例12: examineBuildingsWithSunset
import java.util.Deque; //导入方法依赖的package包/类
public static Deque<BuildingWithHeight> examineBuildingsWithSunset(Iterator<Integer> sequence) {
Deque<BuildingWithHeight> stack = new ArrayDeque<>();
int c = 0;
while (sequence.hasNext()) {
Integer temp = sequence.next();
while (stack.peekFirst()!=null && temp >= stack.peekFirst().height) {
stack.removeFirst();
}
stack.addFirst(new BuildingWithHeight(c++,temp));
}
return stack;
}
开发者ID:gardncl,项目名称:elements-of-programming-interviews-solutions,代码行数:13,代码来源:ComputeBuildingsWithView.java
示例13: pushToWorklist
import java.util.Deque; //导入方法依赖的package包/类
protected static void pushToWorklist(Node expectedNode, Node actualNode, NodeMap<Node> nodeMapping, Deque<Pair<Node, Node>> workList) {
nodeMapping.set(expectedNode, actualNode);
if (expectedNode instanceof AbstractEndNode) {
/* To ensure phi nodes have been added, we handle everything before block ends. */
workList.addLast(Pair.create(expectedNode, actualNode));
} else {
workList.addFirst(Pair.create(expectedNode, actualNode));
}
}
示例14: toBitArray
import java.util.Deque; //导入方法依赖的package包/类
BitArray toBitArray(byte[] text) {
Deque<Token> symbols = new LinkedList();
for (Token token = endBinaryShift(text.length).token; token != null; token = token
.getPrevious()) {
symbols.addFirst(token);
}
BitArray bitArray = new BitArray();
for (Token symbol : symbols) {
symbol.appendTo(bitArray, text);
}
return bitArray;
}
示例15: parseTopologyTree
import java.util.Deque; //导入方法依赖的package包/类
protected synchronized void parseTopologyTree() {
if (machineNodes == null) {
Node root = getClusterTopology();
SortedSet<MachineNode> mNodes = new TreeSet<MachineNode>();
SortedSet<RackNode> rNodes = new TreeSet<RackNode>();
// dfs search of the tree.
Deque<Node> unvisited = new ArrayDeque<Node>();
Deque<Integer> distUnvisited = new ArrayDeque<Integer>();
unvisited.add(root);
distUnvisited.add(0);
for (Node n = unvisited.poll(); n != null; n = unvisited.poll()) {
int distance = distUnvisited.poll();
if (n instanceof RackNode) {
rNodes.add((RackNode) n);
mNodes.addAll(((RackNode) n).getMachinesInRack());
if (distance + 1 > maximumDistance) {
maximumDistance = distance + 1;
}
} else if (n instanceof MachineNode) {
mNodes.add((MachineNode) n);
if (distance > maximumDistance) {
maximumDistance = distance;
}
} else {
for (Node child : n.getChildren()) {
unvisited.addFirst(child);
distUnvisited.addFirst(distance+1);
}
}
}
machineNodes = Collections.unmodifiableSortedSet(mNodes);
rackNodes = Collections.unmodifiableSortedSet(rNodes);
}
}