Example usage for com.google.common.base Predicate apply

List of usage examples for com.google.common.base Predicate apply

Introduction

In this page you can find the example usage for com.google.common.base Predicate apply.

Prototype

boolean apply(@Nullable T input);

Source Link

Document

Returns the result of applying this predicate to input .

Usage

From source file:com.clarkparsia.fourstore.cli.Console.java

public static void main(String[] args) throws Exception {
    OPTION_TO_CMD.put(HelpCmd.class, new HelpCommand());
    OPTION_TO_CMD.put(Query.class, new QueryCommand());
    OPTION_TO_CMD.put(Remove.class, new RemoveCommand());
    OPTION_TO_CMD.put(Add.class, new AddCommand());
    OPTION_TO_CMD.put(Size.class, new SizeCommand());

    //      String[] aFakeArgs = new String[] { "query", "--help" };
    //      String[] aFakeArgs = new String[] { "help", "query" };
    //      String[] aFakeArgs = new String[] { "query", "--url", "http://vx.int.clarkparsia.com:8000" , "-q", "select ?s where { ?s ?p ?o } limit 5"};
    //      String[] aFakeArgs = new String[] { "size", "--url", "http://vx.int.clarkparsia.com:8000" };
    ///*from  ww w.j  a  v a 2s. c o  m*/
    //      args = aFakeArgs;

    try {
        if (args.length == 0) {
            System.err.println("Type 'help' for usage information.");
        } else {
            Class<?> aClass = cliForCommand(args[0]);
            Predicate aCmd = OPTION_TO_CMD.get(aClass);

            aCmd.apply(CliFactory.createCli(aClass).parseArguments(Arrays.copyOfRange(args, 1, args.length)));

        }
    } catch (ArgumentValidationException e) {
        System.out.println(e.getMessage());
    }
}

From source file:playground.michalm.util.postprocess.SubNetworkLinkStats.java

public static void main(String[] args) {
    String dir = "d:\\PP-rad\\poznan\\";
    String networkFile = dir + "network.xml";
    String linkStats = dir + "40.linkstats.txt.gz";
    String polygonFile = dir + "poznan_polygon\\poznan_city_polygon.shp";
    boolean includeBorderLinks = false;
    String filteredLinkStats = dir + "40.linkstats-filtered.txt.gz";

    Geometry polygonGeometry = PolygonBasedFilter.readPolygonGeometry(polygonFile);
    Predicate<Link> linkInsidePolygonPredicate = PolygonBasedFilter
            .createLinkInsidePolygonPredicate(polygonGeometry, includeBorderLinks);

    Scenario scenario = ScenarioUtils.createScenario(VrpConfigUtils.createConfig());
    MatsimNetworkReader nr = new MatsimNetworkReader(scenario);
    nr.readFile(networkFile);/* ww w .  j a  v  a  2s. c  o  m*/

    Map<Id<Link>, ? extends Link> linkMap = scenario.getNetwork().getLinks();

    try (BufferedReader br = IOUtils.getBufferedReader(linkStats);
            PrintWriter pw = new PrintWriter(IOUtils.getBufferedWriter(filteredLinkStats))) {
        String header = br.readLine();
        pw.println(header);

        String line;
        while ((line = br.readLine()) != null) {
            String linkId = new StringTokenizer(line).nextToken();// linkId - first column
            Link link = linkMap.get(Id.create(linkId, Link.class));

            if (linkInsidePolygonPredicate.apply(link)) {
                pw.println(line);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.welyab.ayszu.util.collections.AyszuArrays.java

public static <T> boolean contains(T[] array, Predicate<T> test) {
    for (T t : array) {
        if (test.apply(t)) {
            return true;
        }/*w ww .  ja  v  a  2 s .c o m*/
    }
    return false;
}

From source file:org.loadui.testfx.Assertions.java

public static <T extends Node> void verifyThat(T node, Predicate<T> predicate) {
    if (!predicate.apply(node))
        throw new AssertionError("Predicate failed for '" + node + "'. Screenshot saved as "
                + GuiTest.captureScreenshot().getAbsolutePath());
}

From source file:org.blockartistry.mod.ThermalRecycling.util.function.Apply.java

public static <T> void forEach(final T[] list, final Predicate<T> pred) {
    for (final T e : list)
        pred.apply(e);
}

From source file:org.blockartistry.mod.ThermalRecycling.util.function.Apply.java

public static <T> Iterable<T> forEach(final Iterable<T> iterable, final Predicate<T> pred) {
    for (final T e : iterable)
        pred.apply(e);
    return iterable;
}

From source file:org.loadui.testfx.Assertions.java

public static <T extends Node> void verifyThat(String query, Predicate<T> predicate) {
    T node = find(query);/*w w w.ja  va 2 s  . co  m*/
    if (!predicate.apply(node))
        throw new AssertionError("Predicate failed for query '" + query + "'. Screenshot saved as "
                + GuiTest.captureScreenshot().getAbsolutePath());
}

From source file:edu.umd.cs.psl.application.util.Grounding.java

public static void groundAll(Model m, ModelApplication app, com.google.common.base.Predicate<Kernel> filter) {
    for (Kernel me : m.getKernels()) {
        if (filter.apply(me))
            me.groundAll(app);//from  w  w w .j  ava2s . c o  m
    }
}

From source file:org.janusgraph.graphdb.query.condition.ConditionUtil.java

public static final <E extends JanusGraphElement> void traversal(Condition<E> condition,
        Predicate<Condition<E>> evaluator) {
    if (!evaluator.apply(condition))
        return; //Abort if the evaluator returns false

    if (condition.getType() == Condition.Type.LITERAL) {
        return;//  w w  w.  j a v  a2 s .  c o m
    } else if (condition instanceof Not) {
        traversal(((Not) condition).getChild(), evaluator);
    } else if (condition instanceof MultiCondition) {
        for (Condition<E> child : condition.getChildren())
            traversal(child, evaluator);
    } else
        throw new IllegalArgumentException("Unexpected condition type: " + condition);
}

From source file:org.caleydo.view.relationshipexplorer.ui.filter.FilterUtil.java

public static <T> Set<T> filter(Collection<T> itemsToFilter, Predicate<T> filter) {
    Set<T> resultSet = new HashSet<>();
    for (T item : itemsToFilter) {
        if (filter.apply(item)) {
            resultSet.add(item);/*w  w  w.  ja va 2s  . c  o  m*/
        }
    }
    return resultSet;
}