當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。