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

de.zalando.toga.generator.dimensions.Dimension Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
package de.zalando.toga.generator.dimensions;

import com.fasterxml.jackson.databind.JsonNode;

import java.util.List;

public abstract class Dimension {

    protected final String name;

    public Dimension(String name) {
        this.name = name;
    }

    public static Dimension from(String name, JsonNode node) {

        JsonNode typeNode = node.path("type");
        if (typeNode.isMissingNode() || !typeNode.isValueNode()) {
            throw new IllegalArgumentException("Could not derive type from node [" + node.toString() + "].");
        }

        String type = typeNode.asText();

        switch (type) {
            case "object":
                return new ObjectDimension(name, node);
            case "string":
                return new StringDimension(name, node);
            default:
                throw new IllegalArgumentException("JSON attribute with type [" + type + "] is not supported.");
        }
    }

    public String getFieldName() {
        return name;
    }

    /**
     * Generate a list of JSON representations of the dimension.
     * This generated JSON is intended to be combined into JSON objects right away without further modification.
     * 
     * @return a list of json representations with all the different options the dimension contains.
     */
    public abstract List getValueDimensions();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy