Example usage for com.google.common.base Predicates not

List of usage examples for com.google.common.base Predicates not

Introduction

In this page you can find the example usage for com.google.common.base Predicates not.

Prototype

public static <T> Predicate<T> not(Predicate<T> predicate) 

Source Link

Document

Returns a predicate that evaluates to true if the given predicate evaluates to false .

Usage

From source file:brooklyn.entity.waratek.cloudvm.JavaVirtualMachineSshDriver.java

@Override
protected List<String> getJmxJavaConfigOptions() {
    return MutableList.copyOf(Iterables.filter(super.getJmxJavaConfigOptions(),
            Predicates.not(Predicates.containsPattern("javaagent"))));
}

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);//from  w w w. j  a  va2 s .  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;
}

From source file:org.opentestsystem.shared.progman.service.impl.AssetGroupServiceImpl.java

@Override
public void cascadeComponentChanges(final Component component, final boolean retainThisComponent) {
    final List<AssetGroup> foundGroups = this.assetGroupRepository
            .findByComponentId(new ObjectId(component.getId()));
    final List<AssetGroup> updatedGroups = Lists.newArrayList(Iterables.transform(foundGroups,
            new AssetGroupComponentTransformer(component, retainThisComponent)));
    if (!CollectionUtils.isEmpty(updatedGroups)) {
        final List<AssetGroup> groupsToSave = Lists
                .newArrayList(Iterables.filter(updatedGroups, COMPONENT_SAVE_FILTER));
        if (!CollectionUtils.isEmpty(groupsToSave)) {
            this.assetGroupRepository.save(groupsToSave);
        }/*from  w  w  w. j a  v a2 s  .co m*/
        final List<AssetGroup> groupsToRemove = Lists
                .newArrayList(Iterables.filter(updatedGroups, Predicates.not(COMPONENT_SAVE_FILTER)));
        if (!CollectionUtils.isEmpty(groupsToRemove)) {
            this.assetGroupRepository.delete(groupsToRemove);
        }
    }
}

From source file:org.jclouds.compute.internal.BaseLoadBalancerService.java

@Override
public Set<String> loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
        String protocol, int loadBalancerPort, int instancePort) {
    checkNotNull(loadBalancerName, "loadBalancerName");
    checkNotNull(protocol, "protocol");
    checkArgument(protocol.toUpperCase().equals("HTTP") || protocol.toUpperCase().equals("TCP"),
            "Acceptable values for protocol are HTTP or TCP");

    Map<Location, Set<String>> locationMap = Maps.newHashMap();
    for (NodeMetadata node : Iterables.filter(
            context.getComputeService().listNodesDetailsMatching(NodePredicates.all()),
            Predicates.and(filter, Predicates.not(NodePredicates.TERMINATED)))) {
        Set<String> ids = locationMap.get(node.getLocation());
        if (ids == null)
            ids = Sets.newHashSet();//from   w ww. j  a  v  a 2s  .c  o m
        ids.add(node.getProviderId());
        locationMap.put(node.getLocation(), ids);
    }
    Set<String> dnsNames = Sets.newHashSet();
    for (Location location : locationMap.keySet()) {
        logger.debug(">> creating load balancer (%s)", loadBalancerName);
        String dnsName = loadBalancerStrategy.execute(location, loadBalancerName, protocol, loadBalancerPort,
                instancePort, locationMap.get(location));
        dnsNames.add(dnsName);
        logger.debug("<< created load balancer (%s) DNS (%s)", loadBalancerName, dnsName);
    }
    return dnsNames;
}

From source file:org.apache.bazel.checkstyle.PythonCheckstyle.java

@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {

    ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
    SpawnInfo spawnInfo = info.getExtension(SpawnInfo.spawnInfo);

    return Collections2.filter(spawnInfo.getInputFileList(),
            Predicates.and(//from  w  w  w . j a v  a2s.c  om
                    Predicates.or(Predicates.containsPattern(".*/src/.+\\.py[c]{0,1}$"),
                            Predicates.containsPattern("^heronpy/.+\\.py[c]{0,1}$")),
                    Predicates.not(Predicates.containsPattern("third_party/")),
                    Predicates.not(Predicates.containsPattern("integration_test/"))));
}

From source file:com.bigfatgun.fixjures.dao.MyBusinessObjectDAOImpl.java

@Override
public List<MyBusinessObject> findByNegativeAccountBalanceOrderedByIdDescending() {
    return getHelper().findAllOrderedWhere(ASCENDING_ID.reverse(), Predicates.not(POSITIVE_ACCOUNT_BALANCE));
}

From source file:com.facebook.buck.query.RdepsFunction.java

/**
 * Evaluates to the reverse dependencies of the argument 'x' in the transitive closure of the
 * set 'u'. Breadth first search from the set 'x' until there are no more unvisited nodes in the
 * reverse transitive closure or the maximum depth (if supplied) is reached.
 *///from   www . j  av  a2s  .c  o  m
@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    Set<QueryTarget> universeSet = args.get(0).getExpression().eval(env, executor);
    env.buildTransitiveClosure(universeSet, Integer.MAX_VALUE, executor);
    Predicate<QueryTarget> inUniversePredicate = env.getTransitiveClosure(universeSet)::contains;

    // LinkedHashSet preserves the order of insertion when iterating over the values.
    // The order by which we traverse the result is meaningful because the dependencies are
    // traversed level-by-level.
    Set<QueryTarget> visited = new LinkedHashSet<>();
    Set<QueryTarget> argumentSet = args.get(1).getExpression().eval(env, executor);
    Collection<QueryTarget> current = argumentSet;

    int depthBound = args.size() > 2 ? args.get(2).getInteger() : Integer.MAX_VALUE;
    // Iterating depthBound+1 times because the first one processes the given argument set.
    for (int i = 0; i <= depthBound; i++) {
        // Restrict the search to nodes in the transitive closure of the universe set.
        Iterable<QueryTarget> currentInUniverse = Iterables.filter(current, inUniversePredicate);

        // Filter nodes visited before.
        Collection<QueryTarget> next = env
                .getReverseDeps(Iterables.filter(currentInUniverse, Predicates.not(visited::contains)));
        Iterables.addAll(visited, currentInUniverse);
        if (next.isEmpty()) {
            break;
        }
        current = next;
    }
    return visited;
}

From source file:org.apache.bazel.checkstyle.CppCheckstyle.java

@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {

    ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
    CppCompileInfo cppInfo = info.getExtension(CppCompileInfo.cppCompileInfo);

    return Collections2.filter(cppInfo.getSourcesAndHeadersList(),
            Predicates.and(Predicates.not(Predicates.containsPattern("external/")),
                    Predicates.not(Predicates.containsPattern("third_party/")),
                    Predicates.not(Predicates.containsPattern("config/heron-config.h")),
                    Predicates.not(Predicates.containsPattern(".*pb.h$")),
                    Predicates.not(Predicates.containsPattern(".*cc_wrapper.sh$")),
                    Predicates.not(Predicates.containsPattern(".*pb.cc$"))));
}

From source file:net.pterodactylus.sone.web.KnownSonesPage.java

/**
 * {@inheritDoc}//from   w w  w.  java2  s .com
 */
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext)
        throws RedirectException {
    super.processTemplate(request, templateContext);
    String sortField = request.getHttpRequest().getParam("sort");
    String sortOrder = request.getHttpRequest().getParam("order");
    String filter = request.getHttpRequest().getParam("filter");
    templateContext.set("sort", (sortField != null) ? sortField : "name");
    templateContext.set("order", (sortOrder != null) ? sortOrder : "asc");
    templateContext.set("filter", filter);
    final Sone currentSone = getCurrentSone(request.getToadletContext(), false);
    Collection<Sone> knownSones = Collections2.filter(webInterface.getCore().getSones(),
            Sone.EMPTY_SONE_FILTER);
    if ((currentSone != null) && "followed".equals(filter)) {
        knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {

            @Override
            public boolean apply(Sone sone) {
                return currentSone.hasFriend(sone.getId());
            }
        });
    } else if ((currentSone != null) && "not-followed".equals(filter)) {
        knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {

            @Override
            public boolean apply(Sone sone) {
                return !currentSone.hasFriend(sone.getId());
            }
        });
    } else if ("new".equals(filter)) {
        knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {

            /**
             * {@inheritDoc}
             */
            @Override
            public boolean apply(Sone sone) {
                return !sone.isKnown();
            }
        });
    } else if ("not-new".equals(filter)) {
        knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {

            /**
             * {@inheritDoc}
             */
            @Override
            public boolean apply(Sone sone) {
                return sone.isKnown();
            }
        });
    } else if ("own".equals(filter)) {
        knownSones = Collections2.filter(knownSones, Sone.LOCAL_SONE_FILTER);
    } else if ("not-own".equals(filter)) {
        knownSones = Collections2.filter(knownSones, Predicates.not(Sone.LOCAL_SONE_FILTER));
    }
    List<Sone> sortedSones = new ArrayList<Sone>(knownSones);
    if ("activity".equals(sortField)) {
        if ("asc".equals(sortOrder)) {
            Collections.sort(sortedSones, Ordering.from(Sone.LAST_ACTIVITY_COMPARATOR).reverse());
        } else {
            Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR);
        }
    } else if ("posts".equals(sortField)) {
        if ("asc".equals(sortOrder)) {
            Collections.sort(sortedSones, Ordering.from(Sone.POST_COUNT_COMPARATOR).reverse());
        } else {
            Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR);
        }
    } else if ("images".equals(sortField)) {
        if ("asc".equals(sortOrder)) {
            Collections.sort(sortedSones, Ordering.from(Sone.IMAGE_COUNT_COMPARATOR).reverse());
        } else {
            Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR);
        }
    } else {
        if ("desc".equals(sortOrder)) {
            Collections.sort(sortedSones, Ordering.from(Sone.NICE_NAME_COMPARATOR).reverse());
        } else {
            Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR);
        }
    }
    Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25)
            .setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
    templateContext.set("pagination", sonePagination);
    templateContext.set("knownSones", sonePagination.getItems());
}

From source file:com.ignorelist.kassandra.steam.scraper.HtmlTagLoader.java

@Override
public GameInfo load(Long gameId, EnumSet<TagType> types) {
    GameInfo gameInfo = new GameInfo();
    gameInfo.setId(gameId);/*  w  w w.j  a va  2  s  . com*/
    try {
        if (!types.isEmpty()) {
            InputStream inputStream = cache.get(gameId.toString());
            try {
                Document document = Jsoup.parse(inputStream, Charsets.UTF_8.name(), buildPageUrl(gameId));

                Elements appName = document.select("div.apphub_AppName");
                Element nameElement = Iterables.getFirst(appName, null);
                if (null != nameElement && null != nameElement.text()) {
                    gameInfo.setName(nameElement.text().trim());
                }

                Elements appIconElements = document.select("div.apphub_AppIcon img");
                gameInfo.setIcon(getSrcUri(appIconElements));

                Elements headerImageElements = document.select("img.game_header_image_full");
                gameInfo.setHeaderImage(getSrcUri(headerImageElements));
                final SetMultimap<TagType, String> tags = gameInfo.getTags();

                if (types.contains(TagType.CATEGORY)) {
                    Elements categories = document.select("div#category_block a.name");
                    copyText(categories, tags.get(TagType.CATEGORY));
                }
                if (types.contains(TagType.GENRE)) {
                    Elements genres = document.select("div.details_block a[href*=/genre/]");
                    copyText(genres, tags.get(TagType.GENRE));
                }
                if (types.contains(TagType.USER)) {
                    Elements userTags = document.select("a.app_tag");
                    copyText(Iterables.filter(userTags, Predicates.not(DISPLAY_NONE_PREDICATE)),
                            tags.get(TagType.USER));
                    copyText(Iterables.filter(userTags, DISPLAY_NONE_PREDICATE), tags.get(TagType.USER_HIDDEN));
                }
                if (types.contains(TagType.VR)) {
                    Elements vrSupport = document
                            .select("div.game_area_details_specs a.name[href*=#vrsupport=");
                    copyText(vrSupport, tags.get(TagType.VR));
                }
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        }
    } catch (ExecutionException ex) {
        Logger.getLogger(HtmlTagLoader.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HtmlTagLoader.class.getName()).log(Level.SEVERE, null, ex);
    }

    return gameInfo;
}