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


Java Deque.pollLast方法代码示例

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


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

示例1: bfsHelper

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Performs a BFS from a given starting pixel in order to determine the
 * border of the image.
 *
 * @param x the x coordinate of the starting point.
 * @param y the y coordinate of the starting point.
 */
private void bfsHelper(int x, int y) {
  Deque<Point<Integer>> queue = new ArrayDeque<>();
  queue.push(new Point<>(x, y));

  while (!queue.isEmpty()) {
    Point<Integer> popped = queue.pollLast();
    borderPoints.add(popped);

    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        Point<Integer> next = new Point<>(popped.getX() + i, popped.getY() + j);

        if (picture.contains(next) &&
            borderColor.sameColor(picture.getPixel(next.getX(), next.getY()),
                BLACK_SENSITIVITY) && !visited[next.getX()][next.getY()]) {
            visited[next.getX()][next.getY()] = true;
            queue.addLast(next);
        }
      }
    }
  }
}
 
开发者ID:catalincraciun,项目名称:scancode,代码行数:30,代码来源:CornerAnalyzer.java

示例2: setAncestorFilter

import java.util.Deque; //导入方法依赖的package包/类
private <U> void setAncestorFilter(StructuredQuery.Builder<U> queryBuilder) {
	Datastore datastore = datastoreOptions.getService();

	Deque<PathElement> ancestors = Context.getAncestors();
	Deque<PathElement> init = new LinkedList<>();
	init.addAll(ancestors);
	PathElement last = init.pollLast();

	if (last != null) {
		KeyFactory keyFactory = datastore.newKeyFactory();
		keyFactory.addAncestors(init).setKind(last.getKind());
		Key key = last.hasId() ? keyFactory.newKey(last.getId())
				: keyFactory.newKey(last.getName());
		queryBuilder.setFilter(StructuredQuery.PropertyFilter.hasAncestor(key));
	}
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:17,代码来源:SimpleGcloudDatastoreRepository.java

示例3: setAncestorFilter

import java.util.Deque; //导入方法依赖的package包/类
protected StructuredQuery.Filter setAncestorFilter(StructuredQuery.Filter filter) {
	Datastore datastore = datastoreOptions.getService();

	Deque<PathElement> ancestors = Context.getAncestors();
	Deque<PathElement> init = new LinkedList<>();
	init.addAll(ancestors);
	PathElement last = init.pollLast();

	if (last == null) {
		return filter;
	}
	else {
		KeyFactory keyFactory = datastore.newKeyFactory();
		keyFactory.addAncestors(init).setKind(last.getKind());
		Key key = last.hasId()
				? keyFactory.newKey(last.getId()) : keyFactory.newKey(last.getName());
		StructuredQuery.Filter ancestorFilter = StructuredQuery.PropertyFilter.hasAncestor(key);
		if (filter == null) {
			return ancestorFilter;
		}
		else {
			return StructuredQuery.CompositeFilter.and(filter, ancestorFilter);
		}
	}
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:26,代码来源:GcloudDatastoreQueryCreator.java

示例4: splitAndReenqueue

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Split the big batch that has been rejected and reenqueue the split batches in to the accumulator.
 * @return the number of split batches.
 */
public int splitAndReenqueue(ProducerBatch bigBatch) {
    // Reset the estimated compression ratio to the initial value or the big batch compression ratio, whichever
    // is bigger. There are several different ways to do the reset. We chose the most conservative one to ensure
    // the split doesn't happen too often.
    CompressionRatioEstimator.setEstimation(bigBatch.topicPartition.topic(), compression,
                                            Math.max(1.0f, (float) bigBatch.compressionRatio()));
    Deque<ProducerBatch> dq = bigBatch.split(this.batchSize);
    int numSplitBatches = dq.size();
    Deque<ProducerBatch> partitionDequeue = getOrCreateDeque(bigBatch.topicPartition);
    while (!dq.isEmpty()) {
        ProducerBatch batch = dq.pollLast();
        incomplete.add(batch);
        // We treat the newly split batches as if they are not even tried.
        synchronized (partitionDequeue) {
            partitionDequeue.addFirst(batch);
        }
    }
    return numSplitBatches;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:RecordAccumulator.java

示例5: createLoads

import java.util.Deque; //导入方法依赖的package包/类
private void createLoads(DefUseTree tree, ConstantTree constTree, AbstractBlockBase<?> startBlock) {
    Deque<AbstractBlockBase<?>> worklist = new ArrayDeque<>();
    worklist.add(startBlock);
    while (!worklist.isEmpty()) {
        AbstractBlockBase<?> block = worklist.pollLast();
        if (constTree.get(Flags.CANDIDATE, block)) {
            constTree.set(Flags.MATERIALIZE, block);
            // create and insert load
            insertLoad(tree.getConstant(), tree.getVariable().getValueKind(), block, constTree.getCost(block).getUsages());
        } else {
            AbstractBlockBase<?> dominated = block.getFirstDominated();
            while (dominated != null) {
                if (constTree.isMarked(dominated)) {
                    worklist.addLast(dominated);
                }
                dominated = dominated.getDominatedSibling();
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ConstantLoadOptimization.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: processStack

import java.util.Deque; //导入方法依赖的package包/类
private static void processStack(int maxMethodId, Deque<Item<RuntimeCCTNode>> stack, Plugin ... plugins) {
    while (!stack.isEmpty()) {
        Item<RuntimeCCTNode> item = stack.pollLast();
        if (item != null) {
            item.process(maxMethodId);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:RuntimeCCTNodeProcessor.java

示例8: formatConjestionDistance

import java.util.Deque; //导入方法依赖的package包/类
private Deque<Integer> formatConjestionDistance(List<RoadConditionItem> conditionItems, int eIndex, double totalDistance) {
    Deque<Integer> dists = new ArrayDeque<Integer>();
    RoadConditionItem item;
    int t;
    double maxIndex = conditionItems.get(conditionItems.size() - 1).curItemEndIndex;
    for (RoadConditionItem conditionItem : conditionItems) {
        conditionItem.curItemEndIndex = (int) (conditionItem.curItemEndIndex / maxIndex * totalDistance);
    }
    for (int i = 0; i < eIndex; i++) {
        item = conditionItems.get(i);
        if (dists.size() == 0) {
            if (item.roadConditionType > RoadConditionItem.ROAD_CONDITION_TYPE_Straightway) {
                dists.offer(i == 0 ? item.curItemEndIndex : item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex);
            }
        } else {
            t = dists.size();
            if ((t & 1) == 1) {//奇数,拥堵长度
                if (item.roadConditionType > RoadConditionItem.ROAD_CONDITION_TYPE_Straightway) {
                    dists.offer(dists.pollLast() + (item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                } else {
                    dists.offer((item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                }
            } else {//偶数,顺畅长度
                if (item.roadConditionType > RoadConditionItem.ROAD_CONDITION_TYPE_Straightway) {
                    if (dists.getLast() <= 100) {
                        dists.pollLast();
                        dists.offer(dists.pollLast() + (item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                    } else {
                        dists.offer((item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                    }
                } else {
                    dists.offer(dists.pollLast() + (item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                }
            }
        }
    }
    return dists;
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:39,代码来源:NavigatorService.java

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

示例10: deleteDirectoryContents

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Wipes out content of a directory starting from a given directory.
 *
 * @param directory to be cleaned
 * @param retain if true, the given directory will be retained.
 * @throws IOException
 */
public static void deleteDirectoryContents(File directory, boolean retain) throws IOException {
  if (!directory.isDirectory()) {
    throw new IOException("Not a directory: " + directory);
  }

  // avoid using guava's Queues.newArrayDeque() since this is a utility class that can be used in
  // all sorts of
  // contexts, some of which may use clashing guava versions... For example, when explore launches
  // a Hive query,
  // it includes hive-exec.jar which bundles guava 11 in its jar...
  Deque<File> stack = new ArrayDeque<>();
  stack.addAll(listFiles(directory));

  while (!stack.isEmpty()) {
    File file = stack.peekLast();
    List<File> files = listFiles(file);
    if (files.isEmpty()) {
      if (!file.delete()) {
        throw new IOException("Failed to delete file " + file);
      }
      stack.pollLast();
    } else {
      stack.addAll(files);
    }
  }

  if (!retain) {
    if (!directory.delete()) {
      throw new IOException("Failed to delete directory " + directory);
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:40,代码来源:DirUtils.java

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

示例12: doProcessGraphForItem

import java.util.Deque; //导入方法依赖的package包/类
@Override
@SuppressWarnings({"checkstyle:parameternumber"})
public boolean doProcessGraphForItem(final Item item, final Set<String> relations,
        final Map<String, Set<String>> relations2, final Map<String, List<String>> relationPaths,
        final RelationsReporter reporter, final RelationshipsModel model, final Set<String> notRelatedToTypes,
        final Set<String> disallowedTypes, final Set<String> visitedIds,
        // Equivalence parameters
        final boolean followEquivalence, final ItemEquivalence itemEquivalence, // Determine
                                                                                // equivalence
                                                                                // relationships
        final RelationsReporter equivalenceReporter, // Report equivalence relationships an
                                                     // equivalence jump
        final Set<String> equivalenceRelations) throws RelationPropertyNotFound {

    querySourceItem = item;

    ConnectedRelationships entityRelationships = getItemRelationships(item, model);
    disallowedTypes.clear();
    // prevents returning to the same top ItemType.
    disallowedTypes.add(item.getTypeId());
    EquivalentInfo equivalentInfo = null;
    if (followEquivalence) {
        equivalentInfo = new EquivalentInfo(itemEquivalence, equivalenceReporter, null, equivalenceRelations);
    }
    Deque<RelationshipCall> stack = new ArrayDeque<>();

    /***
     * Stop Information that will be tested by the ConnectedRelationships in order to stop the
     * graph Traversal. Initialises it for the source of the traversal.
     */
    ConditionalStopInformation stopInformation = new ConditionalStopInformation(querySourceItem);

    stack.push(new RelationshipCall(item, relations, relations2, relationPaths, new ArrayList<String>(), reporter,
            true, model, entityRelationships, null, disallowedTypes, visitedIds, notRelatedToTypes,
            // Equivalence parameters
            equivalentInfo, stopInformation));
    boolean result = false;
    while (!stack.isEmpty()) {
        RelationshipCall call = stack.pollLast();
        result = processItemInGraph(stack, call.item, call.relations, call.relations2, call.relationPaths,
                call.relationPath, call.reporter, call.top, call.model, call.entityRelationships,
                call.disallowedRelationship, call.disallowedTypes, call.visitedIds, call.notRelatedToTypes,
                call.equivalentInfo, call.stopInformation);
    }
    return result;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:47,代码来源:GraphProcessorImplIter.java


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