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.davidbracewell.math.distance.EuclideanDistance.java
@Override public double calculate(Map<?, ? extends Number> m1, Map<?, ? extends Number> m2) { Preconditions.checkNotNull(m1, "Vectors cannot be null"); Preconditions.checkNotNull(m2, "Vectors cannot be null"); double diff = 0d; Set<?> union = Sets.union(m1.keySet(), m2.keySet()); for (Object key : union) { if (!m1.containsKey(key)) { diff += Math.pow(m2.get(key).doubleValue(), 2); } else if (!m2.containsKey(key)) { diff += Math.pow(m1.get(key).doubleValue(), 2); } else {/*from ww w .j av a2s.c om*/ diff += Math.pow(m1.get(key).doubleValue() - m2.get(key).doubleValue(), 2); } } return Math.sqrt(diff); }
From source file:org.sosy_lab.cpachecker.cfa.ast.c.FileLocationCollectingVisitor.java
@Override public Set<FileLocation> visit(CArraySubscriptExpression pE) throws RuntimeException { return Sets.union(Collections.singleton(pE.getFileLocation()), Sets.union(pE.getArrayExpression().accept(this), pE.getSubscriptExpression().accept(this))); }
From source file:com.google.gerrit.testutil.FakeAccountByEmailCache.java
@Override public synchronized Set<Account.Id> get(String email) { return Collections.unmodifiableSet(Sets.union(byEmail.get(email), anyEmail)); }
From source file:org.eclipse.sw360.datahandler.permissions.ReleasePermissions.java
protected ReleasePermissions(Release document, User user) { super(document, user); moderators = Sets.union(toSingletonSet(document.createdBy), nullToEmptySet(document.moderators)); contributors = Sets.union(moderators, nullToEmptySet(document.contributors)); attachmentContentIds = nullToEmptySet(document.getAttachments()).stream() .map(a -> a.getAttachmentContentId()).collect(Collectors.toSet()); }
From source file:com.techshroom.wood.module.ModuleDependencyInjector.java
private static void doInject(Module m, Map<String, Module> moduleMap) throws Exception { Set<String> allowedDeps = Sets .union(m.getMetadata().getLoadAfterModules(), m.getMetadata().getRequiredModules()).stream() .map(ModuleDependency::getId).collect(Collectors.toSet()); Collection<Field> injectFields = Stream.of(m.getClass().getDeclaredFields()) .filter(f -> f.isAnnotationPresent(Dependency.class)).collect(Collectors.toSet()); for (Field f : injectFields) { String id = f.getAnnotation(Dependency.class).value(); checkState(allowedDeps.contains(id), "id %s is not a declared dependency of module %s", id, m.getMetadata().getId()); if (moduleMap.containsKey(id)) { f.setAccessible(true);/* w w w .java2 s . c om*/ MODS.setInt(f, MODS.getInt(f) & ~(Modifier.FINAL)); f.set(m, moduleMap.get(id)); } } }
From source file:org.eclipse.emf.compare.ide.ui.internal.logical.resolver.DefaultImplicitDependencies.java
public Set<URI> of(URI uri, URIConverter uriConverter) { return Sets.union(Collections.singleton(uri), registry.getDependencies(uri, uriConverter)); }
From source file:alluxio.cli.validation.ClusterConfConsistencyValidationTask.java
@Override public TaskResult validate(Map<String, String> optionMap) throws InterruptedException { Set<String> masters = new HashSet<>(Utils.readNodeList("masters")); Set<String> workers = new HashSet<>(Utils.readNodeList("workers")); Set<String> nodes = Sets.union(masters, workers); Map<String, Properties> allProperties = new HashMap<>(); Set<String> propertyNames = new HashSet<>(); if (masters.isEmpty()) { System.err.println("No master nodes specified in conf/masters file"); return TaskResult.SKIPPED; }/* ww w. j a va2s . co m*/ if (workers.isEmpty()) { System.err.println("No worker nodes specified in conf/workers file"); return TaskResult.SKIPPED; } TaskResult result = TaskResult.OK; for (String node : nodes) { Properties props = getNodeConf(node); if (props == null) { result = TaskResult.FAILED; continue; } allProperties.put(node, props); propertyNames.addAll(props.stringPropertyNames()); } for (String propertyName : propertyNames) { PropertyKey propertyKey = PropertyKey.fromString(propertyName); PropertyKey.ConsistencyCheckLevel level = propertyKey.getConsistencyLevel(); if (level == PropertyKey.ConsistencyCheckLevel.IGNORE) { continue; } PropertyKey.Scope scope = propertyKey.getScope(); Set<String> targetNodes = ImmutableSet.of(); if (scope.contains(PropertyKey.Scope.MASTER)) { targetNodes = masters; } if (scope.contains(PropertyKey.Scope.WORKER)) { targetNodes = Sets.union(targetNodes, workers); } if (targetNodes.size() < 2) { continue; } String baseNode = null; String baseValue = null; boolean isConsistent = true; String errLabel; TaskResult errLevel; switch (level) { case ENFORCE: errLabel = "Error"; errLevel = TaskResult.FAILED; break; case WARN: errLabel = "Warning"; errLevel = TaskResult.WARNING; break; default: System.err.format("Error: Consistency check level \"%s\" for property \"%s\" is invalid.%n", level.name(), propertyName); result = TaskResult.FAILED; continue; } for (String remoteNode : targetNodes) { if (baseNode == null) { baseNode = remoteNode; Properties baselineProps = allProperties.get(baseNode); baseValue = baselineProps.getProperty(propertyName); continue; } String remoteValue = allProperties.get(remoteNode).getProperty(propertyName); if (!StringUtils.equals(remoteValue, baseValue)) { System.err.format("%s: Property \"%s\" is inconsistent between node %s and %s.%n", errLabel, propertyName, baseNode, remoteNode); System.err.format(" %s: %s%n %s: %s%n", baseNode, Objects.toString(baseValue, "not set"), remoteNode, Objects.toString(remoteValue, "not set")); isConsistent = false; } } if (!isConsistent) { result = result == TaskResult.FAILED ? TaskResult.FAILED : errLevel; } } return result; }
From source file:org.eclipse.sw360.datahandler.permissions.ComponentPermissions.java
protected ComponentPermissions(Component document, User user) { super(document, user); //Should depend on permissions of contained releases this.createdBy = toSingletonSet(document.createdBy); moderators = Sets.union(toSingletonSet(document.createdBy), nullToEmptySet(document.moderators)); attachmentContentIds = nullToEmptySet(document.getAttachments()).stream() .map(a -> a.getAttachmentContentId()).collect(Collectors.toSet()); }
From source file:edu.umd.cs.psl.model.set.term.SetUnion.java
@Override public Set<BasicSetTerm> getBasicTerms() { return Sets.union(left.getBasicTerms(), right.getBasicTerms()); }
From source file:org.sleuthkit.autopsy.timeline.datamodel.EventCluster.java
/** * merge two event clusters into one new event cluster. * * @param cluster1// w w w .j a va2s .c o m * @param cluster2 * * @return a new event cluster that is the result of merging the given * events clusters */ public static EventCluster merge(EventCluster cluster1, EventCluster cluster2) { if (cluster1.getEventType() != cluster2.getEventType()) { throw new IllegalArgumentException("event clusters are not compatible: they have different types"); } if (!cluster1.getDescription().equals(cluster2.getDescription())) { throw new IllegalArgumentException( "event clusters are not compatible: they have different descriptions"); } Sets.SetView<Long> idsUnion = Sets.union(cluster1.getEventIDs(), cluster2.getEventIDs()); Sets.SetView<Long> hashHitsUnion = Sets.union(cluster1.getEventIDsWithHashHits(), cluster2.getEventIDsWithHashHits()); Sets.SetView<Long> taggedUnion = Sets.union(cluster1.getEventIDsWithTags(), cluster2.getEventIDsWithTags()); return new EventCluster(IntervalUtils.span(cluster1.span, cluster2.span), cluster1.getEventType(), idsUnion, hashHitsUnion, taggedUnion, cluster1.getDescription(), cluster1.lod); }