All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jnosql.mapping.graph.DefaultVertexUntilTraversal Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
/*
 *  Copyright (c) 2022 Contributors to the Eclipse Foundation
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   and Apache License v2.0 which accompanies this distribution.
 *   The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 *   and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
 *
 *   You may elect to redistribute this code under either of these licenses.
 *
 *   Contributors:
 *
 *   Otavio Santana
 */
package org.eclipse.jnosql.mapping.graph;

import jakarta.nosql.Entity;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static java.util.Objects.requireNonNull;

class DefaultVertexUntilTraversal extends AbstractVertexTraversal implements VertexUntilTraversal {


    DefaultVertexUntilTraversal(Supplier> supplier, Function,
            GraphTraversal> flow, GraphConverter converter) {
        super(supplier, flow, converter);
    }

    @Override
    public VertexTraversal has(String propertyKey, Object value) {

        requireNonNull(propertyKey, "propertyKey is required");
        requireNonNull(value, "value is required");
        Traversal condition = __.has(propertyKey, value);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal has(String propertyKey) {
        requireNonNull(propertyKey, "propertyKey is required");
        Traversal condition = __.has(propertyKey);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal has(String propertyKey, P predicate) {
        requireNonNull(propertyKey, "propertyKey is required");
        requireNonNull(predicate, "predicate is required");
        Traversal condition = __.has(propertyKey, predicate);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal has(T accessor, Object value) {
        requireNonNull(accessor, "accessor is required");
        requireNonNull(value, "value is required");
        Traversal condition = __.has(accessor, value);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal has(T accessor, P predicate) {
        requireNonNull(accessor, "accessor is required");
        requireNonNull(predicate, "predicate is required");
        Traversal condition = __.has(accessor, predicate);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal hasNot(String propertyKey) {
        requireNonNull(propertyKey, "propertyKey is required");
        Traversal condition = __.hasNot(propertyKey);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal out(String... labels) {
        Stream.of(labels).forEach(l -> Objects.requireNonNull(l, "label is required"));
        Traversal condition = __.out(labels);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal in(String... labels) {
        Stream.of(labels).forEach(l -> Objects.requireNonNull(l, "label is required"));
        Traversal condition = __.in(labels);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal both(String... labels) {
        Stream.of(labels).forEach(l -> Objects.requireNonNull(l, "label is required"));
        Traversal condition = __.both(labels);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public VertexTraversal hasLabel(String label) {
        requireNonNull(label, "label is required");
        Traversal condition = __.hasLabel(label);
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.until(condition)), converter);
    }

    @Override
    public  VertexTraversal hasLabel(Class type) {
        requireNonNull(type, "type is required");
        Entity entity = type.getAnnotation(Entity.class);
        String label = Optional.ofNullable(entity).map(Entity::value).orElse(type.getName());
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.hasLabel(label)), converter);
    }

    @Override
    public  VertexTraversal hasLabel(P predicate) {
        requireNonNull(predicate, "predicate is required");
        return new DefaultVertexTraversal(supplier, flow.andThen(g -> g.hasLabel(predicate)), converter);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy