Java 类it.unimi.dsi.fastutil.ints.AbstractIntIterator 实例源码

项目:yalder    文件:AbstractInt2IntMap.java   
/** Returns a type-specific-set view of the keys of this map.
 *
 * <P>The view is backed by the set returned by {@link #entrySet()}. Note that
 * <em>no attempt is made at caching the result of this method</em>, as this would
 * require adding some attributes that lightweight implementations would
 * not need. Subclasses may easily override this policy by calling
 * this method and caching the result, but implementors are encouraged to
 * write more efficient ad-hoc implementations.
 *
 * @return a set view of the keys of this map; it may be safely cast to a type-specific interface.
 */
public IntSet keySet() {
 return new AbstractIntSet () {
   public boolean contains( final int k ) { return containsKey( k ); }
   public int size() { return AbstractInt2IntMap.this.size(); }
   public void clear() { AbstractInt2IntMap.this.clear(); }
   public IntIterator iterator() {
    return new AbstractIntIterator () {
      final ObjectIterator<Map.Entry<Integer,Integer>> i = entrySet().iterator();
      public int nextInt() { return ((Int2IntMap.Entry )i.next()).getIntKey(); };
      public boolean hasNext() { return i.hasNext(); }
     };
   }
  };
}
项目:yalder    文件:AbstractInt2IntMap.java   
/** Returns a type-specific-set view of the values of this map.
 *
 * <P>The view is backed by the set returned by {@link #entrySet()}. Note that
 * <em>no attempt is made at caching the result of this method</em>, as this would
 * require adding some attributes that lightweight implementations would
 * not need. Subclasses may easily override this policy by calling
 * this method and caching the result, but implementors are encouraged to
 * write more efficient ad-hoc implementations.
 *
 * @return a set view of the values of this map; it may be safely cast to a type-specific interface.
 */
public IntCollection values() {
 return new AbstractIntCollection () {
   public boolean contains( final int k ) { return containsValue( k ); }
   public int size() { return AbstractInt2IntMap.this.size(); }
   public void clear() { AbstractInt2IntMap.this.clear(); }
   public IntIterator iterator() {
    return new AbstractIntIterator () {
      final ObjectIterator<Map.Entry<Integer,Integer>> i = entrySet().iterator();
      public int nextInt() { return ((Int2IntMap.Entry )i.next()).getIntValue(); };
      public boolean hasNext() { return i.hasNext(); }
     };
   }
  };
}
项目:WebGraph    文件:ImmutableGraph.java   
/** Returns an iterator enumerating the outdegrees of the nodes of this graph.
 * 
 * @return  an iterator enumerating the outdegrees of the nodes of this graph.
 */
public IntIterator outdegrees() {
    return randomAccess() ? 
    new AbstractIntIterator() {
        private final int n = numNodes();
        private int next = 0;
        @Override
        public boolean hasNext() {
            return next < n;
        }
        @Override
        public int nextInt() {
            if ( ! hasNext() ) throw new NoSuchElementException();
            return outdegree( next++ ); 
        }
    } :
    new AbstractIntIterator() {
        private final NodeIterator nodeIterator = nodeIterator();
        @Override
        public boolean hasNext() {
            return nodeIterator.hasNext();
        }
        @Override
        public int nextInt() {
            nodeIterator.nextInt();
            return nodeIterator.outdegree();
        }
    };
}