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

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

Introduction

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

Prototype

@GwtIncompatible("NavigableSet")
@SuppressWarnings("unchecked")
@CheckReturnValue
public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate) 

Source Link

Document

Returns the elements of a NavigableSet , unfiltered , that satisfy a predicate.

Usage

From source file:org.sosy_lab.cpachecker.util.precondition.segkro.MinCorePrio.java

protected Set<BooleanFormula> predicatesOnlyOnLiveVariables(final Set<BooleanFormula> pFrom,
        final CFANode pLocation) {

    return Sets.filter(pFrom, new Predicate<BooleanFormula>() {
        @Override//from  w ww. j  a v a 2s .com
        public boolean apply(BooleanFormula pArg0) {
            Set<String> predOnVars = mgrv.extractVariableNames(pArg0);
            for (String instantiatedVarName : predOnVars) {
                final String varName = FormulaManagerView.parseName(instantiatedVarName).getFirst();
                if (!cfa.getLiveVariables().get().isVariableLive(varName, pLocation)) {
                    return false;
                }
            }
            return true;
        }
    });
}

From source file:com.willowtreeapps.saguaro.plugin.SaguaroGenerate.java

private Set<LicenseDependency> getDependenciesWithoutLicenses(final Set<LicenseDependency> dependencies) {
    return Sets.filter(dependencies, new Predicate<LicenseDependency>() {
        @Override//ww w. j a  v  a2s  . com
        public boolean apply(LicenseDependency dependency) {
            return dependency.getLicenses().isEmpty();
        }
    });
}

From source file:com.github.benmanes.caffeine.cache.testing.CacheGenerator.java

/** Returns the Cartesian set of the possible cache configurations. */
@SuppressWarnings("unchecked")
private Set<List<Object>> combinations() {
    Set<Boolean> asyncLoading = ImmutableSet.of(true, false);
    Set<Stats> statistics = filterTypes(options.stats(), cacheSpec.stats());
    Set<ReferenceType> keys = filterTypes(options.keys(), cacheSpec.keys());
    Set<ReferenceType> values = filterTypes(options.values(), cacheSpec.values());
    Set<Compute> computations = filterTypes(options.compute(), cacheSpec.compute());
    Set<Implementation> implementations = filterTypes(options.implementation(), cacheSpec.implementation());

    if (isAsyncLoadingOnly) {
        values = values.contains(ReferenceType.STRONG) ? ImmutableSet.of(ReferenceType.STRONG)
                : ImmutableSet.of();/*from  ww  w  .  java2 s. com*/
        computations = Sets.filter(computations, Compute.ASYNC::equals);
    }
    if (isAsyncLoadingOnly || computations.equals(ImmutableSet.of(Compute.ASYNC))) {
        implementations = implementations.contains(Implementation.Caffeine)
                ? ImmutableSet.of(Implementation.Caffeine)
                : ImmutableSet.of();
    }
    if (computations.equals(ImmutableSet.of(Compute.SYNC))) {
        asyncLoading = ImmutableSet.of(false);
    }

    if (computations.isEmpty() || implementations.isEmpty() || keys.isEmpty() || values.isEmpty()) {
        return ImmutableSet.of();
    }
    return Sets.cartesianProduct(ImmutableSet.copyOf(cacheSpec.initialCapacity()),
            ImmutableSet.copyOf(statistics), ImmutableSet.copyOf(cacheSpec.weigher()),
            ImmutableSet.copyOf(cacheSpec.maximumSize()), ImmutableSet.copyOf(cacheSpec.expireAfterAccess()),
            ImmutableSet.copyOf(cacheSpec.expireAfterWrite()),
            ImmutableSet.copyOf(cacheSpec.refreshAfterWrite()),
            ImmutableSet.copyOf(cacheSpec.advanceOnPopulation()), ImmutableSet.copyOf(keys),
            ImmutableSet.copyOf(values), ImmutableSet.copyOf(cacheSpec.executor()),
            ImmutableSet.copyOf(cacheSpec.removalListener()), ImmutableSet.copyOf(cacheSpec.population()),
            ImmutableSet.of(true, isLoadingOnly), ImmutableSet.copyOf(asyncLoading),
            ImmutableSet.copyOf(computations), ImmutableSet.copyOf(cacheSpec.loader()),
            ImmutableSet.copyOf(cacheSpec.writer()), ImmutableSet.copyOf(implementations));
}

