a fork of EvalEx by ezylang with a handful of breaking changes
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

I wish switch patterns worked with jabel...

+54 -103
+22 -52
src/main/java/com/ezylang/evalex/data/conversion/ArrayConverter.java
··· 15 15 */ 16 16 package com.ezylang.evalex.data.conversion; 17 17 18 + import static com.ezylang.evalex.data.EvaluationValue.arrayValue; 19 + 18 20 import com.ezylang.evalex.config.ExpressionConfiguration; 19 21 import com.ezylang.evalex.data.EvaluationValue; 20 22 import java.util.ArrayList; ··· 25 27 public class ArrayConverter implements ConverterIfc { 26 28 @Override 27 29 public EvaluationValue convert(Object object, ExpressionConfiguration configuration) { 28 - if (object.getClass().isArray()) { 29 - return EvaluationValue.arrayValue(convertArray(object, configuration)); 30 - } 31 - if (object instanceof List<?> list) { 32 - return EvaluationValue.arrayValue(convertList(list, configuration)); 33 - } 30 + if (object.getClass().isArray()) return arrayValue(convertArray(object, configuration)); 31 + if (object instanceof List<?> list) return arrayValue(convertList(list, configuration)); 34 32 throw illegalArgument(object); 35 33 } 36 34 ··· 47 45 } 48 46 49 47 private List<EvaluationValue> convertArray(Object array, ExpressionConfiguration configuration) { 50 - if (array instanceof int[] arr) { 51 - return convertIntArray(arr, configuration); 52 - } else if (array instanceof long[] arr) { 53 - return convertLongArray(arr, configuration); 54 - } else if (array instanceof double[] arr) { 55 - return convertDoubleArray(arr, configuration); 56 - } else if (array instanceof float[] arr) { 57 - return convertFloatArray(arr, configuration); 58 - } else if (array instanceof short[] arr) { 59 - return convertShortArray(arr, configuration); 60 - } else if (array instanceof char[] arr) { 61 - return convertCharArray(arr, configuration); 62 - } else if (array instanceof byte[] arr) { 63 - return convertByteArray(arr, configuration); 64 - } else if (array instanceof boolean[] arr) { 65 - return convertBooleanArray(arr, configuration); 66 - } else { 67 - return convertObjectArray((Object[]) array, configuration); 68 - } 48 + if (array instanceof int[] arr) return convertIntArray(arr, configuration); 49 + if (array instanceof long[] arr) return convertLongArray(arr, configuration); 50 + if (array instanceof double[] arr) return convertDoubleArray(arr, configuration); 51 + if (array instanceof float[] arr) return convertFloatArray(arr, configuration); 52 + if (array instanceof short[] arr) return convertShortArray(arr, configuration); 53 + if (array instanceof char[] arr) return convertCharArray(arr, configuration); 54 + if (array instanceof byte[] arr) return convertByteArray(arr, configuration); 55 + if (array instanceof boolean[] arr) return convertBooleanArray(arr, configuration); 56 + return convertObjectArray((Object[]) array, configuration); 69 57 } 70 58 71 59 private List<EvaluationValue> convertIntArray( 72 60 int[] array, ExpressionConfiguration configuration) { 73 61 List<EvaluationValue> list = new ArrayList<>(); 74 - for (int i : array) { 75 - list.add(EvaluationValue.of(i, configuration)); 76 - } 62 + for (int i : array) list.add(EvaluationValue.of(i, configuration)); 77 63 return list; 78 64 } 79 65 80 66 private List<EvaluationValue> convertLongArray( 81 67 long[] array, ExpressionConfiguration configuration) { 82 68 List<EvaluationValue> list = new ArrayList<>(); 83 - for (long l : array) { 84 - list.add(EvaluationValue.of(l, configuration)); 85 - } 69 + for (long l : array) list.add(EvaluationValue.of(l, configuration)); 86 70 return list; 87 71 } 88 72 89 73 private List<EvaluationValue> convertDoubleArray( 90 74 double[] array, ExpressionConfiguration configuration) { 91 75 List<EvaluationValue> list = new ArrayList<>(); 92 - for (double d : array) { 93 - list.add(EvaluationValue.of(d, configuration)); 94 - } 76 + for (double d : array) list.add(EvaluationValue.of(d, configuration)); 95 77 return list; 96 78 } 97 79 98 80 private List<EvaluationValue> convertFloatArray( 99 81 float[] array, ExpressionConfiguration configuration) { 100 82 List<EvaluationValue> list = new ArrayList<>(); 101 - for (float f : array) { 102 - list.add(EvaluationValue.of(f, configuration)); 103 - } 83 + for (float f : array) list.add(EvaluationValue.of(f, configuration)); 104 84 return list; 105 85 } 106 86 107 87 private List<EvaluationValue> convertShortArray( 108 88 short[] array, ExpressionConfiguration configuration) { 109 89 List<EvaluationValue> list = new ArrayList<>(); 110 - for (short s : array) { 111 - list.add(EvaluationValue.of(s, configuration)); 112 - } 90 + for (short s : array) list.add(EvaluationValue.of(s, configuration)); 113 91 return list; 114 92 } 115 93 116 94 private List<EvaluationValue> convertCharArray( 117 95 char[] array, ExpressionConfiguration configuration) { 118 96 List<EvaluationValue> list = new ArrayList<>(); 119 - for (char c : array) { 120 - list.add(EvaluationValue.of(c, configuration)); 121 - } 97 + for (char c : array) list.add(EvaluationValue.of(c, configuration)); 122 98 return list; 123 99 } 124 100 125 101 private List<EvaluationValue> convertByteArray( 126 102 byte[] array, ExpressionConfiguration configuration) { 127 103 List<EvaluationValue> list = new ArrayList<>(); 128 - for (byte b : array) { 129 - list.add(EvaluationValue.of(b, configuration)); 130 - } 104 + for (byte b : array) list.add(EvaluationValue.of(b, configuration)); 131 105 return list; 132 106 } 133 107 134 108 private List<EvaluationValue> convertBooleanArray( 135 109 boolean[] array, ExpressionConfiguration configuration) { 136 110 List<EvaluationValue> list = new ArrayList<>(); 137 - for (boolean b : array) { 138 - list.add(EvaluationValue.of(b, configuration)); 139 - } 111 + for (boolean b : array) list.add(EvaluationValue.of(b, configuration)); 140 112 return list; 141 113 } 142 114 143 115 private List<EvaluationValue> convertObjectArray( 144 116 Object[] array, ExpressionConfiguration configuration) { 145 117 List<EvaluationValue> list = new ArrayList<>(); 146 - for (Object o : array) { 147 - list.add(EvaluationValue.of(o, configuration)); 148 - } 118 + for (Object o : array) list.add(EvaluationValue.of(o, configuration)); 149 119 return list; 150 120 } 151 121 }
+14 -24
src/main/java/com/ezylang/evalex/data/conversion/DateTimeConverter.java
··· 15 15 */ 16 16 package com.ezylang.evalex.data.conversion; 17 17 18 + import static com.ezylang.evalex.data.EvaluationValue.dateTimeValue; 19 + 18 20 import com.ezylang.evalex.config.ExpressionConfiguration; 19 21 import com.ezylang.evalex.data.EvaluationValue; 20 22 import java.time.*; ··· 30 32 31 33 @Override 32 34 public EvaluationValue convert(Object object, ExpressionConfiguration configuration) { 33 - 34 - if (object instanceof Instant instant) { 35 - return EvaluationValue.dateTimeValue(instant); 36 - } else if (object instanceof ZonedDateTime dateTime) { 37 - return EvaluationValue.dateTimeValue(dateTime.toInstant()); 38 - } else if (object instanceof OffsetDateTime dateTime) { 39 - return EvaluationValue.dateTimeValue(dateTime.toInstant()); 40 - } else if (object instanceof LocalDate localDate) { 41 - return EvaluationValue.dateTimeValue( 42 - localDate.atStartOfDay().atZone(configuration.getZoneId()).toInstant()); 43 - } else if (object instanceof LocalDateTime dateTime) { 44 - return EvaluationValue.dateTimeValue(dateTime.atZone(configuration.getZoneId()).toInstant()); 45 - } else if (object instanceof Date date) { 46 - return EvaluationValue.dateTimeValue(date.toInstant()); 47 - } else if (object instanceof Calendar calendar) { 48 - return EvaluationValue.dateTimeValue(calendar.toInstant()); 49 - } else { 50 - throw illegalArgument(object); 51 - } 35 + if (object instanceof Instant instant) return dateTimeValue(instant); 36 + if (object instanceof ZonedDateTime dateTime) return dateTimeValue(dateTime.toInstant()); 37 + if (object instanceof OffsetDateTime dateTime) return dateTimeValue(dateTime.toInstant()); 38 + if (object instanceof LocalDate localDate) 39 + return dateTimeValue(localDate.atStartOfDay().atZone(configuration.getZoneId()).toInstant()); 40 + if (object instanceof LocalDateTime dateTime) 41 + return dateTimeValue(dateTime.atZone(configuration.getZoneId()).toInstant()); 42 + if (object instanceof Date date) return dateTimeValue(date.toInstant()); 43 + if (object instanceof Calendar calendar) return dateTimeValue(calendar.toInstant()); 44 + throw illegalArgument(object); 52 45 } 53 46 54 47 /** ··· 62 55 * @return A parsed {@link Instant} if parsing was successful, else <code>null</code>. 63 56 */ 64 57 public Instant parseDateTime(String value, ZoneId zoneId, List<DateTimeFormatter> formatters) { 65 - for (DateTimeFormatter formatter : formatters) { 58 + for (DateTimeFormatter formatter : formatters) 66 59 try { 67 60 return parseToInstant(value, zoneId, formatter); 68 61 } catch (DateTimeException ignored) { 69 62 // ignore 70 63 } 71 - } 72 64 return null; 73 65 } 74 66 ··· 78 70 if (parsedZoneId == null) { 79 71 LocalDate parsedDate = ta.query(TemporalQueries.localDate()); 80 72 LocalTime parsedTime = ta.query(TemporalQueries.localTime()); 81 - if (parsedTime == null) { 82 - parsedTime = parsedDate.atStartOfDay().toLocalTime(); 83 - } 73 + if (parsedTime == null) parsedTime = parsedDate.atStartOfDay().toLocalTime(); 84 74 ta = ZonedDateTime.of(parsedDate, parsedTime, zoneId); 85 75 } 86 76 return Instant.from(ta);
+13 -20
src/main/java/com/ezylang/evalex/data/conversion/NumberConverter.java
··· 15 15 */ 16 16 package com.ezylang.evalex.data.conversion; 17 17 18 + import static com.ezylang.evalex.data.EvaluationValue.numberValue; 19 + 18 20 import com.ezylang.evalex.config.ExpressionConfiguration; 19 21 import com.ezylang.evalex.data.EvaluationValue; 20 22 import java.math.BigDecimal; ··· 25 27 26 28 @Override 27 29 public EvaluationValue convert(Object object, ExpressionConfiguration configuration) { 28 - if (object instanceof BigDecimal decimal) { 29 - return EvaluationValue.numberValue(decimal); 30 - } else if (object instanceof BigInteger integer) { 31 - return EvaluationValue.numberValue(new BigDecimal(integer, configuration.getMathContext())); 32 - } else if (object instanceof Double d) { 33 - return EvaluationValue.numberValue( 34 - new BigDecimal(Double.toString(d), configuration.getMathContext())); 35 - } else if (object instanceof Float f) { 36 - return EvaluationValue.numberValue(BigDecimal.valueOf(f)); 37 - } else if (object instanceof Integer i) { 38 - return EvaluationValue.numberValue(BigDecimal.valueOf(i)); 39 - } else if (object instanceof Long l) { 40 - return EvaluationValue.numberValue(BigDecimal.valueOf(l)); 41 - } else if (object instanceof Short s) { 42 - return EvaluationValue.numberValue(BigDecimal.valueOf(s)); 43 - } else if (object instanceof Byte b) { 44 - return EvaluationValue.numberValue(BigDecimal.valueOf(b)); 45 - } else { 46 - throw illegalArgument(object); 47 - } 30 + if (object instanceof BigDecimal decimal) return numberValue(decimal); 31 + if (object instanceof BigInteger integer) 32 + return numberValue(new BigDecimal(integer, configuration.getMathContext())); 33 + if (object instanceof Double d) 34 + return numberValue(new BigDecimal(Double.toString(d), configuration.getMathContext())); 35 + if (object instanceof Float f) return numberValue(BigDecimal.valueOf(f)); 36 + if (object instanceof Integer i) return numberValue(BigDecimal.valueOf(i)); 37 + if (object instanceof Long l) return numberValue(BigDecimal.valueOf(l)); 38 + if (object instanceof Short s) return numberValue(BigDecimal.valueOf(s)); 39 + if (object instanceof Byte b) return numberValue(BigDecimal.valueOf(b)); 40 + throw illegalArgument(object); 48 41 } 49 42 50 43 @Override
+5 -7
src/main/java/com/ezylang/evalex/data/conversion/StringConverter.java
··· 15 15 */ 16 16 package com.ezylang.evalex.data.conversion; 17 17 18 + import static com.ezylang.evalex.data.EvaluationValue.stringValue; 19 + 18 20 import com.ezylang.evalex.config.ExpressionConfiguration; 19 21 import com.ezylang.evalex.data.EvaluationValue; 20 22 ··· 23 25 24 26 @Override 25 27 public EvaluationValue convert(Object object, ExpressionConfiguration configuration) { 26 - if (object instanceof CharSequence sequence) { 27 - return EvaluationValue.stringValue(sequence.toString()); 28 - } else if (object instanceof Character character) { 29 - return EvaluationValue.stringValue(character.toString()); 30 - } else { 31 - throw illegalArgument(object); 32 - } 28 + if (object instanceof CharSequence sequence) return stringValue(sequence.toString()); 29 + if (object instanceof Character character) return stringValue(character.toString()); 30 + throw illegalArgument(object); 33 31 } 34 32 35 33 @Override