Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.P#within()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.P#within() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandlePMultiValue() throws Exception  {
    assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));

    final P o = P.within(1,2,3);
    assertEquals(o, serializeDeserialize(mapper, o, P.class));
}
 
Example 2
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandlePSingleValue() throws Exception  {
    assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));

    final P o = P.within(1);
    assertEquals(o, serializeDeserialize(mapper, o, P.class));
}
 
Example 3
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandlePMultiValueAsCollection() throws Exception  {
    assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));

    final P o = P.within(Arrays.asList(1,2,3));
    assertEquals(o, serializeDeserialize(mapper, o, P.class));
}
 
Example 4
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReadPWithJsonArray() throws Exception {
    // for some reason v3 is forgiving about the naked json array - leaving this here for backward compaitiblity,
    // but should be a g:List (i think)
    assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));

    final P o = P.within(Arrays.asList(1,2,3));
    assertEquals(o, mapper.readValue("{\"@type\": \"g:P\", \"@value\": {\"predicate\": \"within\", \"value\": [{\"@type\": \"g:Int32\", \"@value\": 1},{\"@type\": \"g:Int32\", \"@value\": 2},{\"@type\": \"g:Int32\", \"@value\": 3}]}}", Object.class));
}
 
Example 5
Source File: GraphSONMapperEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReadPWithGraphSONList() throws Exception {
    assumeThat(version, startsWith("v3"));

    final P o = P.within(Arrays.asList(1,2,3));
    assertEquals(o, mapper.readValue("{\"@type\": \"g:P\", \"@value\": {\"predicate\": \"within\", \"value\": {\"@type\": \"g:List\", \"@value\": [{\"@type\": \"g:Int32\", \"@value\": 1},{\"@type\": \"g:Int32\", \"@value\": 2},{\"@type\": \"g:Int32\", \"@value\": 3}]}}}", Object.class));
}
 
Example 6
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public static P<Object> parsePredicate(String predicate) {
    /*
     * Extract P from json string like {"properties": {"age": "P.gt(18)"}}
     * the `predicate` may actually be like "P.gt(18)"
     */
    Pattern pattern = Pattern.compile("^P\\.([a-z]+)\\(([\\S ]*)\\)$");
    Matcher matcher = pattern.matcher(predicate);
    if (!matcher.find()) {
        throw new HugeException("Invalid predicate: %s", predicate);
    }

    String method = matcher.group(1);
    String value = matcher.group(2);
    switch (method) {
        case "eq":
            return P.eq(predicateNumber(value));
        case "neq":
            return P.neq(predicateNumber(value));
        case "lt":
            return P.lt(predicateNumber(value));
        case "lte":
            return P.lte(predicateNumber(value));
        case "gt":
            return P.gt(predicateNumber(value));
        case "gte":
            return P.gte(predicateNumber(value));
        case "between":
            Number[] params = predicateNumbers(value, 2);
            return P.between(params[0], params[1]);
        case "inside":
            params = predicateNumbers(value, 2);
            return P.inside(params[0], params[1]);
        case "outside":
            params = predicateNumbers(value, 2);
            return P.outside(params[0], params[1]);
        case "within":
            return P.within(predicateArgs(value));
        case "contains":
            // Just for inner use case like auth filter
            return ConditionP.contains(predicateArg(value));
        default:
            throw new NotSupportException("predicate '%s'", method);
    }
}