-
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.
Broke out more conversions and updated tests
- Loading branch information
Showing
11 changed files
with
444 additions
and
173 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/cedarsoftware/util/convert/AtomicBooleanConversion.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class AtomicBooleanConversion { | ||
|
||
public static Byte toByte(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.BYTE_ONE : CommonValues.BYTE_ZERO; | ||
} | ||
|
||
public static Short toShort(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.SHORT_ONE : CommonValues.SHORT_ZERO; | ||
} | ||
|
||
public static Integer toInteger(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO; | ||
} | ||
|
||
public static Long toLong(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.LONG_ONE : CommonValues.LONG_ZERO; | ||
} | ||
|
||
public static AtomicInteger toAtomicInteger(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? new AtomicInteger(1) : new AtomicInteger (0); | ||
} | ||
|
||
public static AtomicLong toAtomicLong(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? new AtomicLong(1) : new AtomicLong(0); | ||
} | ||
|
||
public static Character toCharacter(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.CHARACTER_ONE : CommonValues.CHARACTER_ZERO; | ||
} | ||
|
||
public static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? BigDecimal.ONE : BigDecimal.ZERO; | ||
} | ||
} |
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,8 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* @author John DeRegnaucourt ([email protected]) | ||
|
@@ -36,14 +38,39 @@ public static Integer toInteger(Object from, Converter converter, ConverterOptio | |
return b.booleanValue() ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO; | ||
} | ||
|
||
public static AtomicLong toAtomicLong(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return new AtomicLong(b.booleanValue() ? 1 : 0); | ||
} | ||
|
||
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 BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean)from; | ||
return b ? BigDecimal.ONE : BigDecimal.ZERO; | ||
} | ||
|
||
public static Float toFloat(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.FLOAT_ONE : CommonValues.FLOAT_ZERO; | ||
} | ||
|
||
public static Double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO; | ||
} | ||
|
||
public static Float atomicToFloat(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.FLOAT_ONE : CommonValues.FLOAT_ZERO; | ||
} | ||
|
||
public static Double atomicToDouble(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO; | ||
} | ||
|
||
public static Byte atomicToByte(Object from, Converter converter, ConverterOptions options) { | ||
|
@@ -70,24 +97,4 @@ public static Long atomicToCharacter(Object from, Converter converter, Converter | |
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.LONG_ONE : CommonValues.LONG_ZERO; | ||
} | ||
|
||
public static Float toFloat(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.FLOAT_ONE : CommonValues.FLOAT_ZERO; | ||
} | ||
|
||
public static Double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO; | ||
} | ||
|
||
public static Float atomicToFloat(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.FLOAT_ONE : CommonValues.FLOAT_ZERO; | ||
} | ||
|
||
public static Double atomicToDouble(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/cedarsoftware/util/convert/CalendarConversion.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class CalendarConversion { | ||
public static Date toDate(Object fromInstance, Converter converter, ConverterOptions options) { | ||
Calendar from = (Calendar)fromInstance; | ||
return from.getTime(); | ||
} | ||
|
||
public static AtomicLong toAtomicLong(Object fromInstance, Converter converter, ConverterOptions options) { | ||
Calendar from = (Calendar)fromInstance; | ||
return new AtomicLong(from.getTime().getTime()); | ||
} | ||
|
||
public static BigDecimal toBigDecimal(Object fromInstance, Converter converter, ConverterOptions options) { | ||
Calendar from = (Calendar)fromInstance; | ||
return BigDecimal.valueOf(from.getTime().getTime()); | ||
} | ||
|
||
public static BigInteger toBigInteger(Object fromInstance, Converter converter, ConverterOptions options) { | ||
Calendar from = (Calendar)fromInstance; | ||
return BigInteger.valueOf(from.getTime().getTime()); | ||
} | ||
} |
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
Oops, something went wrong.