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

net.jbock.convert.match.Match Maven / Gradle / Ivy

There is a newer version: 5.18
Show newest version
package net.jbock.convert.match;

import io.jbock.javapoet.CodeBlock;
import net.jbock.annotated.Item;
import net.jbock.common.ValidationFailure;
import net.jbock.model.Multiplicity;

import javax.lang.model.type.TypeMirror;
import java.util.Optional;

import static net.jbock.model.Multiplicity.OPTIONAL;

public final class Match {

    /* baseType (List) == A
    /* baseType (Optional) == A
     * baseType (OptionalInt) == Integer
     * baseType (int) == Integer
     */
    private final TypeMirror baseType;
    private final Optional extractExpr;
    private final Multiplicity multiplicity;
    private final M item;

    private Match(
            TypeMirror baseType,
            Multiplicity multiplicity,
            Optional extractExpr,
            M item) {
        this.baseType = baseType;
        this.multiplicity = multiplicity;
        this.extractExpr = extractExpr;
        this.item = item;
    }

    static 
    Match createWithExtract(
            TypeMirror baseType,
            CodeBlock extractExpr,
            M item) {
        return new Match<>(baseType, OPTIONAL, Optional.of(extractExpr), item);
    }

    static 
    Match create(
            TypeMirror baseType,
            Multiplicity multiplicity,
            M item) {
        return new Match<>(baseType, multiplicity, Optional.empty(), item);
    }

    public TypeMirror baseType() {
        return baseType;
    }

    public Multiplicity multiplicity() {
        return multiplicity;
    }

    public M item() {
        return item;
    }

    public ValidationFailure fail(String message) {
        return item().fail(message);
    }

    public Optional extractExpr() {
        return extractExpr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy