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


Java AbstractIterator类代码示例

本文整理汇总了Java中com.google.common.collect.AbstractIterator的典型用法代码示例。如果您正苦于以下问题:Java AbstractIterator类的具体用法?Java AbstractIterator怎么用?Java AbstractIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: iterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Provides an efficient summary of the changes, without doing too much unnecessary work.
 * - Will only emit changes of a single type (from a single delegate change set)
 * - Will return no more than the specified maximum of number of changes
 */
public Iterator<TaskStateChange> iterator() {

    return new AbstractIterator<TaskStateChange>() {
        Iterator<TaskStateChange> changes;
        int count;

        @Override
        protected TaskStateChange computeNext() {
            if (changes == null) {
                changes = firstDirtyIterator();
            }

            if (count < maxReportedChanges && changes != null && changes.hasNext()) {
                count++;
                return changes.next();
            }
            return endOfData();
        }
    };
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:SummaryTaskStateChanges.java

示例2: iterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Iterator over all present inhabitants of ordinal domain.
 * @return snapshot iterator of elements in ordinal domain.
 */
@Override
public Iterator<E> iterator() {
  return new AbstractIterator<E>() {
    private final int length = length();
    private int index = 0;

    @Override
    protected E computeNext() {
      int p = index++;
      if (p < length) {
        return get(p);
      }
      return endOfData();
    }
  };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:OrdinalDomain.java

示例3: metrics

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
@Override public Iterable<AbstractMetric> metrics() {
  return new Iterable<AbstractMetric>() {
    final Iterator<AbstractMetric> it = delegate.metrics().iterator();
    @Override public Iterator<AbstractMetric> iterator() {
      return new AbstractIterator<AbstractMetric>() {
        @Override public AbstractMetric computeNext() {
          while (it.hasNext()) {
            AbstractMetric next = it.next();
            if (filter.accepts(next.name())) {
              return next;
            }
          }
          return endOfData();
        }
      };
    }
  };
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:MetricsRecordFiltered.java

示例4: iterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
@Override
public UnmodifiableIterator<E> iterator() {
  final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator();
  return new AbstractIterator<E>() {
    @Override
    protected E computeNext() {
      while (entries.hasNext()) {
        Entry<E, ?> entry = entries.next();
        if (targetNode.equals(entry.getValue())) {
          return entry.getKey();
        }
      }
      return endOfData();
    }
  };
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:MultiEdgesConnecting.java

示例5: linesIterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Returns an iterator over the lines in the string. If the string ends in a newline, a final
 * empty string is not included, to match the behavior of BufferedReader/LineReader.readLine().
 */
private Iterator<String> linesIterator() {
  return new AbstractIterator<String>() {
    Iterator<String> lines = LINE_SPLITTER.split(seq).iterator();

    @Override
    protected String computeNext() {
      if (lines.hasNext()) {
        String next = lines.next();
        // skip last line if it's empty
        if (lines.hasNext() || !next.isEmpty()) {
          return next;
        }
      }
      return endOfData();
    }
  };
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:CharSource.java

示例6: iterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
@Override
public Iterator<C> iterator() {
  return new AbstractIterator<C>() {
    Iterator<Object[]> it = map.values().iterator();
    Object[] counters = it.hasNext() ? it.next() : null;
    int i = 0;
    @Override
    protected C computeNext() {
      while (counters != null) {
        while (i < counters.length) {
          @SuppressWarnings("unchecked")
          C counter = (C) counters[i++];
          if (counter != null) return counter;
        }
        i = 0;
        counters = it.hasNext() ? it.next() : null;
      }
      return endOfData();
    }
  };
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:FileSystemCounterGroup.java

示例7: getWrappingIterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
public static <T extends Object> Iterator<T> getWrappingIterator(final int startIdx, final List<T> list)
{
	return new AbstractIterator<T>()
	{
		private int idx = Math.max(0, Math.min(startIdx, list.size() - 1));

		@Override
		protected T computeNext()
		{
			T o = list.get(idx);

			idx++;
			if(idx >= list.size())
			{
				idx = 0;
			}

			return o;
		}
	};
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:22,代码来源:RepoService.java

示例8: lines

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Returns an iterable over the lines in the string. If the string ends in a newline, a final
 * empty string is not included to match the behavior of BufferedReader/LineReader.readLine().
 */
private Iterable<String> lines() {
  return new Iterable<String>() {
    @Override
    public Iterator<String> iterator() {
      return new AbstractIterator<String>() {
        Iterator<String> lines = LINE_SPLITTER.split(seq).iterator();

        @Override
        protected String computeNext() {
          if (lines.hasNext()) {
            String next = lines.next();
            // skip last line if it's empty
            if (lines.hasNext() || !next.isEmpty()) {
              return next;
            }
          }
          return endOfData();
        }
      };
    }
  };
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:27,代码来源:CharSource.java

示例9: entry

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
public Iterable<Entry<String, T>> entry() {
    return () -> new AbstractIterator<Entry<String, T>>() {
        NodeHolder holder;
        Iterator<String> ite;

        {
            holder = new NodeHolder();
            ite = keys(holder);
        }

        @Override
        protected Entry<String, T> computeNext() {
            if (!ite.hasNext()) {
                return endOfData();
            }
            String key = ite.next();
            if (key != null) {
                return new AbstractMap.SimpleEntry<>(key, (T) holder.node.value);
            }
            return endOfData();
        }
    };
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:24,代码来源:BinTrieTree.java

示例10: iterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
@Override
public Iterator<Vertex> iterator() {
    return new AbstractIterator<Vertex>() {
        Vertex point = first;

        @Override
        protected Vertex computeNext() {
            if (point == null) {
                return endOfData();
            } else {
                Vertex old = point;
                point = old.next;
                return old;
            }
        }
    };
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:18,代码来源:VertexRow.java

示例11: iterator

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
@Override
public Iterator<ObjectEntry<T, R>> iterator() {
  abstract class __SeparatorRegions_1 extends AbstractIterator<ObjectEntry<T, R>> {
    ObjectEntry<T, R> next;
  }
  
  return new __SeparatorRegions_1() {
    {
      next = SeparatorRegions.this.first;
    }
    @Override
    protected ObjectEntry<T, R> computeNext() {
      ObjectEntry<T, R> _xblockexpression = null;
      {
        if ((this.next == null)) {
          return this.endOfData();
        }
        final ObjectEntry<T, R> current = this.next;
        this.next = this.next.getTrailingObject();
        _xblockexpression = current;
      }
      return _xblockexpression;
    }
  };
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:SeparatorRegions.java

示例12: take

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Returns a view on this iterator that provides at most the first <code>count</code> entries.
 * 
 * @param iterator
 *            the iterator. May not be <code>null</code>.
 * @param count
 *            the number of elements that should be returned at most.
 * @return an iterator with <code>count</code> elements. Never <code>null</code>.
 * @throws IllegalArgumentException
 *             if <code>count</code> is negative.
 */
@Pure
public static <T> Iterator<T> take(final Iterator<T> iterator, final int count) {
	if (iterator == null)
		throw new NullPointerException("iterator");
	if (count < 0)
		throw new IllegalArgumentException("Cannot take a negative number of elements. Argument 'count' was: "
				+ count);
	if (count == 0)
		return ImmutableSet.<T>of().iterator();
	return new AbstractIterator<T>() {

		private int remaining = count;

		@Override
		protected T computeNext() {
			if (remaining <= 0)
				return endOfData();
			if (!iterator.hasNext())
				return endOfData();
			remaining--;
			return iterator.next();
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:36,代码来源:IteratorExtensions.java

示例13: drop

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Returns a view on this iterator that provides all elements except the first <code>count</code> entries.
 * 
 * @param iterator
 *            the iterator. May not be <code>null</code>.
 * @param count
 *            the number of elements that should be dropped.
 * @return an iterator without the first <code>count</code> elements. Never <code>null</code>.
 * @throws IllegalArgumentException
 *             if <code>count</code> is negative.
 */
public static <T> Iterator<T> drop(final Iterator<T> iterator, final int count) {
	if (iterator == null)
		throw new NullPointerException("iterator");
	if (count == 0)
		return iterator;
	if (count < 0)
		throw new IllegalArgumentException("Cannot drop a negative number of elements. Argument 'count' was: "
				+ count);
	return new AbstractIterator<T>() {
		{
			int i = count;
			while (i > 0 && iterator.hasNext()) {
				iterator.next();
				i--;
			}
		}

		@Override
		protected T computeNext() {
			if (!iterator.hasNext())
				return endOfData();
			return iterator.next();
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:37,代码来源:IteratorExtensions.java

示例14: takeWhile

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Returns an Iterator containing all elements starting from the head of the source up to and excluding the first
 * element that violates the predicate. The resulting Iterator is a lazily computed view, so any modifications to the
 * underlying Iterators will be reflected on iteration. The result does not support {@link Iterator#remove()}
 * 
 * @param iterator
 *            the elements from which to take. May not be <code>null</code>.
 * @param predicate
 *            the predicate which decides whether to keep taking elements. May not be <code>null</code>.
 * @return the taken elements
 * @since 2.7
 */
public static <T> Iterator<T> takeWhile(final Iterator<? extends T> iterator, final Function1<? super T, Boolean> predicate) {
	if (iterator == null)
		throw new NullPointerException("iterator");
	if (predicate == null)
		throw new NullPointerException("predicate");
	return new AbstractIterator<T>() {
		@Override
		protected T computeNext() {
			if (!iterator.hasNext())
				return endOfData();
			T next = iterator.next();
			if (predicate.apply(next)) {
				return next;
			} else {
				return endOfData();
			}
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:32,代码来源:IteratorExtensions.java

示例15: indexed

import com.google.common.collect.AbstractIterator; //导入依赖的package包/类
/**
 * Returns an Iterator of Pairs where the nth pair is created by taking the nth element of the source as the value
 * and its 0-based index as the key. E.g.
 * <code>zipWitIndex(#["a", "b", "c"]) == #[(0, "a"), (1, "b"), (2, "c")]</code>
 * 
 * If the index would overflow, {@link Integer#MAX_VALUE} is returned for all subsequent elements.
 * 
 * The resulting Iterator is a lazily computed view, so any modifications to the underlying Iterator will be
 * reflected on iteration. The result does not support {@link Iterator#remove()}
 * 
 * @param iterator
 *            the elements. May not be <code>null</code>.
 * @return the zipped result
 * @since 2.7
 */
public static <A> Iterator<Pair<Integer, A>> indexed(final Iterator<? extends A> iterator) {
	if (iterator == null)
		throw new NullPointerException("iterator");
	return new AbstractIterator<Pair<Integer, A>>() {
		int i = 0;
		@Override
		protected Pair<Integer, A> computeNext() {
			if (iterator.hasNext()) {
				Pair<Integer, A> next = new Pair<Integer, A>(i, iterator.next());
				if (i != Integer.MAX_VALUE)
					i++;
				return next;
			} else {
				return endOfData();
			}
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:34,代码来源:IteratorExtensions.java


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