-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved more String conversions to StringConversion.java, following est…
…ablished naming patterns.
- Loading branch information
Showing
2 changed files
with
39 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.math.RoundingMode; | ||
import java.util.Date; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import com.cedarsoftware.util.DateUtilities; | ||
|
||
/** | ||
* @author John DeRegnaucourt ([email protected]) | ||
* <br> | ||
|
@@ -157,6 +162,14 @@ static Double toDouble(Object from, Converter converter, ConverterOptions option | |
} | ||
} | ||
|
||
static AtomicBoolean toAtomicBoolean(Object from, Converter converter, ConverterOptions options) { | ||
String str = ((String) from).trim(); | ||
if (str.isEmpty()) { | ||
return new AtomicBoolean(false); | ||
} | ||
return new AtomicBoolean("true".equalsIgnoreCase(str)); | ||
} | ||
|
||
static AtomicInteger toAtomicInteger(Object from, Converter converter, ConverterOptions options) { | ||
String str = ((String) from).trim(); | ||
if (str.isEmpty()) { | ||
|
@@ -208,7 +221,20 @@ public static char toCharacter(Object from, Converter converter, ConverterOption | |
return (char) Integer.parseInt(str.trim()); | ||
} | ||
|
||
public static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
static BigInteger toBigInteger(Object from, Converter converter, ConverterOptions options) { | ||
String str = ((String) from).trim(); | ||
if (str.isEmpty()) { | ||
return BigInteger.ZERO; | ||
} | ||
try { | ||
BigDecimal bigDec = new BigDecimal(str); | ||
return bigDec.toBigInteger(); | ||
} catch (NumberFormatException e) { | ||
throw new IllegalArgumentException("Value: " + from + " not parseable as a BigInteger value."); | ||
} | ||
} | ||
|
||
static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOptions options) { | ||
String str = ((String) from).trim(); | ||
if (str.isEmpty()) { | ||
return BigDecimal.ZERO; | ||
|
@@ -219,4 +245,13 @@ public static BigDecimal toBigDecimal(Object from, Converter converter, Converte | |
throw new IllegalArgumentException("Value: " + from + " not parseable as a BigDecimal value."); | ||
} | ||
} | ||
|
||
static java.sql.Date toSqlDate(Object from, Converter converter, ConverterOptions options) { | ||
String str = ((String) from).trim(); | ||
Date date = DateUtilities.parseDate(str); | ||
if (date == null) { | ||
return null; | ||
} | ||
return new java.sql.Date(date.getTime()); | ||
} | ||
} |