-
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.
Merge pull request #82 from kpartlow/master
Broke out more conversions, Updated defaults on interface, getting ready to start date conversions
- Loading branch information
Showing
14 changed files
with
825 additions
and
448 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
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 Float toFloat(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.FLOAT_ONE : CommonValues.FLOAT_ZERO; | ||
} | ||
|
||
public static Double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.DOUBLE_ONE : CommonValues.DOUBLE_ZERO; | ||
} | ||
|
||
public static boolean toBoolean(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get(); | ||
} | ||
|
||
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]) | ||
|
@@ -23,71 +25,51 @@ | |
public class BooleanConversion { | ||
public static Byte toByte(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.BYTE_ONE : CommonValues.BYTE_ZERO; | ||
return b ? CommonValues.BYTE_ONE : CommonValues.BYTE_ZERO; | ||
} | ||
|
||
public static Short toShort(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.SHORT_ONE : CommonValues.SHORT_ZERO; | ||
return b ? CommonValues.SHORT_ONE : CommonValues.SHORT_ZERO; | ||
} | ||
|
||
public static Integer toInteger(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b.booleanValue() ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO; | ||
return b ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO; | ||
} | ||
|
||
public static Long toLong(Object from, Converter converter, ConverterOptions options) { | ||
public static AtomicLong toAtomicLong(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; | ||
} | ||
|
||
public static Short atomicToShort(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.SHORT_ONE : CommonValues.SHORT_ZERO; | ||
return new AtomicLong(b ? 1 : 0); | ||
} | ||
|
||
public static Integer atomicToInteger(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.INTEGER_ONE : CommonValues.INTEGER_ZERO; | ||
public static AtomicBoolean toAtomicBoolean(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return new AtomicBoolean(b); | ||
} | ||
|
||
public static Long atomicToLong(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.LONG_ONE : CommonValues.LONG_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 Long atomicToCharacter(Object from, Converter converter, ConverterOptions options) { | ||
AtomicBoolean b = (AtomicBoolean) from; | ||
return b.get() ? CommonValues.LONG_ONE : CommonValues.LONG_ZERO; | ||
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; | ||
return b ? 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; | ||
return b ? 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 char toCharacter(Object from, Converter converter, ConverterOptions options) { | ||
Boolean b = (Boolean) from; | ||
return b ? CommonValues.CHARACTER_ONE : CommonValues.CHARACTER_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()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/cedarsoftware/util/convert/CharacterConversion.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,18 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class CharacterConversion { | ||
public static boolean toBoolean(Object from, Converter converter, ConverterOptions options) { | ||
Character c = (Character) from; | ||
return c != CommonValues.CHARACTER_ZERO; | ||
} | ||
|
||
public static double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
return (char) from; | ||
} | ||
|
||
public static float toFloat(Object from, Converter converter, ConverterOptions options) { | ||
return (char) from; | ||
} | ||
} |
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.