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


Java Deque.descendingIterator方法代码示例

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


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

示例1: addOrModify

import java.util.Deque; //导入方法依赖的package包/类
@Override
protected void addOrModify(Deque<DebugEntry> entries, Object message)
{
    String msg = (String)message;
    String requestId = getRequestId(msg);
    if (requestId != null)
    {
        Iterator<DebugEntry> iterator = entries.descendingIterator();
        while (iterator.hasNext())
        {
            DebugEntry entry = iterator.next();
            if (requestId.equals(entry.requestId))
            {
                entry.addLine(msg);
                return;
            }
        }
        entries.add(new DebugEntry(requestId, msg));
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:TransformerDebugLog.java

示例2: getTrailingAverage

import java.util.Deque; //导入方法依赖的package包/类
private Integer getTrailingAverage(Deque<Entry<Long, Long>> list, int seconds) {
  Entry<Long,Long> latest = list.peekLast();
  Entry<Long,Long> old = list.peekFirst();
  Iterator<Entry<Long,Long>> iter = list.descendingIterator();
  while (iter.hasNext()) {
    Entry<Long,Long> e = iter.next();
    if (e.getKey() - latest.getKey() > seconds * ONE_BILLION) {
      old = e;
      break;
    }
  }

  final long oldKey = old.getKey();
  final long latestKey = latest.getKey();
  if (oldKey == latestKey) {
    return null;
  } else {
    return (int) (100 * (old.getValue() - latest.getValue()) / (oldKey - latestKey));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:ThreadsStatsCollector.java

示例3: run

import java.util.Deque; //导入方法依赖的package包/类
public void run(Deque<Integer> deq) {
    while (deq.size() > 1) {
        Iterator<Integer> it = deq.iterator();
        it.next(); it.remove();
        it = deq.descendingIterator();
        it.next(); it.remove();
    }
    System.out.println(deq);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ChorusLine.java

示例4: isLink

import java.util.Deque; //导入方法依赖的package包/类
private static boolean isLink(
    @NonNull final FileObject file,
    @NonNull final Deque<? extends FileObject> path,
    @NullAllowed final Stats stats) {
    final long st = System.currentTimeMillis();
    boolean hasLink = false;
    try {
        final Iterator<? extends FileObject> it = path.descendingIterator();
        while (it.hasNext()) {
            final FileObject pathElement = it.next();
            if (file.getNameExt().equals(pathElement.getNameExt())) {
                try {
                    if (mockLinkTypes != null ?
                        mockLinkTypes.get(Pair.<FileObject,FileObject>of(pathElement, file)) :
                        isSameFile(file, pathElement)) {
                        hasLink = true;
                        break;
                    }
                } catch (IOException ioe) {
                    LOG.log(
                        Level.INFO,
                        "Cannot convert to cannonical files {0} and {1}",   //NOI18N
                        new Object[]{
                            file,
                            pathElement
                        });
                    LOG.log(
                        Level.FINE,
                        null,
                        ioe);
                    break;
                }
            }
        }
        return hasLink;
    } finally {
        long et = System.currentTimeMillis();
        if (stats != null) {
            stats.linkCheckTime+= (et-st);
            if (hasLink) {
                stats.linkCount++;
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:FileObjectCrawler.java

示例5: enqueueChildren

import java.util.Deque; //导入方法依赖的package包/类
private static void enqueueChildren(final Node node, final Class<?> nodeClass, final List<Field> children) {
    final Deque<Class<?>> stack = new ArrayDeque<>();

    /**
     * Here is some ugliness that can be overcome by proper ChildNode annotations
     * with proper orders. Right now we basically sort all classes up to Node
     * with super class first, as this often is the natural order, e.g. base
     * before index for an IndexNode.
     *
     * Also there are special cases as this is not true for UnaryNodes(lhs) and
     * BinaryNodes extends UnaryNode (with lhs), and TernaryNodes.
     *
     * TODO - generalize traversal with an order built on annotations and this
     * will go away.
     */
    Class<?> clazz = nodeClass;
    do {
        stack.push(clazz);
        clazz = clazz.getSuperclass();
    } while (clazz != null);

    if (node instanceof TernaryNode) {
        // HACK juggle "third"
        stack.push(stack.removeLast());
    }
    // HACK change operator order for BinaryNodes to get lhs first.
    final Iterator<Class<?>> iter = node instanceof BinaryNode ? stack.descendingIterator() : stack.iterator();

    while (iter.hasNext()) {
        final Class<?> c = iter.next();
        for (final Field f : c.getDeclaredFields()) {
            try {
                f.setAccessible(true);
                final Object child = f.get(node);
                if (child == null) {
                    continue;
                }

                if (child instanceof Node) {
                    children.add(f);
                } else if (child instanceof Collection) {
                    if (!((Collection<?>)child).isEmpty()) {
                        children.add(f);
                    }
                }
            } catch (final IllegalArgumentException | IllegalAccessException e) {
                return;
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:52,代码来源:ASTWriter.java

示例6: testTraversalEquivalence

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Various ways of traversing a collection yield same elements
 */
public void testTraversalEquivalence() {
    Collection c = impl.emptyCollection();
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    int n = rnd.nextInt(6);
    for (int i = 0; i < n; i++) c.add(impl.makeElement(i));
    ArrayList iterated = new ArrayList();
    ArrayList iteratedForEachRemaining = new ArrayList();
    ArrayList tryAdvanced = new ArrayList();
    ArrayList spliterated = new ArrayList();
    ArrayList splitonced = new ArrayList();
    ArrayList forEached = new ArrayList();
    ArrayList streamForEached = new ArrayList();
    ConcurrentLinkedQueue parallelStreamForEached = new ConcurrentLinkedQueue();
    ArrayList removeIfed = new ArrayList();
    for (Object x : c) iterated.add(x);
    c.iterator().forEachRemaining(iteratedForEachRemaining::add);
    for (Spliterator s = c.spliterator();
         s.tryAdvance(tryAdvanced::add); ) {}
    c.spliterator().forEachRemaining(spliterated::add);
    {                       // trySplit returns "strict prefix"
        Spliterator s1 = c.spliterator(), s2 = s1.trySplit();
        if (s2 != null) s2.forEachRemaining(splitonced::add);
        s1.forEachRemaining(splitonced::add);
    }
    c.forEach(forEached::add);
    c.stream().forEach(streamForEached::add);
    c.parallelStream().forEach(parallelStreamForEached::add);
    c.removeIf(e -> { removeIfed.add(e); return false; });
    boolean ordered =
        c.spliterator().hasCharacteristics(Spliterator.ORDERED);
    if (c instanceof List || c instanceof Deque)
        assertTrue(ordered);
    HashSet cset = new HashSet(c);
    assertEquals(cset, new HashSet(parallelStreamForEached));
    if (ordered) {
        assertEquals(iterated, iteratedForEachRemaining);
        assertEquals(iterated, tryAdvanced);
        assertEquals(iterated, spliterated);
        assertEquals(iterated, splitonced);
        assertEquals(iterated, forEached);
        assertEquals(iterated, streamForEached);
        assertEquals(iterated, removeIfed);
    } else {
        assertEquals(cset, new HashSet(iterated));
        assertEquals(cset, new HashSet(iteratedForEachRemaining));
        assertEquals(cset, new HashSet(tryAdvanced));
        assertEquals(cset, new HashSet(spliterated));
        assertEquals(cset, new HashSet(splitonced));
        assertEquals(cset, new HashSet(forEached));
        assertEquals(cset, new HashSet(streamForEached));
        assertEquals(cset, new HashSet(removeIfed));
    }
    if (c instanceof Deque) {
        Deque d = (Deque) c;
        ArrayList descending = new ArrayList();
        ArrayList descendingForEachRemaining = new ArrayList();
        for (Iterator it = d.descendingIterator(); it.hasNext(); )
            descending.add(it.next());
        d.descendingIterator().forEachRemaining(
            e -> descendingForEachRemaining.add(e));
        Collections.reverse(descending);
        Collections.reverse(descendingForEachRemaining);
        assertEquals(iterated, descending);
        assertEquals(iterated, descendingForEachRemaining);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:70,代码来源:Collection8Test.java

示例7: enqueueChildren

import java.util.Deque; //导入方法依赖的package包/类
private static void enqueueChildren(final Node node, final Class<?> nodeClass, final List<Field> children) {
    final Deque<Class<?>> stack = new ArrayDeque<>();

    /**
     * Here is some ugliness that can be overcome by proper ChildNode annotations
     * with proper orders. Right now we basically sort all classes up to Node
     * with super class first, as this often is the natural order, e.g. base
     * before index for an IndexNode.
     *
     * Also there are special cases as this is not true for UnaryNodes(lhs) and
     * BinaryNodes extends UnaryNode (with lhs), and TernaryNodes.
     *
     * TODO - generalize traversal with an order built on annotations and this
     * will go away.
     */
    Class<?> clazz = nodeClass;
    do {
        stack.push(clazz);
        clazz = clazz.getSuperclass();
    } while (clazz != null);

    if (node instanceof TernaryNode) {
        // HACK juggle "third"
        stack.push(stack.removeLast());
    }
    // HACK change operator order for BinaryNodes to get lhs first.
    final Iterator<Class<?>> iter = node instanceof BinaryNode ? stack.descendingIterator() : stack.iterator();

    while (iter.hasNext()) {
        final Class<?> c = iter.next();
        for (final Field f : accessibleFields.get(c)) {
            try {
                final Object child = f.get(node);
                if (child == null) {
                    continue;
                }

                if (child instanceof Node) {
                    children.add(f);
                } else if (child instanceof Collection) {
                    if (!((Collection<?>)child).isEmpty()) {
                        children.add(f);
                    }
                }
            } catch (final IllegalArgumentException | IllegalAccessException e) {
                return;
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:51,代码来源:ASTWriter.java


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