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

io.github.xmljim.json.jsonpath.function.info.ArgumentInfo Maven / Gradle / Ivy

The newest version!
package io.github.xmljim.json.jsonpath.function.info;

import io.github.xmljim.json.jsonpath.JsonPathException;
import io.github.xmljim.json.jsonpath.function.Argument;
import io.github.xmljim.json.model.JsonObject;

public record ArgumentInfo(String name, ArgumentScope scope, String description, Class> type) {

    public static ArgumentInfo fromArgumentDefinition(ArgumentDefinition definition) {
        return new ArgumentInfo(definition.name(), definition.scope(), definition.description(), definition.argType());
    }

    @SuppressWarnings("unchecked")
    public static ArgumentInfo fromJson(JsonObject record) {
        try {
            return new ArgumentInfo(String.valueOf(record.get("name")),
                ArgumentScope.valueOf(String.valueOf(record.get("scope"))),
                String.valueOf(record.get("description")),
                (Class>) Class.forName(String.valueOf(record.get("typeClass")))
            );
        } catch (ClassNotFoundException e) {
            throw new JsonPathException("Argument argType not found: " + e.getMessage());
        }

    }

    public String toString() {
        StringBuilder builder = new StringBuilder();

        switch (scope()) {
            case REQUIRED -> builder.append(name());
            case OPTIONAL -> builder.append("[").append(name()).append("]");
            case VARARGS -> builder.append("[").append(name()).append("...").append("]");
        }

        return builder.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy