-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved common lambdas to methods so that a method reference could be r…
…e-used (reduce code in jar)
- Loading branch information
Showing
8 changed files
with
289 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,24 @@ | |
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* @author John DeRegnaucourt ([email protected]) | ||
* Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
public class BooleanConversion { | ||
public static Byte toByte(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
|
@@ -18,12 +36,16 @@ public static Integer toInteger(Object from, Converter converter, ConverterOptio | |
return b.booleanValue() ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO; | ||
} | ||
|
||
|
||
public static Long toLong(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.LONG_ONE : CommonValues.LONG_ZERO; | ||
} | ||
|
||
public static AtomicBoolean numberToAtomicBoolean(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return new AtomicBoolean(number.longValue() != 0); | ||
} | ||
|
||
public static Byte atomicToByte(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.BYTE_ONE : CommonValues.BYTE_ZERO; | ||
|
@@ -68,6 +90,4 @@ public static Double atomicToDouble(Object from, Converter converter, ConverterO | |
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO; | ||
} | ||
|
||
|
||
} |
20 changes: 17 additions & 3 deletions
20
src/main/java/com/cedarsoftware/util/convert/CommonValues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
public class CommonValues { | ||
public static final Byte BYTE_ZERO = (byte) 0; | ||
public static final Byte BYTE_ONE = (byte) 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
|
||
/** | ||
* @author John DeRegnaucourt ([email protected]) | ||
* Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
@FunctionalInterface | ||
public interface Convert<T> { | ||
T convert(Object from, Converter converter, ConverterOptions options); | ||
|
232 changes: 109 additions & 123 deletions
232
src/main/java/com/cedarsoftware/util/convert/Converter.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,23 @@ | |
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
public interface ConverterOptions { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,23 @@ | |
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
public class DefaultConverterOptions implements ConverterOptions { | ||
|
||
private final Map<String, Object> customOptions; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.ZonedDateTime; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
public class NumberConversion { | ||
|
||
public static byte toByte(Object from, Converter converter, ConverterOptions options) { | ||
|
@@ -28,10 +54,6 @@ public static double toDouble(Object from, Converter converter, ConverterOptions | |
return ((Number) from).doubleValue(); | ||
} | ||
|
||
public static double toDoubleZero(Object from, Converter converter, ConverterOptions options) { | ||
return 0.0d; | ||
} | ||
|
||
public static BigDecimal longToBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
return BigDecimal.valueOf(((Number) from).longValue()); | ||
} | ||
|
@@ -69,5 +91,49 @@ public static char numberToCharacter(Number number) { | |
public static char numberToCharacter(Object from, Converter converter, ConverterOptions options) { | ||
return numberToCharacter((Number) from); | ||
} | ||
} | ||
|
||
public static AtomicInteger numberToAtomicInteger(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return new AtomicInteger(number.intValue()); | ||
} | ||
|
||
public static AtomicLong numberToAtomicLong(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return new AtomicLong(number.longValue()); | ||
} | ||
|
||
public static Date numberToDate(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return new Date(number.longValue()); | ||
} | ||
|
||
public static java.sql.Date numberToSqlDate(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return new java.sql.Date(number.longValue()); | ||
} | ||
|
||
public static Timestamp numberToTimestamp(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return new Timestamp(number.longValue()); | ||
} | ||
|
||
public static Calendar numberToCalendar(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return Converter.initCal(number.longValue()); | ||
} | ||
|
||
public static LocalDate numberToLocalDate(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return LocalDate.ofEpochDay(number.longValue()); | ||
} | ||
|
||
public static LocalDateTime numberToLocalDateTime(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return Instant.ofEpochMilli(number.longValue()).atZone(options.getSourceZoneId()).toLocalDateTime(); | ||
} | ||
|
||
public static ZonedDateTime numberToZonedDateTime(Object from, Converter converter, ConverterOptions options) { | ||
Number number = (Number) from; | ||
return Instant.ofEpochMilli(number.longValue()).atZone(options.getSourceZoneId()); | ||
} | ||
} |
29 changes: 17 additions & 12 deletions
29
src/main/java/com/cedarsoftware/util/convert/VoidConversion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
public class VoidConversion { | ||
|
||
private static final Byte ZERO = (byte) 0; | ||
|
||
public static Object toNull(Object from, Converter converter, ConverterOptions options) { | ||
return null; | ||
} | ||
|
||
public static Boolean toBoolean(Object from, Converter converter, ConverterOptions options) { | ||
return Boolean.FALSE; | ||
} | ||
|
||
public static Object toInt(Object from, Converter converter, ConverterOptions options) { | ||
return ZERO; | ||
} | ||
|
||
} |