Skip to content

Commit

Permalink
[#675] JavaTime dialects: Use Number instead of BigDecimal in JavaTim…
Browse files Browse the repository at this point in the history
…e dialects.
  • Loading branch information
opatrascoiu committed Jun 19, 2024
1 parent d88b42f commit 99c4a27
Show file tree
Hide file tree
Showing 267 changed files with 2,450 additions and 2,044 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
import com.gs.dmn.transformation.template.TemplateProvider;
import com.gs.dmn.validation.DMNValidator;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;

public class JavaTimeDMNDialectDefinition extends AbstractStandardDMNDialectDefinition<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
public class JavaTimeDMNDialectDefinition extends AbstractStandardDMNDialectDefinition<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
//
// DMN Processors
//
Expand All @@ -60,7 +59,7 @@ public NativeTypeFactory createNativeTypeFactory() {
}

@Override
public FEELLib<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> createFEELLib() {
public FEELLib<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> createFEELLib() {
return new JavaTimeFEELLib();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
import com.gs.dmn.transformation.template.TemplateProvider;
import com.gs.dmn.validation.DMNValidator;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;

public class JavaTimeKotlinStandardDMNDialectDefinition extends AbstractStandardDMNDialectDefinition<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
public class JavaTimeKotlinStandardDMNDialectDefinition extends AbstractStandardDMNDialectDefinition<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
//
// DMN Processors
//
Expand All @@ -61,7 +60,7 @@ public NativeTypeFactory createNativeTypeFactory() {
}

@Override
public FEELLib<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> createFEELLib() {
public FEELLib<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> createFEELLib() {
return new JavaTimeFEELLib();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
import com.gs.dmn.transformation.template.TemplateProvider;
import com.gs.dmn.validation.DMNValidator;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;

public class JavaTimePythonStandardDMNDialectDefinition extends AbstractStandardDMNDialectDefinition<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
public class JavaTimePythonStandardDMNDialectDefinition extends AbstractStandardDMNDialectDefinition<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
//
// DMN Processors
//
Expand All @@ -61,7 +60,7 @@ public NativeTypeFactory createNativeTypeFactory() {
}

@Override
public FEELLib<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> createFEELLib() {
public FEELLib<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> createFEELLib() {
return new JavaTimeFEELLib();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public String toNativeType(String feelType) {
public String toQualifiedNativeType(String feelType) {
return FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.get(feelType);
}

@Override
public String getNativeNumberConcreteType() {
return Double.class.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public String toNativeType(String feelType) {
public String toQualifiedNativeType(String feelType) {
return FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.get(feelType);
}

@Override
public String getNativeNumberConcreteType() {
return Double.class.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class JavaTimeNativeTypeFactory extends JavaTypeFactory {
FEEL_TYPE_TO_JAVA_TYPE.put(DATE.getName(), java.time.LocalDate.class.getName());
FEEL_TYPE_TO_JAVA_TYPE.put(STRING.getName(), String.class.getSimpleName());
FEEL_TYPE_TO_JAVA_TYPE.put(BOOLEAN.getName(), Boolean.class.getSimpleName());
FEEL_TYPE_TO_JAVA_TYPE.put(NUMBER.getName(), java.math.BigDecimal.class.getName());
FEEL_TYPE_TO_JAVA_TYPE.put(NUMBER.getName(), java.lang.Number.class.getName());
FEEL_TYPE_TO_JAVA_TYPE.put(ANY.getName(), Object.class.getSimpleName());
FEEL_TYPE_TO_JAVA_TYPE.put(NULL.getName(), Object.class.getSimpleName());
}
Expand All @@ -53,7 +53,7 @@ public class JavaTimeNativeTypeFactory extends JavaTypeFactory {
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(DATE.getName(), java.time.LocalDate.class.getName());
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(STRING.getName(), String.class.getName());
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(BOOLEAN.getName(), Boolean.class.getName());
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(NUMBER.getName(), java.math.BigDecimal.class.getName());
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(NUMBER.getName(), java.lang.Number.class.getName());
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(ANY.getName(), Object.class.getName());
FEEL_TYPE_TO_QUALIFIED_JAVA_TYPE.put(NULL.getName(), Object.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import com.gs.dmn.feel.analysis.semantics.type.*;

import java.math.BigDecimal;

public interface NativeTypeFactory {
String toNativeType(String feelType);

Expand All @@ -31,6 +33,9 @@ public interface NativeTypeFactory {
default String getNativeNumberType() {
return toNativeType(NumberType.NUMBER.getName());
}
default String getNativeNumberConcreteType() {
return BigDecimal.class.getName();
}

default String getNativeDateType() {
return toNativeType(DateType.DATE.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2357,20 +2357,20 @@ public boolean isInteger(TItemDefinition element) {

@Override
public String makeIntegerForInput(String text) {
return this.nativeFactory.constructor(getNativeNumberType(), String.format("java.lang.Integer.toString(%s)", text));
return this.nativeFactory.constructor(this.nativeTypeFactory.getNativeNumberConcreteType(), String.format("java.lang.Integer.toString(%s)", text));
}

@Override
public String makeDecimalForInput(String text) {
return this.nativeFactory.constructor(getNativeNumberType(), String.format("java.lang.Double.toString(%s)", text));
return this.nativeFactory.constructor(this.nativeTypeFactory.getNativeNumberConcreteType(), String.format("java.lang.Double.toString(%s)", text));
}

@Override
public String makeDecimalForDecision(String text) {
if (StringUtils.isBlank(text)) {
return this.nativeFactory.nullLiteral();
} else {
return this.nativeFactory.constructor(getNativeNumberType(), text);
return this.nativeFactory.constructor(this.nativeTypeFactory.getNativeNumberConcreteType(), text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public String extractMemberFromProtoValue(String protoValue, Type type, boolean
type = Type.extractTypeFromConstraint(type);
if (FEELTypes.FEEL_PRIMITIVE_TYPES.contains(type)) {
if (type == NumberType.NUMBER) {
String qNativeType = this.transformer.getNativeTypeFactory().toQualifiedNativeType(((DataType) type).getName());
String qNativeType = this.transformer.getNativeTypeFactory().getNativeNumberConcreteType();
return String.format("%s.valueOf(%s)", qNativeType, protoValue);
} else if (type == BooleanType.BOOLEAN) {
return protoValue;
Expand All @@ -565,7 +565,7 @@ public String extractMemberFromProtoValue(String protoValue, Type type, boolean
String mapFunction;
if (FEELTypes.FEEL_PRIMITIVE_TYPES.contains(elementType)) {
if (elementType == NumberType.NUMBER) {
String qNativeType = this.transformer.getNativeTypeFactory().toQualifiedNativeType(((DataType) elementType).getName());
String qNativeType = this.transformer.getNativeTypeFactory().getNativeNumberConcreteType();
mapFunction = String.format("e -> %s.valueOf(e)", qNativeType);
} else if (elementType == BooleanType.BOOLEAN) {
mapFunction = "e -> e";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import com.gs.dmn.transformation.DMNToJavaTransformer;
import com.gs.dmn.transformation.basic.BasicDMNToJavaTransformer;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;

public class JavaTimeDMNDialectDefinitionTest extends AbstractStandardDMNDialectDefinitionTest<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
public class JavaTimeDMNDialectDefinitionTest extends AbstractStandardDMNDialectDefinitionTest<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
@Override
protected DMNDialectDefinition<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount, TestCases> makeDialect() {
protected DMNDialectDefinition<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount, TestCases> makeDialect() {
return new JavaTimeDMNDialectDefinition();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import com.gs.dmn.transformation.DMNToKotlinTransformer;
import com.gs.dmn.transformation.basic.BasicDMNToKotlinTransformer;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;

public class JavaTimeKotlinStandardDMNDialectDefinitionTest extends AbstractStandardDMNDialectDefinitionTest<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
public class JavaTimeKotlinStandardDMNDialectDefinitionTest extends AbstractStandardDMNDialectDefinitionTest<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount> {
@Override
protected DMNDialectDefinition<BigDecimal, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount, TestCases> makeDialect() {
protected DMNDialectDefinition<Number, LocalDate, TemporalAccessor, TemporalAccessor, TemporalAmount, TestCases> makeDialect() {
return new JavaTimeKotlinStandardDMNDialectDefinition();
}

Expand Down
Loading

0 comments on commit 99c4a27

Please sign in to comment.