Skip to content

Commit 30cd6c2

Browse files
committed
Moved common lambdas to methods so that a method reference could be re-used (reduce code in jar)
1 parent 154b091 commit 30cd6c2

File tree

8 files changed

+289
-147
lines changed

8 files changed

+289
-147
lines changed

src/main/java/com/cedarsoftware/util/convert/BooleanConversion.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
import java.util.concurrent.atomic.AtomicBoolean;
44

5+
/**
6+
* @author John DeRegnaucourt ([email protected])
7+
* Kenny Partlow ([email protected])
8+
* <br>
9+
* Copyright (c) Cedar Software LLC
10+
* <br><br>
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
* <br><br>
15+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
16+
* <br><br>
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
523
public class BooleanConversion {
624
public static Byte toByte(Object from, Converter converter, ConverterOptions options) {
725
Boolean b = (Boolean) from;
@@ -18,12 +36,16 @@ public static Integer toInteger(Object from, Converter converter, ConverterOptio
1836
return b.booleanValue() ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO;
1937
}
2038

21-
2239
public static Long toLong(Object from, Converter converter, ConverterOptions options) {
2340
Boolean b = (Boolean) from;
2441
return b.booleanValue() ? CommonValues.LONG_ONE : CommonValues.LONG_ZERO;
2542
}
2643

44+
public static AtomicBoolean numberToAtomicBoolean(Object from, Converter converter, ConverterOptions options) {
45+
Number number = (Number) from;
46+
return new AtomicBoolean(number.longValue() != 0);
47+
}
48+
2749
public static Byte atomicToByte(Object from, Converter converter, ConverterOptions options) {
2850
AtomicBoolean b = (AtomicBoolean) from;
2951
return b.get() ? CommonValues.BYTE_ONE : CommonValues.BYTE_ZERO;
@@ -68,6 +90,4 @@ public static Double atomicToDouble(Object from, Converter converter, ConverterO
6890
AtomicBoolean b = (AtomicBoolean) from;
6991
return b.get() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO;
7092
}
71-
72-
7393
}

src/main/java/com/cedarsoftware/util/convert/CommonValues.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
package com.cedarsoftware.util.convert;
22

3-
import java.math.BigDecimal;
4-
import java.math.BigInteger;
5-
3+
/**
4+
* @author Kenny Partlow ([email protected])
5+
* <br>
6+
* Copyright (c) Cedar Software LLC
7+
* <br><br>
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
* <br><br>
12+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
13+
* <br><br>
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
620
public class CommonValues {
721
public static final Byte BYTE_ZERO = (byte) 0;
822
public static final Byte BYTE_ONE = (byte) 1;

src/main/java/com/cedarsoftware/util/convert/Convert.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
package com.cedarsoftware.util.convert;
22

3-
3+
/**
4+
* @author John DeRegnaucourt ([email protected])
5+
* Kenny Partlow ([email protected])
6+
* <br>
7+
* Copyright (c) Cedar Software LLC
8+
* <br><br>
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
* <br><br>
13+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
14+
* <br><br>
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
421
@FunctionalInterface
522
public interface Convert<T> {
623
T convert(Object from, Converter converter, ConverterOptions options);

src/main/java/com/cedarsoftware/util/convert/Converter.java

Lines changed: 109 additions & 123 deletions
Large diffs are not rendered by default.

src/main/java/com/cedarsoftware/util/convert/ConverterOptions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
import java.util.Locale;
66
import java.util.TimeZone;
77

8+
/**
9+
* @author Kenny Partlow ([email protected])
10+
* <br>
11+
* Copyright (c) Cedar Software LLC
12+
* <br><br>
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
* <br><br>
17+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
18+
* <br><br>
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
825
public interface ConverterOptions {
926

1027
/**

src/main/java/com/cedarsoftware/util/convert/DefaultConverterOptions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@
77
import java.util.Map;
88
import java.util.concurrent.ConcurrentHashMap;
99

10+
/**
11+
* @author Kenny Partlow ([email protected])
12+
* <br>
13+
* Copyright (c) Cedar Software LLC
14+
* <br><br>
15+
* Licensed under the Apache License, Version 2.0 (the "License");
16+
* you may not use this file except in compliance with the License.
17+
* You may obtain a copy of the License at
18+
* <br><br>
19+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
20+
* <br><br>
21+
* Unless required by applicable law or agreed to in writing, software
22+
* distributed under the License is distributed on an "AS IS" BASIS,
23+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
* See the License for the specific language governing permissions and
25+
* limitations under the License.
26+
*/
1027
public class DefaultConverterOptions implements ConverterOptions {
1128

1229
private final Map<String, Object> customOptions;

src/main/java/com/cedarsoftware/util/convert/NumberConversion.java

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
package com.cedarsoftware.util.convert;
22

33
import java.math.BigDecimal;
4+
import java.sql.Timestamp;
5+
import java.time.Instant;
6+
import java.time.LocalDate;
7+
import java.time.LocalDateTime;
8+
import java.time.ZonedDateTime;
9+
import java.util.Calendar;
10+
import java.util.Date;
11+
import java.util.concurrent.atomic.AtomicInteger;
12+
import java.util.concurrent.atomic.AtomicLong;
413

14+
/**
15+
* @author Kenny Partlow ([email protected])
16+
* <br>
17+
* Copyright (c) Cedar Software LLC
18+
* <br><br>
19+
* Licensed under the Apache License, Version 2.0 (the "License");
20+
* you may not use this file except in compliance with the License.
21+
* You may obtain a copy of the License at
22+
* <br><br>
23+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
24+
* <br><br>
25+
* Unless required by applicable law or agreed to in writing, software
26+
* distributed under the License is distributed on an "AS IS" BASIS,
27+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
* See the License for the specific language governing permissions and
29+
* limitations under the License.
30+
*/
531
public class NumberConversion {
632

733
public static byte toByte(Object from, Converter converter, ConverterOptions options) {
@@ -28,10 +54,6 @@ public static double toDouble(Object from, Converter converter, ConverterOptions
2854
return ((Number) from).doubleValue();
2955
}
3056

31-
public static double toDoubleZero(Object from, Converter converter, ConverterOptions options) {
32-
return 0.0d;
33-
}
34-
3557
public static BigDecimal longToBigDecimal(Object from, Converter converter, ConverterOptions options) {
3658
return BigDecimal.valueOf(((Number) from).longValue());
3759
}
@@ -69,5 +91,49 @@ public static char numberToCharacter(Number number) {
6991
public static char numberToCharacter(Object from, Converter converter, ConverterOptions options) {
7092
return numberToCharacter((Number) from);
7193
}
72-
}
7394

95+
public static AtomicInteger numberToAtomicInteger(Object from, Converter converter, ConverterOptions options) {
96+
Number number = (Number) from;
97+
return new AtomicInteger(number.intValue());
98+
}
99+
100+
public static AtomicLong numberToAtomicLong(Object from, Converter converter, ConverterOptions options) {
101+
Number number = (Number) from;
102+
return new AtomicLong(number.longValue());
103+
}
104+
105+
public static Date numberToDate(Object from, Converter converter, ConverterOptions options) {
106+
Number number = (Number) from;
107+
return new Date(number.longValue());
108+
}
109+
110+
public static java.sql.Date numberToSqlDate(Object from, Converter converter, ConverterOptions options) {
111+
Number number = (Number) from;
112+
return new java.sql.Date(number.longValue());
113+
}
114+
115+
public static Timestamp numberToTimestamp(Object from, Converter converter, ConverterOptions options) {
116+
Number number = (Number) from;
117+
return new Timestamp(number.longValue());
118+
}
119+
120+
public static Calendar numberToCalendar(Object from, Converter converter, ConverterOptions options) {
121+
Number number = (Number) from;
122+
return Converter.initCal(number.longValue());
123+
}
124+
125+
public static LocalDate numberToLocalDate(Object from, Converter converter, ConverterOptions options) {
126+
Number number = (Number) from;
127+
return LocalDate.ofEpochDay(number.longValue());
128+
}
129+
130+
public static LocalDateTime numberToLocalDateTime(Object from, Converter converter, ConverterOptions options) {
131+
Number number = (Number) from;
132+
return Instant.ofEpochMilli(number.longValue()).atZone(options.getSourceZoneId()).toLocalDateTime();
133+
}
134+
135+
public static ZonedDateTime numberToZonedDateTime(Object from, Converter converter, ConverterOptions options) {
136+
Number number = (Number) from;
137+
return Instant.ofEpochMilli(number.longValue()).atZone(options.getSourceZoneId());
138+
}
139+
}
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package com.cedarsoftware.util.convert;
22

3+
/**
4+
* @author Kenny Partlow ([email protected])
5+
* <br>
6+
* Copyright (c) Cedar Software LLC
7+
* <br><br>
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
* <br><br>
12+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a>
13+
* <br><br>
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
320
public class VoidConversion {
4-
5-
private static final Byte ZERO = (byte) 0;
6-
721
public static Object toNull(Object from, Converter converter, ConverterOptions options) {
822
return null;
923
}
10-
11-
public static Boolean toBoolean(Object from, Converter converter, ConverterOptions options) {
12-
return Boolean.FALSE;
13-
}
14-
15-
public static Object toInt(Object from, Converter converter, ConverterOptions options) {
16-
return ZERO;
17-
}
18-
1924
}

0 commit comments

Comments
 (0)