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

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

Introduction

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

Prototype

public static <T> Predicate<T> equalTo(@Nullable T target) 

Source Link

Document

Returns a predicate that evaluates to true if the object being tested equals() the given target or both are null.

Usage

From source file:org.jetbrains.jet.cli.common.CLICompiler.java

/**
 * Executes the compiler on the parsed arguments
 *///from  w w  w . j a  va2  s. c o  m
@NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull A arguments) {
    if (arguments.help) {
        usage(errStream);
        return OK;
    }

    MessageRenderer messageRenderer = getMessageRenderer(arguments);
    errStream.print(messageRenderer.renderPreamble());

    printArgumentsIfNeeded(errStream, arguments, messageRenderer);
    printVersionIfNeeded(errStream, arguments, messageRenderer);

    MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);

    if (arguments.suppressAllWarnings()) {
        collector = new FilteringMessageCollector(collector,
                Predicates.equalTo(CompilerMessageSeverity.WARNING));
    }

    try {
        return exec(collector, arguments);
    } finally {
        errStream.print(messageRenderer.renderConclusion());
    }
}

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

private Set<Race> getOtherRacesForPilot(Pilot pilot, Race race, boolean checkDiscards) {
    Set<Race> otherRaces = new HashSet<Race>(scores.getRaces().size() * 2);

    // Find other races where the pilot is not attending in a mandatory position
    for (Race otherRace : Iterables.filter(scores.getRaces(), Predicates.not(Predicates.equalTo(race)))) {
        if (!scores.hasSimulatedRacePoints(pilot, otherRace)) {
            otherRaces.add(otherRace);// w  ww .j  a  va2s .c  om
        }
    }

    // If averaging should occur after discards, remove discards... unless that removes all races
    if (checkDiscards && !otherRaces.isEmpty() && method == AveragingMethod.AFTER_DISCARDS) {
        Set<Race> discardedRaces = scoresBeforeAveraging.getDiscardedRaces(pilot);
        if (!discardedRaces.containsAll(otherRaces)) {
            otherRaces.removeAll(discardedRaces);
        }
    }

    return otherRaces;
}

From source file:com.android.tools.idea.npw.importing.ModulesTable.java

private Collection<ModuleImportSettingsPane> updateModuleEditors() {
    isRefreshing = true;//from  www  .  ja v a  2 s. c  o  m
    try {
        ModuleToImport primary = myListModel.getPrimary();
        setModuleNameVisibility(primary != null, myListModel.getAllModules().size() > 1);
        if (primary != null) {
            apply(myPrimaryModuleSettings, primary);
        }

        boolean isFirst = true;
        Collection<ModuleImportSettingsPane> editors = Lists.newLinkedList();

        Set<ModuleToImport> allModules = Sets.newTreeSet(new ModuleComparator(myListModel.getCurrentPath()));
        Iterables.addAll(allModules, Iterables.filter(myListModel.getAllModules(),
                Predicates.not(Predicates.equalTo(myListModel.getPrimary()))));

        for (final ModuleToImport module : allModules) {
            final ModuleImportSettingsPane pane = createModuleSetupPanel(module, isFirst);
            if (pane != null) {
                isFirst = false;
                editors.add(pane);
            }
        }
        return editors;
    } finally {
        isRefreshing = false;
    }
}

From source file:com.google.gitiles.ConfigUtil.java

private static boolean anyOf(String a, String... cases) {
    return Iterables.any(ImmutableList.copyOf(cases), Predicates.equalTo(a.toLowerCase()));
}

From source file:org.apache.brooklyn.util.core.osgi.BundleMaker.java

/** creates a ZIP in a temp file from the given classpath folder, 
 * by recursively taking everything in the referenced directories,
 * treating the given folder as the root,
 * respecting the MANIFEST.MF if present (ie putting it first so it is a valid JAR) */
