List of usage examples for com.google.common.collect Sets union
public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2)
From source file:com.facebook.buck.rules.DefaultJavaLibraryRule.java
protected DefaultJavaLibraryRule(BuildRuleParams buildRuleParams, Set<String> srcs, Set<String> resources, @Nullable String proguardConfig, AnnotationProcessingParams annotationProcessingParams, boolean exportDeps, String sourceLevel, String targetLevel) { super(buildRuleParams); this.srcs = ImmutableSortedSet.copyOf(srcs); this.resources = ImmutableSortedSet.copyOf(resources); this.annotationProcessingParams = Preconditions.checkNotNull(annotationProcessingParams); this.proguardConfig = proguardConfig; this.sourceLevel = sourceLevel; this.targetLevel = targetLevel; this.exportDeps = exportDeps; if (!srcs.isEmpty() || !resources.isEmpty()) { File file = new File(getOutputJarPath(getBuildTarget())); this.outputJar = Optional.of(file); } else {/* w w w . j ava 2 s. c om*/ this.outputJar = Optional.absent(); } // Note that both srcs and resources are sorted so that the list order is consistent even if // the iteration order of the sets passed to the constructor changes. See // AbstractBuildRule.getInputsToCompareToOutput() for details. inputsToConsiderForCachingPurposes = ImmutableList.<String>builder().addAll(this.srcs) .addAll(this.resources).build(); outputClasspathEntriesSupplier = Suppliers.memoize(new Supplier<ImmutableSet<String>>() { @Override public ImmutableSet<String> get() { ImmutableSet<String> outputClasspathEntries; // If this java_library exports its dependencies then just return the transitive // dependencies. if (DefaultJavaLibraryRule.this.exportDeps) { outputClasspathEntries = ImmutableSet.copyOf(getTransitiveClasspathEntries().values()); } else if (outputJar.isPresent()) { outputClasspathEntries = ImmutableSet.of(getOutput().getPath()); } else { outputClasspathEntries = ImmutableSet.of(); } return outputClasspathEntries; } }); transitiveClasspathEntriesSupplier = Suppliers .memoize(new Supplier<ImmutableSetMultimap<BuildRule, String>>() { @Override public ImmutableSetMultimap<BuildRule, String> get() { final ImmutableSetMultimap.Builder<BuildRule, String> classpathEntries = ImmutableSetMultimap .builder(); ImmutableSetMultimap<BuildRule, String> classpathEntriesForDeps = Classpaths .getClasspathEntries(getDeps()); classpathEntries.putAll(classpathEntriesForDeps); if (DefaultJavaLibraryRule.this.exportDeps) { classpathEntries.putAll(DefaultJavaLibraryRule.this, classpathEntriesForDeps.values()); } // Only add ourselves to the classpath if there's a jar to be built. if (outputJar.isPresent()) { classpathEntries.putAll(DefaultJavaLibraryRule.this, getOutput().getPath()); } return classpathEntries.build(); } }); declaredClasspathEntriesSupplier = Suppliers .memoize(new Supplier<ImmutableSetMultimap<BuildRule, String>>() { @Override public ImmutableSetMultimap<BuildRule, String> get() { final ImmutableSetMultimap.Builder<BuildRule, String> classpathEntries = ImmutableSetMultimap .builder(); Iterable<JavaLibraryRule> javaLibraryDeps = Iterables.filter( Sets.union(getDeps(), ImmutableSet.of(DefaultJavaLibraryRule.this)), JavaLibraryRule.class); for (JavaLibraryRule rule : javaLibraryDeps) { classpathEntries.putAll(rule, rule.getOutputClasspathEntries()); } return classpathEntries.build(); } }); }
From source file:com.facebook.buck.features.haskell.HaskellLibraryDescription.java
private Archive requireStaticLibrary(BuildTarget baseTarget, ProjectFilesystem projectFilesystem, BuildRuleParams baseParams, ActionGraphBuilder graphBuilder, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, HaskellPlatformsProvider haskellPlatformsProvider, HaskellPlatform platform, HaskellLibraryDescriptionArg args, ImmutableSet<BuildRule> deps, Linker.LinkableDepType depType, boolean hsProfile) { Preconditions.checkArgument(Sets/*from w w w . j ava2 s . c o m*/ .intersection(baseTarget.getFlavors(), Sets.union(Type.FLAVOR_VALUES, haskellPlatformsProvider.getHaskellPlatforms().getFlavors())) .isEmpty()); BuildTarget target = baseTarget.withAppendedFlavors( depType == Linker.LinkableDepType.STATIC ? Type.STATIC.getFlavor() : Type.STATIC_PIC.getFlavor(), platform.getCxxPlatform().getFlavor()); if (hsProfile) { target = target.withAppendedFlavors(HaskellDescriptionUtils.PROF); } else { target = target.withoutFlavors(HaskellDescriptionUtils.PROF); } return (Archive) graphBuilder.computeIfAbsent(target, target1 -> createStaticLibrary(target1, projectFilesystem, baseParams, graphBuilder, pathResolver, ruleFinder, platform, args, deps, depType, hsProfile)); }
From source file:org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository.java
@Override protected RepositoryDescriptor createDescriptor() { String layoutType;/* www . ja v a 2s . c o m*/ boolean m2Compatible; if (layout instanceof GradleRepositoryLayout) { layoutType = "Gradle"; m2Compatible = false; } else if (layout instanceof MavenRepositoryLayout) { layoutType = "Maven"; m2Compatible = true; } else if (layout instanceof IvyRepositoryLayout) { layoutType = "Ivy"; m2Compatible = false; } else if (layout instanceof DefaultIvyPatternRepositoryLayout) { layoutType = "Pattern"; m2Compatible = ((DefaultIvyPatternRepositoryLayout) layout).getM2Compatible(); } else { layoutType = "Unknown"; m2Compatible = false; } return new IvyRepositoryDescriptor.Builder(getName(), getUrl()) .setAuthenticated(getConfiguredCredentials() != null) .setAuthenticationSchemes(getAuthenticationSchemes()).setMetadataSources(metadataSources.asList()) .setLayoutType(layoutType).setM2Compatible(m2Compatible) .setIvyPatterns(Sets.union(layout.getIvyPatterns(), additionalPatternsLayout.ivyPatterns)) .setArtifactPatterns( Sets.union(layout.getArtifactPatterns(), additionalPatternsLayout.artifactPatterns)) .create(); }
From source file:com.github.pms1.tppt.p2.FeatureXmlComparator.java
private void comparePlugins(Map<String, Element> plugins1, Map<String, Element> plugins2, ElementDeltaReporter elementDeltaReporter, AttributesDeltaReporter attributesDeltaReporter) { for (String id : Sets.union(plugins1.keySet(), plugins2.keySet())) { Element e1 = plugins1.get(id); Element e2 = plugins2.get(id); if (e1 == null) { elementDeltaReporter.added(domRenderer.render(e2)); } else if (e2 == null) { elementDeltaReporter.removed(domRenderer.render(e1)); } else {/*from w w w. ja v a2 s .c om*/ compareAttributes(e1, e2, attributesDeltaReporter); } } }
From source file:org.dllearner.utilities.ReasoningUtils.java
/** * partition an array of sets into true, false and unknown, depending on whether they satisfy concept A or B * @param trueConcept the OWL concept used for true partition * @param falseConcept the OWL concept used for false partition * @param sets list of sets to partition * @return an array of Coverage data, one entry for each input set *//*from ww w .j a v a 2 s.c o m*/ @SafeVarargs public final Coverage3[] getCoverage3(OWLClassExpression trueConcept, OWLClassExpression falseConcept, Set<OWLIndividual>... sets) { Coverage3[] rv = new Coverage3[sets.length]; if (!reasoner.isUseInstanceChecks()) { if (reasoner instanceof SPARQLReasoner && ((SPARQLReasoner) reasoner).isUseValueLists()) { for (int i = 0; i < sets.length; ++i) { rv[i] = new Coverage3(); rv[i].total = sets[i].size(); SortedSet<OWLIndividual> trueSet = reasoner.hasType(trueConcept, sets[i]); SortedSet<OWLIndividual> falseSet = reasoner.hasType(falseConcept, sets[i]); rv[i].trueSet.addAll(trueSet); rv[i].falseSet.addAll(falseSet); rv[i].unknownSet.addAll(Sets.difference(sets[i], Sets.union(trueSet, falseSet))); rv[i].trueCount = rv[i].trueSet.size(); rv[i].falseCount = rv[i].falseSet.size(); rv[i].unknownCount = rv[i].unknownSet.size(); } } else { SortedSet<OWLIndividual> trueIndividuals = reasoner.getIndividuals(trueConcept); SortedSet<OWLIndividual> falseIndividuals = reasoner.getIndividuals(falseConcept); for (int i = 0; i < sets.length; ++i) { rv[i] = new Coverage3(); rv[i].total = sets[i].size(); rv[i].trueSet.addAll(Sets.intersection(sets[i], trueIndividuals)); rv[i].falseSet.addAll(Sets.intersection(sets[i], falseIndividuals)); rv[i].unknownSet.addAll(Sets.difference(sets[i], Sets.union(rv[i].trueSet, rv[i].falseSet))); rv[i].trueCount = rv[i].trueSet.size(); rv[i].falseCount = rv[i].falseSet.size(); rv[i].unknownCount = rv[i].unknownSet.size(); } } } else { for (int i = 0; i < sets.length; ++i) { rv[i] = new Coverage3(); rv[i].total = sets[i].size(); for (OWLIndividual example : sets[i]) { if (getReasoner().hasType(trueConcept, example)) { rv[i].trueSet.add(example); } else if (getReasoner().hasType(falseConcept, example)) { rv[i].falseSet.add(example); } else { rv[i].unknownSet.add(example); } if (interrupted()) { return null; } } rv[i].trueCount = rv[i].trueSet.size(); rv[i].falseCount = rv[i].falseSet.size(); rv[i].unknownCount = rv[i].unknownSet.size(); } } return rv; }
From source file:grakn.core.graql.reasoner.query.CompositeQuery.java
@Override public ReasonerQuery conjunction(ReasonerQuery q) { return new CompositeQuery( Graql.and(Sets.union(this.getPattern().getPatterns(), q.getPattern().getPatterns())), this.tx()); }
From source file:com.google.errorprone.scanner.ScannerSupplier.java
/** * Composes this {@link ScannerSupplier} with the {@code other} * {@link ScannerSupplier}. The set of checks that are turned on is the * intersection of the checks on in {@code this} and {@code other}. */// ww w .j a v a 2s. c o m @CheckReturnValue public ScannerSupplier plus(ScannerSupplier other) { ImmutableBiMap<String, BugCheckerInfo> combinedAllChecks = ImmutableBiMap.<String, BugCheckerInfo>builder() .putAll(this.getAllChecks()).putAll(other.getAllChecks()).build(); ImmutableMap<String, SeverityLevel> combinedSeverities = ImmutableMap.<String, BugPattern.SeverityLevel>builder() .putAll(severities()).putAll(other.severities()).build(); ImmutableSet<String> disabled = ImmutableSet.copyOf(Sets.union(disabled(), other.disabled())); return new ScannerSupplierImpl(combinedAllChecks, combinedSeverities, disabled); }
From source file:grakn.core.graql.reasoner.rule.InferenceRule.java
/** * @param parentAtom atom containing constraints (parent) * @param unifier unifier unifying parent with the rule * @return rule with propagated constraints from parent *//*from ww w. j av a2s . co m*/ private InferenceRule propagateConstraints(Atom parentAtom, Unifier unifier) { if (!parentAtom.isRelation() && !parentAtom.isResource()) return this; Atom headAtom = head.getAtom(); //we are only rewriting the conjunction atoms (not complement atoms) as //the constraints are propagated from the conjunctive part anyway and //all variables in the -ve part not referenced in the +ve part have a different scope ReasonerQueryImpl bodyConjunction = getBody().asComposite().getConjunctiveQuery(); Set<Atomic> bodyConjunctionAtoms = new HashSet<>(bodyConjunction.getAtoms()); //transfer value predicates Set<Variable> bodyVars = bodyConjunction.getVarNames(); Set<ValuePredicate> vpsToPropagate = parentAtom.getPredicates(ValuePredicate.class) .flatMap(vp -> vp.unify(unifier).stream()).filter(vp -> bodyVars.contains(vp.getVarName())) .collect(toSet()); bodyConjunctionAtoms.addAll(vpsToPropagate); //if head is a resource merge vps into head if (headAtom.isResource()) { AttributeAtom resourceHead = (AttributeAtom) headAtom; if (resourceHead.getMultiPredicate().isEmpty()) { Set<ValuePredicate> innerVps = parentAtom.getInnerPredicates(ValuePredicate.class) .flatMap(vp -> vp.unify(unifier).stream()).collect(toSet()); bodyConjunctionAtoms.addAll(innerVps); headAtom = AttributeAtom.create(resourceHead.getPattern(), resourceHead.getAttributeVariable(), resourceHead.getRelationVariable(), resourceHead.getPredicateVariable(), resourceHead.getTypeId(), innerVps, resourceHead.getParentQuery()); } } Set<TypeAtom> unifiedTypes = parentAtom.getTypeConstraints().flatMap(type -> type.unify(unifier).stream()) .collect(toSet()); //set rule body types to sub types of combined query+rule types Set<TypeAtom> ruleTypes = bodyConjunction.getAtoms(TypeAtom.class).filter(t -> !t.isRelation()) .collect(toSet()); Set<TypeAtom> allTypes = Sets.union(unifiedTypes, ruleTypes); allTypes.stream().filter(ta -> { SchemaConcept schemaConcept = ta.getSchemaConcept(); SchemaConcept subType = allTypes.stream().map(Atom::getSchemaConcept).filter(Objects::nonNull) .filter(t -> ConceptUtils.nonMetaSups(t).contains(schemaConcept)).findFirst().orElse(null); return schemaConcept == null || subType == null; }).forEach(t -> bodyConjunctionAtoms.add(t.copy(body))); ReasonerQueryImpl rewrittenBodyConj = ReasonerQueries.create(bodyConjunctionAtoms, tx); ResolvableQuery rewrittenBody = getBody().isComposite() ? ReasonerQueries.composite(rewrittenBodyConj, getBody().asComposite().getComplementQueries(), tx) : rewrittenBodyConj; return new InferenceRule(ReasonerQueries.atomic(headAtom), rewrittenBody, rule, tx); }
From source file:org.apache.aurora.scheduler.thrift.ReadOnlySchedulerImpl.java
@Override public Response getRoleSummary() { Multimap<String, IJobKey> jobsByRole = storage.read( storeProvider -> Multimaps.index(storeProvider.getTaskStore().getJobKeys(), IJobKey::getRole)); Multimap<String, IJobKey> cronJobsByRole = Multimaps.index( Iterables.transform(Storage.Util.fetchCronJobs(storage), IJobConfiguration::getKey), IJobKey::getRole);/*from www.ja v a2 s . c o m*/ Set<RoleSummary> summaries = FluentIterable.from(Sets.union(jobsByRole.keySet(), cronJobsByRole.keySet())) .transform( role -> new RoleSummary(role, jobsByRole.get(role).size(), cronJobsByRole.get(role).size())) .toSet(); return ok(Result.roleSummaryResult(new RoleSummaryResult(summaries))); }
From source file:com.opengamma.strata.measure.swap.SwapMeasureCalculations.java
private CurrencyParameterSensitivities pv01SemiParallelGammaBucketed(ResolvedSwapTrade trade, RatesMarketData marketData) {//from w ww.j a va2 s . c o m // find the curve identifiers and resolve to a single curve ResolvedSwap product = trade.getProduct(); if (product.isCrossCurrency()) { throw new IllegalArgumentException( "Implementation only supports a single curve, but swap is cross-currency"); } Currency currency = product.getLegs().get(0).getCurrency(); Set<Index> indices = product.allIndices(); ImmutableSet<MarketDataId<?>> discountIds = marketData.getLookup().getDiscountMarketDataIds(currency); ImmutableSet<MarketDataId<?>> forwardIds = indices.stream() .flatMap(idx -> marketData.getLookup().getForwardMarketDataIds(idx).stream()) .collect(toImmutableSet()); Set<MarketDataId<?>> allIds = Sets.union(discountIds, forwardIds); if (allIds.size() != 1) { throw new IllegalArgumentException(Messages.format( "Implementation only supports a single curve, but lookup refers to more than one: {}", allIds)); } MarketDataId<?> singleId = allIds.iterator().next(); if (!(singleId instanceof CurveId)) { throw new IllegalArgumentException(Messages.format( "Implementation only supports a single curve, but lookup does not refer to a curve: {} {}", singleId.getClass().getName(), singleId)); } CurveId curveId = (CurveId) singleId; Curve curve = marketData.getMarketData().getValue(curveId); // calculate gamma CurrencyParameterSensitivity gamma = CurveGammaCalculator.DEFAULT.calculateSemiParallelGamma(curve, currency, c -> calculateCurveSensitivity(trade, marketData, curveId, c)); return CurrencyParameterSensitivities.of(gamma).multipliedBy(ONE_BASIS_POINT * ONE_BASIS_POINT); }