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

org.vertexium.cli.model.ModelBase Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cli.model;

import org.vertexium.Authorizations;
import org.vertexium.Graph;
import org.vertexium.cli.VertexiumScript;

import java.lang.reflect.Method;
import java.util.Set;
import java.util.TreeSet;

public abstract class ModelBase {
    public Graph getGraph() {
        return VertexiumScript.getGraph();
    }

    public static Authorizations getAuthorizations() {
        return VertexiumScript.getAuthorizations();
    }

    public static Long getTime() {
        return VertexiumScript.getTime();
    }

    public String[] getMethods() {
        Set methodsNames = new TreeSet<>();
        for (Method method : this.getClass().getMethods()) {
            methodsNames.add(method.getName());
        }
        for (Method method : Object.class.getMethods()) {
            methodsNames.remove(method.getName());
        }
        return methodsNames.toArray(new String[methodsNames.size()]);
    }

    public String[] getProperties() {
        Set propertyNames = new TreeSet<>();
        for (String methodName : getMethods()) {
            if (methodName.startsWith("get")) {
                methodName = methodName.substring("get".length());
                methodName = methodName.substring(0, 1).toLowerCase() + (methodName.length() > 1 ? methodName.substring(1) : "");
                propertyNames.add(methodName);
            }
        }
        return propertyNames.toArray(new String[propertyNames.size()]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy