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

sh.ivan.zod.schema.EnumSchema Maven / Gradle / Ivy

The newest version!
package sh.ivan.zod.schema;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import sh.ivan.zod.schema.attribute.Attribute;

@Getter
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class EnumSchema extends Schema {
    private final String enumElements;

    public EnumSchema(Class> enumClass, Set attributes) {
        super(attributes);
        this.enumElements = Arrays.stream(enumClass.getEnumConstants())
                .map(Enum::name)
                .map(e -> "'" + e + "'")
                .collect(Collectors.joining(", "));
    }

    @Override
    protected String zodType() {
        return "enum([" + enumElements + "])";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy