List of usage examples for com.google.common.collect Iterables cycle
public static <T> Iterable<T> cycle(T... elements)
From source file:com.facebook.buck.thrift.ThriftCompilerStep.java
@Override protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { return ImmutableList.<String>builder().addAll(compilerPrefix) .add("--gen", String.format("%s:%s", language, Joiner.on(',').join(options))) .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-I"), Iterables.transform(includes, Object::toString))) .add("-o", outputDir.toString()).add(input.toString()).build(); }
From source file:org.calrissian.mango.collect.CloseableIterables.java
/** * Returns a closeable iterable whose iterators cycle indefinitely over the elements of * {@code iterable}.// w ww . j av a 2s .c o m * * <p>That iterator supports {@code remove()} if {@code iterable.iterator()} * does. After {@code remove()} is called, subsequent cycles omit the removed * element, which is no longer in {@code iterable}. The iterator's * {@code hasNext()} method returns {@code true} until {@code iterable} is * empty. * * <p><b>Warning:</b> Typical uses of the resulting iterator may produce an * infinite loop. You should use an explicit {@code break} or be certain that * you will eventually remove all the elements. The close method should be expicitly * called when done with iteration. Tools such as {@code CloseableIterables.autoClose()} * will not work. */ public static <T> CloseableIterable<T> cycle(final CloseableIterable<T> iterable) { return wrap(Iterables.cycle(iterable), iterable); }
From source file:com.google.devtools.build.lib.query2.RBuildFilesFunction.java
@Override public Iterable<ArgumentType> getArgumentTypes() { return Iterables.cycle(ArgumentType.WORD); }
From source file:de.johni0702.sponge.noteblockapi.impl.NBSongPlayers.java
@Override public SongPlayer createLoopingSongPlayer(final Song... song) { return createSongPlayer(new SongProvider() { private Iterator<Song> iter = Iterables.cycle(song).iterator(); @Override/*from w w w. j a va2 s. c o m*/ public Song getNextSong(SongPlayer songPlayer) { return iter.next(); } }); }
From source file:com.facebook.presto.plugin.blackhole.BlackHolePageSourceProvider.java
@Override public ConnectorPageSource createPageSource(ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns) { BlackHoleSplit blackHoleSplit = checkType(split, BlackHoleSplit.class, "BlackHoleSplit"); ImmutableList.Builder<Type> builder = ImmutableList.builder(); for (ColumnHandle column : columns) { builder.add((checkType(column, BlackHoleColumnHandle.class, "BlackHoleColumnHandle")).getColumnType()); }// w w w .j a va 2 s .c om List<Type> types = builder.build(); return new FixedPageSource(Iterables.limit( Iterables.cycle( generateZeroPage(types, blackHoleSplit.getRowsPerPage(), blackHoleSplit.getFieldsLength())), blackHoleSplit.getPagesCount())); }
From source file:org.opendaylight.fpc.utils.AbstractThreadPool.java
/** * Starts the individual threads of the pool. They SHOULD not process * until the count down signal is called via run. * * @see #run()/*from w w w .jav a 2 s .c om*/ * @throws Exception - thrown when an error occurs during start up. */ protected void startUp() throws Exception { this.poolFactory = getPoolFactory(db); for (int x = 0; x < poolSize; ++x) { T worker = poolFactory.get(); pool.add(worker); worker.open(); Thread thread = new Thread(worker); threadPool.add(thread); thread.start(); } this.it = Iterables.cycle(pool).iterator(); }
From source file:com.facebook.buck.cxx.CxxPreprocessStep.java
@VisibleForTesting protected ImmutableList<String> getCommand() { return ImmutableList.<String>builder().add(preprocessor.toString()).add("-E").addAll(flags) .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-I"), Iterables.transform(includes, Functions.toStringFunction()))) .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-isystem"), Iterables.transform(systemIncludes, Functions.toStringFunction()))) .add(input.toString()).build(); }
From source file:com.facebook.buck.features.ocaml.OcamlDebugLauncherStep.java
private String getDebugCmd() { ImmutableList.Builder<String> debugCmd = ImmutableList.builder(); debugCmd.add("rlwrap"); debugCmd.addAll(args.ocamlDebug.getCommandPrefix(resolver)); ImmutableList<String> includesBytecodeFlags = ImmutableList.copyOf(MoreIterables.zipAndConcat( Iterables.cycle(OcamlCompilables.OCAML_INCLUDE_FLAG), args.transitiveBytecodeIncludes)); debugCmd.addAll(includesBytecodeFlags); debugCmd.addAll(args.bytecodeIncludeFlags); debugCmd.add(args.bytecodeOutput.toString()); return Shell.shellQuoteJoin(debugCmd.build(), " ") + " $@"; }
From source file:com.facebook.buck.cxx.AbstractCxxIncludePaths.java
/** * Build a list of compiler flag strings representing the contained paths. * * This method's parameters allow the caller to do some massaging and cleaning-up of paths. * @param pathResolver/*from ww w . j a v a 2 s .com*/ * @param pathShortener used to shorten the {@code -I} and {@code -isystem} paths * @param frameworkPathTransformer used to shorten/convert/transmogrify framework {@code -F} paths */ public ImmutableList<String> getFlags(SourcePathResolver pathResolver, PathShortener pathShortener, Function<FrameworkPath, Path> frameworkPathTransformer, Preprocessor preprocessor) { ImmutableList.Builder<String> builder = ImmutableList.builder(); builder.addAll(CxxHeaders.getArgs(getIPaths(), pathResolver, Optional.of(pathShortener), preprocessor)); builder.addAll(MoreIterables.zipAndConcat(Iterables.cycle("-F"), FluentIterable.from(getFPaths()) .transform(frameworkPathTransformer).transform(Object::toString).toSortedSet(Ordering.natural()))); return builder.build(); }
From source file:com.facebook.buck.ocaml.OcamlDebugLauncherStep.java
private String getDebugCmd() { ImmutableList.Builder<String> debugCmd = ImmutableList.builder(); debugCmd.add("rlwrap"); debugCmd.addAll(args.ocamlDebug.getCommandPrefix(resolver)); Iterable<String> includesBytecodeDirs = FluentIterable.from(args.ocamlInput) .transformAndConcat(new Function<OcamlLibrary, Iterable<String>>() { @Override/* w w w . ja v a 2 s . c o m*/ public Iterable<String> apply(OcamlLibrary input) { return input.getBytecodeIncludeDirs(); } }); ImmutableList<String> includesBytecodeFlags = ImmutableList.copyOf(MoreIterables .zipAndConcat(Iterables.cycle(OcamlCompilables.OCAML_INCLUDE_FLAG), includesBytecodeDirs)); debugCmd.addAll(includesBytecodeFlags); debugCmd.addAll(args.bytecodeIncludeFlags); debugCmd.add(args.bytecodeOutput.toString()); return Shell.shellQuoteJoin(debugCmd.build(), " ") + " $@"; }