本文整理匯總了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());
}