public File createJarFromClasspathDir(String path) {
    File f = Os.newTempFile(path, "zip");
    ZipOutputStream zout = null;//from w ww .  java2s  . co  m
    try {
        if (Urls.getProtocol(path) == null) {
            // default if no URL is classpath
            path = Os.tidyPath(path);
            if (!path.startsWith("/") && optionalDefaultClassForLoading != null) {
                path = "/" + optionalDefaultClassForLoading.getPackage().getName().replace('.', '/') + "/"
                        + path;
            }
            path = "classpath:" + path;
        }

        if (resources.doesUrlExist(Urls.mergePaths(path, MANIFEST_PATH))) {
            InputStream min = resources.getResourceFromUrl(Urls.mergePaths(path, MANIFEST_PATH));
            zout = new JarOutputStream(new FileOutputStream(f), new Manifest(min));
            addUrlItemRecursively(zout, path, path, Predicates.not(Predicates.equalTo(MANIFEST_PATH)));
        } else {
            zout = new JarOutputStream(new FileOutputStream(f));
            addUrlItemRecursively(zout, path, path, Predicates.alwaysTrue());
        }

        return f;

    } catch (Exception e) {
        throw Exceptions.propagateAnnotated("Error creating ZIP from classpath spec " + path, e);

    } finally {
        Streams.closeQuietly(zout);
    }
}

From source file:org.apache.brooklyn.util.collections.CollectionFunctionals.java

public static <K> Predicate<Map<K, ?>> mapSizeEquals(int targetSize) {
    return Predicates.compose(Predicates.equalTo(targetSize), CollectionFunctionals.<K>mapSize());
}

From source file:org.gradle.plugins.ide.idea.internal.IdeaScalaConfigurer.java

private static Map<String, ProjectLibrary> resolveScalaCompilerLibraries(Collection<Project> scalaProjects,
        boolean useScalaSdk) {
    Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newHashMap();
    for (Project scalaProject : scalaProjects) {
        IdeaModule ideaModule = scalaProject.getExtensions().getByType(IdeaModel.class).getModule();
        Iterable<File> files = getIdeaModuleLibraryDependenciesAsFiles(ideaModule);
        ProjectLibrary library = createScalaSdkLibrary(scalaProject, files, useScalaSdk, ideaModule);
        if (library != null) {
            ProjectLibrary duplicate = Iterables.find(scalaCompilerLibraries.values(),
                    Predicates.equalTo(library), null);
            scalaCompilerLibraries.put(scalaProject.getPath(), duplicate == null ? library : duplicate);
        }/*from   ww  w .ja v  a  2  s .co  m*/
    }
    return scalaCompilerLibraries;
}

From source file:org.apache.brooklyn.core.typereg.RegisteredTypePredicates.java

public static Predicate<RegisteredType> tag(final Object tag) {
    return tags(CollectionFunctionals.any(Predicates.equalTo(tag)));
}

From source file:io.druid.query.dimension.ForwardingFilteredDimensionSelector.java

@Override
public ValueMatcher makeValueMatcher(final String value) {
    IdLookup idLookup = idLookup();/*w  w  w.  j  a  v  a2 s.c om*/
    if (idLookup != null) {
        final int valueId = idLookup.lookupId(value);
        if (valueId >= 0 || value == null) {
            return new ValueMatcher() {
                @Override
                public boolean matches() {
                    final IndexedInts baseRow = selector.getRow();
                    final int baseRowSize = baseRow.size();
                    boolean nullRow = true;
                    for (int i = 0; i < baseRowSize; i++) {
                        int forwardedValue = forwardMapping.get(baseRow.get(i));
                        if (forwardedValue >= 0) {
                            // Make the following check after the `forwardedValue >= 0` check, because if forwardedValue is -1 and
                            // valueId is -1, we don't want to return true from matches().
                            if (forwardedValue == valueId) {
                                return true;
                            }
                            nullRow = false;
                        }
                    }
                    // null should match empty rows in multi-value columns
                    return nullRow && value == null;
                }

                @Override
                public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                    inspector.visit("selector", selector);
                }
            };
        } else {
            return BooleanValueMatcher.of(false);
        }
    } else {
        // Employ precomputed BitSet optimization
        return makeValueMatcher(Predicates.equalTo(value));
    }
}

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

@Override
public List<MyBusinessObject> findChildren(final MyBusinessObject parent) {
    return Lists.newArrayList(
            getHelper().findAllWhere(Predicates.compose(Predicates.equalTo(parent), EXTRACT_PARENT)));
}