List of usage examples for com.google.common.collect Iterables concat
public static <T> Iterable<T> concat(Iterable<? extends T> a, Iterable<? extends T> b)
From source file:com.opengamma.engine.depgraph.SimpleResolutionFailureVisitor.java
@Override protected List<ResolutionFailure> visitFunction(ValueRequirement valueRequirement, String function, ValueSpecification desiredOutput, Map<ValueSpecification, ValueRequirement> satisfied, Set<ResolutionFailure> unsatisfied, Set<ResolutionFailure> unsatisfiedAdditional) { return ImmutableList.copyOf(Iterables.concat(unsatisfied, unsatisfiedAdditional)); }
From source file:org.summer.dsl.xbase.scoping.batch.LocalVariableScope.java
@Override public Iterable<IEObjectDescription> getElements(final QualifiedName name) { Collection<IEObjectDescription> localElements = getLocalElementsByName(name); if (localElements.isEmpty()) return getParent().getElements(name); if (looksLikeLocalVariable()) { return localElements; }/*from w w w.j a v a2 s . c o m*/ Iterable<IEObjectDescription> parentElements = getParentElements( new Provider<Iterable<IEObjectDescription>>() { public Iterable<IEObjectDescription> get() { return getParent().getElements(name); } }); // TODO evaluate optimizing this by avoiding the concat thing and doing something smarter than the ParentIterable Iterable<IEObjectDescription> result = Iterables.concat(localElements, parentElements); return result; }
From source file:com.getbase.android.schema.MigrationsHelper.java
public void performMigrations(SQLiteDatabase db, TableMigration... migrations) { for (TableMigration migration : migrations) { final String tempTable = "tmp_" + tempTableIndex++; db.execSQL("ALTER TABLE " + migration.tableName + " RENAME TO " + tempTable); ImmutableSet<String> oldColumns = getColumns(db, tempTable); db.execSQL(migration.createTableStatement); final String tempNewTable = "tmp_" + tempTableIndex++; db.execSQL("ALTER TABLE " + migration.tableName + " RENAME TO " + tempNewTable); ImmutableSet<String> newColumns = getColumns(db, tempNewTable); db.execSQL("ALTER TABLE " + tempNewTable + " RENAME TO " + migration.tableName); Set<String> commonColumns = Sets.intersection(oldColumns, newColumns); Set<String> droppedColumns = Sets.difference(oldColumns, newColumns); if (!droppedColumns.isEmpty()) { Log.w(TAG, "Dropping columns " + Joiner.on(",").join(droppedColumns) + " during migration of " + migration.tableName); }/*from w w w . ja v a 2 s .co m*/ Set<String> addedColumns = Sets.difference(Sets.difference(newColumns, oldColumns), migration.mappings.keySet()); if (!addedColumns.isEmpty()) { Log.w(TAG, "Will try to add new columns " + Joiner.on(",").join(addedColumns) + " during migration of " + migration.tableName); } SetView<String> unmappedColumns = Sets.difference(commonColumns, migration.mappings.keySet()); String insertColumnsString = Joiner.on(",") .join(Iterables.concat(unmappedColumns, migration.mappings.keySet())); String selectColumnsString = Joiner.on(",") .join(Iterables.concat(unmappedColumns, migration.mappings.values())); db.execSQL("INSERT INTO " + migration.tableName + "(" + insertColumnsString + ") SELECT " + selectColumnsString + " FROM " + tempTable); db.execSQL("DROP TABLE " + tempTable); } }
From source file:org.grouplens.lenskit.eval.traintest.MeasurementSuite.java
public Iterable<Metric<TrainTestEvalTask>> getAllMetrics() { return Iterables.concat(testUserMetrics, modelMetrics); }
From source file:org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexLookup.java
/** * Returns the paths that match the given node types. * * @param filter the filter (used for logging) * @return the matched paths (the result might contain duplicate entries) *///from w ww.j a v a 2 s. c o m public Iterable<String> query(Filter filter) { PropertyIndexLookup lookup = new PropertyIndexLookup(root); return Iterables.concat(lookup.query(filter, JCR_PRIMARYTYPE, newName(filter.getPrimaryTypes())), lookup.query(filter, JCR_MIXINTYPES, newName(filter.getMixinTypes()))); }
From source file:org.apache.cassandra.stress.generate.PartitionGenerator.java
public PartitionGenerator(List<Generator> partitionKey, List<Generator> clusteringComponents, List<Generator> valueComponents, Order order) { this.partitionKey = partitionKey; this.clusteringComponents = clusteringComponents; this.valueComponents = valueComponents; this.order = order; this.clusteringDescendantAverages = new int[clusteringComponents.size()]; this.clusteringComponentAverages = new int[clusteringComponents.size()]; for (int i = 0; i < clusteringComponentAverages.length; i++) clusteringComponentAverages[i] = (int) clusteringComponents.get(i).clusteringDistribution.average(); for (int i = clusteringDescendantAverages.length - 1; i >= 0; i--) clusteringDescendantAverages[i] = (int) (i < (clusteringDescendantAverages.length - 1) ? clusteringComponentAverages[i + 1] * clusteringDescendantAverages[i + 1] : 1);/*from ww w. ja v a 2 s . c o m*/ double maxRowCount = 1d; double minRowCount = 1d; for (Generator component : clusteringComponents) { maxRowCount *= component.clusteringDistribution.maxValue(); minRowCount *= component.clusteringDistribution.minValue(); } this.maxRowCount = maxRowCount; this.minRowCount = minRowCount; this.indexMap = new HashMap<>(); int i = 0; for (Generator generator : partitionKey) indexMap.put(generator.name, --i); i = 0; for (Generator generator : Iterables.concat(clusteringComponents, valueComponents)) indexMap.put(generator.name, i++); }
From source file:org.obm.push.mail.BodyPreferencePolicy.java
protected static Comparator<FetchInstruction> betterFitComparator(final List<BodyPreference> bodyPreferences) { final List<MSEmailBodyType> preferences = FluentIterable .from(Iterables.concat(bodyPreferences, DEFAULT_BODY_PREFERENCES)) .transform(bodyPreferenceToMSEmailBodyType()).toList(); final List<MSEmailBodyType> clientPreferences = FluentIterable.from(bodyPreferences) .transform(bodyPreferenceToMSEmailBodyType()).toList(); return new Comparator<FetchInstruction>() { private int computeWeight(FetchInstruction instruction) { int transformationWeight = instruction.getMailTransformation() == MailTransformation.NONE ? 0 : 1; return preferences.indexOf(instruction.getBodyType()) + (preferences.size() * transformationWeight); }/*ww w .ja v a 2 s . c o m*/ @Override public int compare(FetchInstruction o1, FetchInstruction o2) { if (o1.getBodyType().equals(o2.getBodyType()) && o1.getMailTransformation().equals(o2.getMailTransformation())) { return 0; } if (o1.getBodyType() == MSEmailBodyType.MIME) { return 1; } else if (o2.getBodyType() == MSEmailBodyType.MIME) { return -1; } else if (clientPreferences.contains(o1.getBodyType()) && !clientPreferences.contains(o2.getBodyType())) { return -1; } else if (!clientPreferences.contains(o1.getBodyType()) && clientPreferences.contains(o2.getBodyType())) { return 1; } else { return computeWeight(o1) - computeWeight(o2); } } }; }
From source file:com.google.devtools.build.lib.syntax.GlobCriteria.java
/** * Constructs a copy of a given glob critera object, with additional exclude patterns added. * * @param base a glob criteria object to copy. Must be an actual glob * @param excludes a list of pattern strings indicating new excludes to provide * @return a new glob criteria object which contains the same parameters as {@code base}, with * the additional patterns in {@code excludes} added. * @throws IllegalArgumentException if {@code base} is not a glob */// w ww . ja va 2 s .com public static GlobCriteria createWithAdditionalExcludes(GlobCriteria base, List<String> excludes) { Preconditions.checkArgument(base.isGlob()); return fromGlobCall(base.include, ImmutableList.copyOf(Iterables.concat(base.exclude, excludes))); }
From source file:com.sk89q.worldguard.protection.FlagValueCalculator.java
/** * Create a new instance.//from w ww .j a va 2 s .co m * * @param regions a list of applicable regions that must be sorted according to {@link NormativeOrders} * @param globalRegion an optional global region (null to not use one) */ public FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion) { checkNotNull(regions); this.regions = regions; this.globalRegion = globalRegion; if (globalRegion != null) { applicable = Iterables.concat(regions, Arrays.asList(globalRegion)); } else { applicable = regions; } }
From source file:org.xrepl.xscript.scoping.EPackageScopeProvider.java
private <T extends EObject> Iterable<T> getAllInstances(Iterable<? extends EPackage> ePackages, Class<T> type) { Iterable<T> result = emptyList(); for (EPackage ePackage : ePackages) { List<T> allContents = EcoreUtil2.getAllContentsOfType(ePackage, type); result = Iterables.concat(result, allContents); }/*from www . j a v a2 s.c o m*/ return result; }