From source file:org.eclipse.sirius.editor.tree.tools.internal.menu.TreeWizardMenuBuilder.java

private Collection generateRefactoringActions(final ISelection selection, final IEditorPart editor) {
    Set<AbstractEObjectRefactoringAction> allActions = Sets.newLinkedHashSet();
    allActions.add(new InitializeTreeFromEClass(editor, selection));

    return Sets.filter(allActions, new Predicate<AbstractEObjectRefactoringAction>() {

        public boolean apply(AbstractEObjectRefactoringAction candidateAction) {
            return candidateAction.isSelectionValid();
        }/*from   w w w .j a  va2  s.co m*/
    });
}

From source file:gov.nih.nci.caarray.domain.file.FileTypeRegistryImpl.java

/**
 * {@inheritDoc}/*w  ww  .j  ava 2  s. co m*/
 */
@Override
public Set<FileType> getDerivedArrayDataTypes() {
    return Sets.filter(this.types, new Predicate<FileType>() {
        @Override
        public boolean apply(FileType ft) {
            return ft.isDerivedArrayData();
        }
    });
}

From source file:org.smartparam.repository.memory.InMemoryParamRepository.java

@Override
public List<String> listParameters(ParameterFilter filter) {
    if (filter.applyNameFilter()) {
        final Pattern pattern = Pattern.compile(filter.nameFilter());
        Set<String> filteredSet = Sets.filter(listParameters(), new Predicate<String>() {
            @Override/*from  w  w w  .  j a v a2s .  com*/
            public boolean apply(String input) {
                return pattern.matcher(input).matches();
            }
        });

        Ordering<String> ordering = Ordering.natural();
        if (filter.sortDirection() == SortDirection.DESC) {
            ordering = ordering.reverse();
        }
        return ordering.sortedCopy(filteredSet);
    } else {
        return new ArrayList<String>(listParameters());
    }
}

From source file:org.spka.cursus.test.AbstractSPKASeries.java

/**
 * Get all the pilots at a Scotland event (including non-Scotland pilots)
 * (but only up to and including the specified event)
 *///from  w w w  .ja  va2 s . c  o m
public Set<Pilot> getEventResultsPilots(final Series series, final Event event) {
    if (isStrictCountryFilter()) {
        return getSeriesResultsPilots(series, event);
    }

    return Sets.filter(series.getPilots(), new Predicate<Pilot>() {
        @Override
        public boolean apply(@Nonnull Pilot pilot) {
            for (Race race : event.getRaces()) {
                if (race.getAttendees().containsKey(pilot)) {
                    return true;
                }
            }

            for (Race race : pilot.getRaces().keySet()) {
                if (race.getEvent().compareTo(event) <= 0) {
                    return SERIES_COUNTRIES.contains(pilot.getCountry());
                }
            }

            for (Event event_ : pilot.getEvents()) {
                if (event_.compareTo(event) <= 0) {
                    return SERIES_COUNTRIES.contains(pilot.getCountry());
                }
            }

            return false;
        }
    });
}

From source file:com.isotrol.impe3.users.impl.PortalUsersServiceImpl.java

private PortalUserEntity fill(PortalUserEntity entity, PortalUserDTO dto) {
    entity.setName(dto.getUsername());/*from  w w w .j  a  v  a  2 s  .  c o  m*/
    entity.setDisplayName(dto.getDisplayName());
    entity.setEmail(dto.getEmail());
    entity.setActive(dto.isActive());
    final Map<String, String> properties = entity.getProperties();
    properties.clear();
    final Map<String, String> dtop = dto.getProperties();
    if (dtop != null) {
        properties.putAll(Maps.filterKeys(Maps.filterValues(dtop, notNull()), notNull()));

    }
    final Set<String> roles = entity.getRoles();
    roles.clear();
    final Set<String> dtor = dto.getRoles();
    if (dtor != null) {
        roles.addAll(Sets.filter(dtor, notNull()));
    }
    return entity;
}

From source file:com.cloudera.gertrude.space.LayerImpl.java

