forked from jdereg/java-util
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversion Tests LocalDate conversions
- Loading branch information
Showing
17 changed files
with
1,804 additions
and
788 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
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
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
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
63 changes: 60 additions & 3 deletions
63
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 |
---|---|---|
@@ -1,16 +1,73 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import com.cedarsoftware.util.CaseInsensitiveMap; | ||
import com.cedarsoftware.util.CollectionUtilities; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class CharacterConversion { | ||
|
||
private CharacterConversion() { | ||
} | ||
|
||
static boolean toBoolean(Object from) { | ||
char c = (char) from; | ||
return (c == 1) || (c == 't') || (c == 'T') || (c == '1'); | ||
} | ||
|
||
|
||
static boolean toBoolean(Object from, Converter converter, ConverterOptions options) { | ||
Character c = (Character) from; | ||
return c != CommonValues.CHARACTER_ZERO; | ||
return toBoolean(from); | ||
} | ||
|
||
static double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
// downcasting -- not always a safe conversino | ||
static byte toByte(Object from, Converter converter, ConverterOptions options) { | ||
return (byte) (char) from; | ||
} | ||
|
||
static short toShort(Object from, Converter converter, ConverterOptions options) { | ||
return (short) (char) from; | ||
} | ||
|
||
static int toInt(Object from, Converter converter, ConverterOptions options) { | ||
return (char) from; | ||
} | ||
|
||
static long toLong(Object from, Converter converter, ConverterOptions options) { | ||
return (char) from; | ||
} | ||
|
||
static float toFloat(Object from, Converter converter, ConverterOptions options) { | ||
return (char) from; | ||
} | ||
|
||
static double toDouble(Object from, Converter converter, ConverterOptions options) { | ||
return (char) from; | ||
} | ||
|
||
static AtomicInteger toAtomicInteger(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicInteger((char) from); | ||
} | ||
|
||
static AtomicLong toAtomicLong(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicLong((char) from); | ||
} | ||
|
||
static AtomicBoolean toAtomicBoolean(Object from, Converter converter, ConverterOptions options) { | ||
return new AtomicBoolean(toBoolean(from)); | ||
} | ||
|
||
static BigInteger toBigInteger(Object from, Converter converter, ConverterOptions options) { | ||
return BigInteger.valueOf((char) from); | ||
} | ||
|
||
static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
return BigDecimal.valueOf((char) from); | ||
} | ||
} |
Oops, something went wrong.