Package cc.plural.jsonij.jpath

Examples of cc.plural.jsonij.jpath.JPathParser$JPathReader


  public JPath() {
    }

    public static JPath<Component> parse(String path) throws IOException, ParserException {
        JPathParser parser = new JPathParser();
        JPath<Component> jPath = parser.parse(path);
        return jPath;
    }
View Full Code Here


    public void testExpression2() throws IOException, ParserException {
        System.out.println("Test Expression2 - Multiple and Expression Query");

        JSON json = JSON.parse(JSONTestExamples.RESUME_SAMPLE);

        JPathParser jPathParser = new JPathParser();

        JPath<?> path1 = jPathParser.parse("/resume/employment[?(@.city=\"Newcastle\" && @.start date={\"day\":1,\"month\":8,\"year\":2003})]/employer");
        path1.setRecordEvaluateTime(true);
        Value value1 = path1.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value1.nestedSize() + "): " + value1.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        assertEquals("Matrikon", value1.getString());
View Full Code Here

                + "  }\r\n"
                + "}";
        JSON json = JSON.parse(jsonString);
        System.out.println(json.getRoot().getValueType() + "(" + json.getRoot().nestedSize() + "): " + json.getRoot().toJSON());

        JPathParser jPathParser = new JPathParser();
        JPath<?> path1 = jPathParser.parse("/store");
        path1.setRecordEvaluateTime(true);
        Value value = path1.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        JPath<?> path2 = jPathParser.parse("/store/book[-2]");
        path2.setRecordEvaluateTime(true);
        value = path2.evaluate(json);
        System.out.println(value.getValueType() + "--> (" + value.nestedSize() + "): " + value.toJSON() + " (in " + path2.getLastEvaluateTime() + " ms)");

        JPath<?> path3 = jPathParser.parse("/store/book[2]/title");
        path3.setRecordEvaluateTime(true);
        value = path3.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path3.getLastEvaluateTime() + " ms)");

        JPath<?> path4 = jPathParser.parse("/store/book[$]/title");
        path4.setRecordEvaluateTime(true);
        value = path4.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path4.getLastEvaluateTime() + " ms)");

        JPath<?> path5 = jPathParser.parse("/store/book[last()-3]/title");
        path5.setRecordEvaluateTime(true);
        value = path5.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path5.getLastEvaluateTime() + " ms)");

        JPath<?> path6 = jPathParser.parse("/store/book[last()-1337]/title");
        try {
            value = path6.evaluate(json);
        }
        catch (Exception e) {
            System.out.println(e.toString());
View Full Code Here

    @Test
    public void testExpression0() throws IOException, ParserException {
        System.out.println("Test Expression0 - Single Expression Query - String and Double equals");
        JSON json = JSON.parse(JSONTestExamples.STORE_SAMPLE);

        JPathParser jPathParser = new JPathParser();
        JPath<?> path1 = jPathParser.parse("/store");
        path1.setRecordEvaluateTime(true);
        Value value1 = path1.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value1.nestedSize() + "): " + value1.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        JPath<?> path2 = jPathParser.parse("/store/book[?(@.title=\"Sword of Honour\")]/author");
        path2.setRecordEvaluateTime(true);
        Value value2 = path2.evaluate(json);
        System.out.println(value2.getValueType() + "(" + value2.nestedSize() + "): " + value2.toJSON() + " (in " + path2.getLastEvaluateTime() + " ms)");

        JPath<?> path3 = jPathParser.parse("/book[?(@.author=\"J. R. R. Tolkien\")]/title");
        path3.setRecordEvaluateTime(true);
        Value value3 = path3.evaluate(value1);
        System.out.println(value3.getValueType() + "(" + value3.nestedSize() + "): " + value3.toJSON() + " (in " + path3.getLastEvaluateTime() + " ms)");

        JPath<?> path4 = jPathParser.parse("/store/book[?(@.price=8.99)]/title");
        path4.setRecordEvaluateTime(true);
        Value value4 = path4.evaluate(json);
        System.out.println(value4.getValueType() + "(" + value4.nestedSize() + "): " + value4.toJSON() + " (in " + path4.getLastEvaluateTime() + " ms)");
    }
View Full Code Here

    @Test
    public void testExpression1() throws IOException, ParserException {
        System.out.println("Test Expression1 - Single Expression Query String");
        JSON json = JSON.parse(JSONTestExamples.RESUME_SAMPLE);

        JPathParser jPathParser = new JPathParser();
        JPath<?> path1 = jPathParser.parse("/resume/misc\\/other[0]");
        path1.setRecordEvaluateTime(true);
        Value value1 = path1.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value1.nestedSize() + "): " + value1.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        assertEquals("Matrikon Asia-Pacific Heart Award 2005.", value1.getString());

        JPath<?> path2 = jPathParser.parse("/resume/employment[?(@.city=\"Sydney\")]/employer");
        path2.setRecordEvaluateTime(true);
        Value value2 = path2.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value2.nestedSize() + "): " + value2.toJSON() + " (in " + path2.getLastEvaluateTime() + " ms)");

        assertEquals("IBM", value2.getString());
View Full Code Here

     */
    @Test
    public void testParse() throws Exception {
        System.out.println("parse");
        String testString = "/rah/boop[1]/boop[55]";
        JPathParser instance = new JPathParser();
        JPath<Component> result = instance.parse(testString);
        KeyComponent expResult1 = new KeyComponent("rah");
       KeyComponent expResult2 = new KeyComponent("boop");
        SimpleIndexPredicate expResult3 = new SimpleIndexPredicate(1);
        SimpleIndexPredicate expResult5 = new SimpleIndexPredicate(55);
        assertEquals(result.size(), 5, 0);
View Full Code Here

    @Test
    public void testReadKey() throws Exception {
        System.out.println("readKey");
        String testString = "rah/boop[1]";
        JPathParser.JPathReader target = new JPathParser.JPathReader(testString);
        JPathParser instance = new JPathParser();
        KeyComponent expResult = new KeyComponent("rah");
        KeyComponent result = instance.readKey(target);
        assertEquals(expResult, result);
        testString = "boop[1]";
        target = new JPathParser.JPathReader(testString);
        instance = new JPathParser();
        expResult = new KeyComponent("boop");
        result = instance.readKey(target);
        assertEquals(expResult, result);
    }
View Full Code Here

    @Test
    public void testReadSimpleIndex() throws Exception {
        System.out.println("readSimpleIndex");
        String testString = "[1]/";
        JPathParser.JPathReader target = new JPathParser.JPathReader(testString);
        JPathParser instance = new JPathParser();
        SimpleIndexPredicate expResult = new SimpleIndexPredicate(1);
        PredicateComponent result = instance.readPredicate(target);
        assertEquals(expResult, result);
        testString = "[-3]";
        target = new JPathParser.JPathReader(testString);
        expResult = new SimpleIndexPredicate(-3);
        result = instance.readPredicate(target);
        assertEquals(expResult, result);
    }
View Full Code Here

    @Test
    public void testReadLastIndex() throws Exception {
        System.out.println("readLastIndex");
        String testString = "[$]/";
        JPathParser.JPathReader target = new JPathParser.JPathReader(testString);
        JPathParser instance = new JPathParser();

        LastIndexPredicate expResult = new LastIndexPredicate();
        PredicateComponent result = instance.readPredicate(target);
        assertEquals(expResult, result);
        testString = "[last()]/";
        target = new JPathParser.JPathReader(testString);
        result = instance.readPredicate(target);
        assertEquals(expResult, result);
        testString = "[$-1]/";
        target = new JPathParser.JPathReader(testString);
        result = instance.readPredicate(target);
        expResult = new LastIndexPredicate(1);
        assertEquals(expResult, result);
        testString = "[last()-5]/";
        target = new JPathParser.JPathReader(testString);
        result = instance.readPredicate(target);
        expResult = new LastIndexPredicate(5);
        assertEquals(expResult, result);
    }
View Full Code Here

    @Test
    public void testReadAttributeIndex() throws Exception {
        System.out.println("readAttributeIndex");
        String testString = "[?(  \t\t @.firstName     <=     \"RAH\"    )  ]";
        JPathParser.JPathReader target = new JPathParser.JPathReader(testString);
        JPathParser instance = new JPathParser();
        PredicateComponent result = instance.readPredicate(target);
        System.out.println(result);
    }
View Full Code Here

TOP

Related Classes of cc.plural.jsonij.jpath.JPathParser$JPathReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.