当前位置: 首页>>代码示例>>Java>>正文


Java Deque.push方法代码示例

本文整理汇总了Java中java.util.Deque.push方法的典型用法代码示例。如果您正苦于以下问题:Java Deque.push方法的具体用法?Java Deque.push怎么用?Java Deque.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Deque的用法示例。


在下文中一共展示了Deque.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: floodFill

import java.util.Deque; //导入方法依赖的package包/类
private void floodFill(int u, int v, int label) {
	Deque<Point> S = new LinkedList<Point>();	//stack contains pixel coordinates
	S.push(new Point(u, v));
	while (!S.isEmpty()){
		Point p = S.pop();
		int x = p.x;
		int y = p.y;
		if ((x >= 0) && (x < width) && (y >= 0) && (y < height)
				&& getLabel(x, y) == FOREGROUND) {
			setLabel(x, y, label);
			S.push(new Point(x + 1, y));
			S.push(new Point(x, y + 1));
			S.push(new Point(x, y - 1));
			S.push(new Point(x - 1, y));
		}
	}
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:18,代码来源:DepthFirstLabeling.java

示例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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:NativeDependentBinariesResolutionStrategy.java

示例3: zip

import java.util.Deque; //导入方法依赖的package包/类
public static void zip(File directory, final File zipfile) throws IOException {
  final URI base = directory.toURI();
  final Deque<File> queue = new LinkedList<>();
  queue.push(directory);
  try (final OutputStream out = new FileOutputStream(zipfile)) {
    final ZipOutputStream zout = new ZipOutputStream(out);
    while (!queue.isEmpty()) {
      directory = queue.pop();
      for (final File kid : directory.listFiles()) {
        String name = base.relativize(kid.toURI()).getPath();
        if (kid.isDirectory()) {
          queue.push(kid);
          name = name.endsWith("/") ? name : name + "/";
          zout.putNextEntry(new ZipEntry(name));
        } else {
          zout.putNextEntry(new ZipEntry(name));
          StreamUtilities.copy(kid, zout);
          zout.closeEntry();
        }
      }
    }
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:24,代码来源:CompressionUtilities.java

示例4: configurations

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Returns an ordered stream of configurations. The first element is this
 * configuration, the remaining elements are the parent configurations
 * in DFS order.
 *
 * @implNote For now, the assumption is that the number of elements will
 * be very low and so this method does not use a specialized spliterator.
 */
Stream<Configuration> configurations() {
    List<Configuration> allConfigurations = this.allConfigurations;
    if (allConfigurations == null) {
        allConfigurations = new ArrayList<>();
        Set<Configuration> visited = new HashSet<>();
        Deque<Configuration> stack = new ArrayDeque<>();
        visited.add(this);
        stack.push(this);
        while (!stack.isEmpty()) {
            Configuration layer = stack.pop();
            allConfigurations.add(layer);

            // push in reverse order
            for (int i = layer.parents.size() - 1; i >= 0; i--) {
                Configuration parent = layer.parents.get(i);
                if (!visited.contains(parent)) {
                    visited.add(parent);
                    stack.push(parent);
                }
            }
        }
        this.allConfigurations = Collections.unmodifiableList(allConfigurations);
    }
    return allConfigurations.stream();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:Configuration.java

示例5: solution

import java.util.Deque; //导入方法依赖的package包/类
public int solution(String input) {
    Deque<Character> stack = new LinkedList<>();

    for (int i = 0; i < input.length(); i++) {
        char currentChar = input.charAt(i);

        if (currentChar == '(') {
            stack.push(currentChar);
        } else if (stack.isEmpty()) {
            return 0;
        } else if (stack.peek() == pairMap.get(currentChar)) {
            stack.pop();
        }
    }

    return stack.isEmpty() ? 1 : 0;
}
 
开发者ID:webdude21,项目名称:codility-solutions,代码行数:18,代码来源:Solution.java

示例6: handleFlowForSegment

import java.util.Deque; //导入方法依赖的package包/类
private void handleFlowForSegment(Deque<Flow> executionDeque,
		Deque<Flow> resultDeque) {
	FlowBuilder<Flow> localTaskAppFlowBuilder =
			new FlowBuilder<>("Flow" + UUID.randomUUID().toString());

	if(!executionDeque.isEmpty()) {
		localTaskAppFlowBuilder.start(executionDeque.pop());

	}

	while (!executionDeque.isEmpty()) {
		localTaskAppFlowBuilder.next(executionDeque.pop());
	}

	resultDeque.push(localTaskAppFlowBuilder.end());
}
 
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:17,代码来源:ComposedRunnerJobFactory.java

示例7: solution

import java.util.Deque; //导入方法依赖的package包/类
public int solution(int[] input) {
    int blockCount = 0;

    Deque<Integer> stack = new LinkedList<>();


    for (int height : input) {
        while (stack.size() != 0 && stack.peek() > height) {
            stack.pop();
        }

        if (stack.size() == 0 || stack.peek() != height) {
            blockCount++;
            stack.push(height);
        }
    }

    return blockCount;
}
 
开发者ID:webdude21,项目名称:codility-solutions,代码行数:20,代码来源:Solution.java

示例8: pushRecycledView

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Add a view to the Recycler. This view may be reused in the function
 * {@link #popRecycledViewHolder(int)}
 *
 * @param viewHolder A viewHolder to add to the Recycler. It can no longer be used.
 */
void pushRecycledView(@NonNull ViewHolder viewHolder) {
    Deque<ViewHolder> deque = mViewHolders.get(viewHolder.getItemType());
    if (deque == null) {
        deque = new ArrayDeque<>();
        mViewHolders.put(viewHolder.getItemType(), deque);
    }
    deque.push(viewHolder);
}
 
开发者ID:Cleveroad,项目名称:AdaptiveTableLayout,代码行数:15,代码来源:Recycler.java

示例9: layers

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Returns an ordered stream of layers. The first element is is this layer,
 * the remaining elements are the parent layers in DFS order.
 *
 * @implNote For now, the assumption is that the number of elements will
 * be very low and so this method does not use a specialized spliterator.
 */
Stream<ModuleLayer> layers() {
    List<ModuleLayer> allLayers = this.allLayers;
    if (allLayers != null)
        return allLayers.stream();

    allLayers = new ArrayList<>();
    Set<ModuleLayer> visited = new HashSet<>();
    Deque<ModuleLayer> stack = new ArrayDeque<>();
    visited.add(this);
    stack.push(this);

    while (!stack.isEmpty()) {
        ModuleLayer layer = stack.pop();
        allLayers.add(layer);

        // push in reverse order
        for (int i = layer.parents.size() - 1; i >= 0; i--) {
            ModuleLayer parent = layer.parents.get(i);
            if (!visited.contains(parent)) {
                visited.add(parent);
                stack.push(parent);
            }
        }
    }

    this.allLayers = allLayers = Collections.unmodifiableList(allLayers);
    return allLayers.stream();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ModuleLayer.java

示例10: getPathFromRoot

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Constructs a path from the root of the document to the given syntax element.
 * 
 * @param element the element to start with
 * @return top-down path of SyntaxElements from the document root towards the original SyntaxElement
 */
public List<SyntaxElement> getPathFromRoot(SyntaxElement element) {
    Deque<SyntaxElement> stack = new ArrayDeque<>();
    SyntaxElement elementRef = element;
    while (elementRef != null) {
        if (isEndTag(element) ||
                (isEmptyTag(elementRef) && stack.isEmpty()) ||
                (isStartTag(elementRef) && stack.isEmpty())) {
            stack.push(elementRef);
            elementRef = elementRef.getPrevious();
            continue;
        }
        if (isStartTag(elementRef)) {
            if (isEndTag(stack.peek())) {
                SyntaxElement end = stack.peek();
                if (end.getNode().getNodeName().equals(elementRef.getNode().getNodeName())) {
                    stack.pop();
                }
            } else {
                SyntaxElement e = stack.peek();
                stack.push(elementRef);
            }
        }
        elementRef = elementRef.getPrevious();
    }
    // reverse:
    List<SyntaxElement> res = new ArrayList<>(stack.size());
    while ((elementRef = stack.poll()) != null) {
        res.add(elementRef);
    }
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:XMLSyntaxSupport.java

示例11: main

import java.util.Deque; //导入方法依赖的package包/类
public static void main(String[] args) {
	
	//Definindo a pilha do tipo string
	//Com o operador diamond do java não é necessário
	//inserir o tipo na definição em new
	//Stack<String> pilha = new Stack<>();
	
	
	//Implementa as funcionalidades da fila e de uma pilha
	Deque<String> pilha = new ArrayDeque<>();
	
	
	//Colocando um elemento na pilha
	pilha.push("O pequeno Príncipe");
	pilha.push("Don Quixote");
	
	/*
	 * A pilha ficou da seguinte maneira
	 * 
	 * don quixote
	 * O hobbit
	 * O pequeno príncipe
	 */
	
	//Pegando elemento do topo  sem remover da pilha
	System.out.println(pilha.peek());
	
	//Pegando o elemento do topo da pilha e removendo-o
	System.out.println(pilha.pop());
	System.out.println(pilha.pop());
	
}
 
开发者ID:Gigers,项目名称:Examples,代码行数:33,代码来源:Pilha.java

示例12: processSplitFlow

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Processes each node in split as a  DSL Flow.
 * @param node represents a single node in the split.
 * @return Deque of Job Flows that was obtained from the Node.
 */
private Deque<Flow> processSplitFlow(LabelledTaskNode node) {
	TaskParser taskParser = new TaskParser("split_flow", node.stringify(),
			false, true);
	ComposedRunnerVisitor splitElementVisitor = new ComposedRunnerVisitor();
	taskParser.parse().accept(splitElementVisitor);

	Deque splitElementDeque = splitElementVisitor.getFlow();
	Deque<Flow> elementFlowDeque = new LinkedList<>();
	Deque<Flow> resultFlowDeque = new LinkedList<>();

	while (!splitElementDeque.isEmpty()) {

		if (splitElementDeque.peek() instanceof TaskAppNode) {

			TaskAppNode taskAppNode = (TaskAppNode) splitElementDeque.pop();

			if (taskAppNode.hasTransitions()) {
				handleTransition(elementFlowDeque, taskAppNode);
			}
			else {
				elementFlowDeque.push(
						getTaskAppFlow(taskAppNode));
			}
		}
		else if (splitElementDeque.peek() instanceof FlowNode) {
			handleFlowForSegment(elementFlowDeque, resultFlowDeque);
			splitElementDeque.pop();
		}
	}

	return resultFlowDeque;
}
 
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:38,代码来源:ComposedRunnerJobFactory.java

示例13: computeSubstitution

import java.util.Deque; //导入方法依赖的package包/类
private final TypeName computeSubstitution(final ClassName input) {
	// If the FQ name for this type starts with the root class FQ name,
	// then it's a nested type and so the substitution will be in the
	// same relative place in the output class. Otherwise, this is
	// a supertype/superinterface.
	if (input.toString().startsWith(rootClassName.toString())) { // Nested type (or the root type itself)

		// Stack the simple names of the nested types starting at the
		// end (most deeply nested) back until we hit the root
		final Deque<String> stack = new ArrayDeque<>();
		for (ClassName iterator = input;
				!iterator.equals(rootClassName);
				iterator = iterator.enclosingClassName()) {
			stack.push(iterator.simpleName());
		}

		// Now, append the simple names to the output class
		// as nested classes
		ClassName result = outputClassName;
		while (!stack.isEmpty()) {
			result = result.nestedClass(stack.pop());
		}

		return result;
	} else { // Supertype/superinterface
		return outputClassName;
	}
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:29,代码来源:Inventory.java

示例14: toString

import java.util.Deque; //导入方法依赖的package包/类
@Override
public String toString() {
  StringBuilder result = new StringBuilder();
  if (root != null) {
    Deque<Pair<TreeNode,TreePath>> toPrint = new LinkedList<>();
    toPrint.push(new Pair<>(root, TreePath.EMPTY));
    while (!toPrint.isEmpty()) {
      Pair<TreeNode,TreePath> entry = toPrint.pop();
      TreeNode node = entry.getFirst();
      TreePath path = entry.getSecond();
      int pathLength = path.length();
      for (int i = 0; i < pathLength; i++) {
        if (i == pathLength - 1) {
          result.append(" +-");
        } else {
          result.append(path.isLeftAt(i) ? " | " : "   ");
        }
      }
      result.append(node).append('\n');
      if (node != null && !node.isTerminal()) {
        DecisionNode decisionNode = (DecisionNode) node;
        toPrint.push(new Pair<>(decisionNode.getRight(), path.extendRight()));
        toPrint.push(new Pair<>(decisionNode.getLeft(), path.extendLeft()));
      }
    }
  }
  return result.toString();
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:29,代码来源:DecisionTree.java

示例15: extractThriftUnionMetadata

import java.util.Deque; //导入方法依赖的package包/类
private ThriftStructMetadata extractThriftUnionMetadata(Type unionType)
{
    requireNonNull(unionType, "unionType is null");

    Deque<Type> stack = this.stack.get();
    if (stack.contains(unionType)) {
        String path = Stream.concat(stack.stream(), Stream.of(unionType))
                .map(type -> TypeToken.of(type).getRawType().getName())
                .collect(joining("->"));
        throw new IllegalArgumentException(
                "Circular references must be qualified with 'isRecursive' on a @ThriftField annotation in the cycle: " + path);
    }

    stack.push(unionType);
    try {
        ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(this, unionType);
        return builder.build();
    }
    finally {
        Type top = stack.pop();
        checkState(
                unionType.equals(top),
                "ThriftCatalog circularity detection stack is corrupt: expected %s, but got %s",
                unionType,
                top);
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:28,代码来源:ThriftCatalog.java


注:本文中的java.util.Deque.push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。