net.jbock.convert.match.OptionalPrimitive Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbock-compiler Show documentation
Show all versions of jbock-compiler Show documentation
jbock annotation processor
package net.jbock.convert.match;
import io.jbock.javapoet.CodeBlock;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
enum OptionalPrimitive {
INT(OptionalInt.class, Integer.class),
LONG(OptionalLong.class, Long.class),
DOUBLE(OptionalDouble.class, Double.class);
private final Class> type;
private final String numberType;
OptionalPrimitive(Class> type, Class extends Number> numberType) {
this.type = type;
this.numberType = numberType.getCanonicalName();
}
CodeBlock extractExpr() {
return CodeBlock.of(".map($1T::of).orElse($1T.empty())", type);
}
String type() {
return type.getCanonicalName();
}
String numberType() {
return numberType;
}
}