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

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

Introduction

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

Prototype

public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) 

Source Link

Document

Returns the composition of a function and a predicate.

Usage

From source file:com.eucalyptus.reporting.ReportingDataVerifier.java

private static Predicate<ResourceWithRelation<?>> withKeyMatching(final ResourceKey key) {
    return Predicates.compose(Predicates.equalTo(key), key());
}

From source file:forge.card.BoosterGenerator.java

/**
 * This method also modifies passed parameter
 *//*from  ww w .  j  a  v a2s .  c  om*/
private static Predicate<PaperCard> buildExtraPredicate(List<String> operators) {

    List<Predicate<PaperCard>> conditions = new ArrayList<>();

    Iterator<String> itOp = operators.iterator();
    while (itOp.hasNext()) {

        String operator = itOp.next();
        if (StringUtils.isEmpty(operator)) {
            itOp.remove();
            continue;
        }

        if (operator.endsWith("s")) {
            operator = operator.substring(0, operator.length() - 1);
        }

        boolean invert = operator.charAt(0) == '!';
        if (invert) {
            operator = operator.substring(1);
        }

        Predicate<PaperCard> toAdd = null;
        if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) {
            toAdd = Predicates.compose(CardRulesPredicates.splitType(CardSplitType.Transform),
                    PaperCard.FN_GET_RULES);
        } else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) {
            toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard.FN_GET_RULES);
        } else if (operator.equalsIgnoreCase(BoosterSlots.BASIC_LAND)) {
            toAdd = IPaperCard.Predicates.Presets.IS_BASIC_LAND;
        } else if (operator.equalsIgnoreCase(BoosterSlots.TIME_SHIFTED)) {
            toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL;
        } else if (operator.equalsIgnoreCase(BoosterSlots.SPECIAL)) {
            toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL;
        } else if (operator.equalsIgnoreCase(BoosterSlots.MYTHIC)) {
            toAdd = IPaperCard.Predicates.Presets.IS_MYTHIC_RARE;
        } else if (operator.equalsIgnoreCase(BoosterSlots.RARE)) {
            toAdd = IPaperCard.Predicates.Presets.IS_RARE;
        } else if (operator.equalsIgnoreCase(BoosterSlots.UNCOMMON)) {
            toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON;
        } else if (operator.equalsIgnoreCase(BoosterSlots.COMMON)) {
            toAdd = IPaperCard.Predicates.Presets.IS_COMMON;
        } else if (operator.startsWith("name(")) {
            operator = StringUtils.strip(operator.substring(4), "() ");
            String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"');
            toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames));
        } else if (operator.startsWith("color(")) {
            operator = StringUtils.strip(operator.substring("color(".length() + 1), "()\" ");
            switch (operator.toLowerCase()) {
            case "black":
                toAdd = Presets.IS_BLACK;
                break;
            case "blue":
                toAdd = Presets.IS_BLUE;
                break;
            case "green":
                toAdd = Presets.IS_GREEN;
                break;
            case "red":
                toAdd = Presets.IS_RED;
                break;
            case "white":
                toAdd = Presets.IS_WHITE;
                break;
            case "colorless":
                toAdd = Presets.IS_COLORLESS;
                break;
            }
        } else if (operator.startsWith("fromSets(")) {
            operator = StringUtils.strip(operator.substring("fromSets(".length() + 1), "()\" ");
            String[] sets = operator.split(",");
            toAdd = IPaperCard.Predicates.printedInSets(sets);
        } else if (operator.startsWith("fromSheet(") && invert) {
            String sheetName = StringUtils.strip(operator.substring(9), "()\" ");
            Iterable<PaperCard> src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList();
            List<String> cardNames = Lists.newArrayList();
            for (PaperCard card : src) {
                cardNames.add(card.getName());
            }
            toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames));
        }

        if (toAdd == null) {
            continue;
        } else {
            itOp.remove();
        }

        if (invert) {
            toAdd = Predicates.not(toAdd);
        }
        conditions.add(toAdd);

    }

    if (conditions.isEmpty()) {
        return Predicates.alwaysTrue();
    }

    return Predicates.and(conditions);

}

From source file:com.android.builder.internal.packaging.IncrementalPackager.java

/**
 * Updates resources in the archive.//w w w .  jav  a  2s.  c  om
 *
 * @param files the resources to update
 * @throws IOException failed to update the archive
 */
public void updateJavaResources(@NonNull ImmutableMap<RelativeFile, FileStatus> files) throws IOException {
    /*
     * There is a bug somewhere in the proguard build tasks that places .class files as
     * resources. These will be removed here, but this filtering code can -- and should -- be
     * removed once that bug is fixed.
     */
    Predicate<String> isNotClassFile = new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            return !input.endsWith(SdkConstants.DOT_CLASS);
        }
    };

    updateFiles(PackagedFileUpdates.fromIncrementalRelativeFileSet(
            Maps.filterKeys(files, Predicates.compose(isNotClassFile, RelativeFile.EXTRACT_PATH))));
}

From source file:dodola.anole.lib.FileUtils.java

/**
 * Find a list of files in a directory, using a specified path pattern.
 */// w  w  w .  j a v a2 s .  c o m
public static List<File> find(File base, final Pattern pattern) {
    checkArgument(base.isDirectory(), "'base' must be a directory.");
    return Files.fileTreeTraverser().preOrderTraversal(base)
            .filter(Predicates.compose(Predicates.contains(pattern), GET_PATH)).toList();
}

From source file:org.sosy_lab.cpachecker.core.algorithm.precondition.PreconditionHelper.java

private List<BooleanFormula> getAbstractionsOnLocationFromReached(final ReachedSet pReached,
        final PreconditionPartition pPartition, final CFANode pTargetLocation) {

    Preconditions.checkNotNull(pTargetLocation);
    Preconditions.checkNotNull(pPartition);
    Preconditions.checkNotNull(pReached);

    List<BooleanFormula> result = Lists.newArrayList();

    // Also for backwards analysis can exist multiple target states (for the same CFA location)
    FluentIterable<AbstractState> targetStates = from(pReached)
            .filter(Predicates.compose(PredicateAbstractState.FILTER_ABSTRACTION_STATES,
                    toState(PredicateAbstractState.class)))
            .filter(Predicates.compose(equalTo(pTargetLocation), AbstractStates.EXTRACT_LOCATION));

    for (AbstractState s : targetStates) {
        if (isStateFromPartition(s, pPartition)) {

            final ARGState target = (ARGState) s;
            final ARGPath pathToEntryLocation = ARGUtils.getOnePathTo(target); // BACKWARDS analysis: target = entry location

            Verify.verify(pathToEntryLocation != null,
                    "The abstract target-state must be on an abstract path!");

            final PredicateAbstractState state = getTargetAbstractionState(pathToEntryLocation,
                    pTargetLocation);//from  w  ww .  j a v  a 2 s .co m

            // The last abstraction state before the target location contains the negation of the WP
            result.add(mgrv.uninstantiate(state.getAbstractionFormula().asFormula()));
        }
    }

    return result;
}

From source file:edu.harvard.med.screensaver.service.libraries.PlateUpdater.java

@Transactional
public void updatePrimaryPlateConcentrations(Copy copy) {
    ConcentrationStatistics concentrationStatistics = new ConcentrationStatistics();
    copy.setConcentrationStatistics(concentrationStatistics);
    // update the plates using values from the wells
    Collection<Plate> platesToConsider = Sets.newHashSet(copy.getPlates().values());

    for (Iterator<Plate> iter = platesToConsider.iterator(); iter.hasNext();) {
        Plate p = iter.next();//from  ww  w  . j  av  a2s . c  o m
        p.setConcentrationStatistics(new ConcentrationStatistics());
        updatePrimaryWellConcentration(p);
        // update the copy with the values from the plate
        if (p.getMaxMgMlConcentration() != null) {
            if (concentrationStatistics.getMaxMgMlConcentration() == null)
                concentrationStatistics.setMaxMgMlConcentration(p.getMaxMgMlConcentration());
            else if (p.getMaxMgMlConcentration()
                    .compareTo(concentrationStatistics.getMaxMgMlConcentration()) > 0)
                concentrationStatistics.setMaxMgMlConcentration(p.getMaxMgMlConcentration());
            if (concentrationStatistics.getMinMgMlConcentration() == null)
                concentrationStatistics.setMinMgMlConcentration(p.getMinMgMlConcentration());
            else if (p.getMinMgMlConcentration()
                    .compareTo(concentrationStatistics.getMinMgMlConcentration()) < 0)
                concentrationStatistics.setMinMgMlConcentration(p.getMinMgMlConcentration());
        }
        if (p.getMaxMolarConcentration() != null) {
            if (concentrationStatistics.getMaxMolarConcentration() == null)
                concentrationStatistics.setMaxMolarConcentration(p.getMaxMolarConcentration());
            else if (p.getMaxMolarConcentration()
                    .compareTo(concentrationStatistics.getMaxMolarConcentration()) > 0)
                concentrationStatistics.setMaxMolarConcentration(p.getMaxMolarConcentration());
            if (concentrationStatistics.getMinMolarConcentration() == null)
                concentrationStatistics.setMinMolarConcentration(p.getMinMolarConcentration());
            else if (p.getMinMolarConcentration()
                    .compareTo(concentrationStatistics.getMinMolarConcentration()) < 0)
                concentrationStatistics.setMinMolarConcentration(p.getMinMolarConcentration());
        }
        if (!isStoredAtFacility.apply(p.getStatus())) // consider only plates stored at this facility
        {
            iter.remove();
            continue;
        }
    }

    Map<BigDecimal, Integer> mgMlCounts = Maps
            .transformValues(
                    Multimaps.index(
                            Lists.newArrayList(Iterators.filter(platesToConsider.iterator(),
                                    Predicates.compose(Predicates.notNull(),
                                            Plate.ToPrimaryWellMgMlConcentration))),
                            Plate.ToPrimaryWellMgMlConcentration).asMap(),
                    CollectionSize);

    if (!mgMlCounts.isEmpty())
        concentrationStatistics.setPrimaryWellMgMlConcentration(findMaxByValueThenKey(mgMlCounts).getKey());

    Map<MolarConcentration, Integer> molarCounts = Maps
            .transformValues(
                    Multimaps.index(
                            Lists.newArrayList(Iterators.filter(platesToConsider.iterator(),
                                    Predicates.compose(Predicates.notNull(),
                                            Plate.ToPrimaryWellMolarConcentration))),
                            Plate.ToPrimaryWellMolarConcentration).asMap(),
                    CollectionSize);

    if (!molarCounts.isEmpty())
        concentrationStatistics.setPrimaryWellMolarConcentration(findMaxByValueThenKey(molarCounts).getKey());
}

