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:org.eclipse.emf.compare.ide.ui.internal.logical.LogicalModelResolver.java

/**
 * {@inheritDoc}/*  w  w  w  .  j  a  v a 2  s. co m*/
 * 
 * @see org.eclipse.emf.compare.ide.ui.logical.IModelResolver#resolveLocalModel(org.eclipse.core.resources.IResource,
 *      org.eclipse.core.runtime.IProgressMonitor)
 */
public StorageTraversal resolveLocalModel(IResource start, IProgressMonitor monitor) {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);

    if (!(start instanceof IFile)) {
        subMonitor.setWorkRemaining(0);
        return new StorageTraversal(Sets.<IStorage>newLinkedHashSet());
    }

    final SyncResourceSet resourceSet = new SyncResourceSet();
    final StorageURIConverter converter = new StorageURIConverter(resourceSet.getURIConverter());
    resourceSet.setURIConverter(converter);

    if (resourceSet.resolveAll((IFile) start, subMonitor.newChild(95))) {
        final Set<IStorage> storages = Sets.newLinkedHashSet(
                Sets.union(Collections.singleton((IFile) start), converter.getLoadedRevisions()));
        subMonitor.worked(5);
        return new StorageTraversal(storages);
    } else {
        subMonitor.setWorkRemaining(5);
        // We failed to load the starting point. simply return an empty traversal.
    }

    subMonitor.worked(5);

    return new StorageTraversal(Collections.singleton((IFile) start));
}

From source file:org.apache.james.jmap.model.MessageProperties.java

private MessageProperties selectBody() {
    ImmutableSet<MessageProperty> messageProperties = buildOutputMessageProperties();
    if (messageProperties.contains(MessageProperty.body)) {
        return usingProperties(
                Sets.difference(Sets.union(messageProperties, ImmutableSet.of(MessageProperty.textBody)),
                        ImmutableSet.of(MessageProperty.body)));
    }/*from ww w  .  ja v  a2  s .  c o m*/
    return this;
}

From source file:org.dishevelled.venn.model.VennModelImpl.java

/**
 * Create and return a new union view.//from  www  . j  a v a  2 s. c  o  m
 *
 * @return a new union view
 */
private Set<E> createUnion() {
    Set<E> rv = sets.get(0);
    for (Set<E> set : sets) {
        rv = Sets.union(rv, set);
    }
    return rv;
}

From source file:com.github.fhirschmann.clozegen.lib.generators.api.Gap.java

/**
 * Returns an unmodifiable view of all answers (the union of invalid and valid
 * answers)./*from   w w w .  j  av  a2  s .  c o  m*/
 *
 * @return set of invalid and valid answers
 */
public Set<String> getAllAnswers() {
    return Sets.union(getValidAnswers(), getInvalidAnswers());
}

From source file:org.eclipse.viatra.query.runtime.matchers.planning.helpers.FunctionalDependencyHelper.java

/***
 * Returns the dependency set over attributes in {@link targetAttributes} that are implied by a given source dependency set.
 * <p> Note: exponential in the size of the target attribute set.
 * <p> Note: minimality of the returned dependency set is currently not guaranteed.
 * @param originalDependencies all dependencies that are known to hold on a wider set of attributes
 * @param targetAttributes the set of attributes we are interested in
 * @since 1.5/* w  w w .  jav a2  s.  c  o  m*/
 */
