List of usage examples for com.google.common.collect Iterables addAll
public static <T> boolean addAll(Collection<T> addTo, Iterable<? extends T> elementsToAdd)
From source file:com.sina.dip.twill.HelloWorldControllingLiveApplications.java
public static void main(String[] args) { String zkStr = "localhost:2181"; YarnConfiguration yarnConfiguration = new YarnConfiguration(); final TwillRunnerService twillRunner = new YarnTwillRunnerService(yarnConfiguration, zkStr); twillRunner.start();// ww w. j a va 2s .c o m String yarnClasspath = yarnConfiguration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH, "/usr/lib/hadoop/*,/usr/lib/hadoop-0.20-mapreduce/*,/usr/lib/hadoop-hdfs/*,/usr/lib/hadoop-mapreduce/*,/usr/lib/hadoop-yarn/*"); List<String> applicationClassPaths = Lists.newArrayList(); Iterables.addAll(applicationClassPaths, Splitter.on(",").split(yarnClasspath)); final TwillController controller = twillRunner.prepare(new HelloWorldApplication()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationClassPaths(applicationClassPaths) .withBundlerClassAcceptor(new HadoopClassExcluder()).start(); ServiceDiscovered helloWorldService = controller.discoverService("HelloWorldService"); ServiceDiscovered helloWorldService2 = controller.discoverService("HelloWorldService2"); int count = 0; while (true) { boolean flag = true; Iterator<Discoverable> iterator = helloWorldService.iterator(); while (iterator.hasNext()) { Discoverable discoverable = iterator.next(); System.out.println(discoverable.getName() + " : " + discoverable.getSocketAddress()); flag = false; } iterator = helloWorldService2.iterator(); while (iterator.hasNext()) { Discoverable discoverable = iterator.next(); System.out.println(discoverable.getName() + " : " + discoverable.getSocketAddress()); flag = false; } try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { } ++count; if (count == 10) { controller.changeInstances("hello1", 3); controller.changeInstances("hello2", 5); } else if (count == 20) { controller.changeInstances("hello1", 5); controller.changeInstances("hello2", 3); } if (count >= 36 && flag) { break; } } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { Futures.getUnchecked(controller.terminate()); } finally { twillRunner.stop(); } } }); try { controller.awaitTerminated(); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:com.facebook.presto.util.MoreSets.java
public static <T> Set<T> newIdentityHashSet(Iterable<T> elements) { Set<T> set = newIdentityHashSet(); Iterables.addAll(set, requireNonNull(elements, "elements cannot be null")); return set;//w ww . j a va 2 s . c o m }
From source file:com.github.ferstl.maven.pomenforcers.util.CommaSeparatorUtils.java
public static <T> void splitAndAddToCollection(String commaSeparatedItems, Collection<T> collection, Function<String, T> transformer) { Iterable<String> items = COMMA_SPLITTER.split(commaSeparatedItems); // Don't touch the collection if there is nothing to add. if (items.iterator().hasNext()) { collection.clear();//ww w .ja v a 2 s . co m } Iterables.addAll(collection, Iterables.transform(items, transformer)); }
From source file:edu.umn.msi.tropix.persistence.service.impl.TreeUtils.java
static <T> void stackRecursion(final T initObject, final Function<T, ? extends Iterable<T>> childrenFunction, final Closure<T> modifier) { final Stack<T> toProcess = new Stack<T>(); toProcess.add(initObject);//w w w .j a v a 2s. c o m while (!toProcess.isEmpty()) { final T object = toProcess.pop(); Iterables.addAll(toProcess, childrenFunction.apply(object)); modifier.apply(object); } }
From source file:com.google.devtools.build.lib.query2.SkyQueryUtils.java
static <T> ThreadSafeMutableSet<T> getTransitiveClosure(ThreadSafeMutableSet<T> targets, GetFwdDeps<T> getFwdDeps, ThreadSafeMutableSet<T> visited) throws InterruptedException { ThreadSafeMutableSet<T> current = targets; while (!current.isEmpty()) { Iterable<T> toVisit = current.stream().filter(obj -> !visited.contains(obj)) .collect(Collectors.toList()); current = getFwdDeps.getFwdDeps(toVisit); Iterables.addAll(visited, toVisit); }//from w ww .ja v a2 s .com return visited; }
From source file:org.xacml4j.v30.StatusDetail.java
public StatusDetail(Iterable<Object> detail) { this.content = new LinkedList<Object>(); Iterables.addAll(content, detail); }
From source file:org.praat.TextGrid.java
public TextGrid(String name, List<Tier> tiers) { Iterables.addAll(items, tiers); setTimeDomain(); }
From source file:org.gradle.api.internal.changedetection.rules.DiscoveredInputFilesStateChangeRule.java
public static DiscoveredTaskStateChanges create(final TaskExecution previousExecution, final TaskExecution currentExecution, final FileCollectionSnapshotter inputFilesSnapshotter) { return new DiscoveredTaskStateChanges() { private final Collection<File> discoveredFiles = Sets.newHashSet(); public Iterator<TaskStateChange> iterator() { if (previousExecution.getDiscoveredInputFilesSnapshot() == null) { return Collections .<TaskStateChange>singleton( new DescriptiveChange("Discovered input file history is not available.")) .iterator();//from ww w. j a v a2s .co m } Iterables.addAll(discoveredFiles, previousExecution.getDiscoveredInputFilesSnapshot().getFiles()); final FileCollectionSnapshot discoveredFileSnapshot = inputFilesSnapshotter .snapshot(new SimpleFileCollection(discoveredFiles)); return new AbstractIterator<TaskStateChange>() { final FileCollectionSnapshot.ChangeIterator<String> changeIterator = discoveredFileSnapshot .iterateChangesSince(previousExecution.getDiscoveredInputFilesSnapshot()); final ChangeListenerAdapter listenerAdapter = new ChangeListenerAdapter(); @Override protected TaskStateChange computeNext() { if (changeIterator.next(listenerAdapter)) { return listenerAdapter.lastChange; } return endOfData(); } }; } @Override public void newInputs(Set<File> files) { discoveredFiles.clear(); discoveredFiles.addAll(files); } public void snapshotAfterTask() { currentExecution.setDiscoveredInputFilesSnapshot( inputFilesSnapshotter.snapshot(new SimpleFileCollection(discoveredFiles))); } }; }
From source file:ratpack.file.internal.ActivationBackedMimeTypes.java
private static Set<String> extractKnownMimeTypes() { try {/*from ww w.j a v a 2s. c o m*/ Function<Object, String> getMimeTypeFunction = new GetMimeTypeFunction(); Field typeHashField = makeFieldAccessible(Class.forName("com.sun.activation.registries.MimeTypeFile"), "type_hash"); Field mimeTypeFilesField = makeFieldAccessible(MimetypesFileTypeMap.class, "DB"); Object mimeTypeFiles = mimeTypeFilesField.get(MIME_TYPES_MAP); Set<String> mimeTypes = Sets.newHashSet(); for (int i = 0; i < Array.getLength(mimeTypeFiles); i++) { Object mimeTypeFile = Array.get(mimeTypeFiles, i); if (mimeTypeFile != null) { Map<?, ?> typeHash = (Map) typeHashField.get(mimeTypeFile); Iterables.addAll(mimeTypes, Iterables.transform(typeHash.values(), getMimeTypeFunction)); } } return ImmutableSet.copyOf(mimeTypes); } catch (ReflectiveOperationException | NullPointerException ex) { return ImmutableSet.of(); } }
From source file:org.jclouds.chef.domain.SearchResult.java
public SearchResult(long start, Iterable<T> results) { this.start = start; Iterables.addAll(this, results); }