From source file:dodola.anole.lib.FileUtils.java

/**
 * Find a file with the specified name in a given directory .
 *///  w  ww.  j a  va2  s .co m
public static Optional<File> find(File base, final String name) {
    checkArgument(base.isDirectory(), "'base' must be a directory.");
    return Files.fileTreeTraverser().preOrderTraversal(base)
            .filter(Predicates.compose(Predicates.equalTo(name), GET_NAME)).last();
}

From source file:com.android.utils.FileUtils.java

/**
 * Find a list of files in a directory, using a specified path pattern.
 *//*from   ww w .  j  a v a 2s .  c  o  m*/
public static List<File> find(@NonNull File base, @NonNull final Pattern pattern) {
    checkArgument(base.isDirectory(), "'base' must be a directory.");
    return Files.fileTreeTraverser().preOrderTraversal(base)
            .filter(Predicates.compose(Predicates.contains(pattern), GET_PATH)).toList();
}

From source file:org.sosy_lab.cpachecker.core.algorithm.precondition.PreconditionRefinerAlgorithm.java

private Set<ARGState> getStatesAtLocation(final ReachedSet pReachedSet,
        final Predicate<AbstractState> pPartitionFilterPredicate, final CFANode pLoc)
        throws NoTraceFoundException {

    Preconditions.checkNotNull(pPartitionFilterPredicate);
    Preconditions.checkNotNull(pReachedSet);
    Preconditions.checkNotNull(pLoc);//from  w w  w. ja  va2 s.  c om

    ImmutableSet<ARGState> statesAtWpLoc = from(pReachedSet)
            .filter(Predicates.compose(equalTo(pLoc), AbstractStates.EXTRACT_LOCATION))
            .filter(pPartitionFilterPredicate).transform(toState(ARGState.class)).toSet();

    Set<ARGState> relevantStates = Sets.newHashSet(statesAtWpLoc);
    // Also the states that are covered by an abstract state at the WP location have to be considered!!
    for (ARGState e : statesAtWpLoc) {
        relevantStates.addAll(e.getCoveredByThis());
    }

    if (relevantStates.isEmpty()) {
        throw new NoTraceFoundException("No trace to the target location found!");
    }

    return relevantStates;
}

From source file:forge.deck.generation.DeckGeneratorBase.java

protected Iterable<PaperCard> selectCardsOfMatchingColorForPlayer(boolean forAi) {

    // start with all cards
    // remove cards that generated decks don't like
    Predicate<CardRules> canPlay = forAi ? AI_CAN_PLAY : HUMAN_CAN_PLAY;
    Predicate<CardRules> hasColor = new MatchColorIdentity(colors);

    if (useArtifacts) {
        hasColor = Predicates.or(hasColor, COLORLESS_CARDS);
    }/*from w ww .  ja  v  a  2  s.  c  o m*/
    return Iterables.filter(pool.getAllCards(),
            Predicates.compose(Predicates.and(canPlay, hasColor), PaperCard.FN_GET_RULES));
}