public static <A> Map<Set<A>, Set<A>> projectDependencies(Map<Set<A>, Set<A>> originalDependencies,
        Set<A> targetAttributes) {
    // only those attributes are considered as left-hand-side candidates that occur at least once in dependencies
    Set<A> leftCandidates = new HashSet<A>();
    for (Entry<Set<A>, Set<A>> dependency : originalDependencies.entrySet()) {
        if (!isTrivial(dependency.getKey(), dependency.getValue())) // only if non-trivial
            leftCandidates.addAll(Sets.intersection(dependency.getKey(), targetAttributes));
    }

    // Compute an initial list of nontrivial projected dependencies - it does not have to be minimal yet
    Map<Set<A>, Set<A>> initialDependencies = new HashMap<Set<A>, Set<A>>();
    for (Set<A> leftSet : Sets.powerSet(leftCandidates)) {
        Set<A> rightSet = Sets.intersection(closureOf(leftSet, originalDependencies), targetAttributes);
        if (!isTrivial(leftSet, rightSet)) {
            initialDependencies.put(leftSet, rightSet);
        }
    }
    // Don't forget to include constants!
    Set<A> constants = Sets.intersection(closureOf(Collections.<A>emptySet(), originalDependencies),
            targetAttributes);
    if (!constants.isEmpty()) {
        initialDependencies.put(Collections.<A>emptySet(), constants);
    }

    // Omit those dependencies where the LHS has superfluous attributes
    Map<Set<A>, Set<A>> solidDependencies = new HashMap<Set<A>, Set<A>>();
    for (Entry<Set<A>, Set<A>> dependency : initialDependencies.entrySet()) {
        Set<A> leftSet = dependency.getKey();
        Set<A> rightSet = dependency.getValue();
        boolean solid = true;
        for (A skipped : leftSet) { // what if we skip one attribute from the left set?
            Set<A> singleton = Collections.singleton(skipped);
            Set<A> candidate = Sets.difference(leftSet, singleton);
            Set<A> rightCandidate = initialDependencies.get(candidate);
            if (rightCandidate != null) {
                if (Sets.union(rightCandidate, singleton).containsAll(rightSet)) {
                    solid = false;
                    break;
                }
            }
        }
        if (solid) {
            solidDependencies.put(leftSet, rightSet);
        }
    }

    // TODO perform proper minimization, 
    // see e.g. page 45 in http://www.cs.ubc.ca/~hkhosrav/db/slides/03.design%20theory.pdf

    return Collections.unmodifiableMap(solidDependencies);
}

From source file:org.apache.james.webadmin.service.UserQuotaService.java

private Map<Quota.Scope, QuotaDTO> mergeMaps(Map<Quota.Scope, QuotaCount> counts,
        Map<Quota.Scope, QuotaSize> sizes) {
    return Sets.union(counts.keySet(), sizes.keySet()).stream()
            .collect(Collectors.toMap(Function.identity(),
                    scope -> QuotaDTO.builder().count(Optional.ofNullable(counts.get(scope)))
                            .size(Optional.ofNullable(sizes.get(scope))).build()));
}

From source file:net.derquinse.bocas.AbstractGuavaCachingBocas.java

@Override
public final Set<ByteString> contained(Iterable<ByteString> keys) {
    Set<K> ikRequested = toInternalKeySet(keys);
    if (ikRequested.isEmpty()) {
        return ImmutableSet.of();
    }//from w  w  w .j a va  2s .c  om
    Set<K> ikCached = Sets.intersection(ikRequested, cache.asMap().keySet()).immutableCopy();
    Set<K> ikNotCached = Sets.difference(ikRequested, ikCached).immutableCopy();
    Set<ByteString> kCached = toKeySet(ikCached);
    if (ikNotCached.isEmpty()) {
        return kCached;
    }
    Set<ByteString> kFound = bocas.contained(toKeySet(ikNotCached));
    return Sets.union(kCached, kFound).immutableCopy();
}

From source file:ai.grakn.graql.internal.pattern.property.RelationProperty.java

@Override
public Collection<EquivalentFragmentSet> match(Var start) {
    Collection<Var> castingNames = new HashSet<>();

    ImmutableSet<EquivalentFragmentSet> traversals = relationPlayers.stream().flatMap(relationPlayer -> {

        Var castingName = Graql.var();
        castingNames.add(castingName);/*from   ww w  .j  ava2s  .c om*/

        return equivalentFragmentSetFromCasting(start, castingName, relationPlayer);
    }).collect(toImmutableSet());

    ImmutableSet<EquivalentFragmentSet> distinctCastingTraversals = castingNames.stream()
            .flatMap(castingName -> castingNames.stream().filter(otherName -> !otherName.equals(castingName))
                    .map(otherName -> EquivalentFragmentSets.neq(castingName, otherName)))
            .collect(toImmutableSet());

    return Sets.union(traversals, distinctCastingTraversals);
}

