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


Java Deque.peek方法代码示例

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


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

示例1: push

import java.util.Deque; //导入方法依赖的package包/类
private void push(String transformerName, String fromUrl, String sourceMimetype, String targetMimetype,
        long sourceSize, TransformationOptions options, Call callType)
{
    Deque<Frame> ourStack = ThreadInfo.getStack();
    Frame frame = ourStack.peek();

    if (callType == Call.TRANSFORM && frame != null && frame.callType == Call.AVAILABLE)
    {
        frame.setTransformerName(transformerName);
        frame.setSourceSize(sourceSize);
        frame.callType = Call.AVAILABLE_AND_TRANSFORM;
    }

    // Create a new frame. Logging level is set to trace if the file size is 0
    boolean origDebugOutput = ThreadInfo.setDebugOutput(ThreadInfo.getDebugOutput() && sourceSize != 0);
    frame = new Frame(frame, transformerName, fromUrl, sourceMimetype, targetMimetype, sourceSize, options, callType, origDebugOutput);
    ourStack.push(frame);
        
    if (callType == Call.TRANSFORM)
    {
        // Log the basic info about this transformation
        logBasicDetails(frame, sourceSize, options.getUse(), transformerName, (ourStack.size() == 1));
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:TransformerDebug.java

示例2: unavailableTransformer

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Called to identify a transformer that cannot be used during working out
 * available transformers.
 */
public void unavailableTransformer(ContentTransformer transformer, String sourceMimetype, String targetMimetype, long maxSourceSizeKBytes)
{
    if (isEnabled())
    {
        Deque<Frame> ourStack = ThreadInfo.getStack();
        Frame frame = ourStack.peek();

        if (frame != null)
        {
            Deque<String> isTransformableStack = ThreadInfo.getIsTransformableStack();
            String name = (!isTransformableStack.isEmpty())
                ? isTransformableStack.getFirst()
                : getName(transformer);
            boolean debug = (maxSourceSizeKBytes != 0);
            if (frame.unavailableTransformers == null)
            {
                frame.unavailableTransformers = new TreeSet<UnavailableTransformer>();
            }
            String priority = gePriority(transformer, sourceMimetype, targetMimetype);
            frame.unavailableTransformers.add(new UnavailableTransformer(name, priority, maxSourceSizeKBytes, debug));
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:28,代码来源:TransformerDebug.java

示例3: 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

示例4: 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

示例5: main

import java.util.Deque; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scann = new Scanner(System.in);
    Deque<Integer> stack = new ArrayDeque<>();
    Deque<Integer> max = new ArrayDeque<>();
    max.push(Integer.MIN_VALUE);
    int comCount = Integer.parseInt(scann.nextLine());
    String[] comm;
    for (int i = 0; i < comCount; i++) {
        comm = scann.nextLine().split("\\s+");
        switch (comm[0]){
            case "1":
                int num = Integer.parseInt(comm[1]);
                stack.push(Integer.parseInt(comm[1]));
                if (num > max.peek()) max.push(num);
                break;
            case "2":
                if(stack.pop() == max.peek()) max.pop();
                break;
            case "3":
                System.out.println(max.peek());
                break;
        }
    }
}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:25,代码来源:p02_MaximumElement.java

示例6: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public int[] maxSlidingWindow(int[] nums, int k) {
    int len = nums.length;
    if (len == 0) return nums;
    int[] res = new int[len - k + 1];
    
    Deque<Integer> dq = new LinkedList<Integer>();
    for (int i = 0; i < len; i++) {
    	while (!dq.isEmpty() && dq.peekLast() < nums[i])
    		dq.pollLast();
    	
    	dq.offer(nums[i]);
    	
    	if (i >= k - 1) {
    		res[i - k + 1] = dq.peek();
    		if (nums[i - k + 1] == dq.peek())
    			dq.pollFirst();
    	}
    }
	return res;
}
 
开发者ID:JoeZ-EE,项目名称:Aim2Offer,代码行数:21,代码来源:065_MaxInSlidingWindow.java

示例7: 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

示例8: 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

示例9: pop

import java.util.Deque; //导入方法依赖的package包/类
private void pop(Call callType, boolean suppressFinish)
{
    Deque<Frame> ourStack = ThreadInfo.getStack();
    if (!ourStack.isEmpty())
    {
        Frame frame = ourStack.peek();

        if ((frame.callType == callType) ||
            (frame.callType == Call.AVAILABLE_AND_TRANSFORM && callType == Call.AVAILABLE))
        {
            int size = ourStack.size();
            String ms = ms(System.currentTimeMillis() - frame.start);

            logInfo(frame, size, ms);
            
            boolean firstLevel = size == 1;
            if (!suppressFinish && (firstLevel || logger.isTraceEnabled()))
            {
                log(FINISHED_IN + ms +
                    (frame.callType == Call.AVAILABLE ? " Transformer NOT called" : "") +
                    (firstLevel ? "\n" : ""), 
                    firstLevel);
            }
            
            setDebugOutput(frame.origDebugOutput);
            ourStack.pop();
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:TransformerDebug.java

示例10: debug

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Log a message prefixed with the current transformation reference
 * and include a exception, suppressing the stack trace if repeated
 * as we return up the stack of transformers.
 * @param message
 */
public void debug(String message, Throwable t)
{
    if (isEnabled())
    {
        // Trim messages of the form: "Failed... : \n   reader:...\n    writer:..."
        String msg = t.getMessage();
        if (msg != null)
        {
            int i = msg.indexOf(": \n");
            if (i != -1)
            {
                msg = msg.substring(0, i);
            }
            log(message + ' ' + msg);
        }
        else
        {
            log(message);
        }
        
        
        Deque<Frame> ourStack = ThreadInfo.getStack();
        if (!ourStack.isEmpty())
        {
            Frame frame = ourStack.peek();
            frame.setFailureReason(message +' '+ getRootCauseMessage(t));
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:TransformerDebug.java

示例11: current

import java.util.Deque; //导入方法依赖的package包/类
@Nonnull
public static LogContext current() {
    final Deque<LogContext> contextQueue = CONTEXTS.get();
    if (!contextQueue.isEmpty()) {
        return contextQueue.peek();
    } else {
        throw new RuntimeException("Loggable context is absent");
    }
}
 
开发者ID:ivnik,项目名称:smartlog,代码行数:10,代码来源:SmartLog.java

示例12: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public static int[] maxSlidingWindow(int[] nums, int k) {
    Deque<Integer> deque = new ArrayDeque<>();
    int n = nums.length;
    int[] res = new int[n - k + 1];
    for (int i = 0; i < n; i++) {
        if (!deque.isEmpty() && deque.peek() == i - k) deque.poll();
        while (!deque.isEmpty() && nums[deque.peekLast()] < nums[i]) deque.pollLast();
        deque.offer(i);
        if (i >= k - 1) {
            res[i + 1 - k] = nums[deque.peek()];
        }
    }
    return res;
}
 
开发者ID:xy1m,项目名称:PlayGround,代码行数:15,代码来源:MaxSlidingWindow.java

示例13: requiresTransitiveGraph

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Returns a Graph containing only requires transitive edges
 * with transitive reduction.
 */
public Graph<String> requiresTransitiveGraph(Configuration cf,
                                             Set<String> roots)
{
    Deque<String> deque = new ArrayDeque<>(roots);
    Set<String> visited = new HashSet<>();
    Graph.Builder<String> builder = new Graph.Builder<>();

    while (deque.peek() != null) {
        String mn = deque.pop();
        if (visited.contains(mn))
            continue;

        visited.add(mn);
        builder.addNode(mn);
        cf.findModule(mn).get()
          .reference().descriptor().requires().stream()
          .filter(d -> d.modifiers().contains(TRANSITIVE)
                            || d.name().equals("java.base"))
          .map(Requires::name)
          .forEach(d -> {
              deque.add(d);
              builder.addEdge(mn, d);
          });
    }

    return builder.build().reduce();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:ModuleDotGraph.java

示例14: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public int[] maxSlidingWindow(int[] nums, int k) {
    if (k == 0) {
        return new int[0];
    }

    int n = nums.length;

    int[] result = new int[n - k + 1];
    int current = 0;

    Deque<Integer> deque = new ArrayDeque<>();

    for (int i = 0; i < n; i++) {
        while (!deque.isEmpty() && deque.peek() < i - k + 1) {
            deque.poll();
        }

        while(!deque.isEmpty() && nums[deque.peekLast()] < nums[i]) {
            deque.pollLast();
        }

        deque.offer(i);

        if (i >= k - 1) { // allowing sliding window to fit in full initially
            result[current++] = nums[deque.peek()];
        }
    }

    return result;
}
 
开发者ID:viatsko,项目名称:hack,代码行数:31,代码来源:SlidingWindowMaximum.java

示例15: getFunctionType

import java.util.Deque; //导入方法依赖的package包/类
private EnumFunctionType getFunctionType(Token tokend, Deque<Token> deque) throws ParseException
{
    Token token = (Token)deque.peek();

    if (token != null && token.getType() == EnumTokenType.BRACKET_OPEN)
    {
        EnumFunctionType enumfunctiontype1 = EnumFunctionType.parse(token.getText());
        checkNull(enumfunctiontype1, "Unknown function: " + token);
        return enumfunctiontype1;
    }
    else
    {
        EnumFunctionType enumfunctiontype = EnumFunctionType.parse(token.getText());

        if (enumfunctiontype == null)
        {
            return null;
        }
        else if (enumfunctiontype.getCountArguments() > 0)
        {
            throw new ParseException("Missing arguments: " + enumfunctiontype);
        }
        else
        {
            return enumfunctiontype;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:29,代码来源:ExpressionParser.java


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