static Set<Segment> findSegments(NavigableMap<Integer, Set<Segment>> segments, final int bucket,
        final long timeMsec) {
    if (segments != null && bucket >= 0) {
        Map.Entry<Integer, Set<Segment>> e = segments.floorEntry(bucket);
        if (e != null) {
            return Sets.filter(e.getValue(), new Predicate<Segment>() {
                @Override// w  ww  .j  a  va 2  s. c o  m
                public boolean apply(Segment segment) {
                    return segment.getBuckets().contains(bucket) && segment.isEnabled(timeMsec);
                }
            });
        }
    }
    return ImmutableSet.of();
}

From source file:eu.lp0.cursus.scoring.scores.impl.GenericRacePositionsData.java

@Override
protected LinkedListMultimap<Integer, Pilot> calculateRacePositionsWithOrder(Race race) {
    // Create a lap order list containing all pilots
    List<Pilot> lapOrder = new ArrayList<Pilot>(scores.getPilots().size());
    lapOrder.addAll(scores.getLapOrder(race));
    Set<Pilot> pilotsWithLaps = ImmutableSet.copyOf(lapOrder);
    SortedSet<Pilot> pilotsWithoutLaps = new TreeSet<Pilot>(new PilotRaceNumberComparator());
    pilotsWithoutLaps.addAll(Sets.difference(scores.getPilots(), pilotsWithLaps));
    lapOrder.addAll(pilotsWithoutLaps);/*ww w .  jav a  2s  . co  m*/

    // Add penalties to race points
    Map<Pilot, Integer> racePoints = scores.getRacePoints(race);
    Map<Pilot, Integer> racePenalties = scores.getRacePenalties(race);
    Map<Pilot, Integer> racePointsWithPenalties = new HashMap<Pilot, Integer>(scores.getPilots().size() * 2);
    for (Pilot pilot : scores.getPilots()) {
        racePointsWithPenalties.put(pilot, racePoints.get(pilot) + racePenalties.get(pilot));
    }

    // Invert race points with ordered lists of pilots
    TreeMultimap<Integer, Pilot> invRacePoints = TreeMultimap.create(Ordering.natural(),
            Ordering.explicit(lapOrder));
    Multimaps.invertFrom(Multimaps.forMap(racePointsWithPenalties), invRacePoints);

    // Calculate race positions
    LinkedListMultimap<Integer, Pilot> racePositions = LinkedListMultimap.create();
    LinkedList<SortedSet<Pilot>> pilotPointsOrdering = new LinkedList<SortedSet<Pilot>>();
    int position = 1;

    if (simulatedToEnd) {
        Set<Pilot> simulatedRacePoints = scores.getSimulatedRacePoints(race);
        for (Integer points : invRacePoints.keySet()) {
            SortedSet<Pilot> pilots = Sets.filter(invRacePoints.get(points),
                    Predicates.not(Predicates.in(simulatedRacePoints)));
            if (!pilots.isEmpty()) {
                pilotPointsOrdering.add(pilots);
            }
        }
        for (Integer points : invRacePoints.keySet()) {
            SortedSet<Pilot> pilots = Sets.filter(invRacePoints.get(points),
                    Predicates.in(simulatedRacePoints));
            if (!pilots.isEmpty()) {
                pilotPointsOrdering.add(pilots);
            }
        }
    } else {
        for (Integer points : invRacePoints.keySet()) {
            pilotPointsOrdering.add(invRacePoints.get(points));
        }
    }

    for (SortedSet<Pilot> pilots : pilotPointsOrdering) {
        switch (equalPositioning) {
        case ALWAYS:
            // Always put pilots with the same points in the same position
            racePositions.putAll(position, pilots);
            position += pilots.size();
            break;

        case WITHOUT_LAPS:
            // Add everyone with laps (by removing pilots without laps from the set) in separate positions
            for (Pilot pilot : Sets.difference(pilots, pilotsWithoutLaps)) {
                racePositions.put(position, pilot);
                position++;
            }

            // Add everyone without laps (by removing pilots with laps from the set) in the same position
            Set<Pilot> pilots2 = Sets.difference(pilots, pilotsWithLaps);
            racePositions.putAll(position, pilots2);
            position += pilots2.size();
            break;

        case NEVER:
            // Always put pilots with the same points in separate positions
            for (Pilot pilot : pilots) {
                racePositions.put(position, pilot);
                position++;
            }
            break;
        }
    }

    return racePositions;
}