From source file:com.ggvaidya.scinames.summary.DatasetSimilarityView.java

public void init() {
    // Setup stage.
    stage.setTitle("Timepoint similarity");

    // Setup table.
    controller.getTableEditableProperty().set(false);
    //controller.setTableColumnResizeProperty(TableView.CONSTRAINED_RESIZE_POLICY);
    ObservableList<TableColumn> cols = controller.getTableColumnsProperty();
    cols.clear();/*  w w  w  .  ja v a2 s .  c  o m*/

    // Set up columns.
    TableColumn<Dataset, String> colTimepointName = new TableColumn<>("Timepoint");
    colTimepointName.setCellValueFactory(new PropertyValueFactory<>("name"));
    colTimepointName.setPrefWidth(100.0);
    cols.add(colTimepointName);

    // Precalculating.
    double lowest = 100.0;
    Dataset tpLowest1 = null;
    Dataset tpLowest2 = null;

    LOGGER.info("Starting precalculating.");

    Table<Dataset, Dataset, String> data = HashBasedTable.create();
    for (Dataset tp : projectView.getProject().getDatasets()) {
        for (Dataset colTP : projectView.getProject().getDatasets()) {
            if (data.contains(tp, colTP))
                continue;

            NameClusterManager manager = projectView.getProject().getNameClusterManager();
            Set<NameCluster> leftTP = tp.getRecognizedNames(projectView.getProject())
                    .map(n -> manager.getCluster(n).get()).collect(Collectors.toSet());
            Set<NameCluster> rightTP = colTP.getRecognizedNames(projectView.getProject())
                    .map(n -> manager.getCluster(n).get()).collect(Collectors.toSet());

            // Overlapping name concepts.
            Sets.SetView<NameCluster> union = Sets.union(leftTP, rightTP);
            Sets.SetView<NameCluster> intersection = Sets.intersection(leftTP, rightTP);

            double res = (((double) intersection.size()) / union.size() * 100);

            if (lowest > res) {
                lowest = res;
                tpLowest1 = tp;
                tpLowest2 = colTP;
            }

            String result = new BigDecimal(res).setScale(2, RoundingMode.DOWN).toPlainString() + "% ("
                    + intersection.size() + " identical out of " + union.size() + ")";

            data.put(tp, colTP, result);
            data.put(colTP, tp, result);
        }
    }

    LOGGER.info("Precalculating done.");

    // Setup headertext.
    String str_lowest = "";
    if (tpLowest1 != null && tpLowest2 != null) {
        str_lowest = " (lowest: " + new BigDecimal(lowest).setScale(2, RoundingMode.DOWN).toPlainString()
                + "% between " + tpLowest1.getName() + " and " + tpLowest2.getName() + ")";
    }
    controller.getHeaderTextProperty().set("How similar is each timepoint to every other?" + str_lowest);
    controller.getHeaderTextEditableProperty().set(false);

    // Create a column for every timepoint here.
    projectView.getProject().getDatasets().forEach((Dataset colTP) -> {
        TableColumn<Dataset, String> colTimepoint = new TableColumn<>(colTP.getName());
        colTimepoint.setCellValueFactory((TableColumn.CellDataFeatures<Dataset, String> features) -> {
            Dataset tp = features.getValue();

            return new ReadOnlyStringWrapper(data.get(tp, colTP));
        });
        colTimepoint.setPrefWidth(100.0);
        cols.add(colTimepoint);
    });

    // Set table items.
    List<Dataset> timepoints = projectView.getProject().getDatasets();
    controller.getTableItemsProperty().set(FXCollections.observableList(timepoints));
}

From source file:org.ow2.authzforce.core.pdp.api.DefaultHashCollectionFactory.java

@Override
public <E> Set<E> newImmutableSet(final Set<? extends E> set1, final Set<? extends E> set2) {
    return Sets.union(set1, set2);
}