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:org.lisapark.octopus.core.ModelBean.java
/** * * @param bean/*from ww w . j a va 2 s . c o m*/ * @return */ public Double compareByProcessors(ModelBean bean) { Double tolerance = null; Set<String> thisProcs = this.getProcessors(); Set<String> thatProcs = bean.getProcessors(); int diff = Sets.symmetricDifference(thisProcs, thatProcs).size(); int union = Sets.union(thisProcs, thatProcs).size(); if (union > 0) { tolerance = (double) diff / (double) union; } return tolerance; }
From source file:at.sti2.spark.rete.beta.JoinNode.java
/** * Activation coming from an alpha memory. *///from w ww .ja v a 2s . c o m @Override public void rightActivate(WorkingMemoryElement wme) { // If the join node is under dummy root beta node left activation should // fire if (((BetaMemory) parent).isRootNode()) { for (RETENode reteNode : children) reteNode.leftActivate(null, wme); } else { if (tests.size() > 0) { Set<Token> resultSet = null; Set<Token> intermediateSet = new LinkedHashSet<Token>(); for (JoinNodeTest test : tests) { Field arg2Field = test.getArg2Field(); RDFValue testTokenValue = wme.getTriple().getRDFTriple().getValueOfField(test.getArg1Field()); Set<Token> tokensFromIndex = null; if (arg2Field == RDFTriple.Field.SUBJECT) { tokensFromIndex = test.getIndexStructure().getElementsFromSubjectIndex(testTokenValue); } else if (arg2Field == RDFTriple.Field.PREDICATE) { tokensFromIndex = test.getIndexStructure().getElementsFromPredicateIndex(testTokenValue); } else if (arg2Field == RDFTriple.Field.OBJECT) { tokensFromIndex = test.getIndexStructure().getElementsFromObjectIndex(testTokenValue); } // Get Tokens at the level of parent beta memory for (Token token : tokensFromIndex) { Set<Token> childTokensAtBetaMemory = token.getChildTokensAtBetaMemory((BetaMemory) parent); intermediateSet = Sets.union(childTokensAtBetaMemory, intermediateSet); } if (resultSet == null && intermediateSet != null) { resultSet = intermediateSet; } else if (intermediateSet != null) { resultSet = Sets.intersection(resultSet, intermediateSet); } } if (resultSet != null) { for (Token token : resultSet) { // Check if the token and wme are falling into a window if (token.getWme().getTriple().isPermanent() || performTimeWindowTest(token, wme)) { // All tests successful for (RETENode reteNode : children) reteNode.leftActivate(token, wme); } } } } else { ArrayList<Token> elementsFromTokenQueue = ((BetaMemory) parent).getIndexStructure() .getElementsFromTokenQueue(); for (RETENode reteNode : children) for (Token token : elementsFromTokenQueue) reteNode.leftActivate(token, wme); } } }
From source file:org.gradoop.flink.model.impl.operators.matching.common.query.QueryHandler.java
/** * Returns all variables contained in the pattern. * * @return all query variables/* w w w . ja v a 2 s .com*/ */ public Set<String> getAllVariables() { return Sets.union(getVertexVariables(), getEdgeVariables()); }
From source file:org.sonar.server.rule.index.RuleResultSetIterator.java
@Override protected RuleDoc read(ResultSet rs) throws SQLException { RuleDoc doc = new RuleDoc(Maps.<String, Object>newHashMapWithExpectedSize(16)); String ruleKey = rs.getString(1); String repositoryKey = rs.getString(2); RuleKey key = RuleKey.of(repositoryKey, ruleKey); // all the fields must be present, even if value is null doc.setKey(key.toString());// ww w . j ava 2s . c o m doc.setRuleKey(ruleKey); doc.setRepository(repositoryKey); doc.setName(rs.getString(3)); String description = rs.getString(4); String descriptionFormat = rs.getString(5); if (descriptionFormat != null) { if (RuleDto.Format.HTML.equals(RuleDto.Format.valueOf(descriptionFormat))) { doc.setHtmlDescription(description); } else { doc.setHtmlDescription(description == null ? null : Markdown.convertToHtml(description)); } } doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(6))); doc.setStatus(rs.getString(7)); doc.setIsTemplate(rs.getBoolean(8)); doc.setAllTags(Sets.union(stringTagsToSet(rs.getString(9)), stringTagsToSet(rs.getString(10)))); String templateRuleKey = rs.getString(11); String templateRepoKey = rs.getString(12); if (templateRepoKey != null && templateRuleKey != null) { doc.setTemplateKey(RuleKey.of(templateRepoKey, templateRuleKey).toString()); } else { doc.setTemplateKey(null); } doc.setInternalKey(rs.getString(13)); doc.setLanguage(rs.getString(14)); doc.setType(RuleType.valueOf(rs.getInt(15))); doc.setCreatedAt(rs.getLong(16)); doc.setUpdatedAt(rs.getLong(17)); return doc; }
From source file:com.facebook.buck.tools.dxanalysis.MutabilityAnalyzer.java
private void go() { while (true) { madeProgress = false;/* ww w .j ava2 s. c o m*/ for (ClassNode klass : allClasses.values()) { analyzeClass(klass); } if (!madeProgress) { break; } } immutableClasses = ImmutableSet.copyOf(Sets.difference(allClasses.keySet(), Sets.union(trulyMutableClasses, classesWithMutableDescendents))); }
From source file:ai.grakn.graql.internal.reasoner.query.ReasonerQueries.java
/** * create an atomic query by combining an existing atomic query and a substitution * @param q base query for substitution to be attached * @param sub (partial) substitution//from w ww.j ava 2 s.co m * @return atomic query with the substitution contained in the query */ public static ReasonerAtomicQuery atomic(ReasonerAtomicQuery q, Answer sub) { return new ReasonerAtomicQuery(Sets.union(q.getAtoms(), sub.toPredicates(q)), q.tx()); }
From source file:org.sosy_lab.cpachecker.cpa.livevar.DeclarationCollectingVisitor.java
@Override public Set<ASimpleDeclaration> visit(JArrayInitializer exp) throws RuntimeException { Set<ASimpleDeclaration> result = Collections.emptySet(); for (JExpression innerExp : exp.getInitializerExpressions()) { result = Sets.union(result, innerExp.accept(this)); }//w w w .j a v a 2s . c om return result; }
From source file:google.registry.util.CollectionUtils.java
/** Copy an {@link ImmutableSet} and add members. */ @SafeVarargs//ww w. j ava2s .c o m public static <T> ImmutableSet<T> union(Set<T> set, T... newMembers) { return Sets.union(set, ImmutableSet.copyOf(newMembers)).immutableCopy(); }
From source file:org.dishevelled.venn.model.TernaryVennModelImpl.java
/** * Create a new ternary venn model with the specified sets. * * @param first first set, must not be null * @param second second set, must not be null * @param third third set, must not be null *//*from w ww. ja v a 2 s .c om*/ public TernaryVennModelImpl(final Set<? extends E> first, final Set<? extends E> second, final Set<? extends E> third) { if (first == null) { throw new IllegalArgumentException("first must not be null"); } if (second == null) { throw new IllegalArgumentException("second must not be null"); } if (third == null) { throw new IllegalArgumentException("third must not be null"); } // todo defensive copy? this.first = new ObservableSetImpl(first); this.second = new ObservableSetImpl(second); this.third = new ObservableSetImpl(third); // alias ObservableSet<E> f = this.first; ObservableSet<E> s = this.second; ObservableSet<E> t = this.third; firstOnly = Sets.difference(Sets.difference(f, s), t); // f - s - t secondOnly = Sets.difference(Sets.difference(s, f), t); // s - f - t thirdOnly = Sets.difference(Sets.difference(t, f), s); // t - f - s firstSecond = Sets.difference(Sets.intersection(f, s), t); // f n s - t firstThird = Sets.difference(Sets.intersection(f, t), s); // f n t - s secondThird = Sets.difference(Sets.intersection(s, t), f); // s n t - f intersection = Sets.intersection(f, Sets.intersection(s, t)); // f n s n t union = Sets.union(f, Sets.union(s, t)); // f u s u t selection = new SelectionView<E>(union, f, s, t); exclusives = new HashMap<ImmutableBitSet, Set<E>>(7); exclusives.put(toImmutableBitSet(0), firstOnly); exclusives.put(toImmutableBitSet(1), secondOnly); exclusives.put(toImmutableBitSet(2), thirdOnly); exclusives.put(toImmutableBitSet(0, 1), firstSecond); exclusives.put(toImmutableBitSet(0, 2), firstThird); exclusives.put(toImmutableBitSet(1, 2), secondThird); exclusives.put(toImmutableBitSet(0, 1, 2), intersection); }
From source file:com.facebook.buck.core.model.impl.AbstractImmutableUnconfiguredBuildTarget.java
@Override public UnconfiguredBuildTarget withAppendedFlavors(Set<Flavor> flavors) { return ImmutableUnconfiguredBuildTarget.of(getUnflavoredBuildTarget(), Sets.union(getFlavors(), flavors)); }