本文整理汇总了Java中com.google.common.collect.Iterables.cycle方法的典型用法代码示例。如果您正苦于以下问题:Java Iterables.cycle方法的具体用法?Java Iterables.cycle怎么用?Java Iterables.cycle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Iterables
的用法示例。
在下文中一共展示了Iterables.cycle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConcat_infiniteIterable
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public void testConcat_infiniteIterable() throws IOException {
CharSource source = CharSource.wrap("abcd");
Iterable<CharSource> cycle = Iterables.cycle(ImmutableList.of(source));
CharSource concatenated = CharSource.concat(cycle);
String expected = "abcdabcd";
// read the first 8 chars manually, since there's no equivalent to ByteSource.slice
// TODO(cgdecker): Add CharSource.slice?
StringBuilder builder = new StringBuilder();
Reader reader = concatenated.openStream(); // no need to worry about closing
for (int i = 0; i < 8; i++) {
builder.append((char) reader.read());
}
assertEquals(expected, builder.toString());
}
示例2: testConcat_infiniteIterable
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public void testConcat_infiniteIterable() throws IOException {
ByteSource source = ByteSource.wrap(new byte[] {0, 1, 2, 3});
Iterable<ByteSource> cycle = Iterables.cycle(ImmutableList.of(source));
ByteSource concatenated = ByteSource.concat(cycle);
byte[] expected = {0, 1, 2, 3, 0, 1, 2, 3};
assertArrayEquals(expected, concatenated.slice(0, 8).read());
}