Example usage for com.google.common.collect Sets union

List of usage examples for com.google.common.collect Sets union

Introduction

In this page you can find the example usage for com.google.common.collect Sets union.

Prototype

public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2) 

Source Link

Document

Returns an unmodifiable view of the union of two sets.

Usage

From source file:io.mindmaps.graql.internal.query.predicate.AbstractValuePredicate.java

@Override
public ValuePredicate and(ValuePredicate other) {
    ImmutableSet<Object> innerUnion = ImmutableSet
            .copyOf(Sets.union(innerValues, other.admin().getInnerValues()));
    return new AndPredicate(this, other.admin(), innerUnion);
}

From source file:org.sosy_lab.cpachecker.cfa.ast.c.CIdExpressionCollectingVisitor.java

@Override
public Set<CIdExpression> visit(CArraySubscriptExpression pE) throws RuntimeException {
    return Sets.union(pE.getArrayExpression().accept(this), pE.getSubscriptExpression().accept(this));
}

From source file:nl.knaw.huygens.timbuctoo.storage.mongo.MongoDiff.java

private static BSONObject diff(BSONObject oldObj, BSONObject newObj, boolean createNewObj) {
    BSONObject rv = createNewObj ? new BasicBSONObject() : newObj;
    Set<String> allProps = Sets.newHashSet(Sets.union(newObj.keySet(), oldObj.keySet()));
    for (String k : allProps) {

        if (oldObj.containsField(k) && newObj.containsField(k)) {
            Object oldProp = oldObj.get(k);
            Object newProp = newObj.get(k);
            // Nothing should be null because of how the objectmapper serializes to JSON above.
            // If these are both objects, recurse:
            if (oldProp instanceof BSONObject) {
                BSONObject dProp = diff((BSONObject) oldProp, (BSONObject) newProp, createNewObj);
                if (dProp != null) {
                    rv.put(k, dProp);/* w  w  w  .j a  v  a 2 s  .c  om*/
                } else {
                    rv.removeField(k);
                }
                // If they are lists, recurse:
            } else if (oldProp instanceof List) {
                @SuppressWarnings("unchecked")
                List<Object> oldList = (List<Object>) oldProp;
                @SuppressWarnings("unchecked")
                List<Object> newList = (List<Object>) newProp;
                if (oldList != null && newList != null && oldList.size() == newList.size()) {
                    boolean gotDiffs = false;
                    for (Object oldListItem : oldList) {
                        int newListIndex = newList.indexOf(oldListItem);
                        Object newListItem = newList.get(newListIndex);

                        if (oldListItem instanceof BSONObject && newListItem instanceof BSONObject) {
                            Object diffObj = diff((BSONObject) oldListItem, (BSONObject) newListItem,
                                    createNewObj);
                            gotDiffs = gotDiffs || (diffObj != null);
                            newList.set(newListIndex, diffObj);
                        } else if (oldListItem.equals(newListItem)) {
                            newList.set(newListIndex, null);
                        } else {
                            gotDiffs = true;
                        }
                    }
                    if (gotDiffs) {
                        rv.put(k, newList);
                    } else {
                        rv.removeField(k);
                    }
                } else {
                    rv.put(k, newList);
                }
                // Otherwise, remove if equal:
            } else if (oldProp.equals(newProp)) {
                rv.removeField(k);
            }
        } else if (!newObj.containsField(k)) {
            rv.put(k, null);
        } else if (createNewObj) {
            // If oldObj didn't contain this field, and newObj did,
            // put it in the result (only necessary if we're constructing a new object).
            rv.put(k, newObj.get(k));
        }
    }
    if (rv.toMap().isEmpty()) {
        return null;
    }
    return rv;
}

From source file:PageComparison.Shingle.java

public float jaccard_similarity_coeff(Set<String> shinglesA, Set<String> shinglesB) {
    float neumerator = Sets.intersection(shinglesA, shinglesB).size();
    float denominator = Sets.union(shinglesA, shinglesB).size();
    float result = (neumerator / denominator);
    return result;
}

From source file:org.pentaho.di.trans.dataservice.ui.AbstractModel.java

protected void firePropertyChanges(Map<String, Object> previous) {
    Map<String, Object> update = buildSnapshot(snapshot());
    for (String attr : Sets.union(update.keySet(), previous.keySet())) {
        firePropertyChange(attr, previous.get(attr), update.get(attr));
    }//from w ww . j  av a  2  s. c o m
}

From source file:org.jetbrains.jet.codegen.KotlinCodegenFacade.java

public static void compileCorrectFiles(@NotNull GenerationState state,
        @NotNull CompilationErrorHandler errorHandler) {
    prepareForCompilation(state);//from  ww w . j  av  a2s  . co  m

    MultiMap<FqName, JetFile> packageFqNameToFiles = new MultiMap<FqName, JetFile>();
    for (JetFile file : state.getFiles()) {
        if (file == null)
            throw new IllegalArgumentException("A null file given for compilation");
        packageFqNameToFiles.putValue(file.getPackageFqName(), file);
    }

    Set<FqName> removedPackageFiles = new HashSet<FqName>(state.getPackagesWithRemovedFiles());
    for (FqName fqName : Sets.union(removedPackageFiles, packageFqNameToFiles.keySet())) {
        generatePackage(state, fqName, packageFqNameToFiles.get(fqName), errorHandler);
    }

    state.getFactory().done();
}

From source file:com.google.gerrit.server.index.IndexUtils.java

public static Set<String> changeFields(QueryOptions opts) {
    // Ensure we request enough fields to construct a ChangeData. We need both
    // change ID and project, which can either come via the Change field or
    // separate fields.
    Set<String> fs = opts.fields();
    if (fs.contains(CHANGE.getName())) {
        // A Change is always sufficient.
        return fs;
    }//from  ww w .j  a va2 s  .c  om
    if (fs.contains(PROJECT.getName()) && fs.contains(LEGACY_ID.getName())) {
        return fs;
    }
    return Sets.union(fs, ImmutableSet.of(LEGACY_ID.getName(), PROJECT.getName()));
}

From source file:com.siemens.sw360.datahandler.permissions.ReleasePermissions.java

protected ReleasePermissions(Release document, User user) {
    super(document, user);

    moderators = Sets.union(toSingletonSet(document.createdBy),
            CommonUtils.nullToEmptySet(document.moderators));
    contributors = Sets.union(moderators, CommonUtils.nullToEmptySet(document.contacts));

}

From source file:dynamicrefactoring.domain.xml.XMLRefactoringsCatalog.java

/**
 * Obtiene la instancia del catalogo.//from   w w w.  ja v  a  2s . co m
 * 
 * @return instancia del catalogo
 */
public static RefactoringsCatalog getInstance() {
    if (instance == null) {

        instance = new XMLRefactoringsCatalog(Sets.union(
                getRefactoringsFromDir(RefactoringPlugin.getNonEditableDynamicRefactoringsDir(), false),
                getRefactoringsFromDir(RefactoringPlugin.getDynamicRefactoringsDir(), true)));

    }
    return instance;
}

From source file:org.dllearner.utilities.datastructures.SortedSetTuple.java

public Set<T> getCompleteSet() {
    return Sets.union(posSet, negSet);
}