List of usage examples for com.google.common.collect Iterators addAll
public static <T> boolean addAll(Collection<T> addTo, Iterator<? extends T> iterator)
From source file:net.automatalib.commons.util.settings.SettingsSource.java
static <S extends SettingsSource> void readSettings(Class<S> clazz, Properties p) { ServiceLoader<S> loader = ServiceLoader.load(clazz); List<S> sources = new ArrayList<>(); Iterators.addAll(sources, loader.iterator()); sources.sort(Comparator.comparingInt(SettingsSource::getPriority)); for (S source : sources) { source.loadSettings(p);/*from w w w . j av a 2 s . com*/ } }
From source file:org.janusgraph.diskstorage.util.EntryArrayList.java
public static EntryArrayList of(Iterable<? extends Entry> i) { // This is adapted from Guava's Lists.newArrayList implementation EntryArrayList result;/*ww w . j a va 2s . c o m*/ if (i instanceof Collection) { // Let ArrayList's sizing logic work, if possible result = new EntryArrayList((Collection) i); } else { // Unknown size result = new EntryArrayList(); Iterators.addAll(result, i.iterator()); } return result; }
From source file:edu.harvard.med.screensaver.util.PowerSet.java
public static <T> Set<Set<T>> powerSet(Set<T> values) { Set<Set<T>> powerSet = new HashSet<Set<T>>(); Iterators.addAll(powerSet, powerSetIterator(values)); return powerSet; }
From source file:org.obeonetwork.dsl.uml2.design.api.services.PackageContainmentServices.java
/** * Get all the packageable elements available in the semantic resources. * * @param element/*from w w w. j av a 2 s .c o m*/ * Semantic element * @return All the packageable elements */ public List<EObject> getAllPackageableElements(Element element) { final List<EObject> result = Lists.newArrayList(); final List<Package> rootPkgs = getAllAvailableRootPackages(element); result.addAll(rootPkgs); for (final Package pkg : rootPkgs) { Iterators.addAll(result, Iterators.filter(pkg.eAllContents(), Predicates.instanceOf(PackageableElement.class))); } if (element instanceof Package) { result.removeAll(((Package) element).getPackagedElements()); } return result; }
From source file:org.gradle.api.internal.tasks.properties.GetOutputFilesVisitor.java
@Override public void visitOutputFileProperty(TaskOutputFilePropertySpec outputFileProperty) { hasDeclaredOutputs = true;/*w w w . j av a 2s. c o m*/ if (outputFileProperty instanceof CompositeTaskOutputPropertySpec) { Iterators.addAll(specs, ((CompositeTaskOutputPropertySpec) outputFileProperty).resolveToOutputProperties()); } else { if (outputFileProperty instanceof CacheableTaskOutputFilePropertySpec) { File outputFile = ((CacheableTaskOutputFilePropertySpec) outputFileProperty).getOutputFile(); if (outputFile == null) { return; } } specs.add(outputFileProperty); } }
From source file:org.movsim.simulator.roadnetwork.RoadSegmentUtils.java
private static Collection<Vehicle> sortVehicles(Iterator<Vehicle> vehicleIterator, Comparator<Vehicle> vehComparator) { List<Vehicle> vehicles = new ArrayList<>(500); Iterators.addAll(vehicles, vehicleIterator); Collections.sort(vehicles, vehComparator); return vehicles; }
From source file:org.commoncrawl.mapred.pipelineV3.domainmeta.subdomaincounts.SubDomainCountsReducer.java
@Override public void reduce(TextBytes key, Iterator<TextBytes> values, OutputCollector<TextBytes, IntWritable> output, Reporter reporter) throws IOException { HashSet<String> subDomains = new HashSet<String>(); Iterators.addAll(subDomains, Iterators.transform(values, new Function<TextBytes, String>() { @Override//from w w w . j av a 2s . c o m public String apply(TextBytes arg0) { return arg0.toString(); } })); if (subDomains.size() > 1) { output.collect(key, new IntWritable(subDomains.size())); } }
From source file:org.commoncrawl.mapred.pipelineV3.domainmeta.linkstats.UniqueIncomingRootDomainCounter.java
@Override public void reduce(TextBytes key, Iterator<TextBytes> values, OutputCollector<TextBytes, TextBytes> output, Reporter reporter) throws IOException { HashSet<String> rootDomainList = new HashSet<String>(); Iterators.addAll(rootDomainList, Iterators.transform(values, new Function<TextBytes, String>() { @Override// w ww .j a v a 2 s . c o m public String apply(TextBytes arg0) { return arg0.toString(); } })); JsonObject jsonObject = new JsonObject(); JsonArray jsonArray = new JsonArray(); jsonObject.addProperty("domain-count", rootDomainList.size()); for (String domain : rootDomainList) { jsonArray.add(new JsonPrimitive(domain)); } jsonObject.add("domains", jsonArray); if (rootDomainList.size() != 0) { output.collect(key, new TextBytes(jsonObject.toString())); } }
From source file:com.threerings.cast.util.CastUtil.java
/** * Returns a new character descriptor populated with a random set of components. *///w w w . j a v a2 s.c o m public static CharacterDescriptor getRandomDescriptor(ComponentRepository crepo, String gender, String[] COMP_CLASSES, ColorPository cpos, String[] COLOR_CLASSES) { // get all available classes ArrayList<ComponentClass> classes = Lists.newArrayList(); for (String element : COMP_CLASSES) { String cname = gender + "/" + element; ComponentClass cclass = crepo.getComponentClass(cname); // make sure the component class exists if (cclass == null) { log.warning("Missing definition for component class", "class", cname); continue; } // make sure there are some components in this class Iterator<Integer> iter = crepo.enumerateComponentIds(cclass); if (!iter.hasNext()) { log.info("Skipping class for which we have no components", "class", cclass); continue; } classes.add(cclass); } // select the components int[] components = new int[classes.size()]; Colorization[][] zations = new Colorization[components.length][]; for (int ii = 0; ii < components.length; ii++) { ComponentClass cclass = classes.get(ii); // get the components available for this class ArrayList<Integer> choices = Lists.newArrayList(); Iterators.addAll(choices, crepo.enumerateComponentIds(cclass)); // each of our components has up to four colorizations: two "global" skin colorizations // and potentially a primary and secondary clothing colorization; in a real system one // would probably keep a separate database of which character component required which // colorizations, but here we just assume everything could have any of the four // colorizations; it *usually* doesn't hose an image if you apply a recoloring that it // does not support, but it can match stray colors unnecessarily zations[ii] = new Colorization[COLOR_CLASSES.length]; for (int zz = 0; zz < COLOR_CLASSES.length; zz++) { zations[ii][zz] = cpos.getRandomStartingColor(COLOR_CLASSES[zz]).getColorization(); } // choose a random component if (choices.size() > 0) { int idx = RandomUtil.getInt(choices.size()); components[ii] = choices.get(idx).intValue(); } else { log.info("Have no components in class", "class", cclass); } } return new CharacterDescriptor(components, zations); }
From source file:jflowmap.views.flowmap.VisualNodeCluster.java
private VisualNodeCluster(int id, Paint color, Iterator<VisualNode> it) { this.nodes = new ArrayList<VisualNode>(); this.tag = ClusterTag.createFor(id, color); Iterators.addAll(nodes, it); updateClusterTags();/*w w w . ja va 2 s . c om*/ }