public class OAConverter extends Object
contains two key static methods: toString(Object, format) & toObject(class, String, format)
OAConverterNumber
,
OAConverterOADate
,
OAString.format()
,
OADate
Modifier and Type | Field and Description |
---|---|
protected static String |
bigDecimalFormat |
protected static String |
booleanFormat |
protected static String |
dateFormat |
protected static String |
dateTimeFormat |
protected static String |
decimalFormat |
protected static Hashtable |
hashtable |
protected static String |
integerFormat |
protected static String |
moneyFormat |
protected static String |
timeFormat |
Constructor and Description |
---|
OAConverter() |
Modifier and Type | Method and Description |
---|---|
static double |
add(double d,
double d1) |
static double |
add(double d1,
double d2,
int decimalPlaces) |
static double |
add(double d,
double d1,
int decimalPlaces,
int roundType) |
static double |
add(double d,
Number n) |
static double |
add(double d,
Number n,
int decimalPlaces) |
static double |
add(double d,
Number n,
int decimalPlaces,
int roundType) |
static double |
add(Number d,
double d1) |
static double |
add(Number d,
double d1,
int decimalPlaces) |
static double |
add(Number d,
double d1,
int decimalPlaces,
int roundType) |
static double |
add(Number n1,
Number n2) |
static double |
add(Number n1,
Number n2,
int decimalPlaces) |
static double |
add(Number n1,
Number n2,
int decimalPlaces,
int roundType) |
static void |
addConverter(Class clazz,
OAConverterInterface oci) |
static int |
compare(double d1,
double d2,
int decimalPlaces)
Compare two doubles, using fixed decimal places.
|
static Object |
convert(Class clazz,
boolean value)
Convert a boolean to another type "clazz".
|
static Object |
convert(Class clazz,
boolean value,
String fmt)
Convert a boolean to another type "clazz".
|
static Object |
convert(Class clazz,
byte value)
Convert a byte to another type "clazz".
|
static Object |
convert(Class clazz,
byte value,
String fmt)
Convert a byte to another type "clazz".
|
static Object |
convert(Class clazz,
char value)
Convert a char to another type "clazz".
|
static Object |
convert(Class clazz,
char value,
String fmt)
Convert a char to another type "clazz".
|
static Object |
convert(Class clazz,
double value)
Convert a double to another type "clazz".
|
static Object |
convert(Class clazz,
double value,
String fmt)
Convert a double to another type "clazz".
|
static Object |
convert(Class clazz,
float value)
Convert an float to another type "clazz".
|
static Object |
convert(Class clazz,
float value,
String fmt)
Convert a float to another type "clazz".
|
static Object |
convert(Class clazz,
int value)
Convert an int to another type "clazz".
|
static Object |
convert(Class clazz,
int value,
String fmt)
Convert an int to another type "clazz".
|
static Object |
convert(Class clazz,
long value)
Convert a long to another type "clazz".
|
static Object |
convert(Class clazz,
long value,
String fmt)
Convert a long to another type "clazz".
|
static Object |
convert(Class clazz,
Object value)
Convert an Object to another type "clazz".
|
static Object |
convert(Class clazz,
Object value,
String fmt)
Convert an object "value" to another type "clazz" using a format "fmt"
|
static Object |
convert(Class clazz,
short value)
Convert an short to another type "clazz".
|
static Object |
convert(Class clazz,
short value,
String fmt)
Convert a short to another type "clazz".
|
static double |
divide(double d,
double d1) |
static double |
divide(double d1,
double d2,
int decimalPlaces) |
static double |
divide(double d,
double d1,
int decimalPlaces,
int roundType) |
static double |
divide(double d,
Number n) |
static double |
divide(double d,
Number n,
int decimalPlaces) |
static double |
divide(double d,
Number n,
int decimalPlaces,
int roundType) |
static double |
divide(Number d,
double d1) |
static double |
divide(Number d,
double d1,
int decimalPlaces) |
static double |
divide(Number d,
double d1,
int decimalPlaces,
int roundType) |
static double |
divide(Number n1,
Number n2) |
static double |
divide(Number n1,
Number n2,
int decimalPlaces) |
static double |
divide(Number n1,
Number n2,
int decimalPlaces,
int roundType) |
static String |
getBigDecimalFormat()
Default format to use for BigDecimal numbers, mostly to represent currency.
|
static String |
getBooleanFormat()
default format to use for boolean values when converted to a String.
|
static OAConverterInterface |
getConverter(Class clazz)
Returns a OAConverterInterface Object for a specific Class.
|
static String |
getCurrencyFormat() |
static String |
getDateFormat()
Default format to use for dates.
|
static String |
getDateTimeFormat()
default format to use for datetimes.
|
static String |
getDecimalFormat()
Default format to use for decimal numbers (floats, doubles).
|
static String |
getFormat(Class clazz)
Returns formatting default String to use for specific Class.
|
static String |
getIntegerFormat()
Default format to use for integer values.
|
static String |
getMoneyFormat()
Default format to use for Money/Currency.
|
static String |
getTimeFormat()
default format to use for times.
|
static boolean |
isEqual(double d1,
double d2) |
static boolean |
isEqual(double d1,
double d2,
int decimalPlaces)
Compare two doubles, using fixed decimal places.
|
static void |
main(String[] args) |
static double |
multiply(double d,
double d1) |
static double |
multiply(double d1,
double d2,
int decimalPlaces) |
static double |
multiply(double d,
double d1,
int decimalPlaces,
int roundType) |
static double |
multiply(double d,
Number n) |
static double |
multiply(double d,
Number n,
int decimalPlaces) |
static double |
multiply(double d,
Number n,
int decimalPlaces,
int roundType) |
static double |
multiply(Number d,
double d1) |
static double |
multiply(Number d,
double d1,
int decimalPlaces) |
static double |
multiply(Number d,
double d1,
int decimalPlaces,
int roundType) |
static double |
multiply(Number n1,
Number n2) |
static double |
multiply(Number n1,
Number n2,
int decimalPlaces) |
static double |
multiply(Number n1,
Number n2,
int decimalPlaces,
int roundType) |
static double |
round(double d,
int decimalPlaces)
Uses BigDecimal to round number to "decimalPlaces" amount of decimal numbers.
|
static double |
round(double d,
int accurateDecimalPlaces,
int decimalPlaces)
Uses BigDecimal to round number to "decimalPlaces" amount of decimal numbers.
|
static double |
round(double d,
int accurateDecimalPlaces,
int decimalPlaces,
int roundType)
Uses BigDecimal to round number to "decimalPlaces" amount of decimal numbers.
|
static void |
setBigDecimalFormat(String fmt)
Default format to use for BigDecimal numbers, mostly to represent currency.
|
static void |
setBooleanFormat(String fmt)
Set default format for booleans.
|
static void |
setDateFormat(String fmt)
Set default format for Dates.
|
static void |
setDateTimeFormat(String fmt)
Set default format for DateTimes.
|
static void |
setDecimalFormat(String fmt)
Set default format for Decimal numbers (floats/doubles).
|
static void |
setIntegerFormat(String fmt)
Set default format for Integers.
|
static void |
setMoneyFormat(String fmt)
Default format to use for Money/Currency.
|
static void |
setTimeFormat(String fmt)
Set default format for Times.
|
static double |
subtract(double d1,
double d2) |
static double |
subtract(double d1,
double d2,
int decimalPlaces) |
static double |
subtract(double d,
double d1,
int decimalPlaces,
int roundType) |
static double |
subtract(double d,
Number n) |
static double |
subtract(double d,
Number n,
int decimalPlaces) |
static double |
subtract(double d,
Number n,
int decimalPlaces,
int roundType) |
static double |
subtract(Number d,
double d1) |
static double |
subtract(Number d,
double d1,
int decimalPlaces) |
static double |
subtract(Number d,
double d1,
int decimalPlaces,
int roundType) |
static double |
subtract(Number n1,
Number n2) |
static double |
subtract(Number n1,
Number n2,
int decimalPlaces) |
static double |
subtract(Number n1,
Number n2,
int decimalPlaces,
int roundType) |
static BigDecimal |
toBigDecimal(Object value)
Convert an Object to a BigDecimal.
|
static boolean |
toBoolean(Object value)
Convert an Object to a boolean.
|
static byte |
toByte(Object value)
Convert an Object to a byte.
|
static char |
toChar(Object value)
Convert an Object to a char.
|
static OADate |
toDate(Object value)
Convert a String to an OADate.
|
static OADate |
toDate(Object value,
String fmt)
Convert a String to an OADate.
|
static OADateTime |
toDateTime(String value)
Convert a String to an OADateTime.
|
static OADateTime |
toDateTime(String value,
String fmt)
Convert a String to an OADateTime.
|
static double |
toDouble(Object value)
Convert an Object to a double.
|
static float |
toFloat(Object value)
Convert an Object to a float.
|
static int |
toInt(Object value)
Convert an Object to an int.
|
static long |
toLong(double d,
int decimalPlaces)
Convert to a long, with "assumed" decimalPlaces
|
static long |
toLong(Object value)
Convert an Object to a long.
|
static short |
toShort(Object value)
Convert an Object to a short.
|
static String |
toString(boolean b)
Convert boolean value to a String, using Boolean(b).toString()
|
static String |
toString(boolean b,
boolean bUseDefaultFormat) |
static String |
toString(boolean b,
String fmt)
Convert boolean value to a String.
|
static String |
toString(Boolean b,
String fmt)
Convert boolean value to a String.
|
static String |
toString(char c)
Convert a character to a String.
|
static String |
toString(char c,
boolean bUseDefaultFormat) |
static String |
toString(double d)
Convert a double to a String
|
static String |
toString(double d,
boolean bUseDefaultFormat) |
static String |
toString(double d,
String fmt)
Convert a double to a String, using a specific format.
|
static String |
toString(long l)
Convert a long to a String.
|
static String |
toString(long l,
boolean bUseDefaultFormat) |
static String |
toString(long l,
String fmt)
Convert a long to a String, using a specific format.
|
static String |
toString(Object obj)
Convert an Object to a String, without formatting.
|
static String |
toString(Object obj,
boolean bUseDefaultFormat) |
static String |
toString(Object obj,
String fmt)
Convert an Object to a String, using a specific format.
|
static OATime |
toTime(Object value)
Convert a String to an OATime.
|
static OATime |
toTime(Object value,
String fmt)
Convert a String to an OATime.
|
protected static Hashtable hashtable
protected static String dateFormat
protected static String timeFormat
protected static String dateTimeFormat
protected static String integerFormat
protected static String decimalFormat
protected static String bigDecimalFormat
protected static String moneyFormat
protected static String booleanFormat
public static OAConverterInterface getConverter(Class clazz)
OAConverterInterface
public static void addConverter(Class clazz, OAConverterInterface oci)
public static String getFormat(Class clazz)
public static String getDateFormat()
Note: OAConverter.toString() will not automatically use this format unless it is sent as a parameter. This method is to be used as a global area for other APIs to store default system formatting. Note: OADate is used for formatting dates and has its own default formatting if one is not supplied.
public static void setDateFormat(String fmt)
getDateFormat()
public static String getTimeFormat()
public static void setTimeFormat(String fmt)
getTimeFormat()
public static String getDateTimeFormat()
public static void setDateTimeFormat(String fmt)
getDateTimeFormat()
public static String getIntegerFormat()
Note: OAConverter.toString() will not automatically use this format unless it is sent as a parameter. This method is to be used as a global area for other APIs to store default system formatting. see OANumberConverter#OANumberConverter for format options
public static void setIntegerFormat(String fmt)
getIntegerFormat()
public static String getDecimalFormat()
Note: OAConverter.toString() will not automatically use this format unless it is sent as a parameter. This method is to be used as a global area for other APIs to store default system formatting.
for format options
public static void setDecimalFormat(String fmt)
getDecimalFormat()
public static String getBigDecimalFormat()
public static void setBigDecimalFormat(String fmt)
for format options
public static String getMoneyFormat()
public static String getCurrencyFormat()
public static void setMoneyFormat(String fmt)
public static String getBooleanFormat()
Note: OAConverter.toString() will not automatically use this format unless it is sent as a parameter. This method is to be used as a global area for other APIs to store default system formatting. param fmt is a String with a semicolon seperating the three values "true;false;null" Example: ("true;false");
public static void setBooleanFormat(String fmt)
getBooleanFormat()
public static double round(double d, int accurateDecimalPlaces, int decimalPlaces, int roundType)
Notes:
Since doubles are floating point numbers, there is a chance for loss of precision.
For rounding, this could cause a problem when the digit that is being removed should be
a 5, in which case the previous digit might need to be changed based on the type of rounding
that is being performed (ex: BigDecimal.ROUND_HALF_UP, ROUND_HALF_DOWN, etc.).
Floating point numbers mostly lose precision when being used for a lot of calculations.
Example: a number "1.5" could be represented as "1.499999" or "1.500001" as a double.
The round method allows you to specify the number of decimal places that you know the number currently should have.
The round method will first round the number to this amount of decimal places before performing the round.
SEE: https://stackoverflow.com/questions/2808535/round-a-double-to-2-decimal-places
accurateDecimalPlaces
- is number of decimal places that number should have. See note above.decimalPlaces
- is number of decimal places that number needs to be rounded to.roundType
- is type of rounding to perform. See BigDecimal for types of rounding, ex: BigDecimal.ROUND_HALF_UPBigDecimal
public static double round(double d, int accurateDecimalPlaces, int decimalPlaces)
By Default, uses BigDecimal.ROUND_HALF_UP.
accurateDecimalPlaces
- is number of decimal places that number should have. See note above.decimalPlaces
- number of decimal places to round toNotes about rounding
,
BigDecimal
public static double round(double d, int decimalPlaces)
By Default, uses BigDecimal.ROUND_HALF_UP.
decimalPlaces
- number of decimal places to round toNotes about rounding
,
BigDecimal
public static long toLong(double d, int decimalPlaces)
public static int compare(double d1, double d2, int decimalPlaces)
public static boolean isEqual(double d1, double d2, int decimalPlaces)
public static boolean isEqual(double d1, double d2)
public static double add(double d, Number n, int decimalPlaces, int roundType)
public static double add(Number d, double d1, int decimalPlaces, int roundType)
public static double add(double d, double d1, int decimalPlaces, int roundType)
public static double add(double d, Number n, int decimalPlaces)
public static double add(Number d, double d1, int decimalPlaces)
public static double add(double d1, double d2, int decimalPlaces)
public static double add(double d, Number n)
public static double add(Number d, double d1)
public static double add(double d, double d1)
public static double subtract(double d, Number n, int decimalPlaces, int roundType)
public static double subtract(Number d, double d1, int decimalPlaces, int roundType)
public static double subtract(double d, double d1, int decimalPlaces, int roundType)
public static double subtract(double d, Number n, int decimalPlaces)
public static double subtract(Number d, double d1, int decimalPlaces)
public static double subtract(double d1, double d2, int decimalPlaces)
public static double subtract(double d, Number n)
public static double subtract(Number d, double d1)
public static double subtract(double d1, double d2)
public static double multiply(double d, Number n, int decimalPlaces, int roundType)
public static double multiply(Number d, double d1, int decimalPlaces, int roundType)
public static double multiply(double d, double d1, int decimalPlaces, int roundType)
public static double multiply(double d, Number n, int decimalPlaces)
public static double multiply(Number d, double d1, int decimalPlaces)
public static double multiply(double d1, double d2, int decimalPlaces)
public static double multiply(double d, Number n)
public static double multiply(Number d, double d1)
public static double multiply(double d, double d1)
public static double divide(double d, Number n, int decimalPlaces, int roundType)
public static double divide(Number d, double d1, int decimalPlaces, int roundType)
public static double divide(double d, double d1, int decimalPlaces, int roundType)
public static double divide(double d, Number n, int decimalPlaces)
public static double divide(Number d, double d1, int decimalPlaces)
public static double divide(double d1, double d2, int decimalPlaces)
public static double divide(double d, Number n)
public static double divide(Number d, double d1)
public static double divide(double d, double d1)
public static Object convert(Class clazz, Object value, String fmt)
This will call getConverter(clazz). If the converter is null or it returns a null, then getConverter(value.getClass()) will be called.
Note: If clazz is String and value is null, then a blank String "" is returned.
fmt
- is format to use for parsing/formatting.
returns converted object of type clazz or null if converstion can not be done.getConverter(java.lang.Class)
public static Object convert(Class clazz, Object value)
convert(Class,Object,String)
public static Object convert(Class clazz, double value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, double value)
convert(Class,Object,String)
public static Object convert(Class clazz, float value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, float value)
convert(Class,Object,String)
public static Object convert(Class clazz, long value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, long value)
convert(Class,Object,String)
public static Object convert(Class clazz, int value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, int value)
convert(Class,Object,String)
public static Object convert(Class clazz, short value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, short value)
convert(Class,Object,String)
public static Object convert(Class clazz, char value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, char value)
convert(Class,Object,String)
public static Object convert(Class clazz, byte value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, byte value)
convert(Class,Object,String)
public static Object convert(Class clazz, boolean value, String fmt)
convert(Class,Object,String)
public static Object convert(Class clazz, boolean value)
convert(Class,Object,String)
public static double toDouble(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static BigDecimal toBigDecimal(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static float toFloat(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static long toLong(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static int toInt(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static short toShort(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static char toChar(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static byte toByte(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static boolean toBoolean(Object value)
IllegalArgumentException
- if number is not a valid numberconvert(Class,Object,String)
public static OADateTime toDateTime(String value, String fmt)
convert(Class,Object,String)
,
OADateTime
public static OADateTime toDateTime(String value)
convert(Class,Object,String)
public static OADate toDate(Object value, String fmt)
convert(Class,Object,String)
,
OADateTime
public static OADate toDate(Object value)
convert(Class,Object,String)
,
OADateTime
public static OATime toTime(Object value, String fmt)
convert(Class,Object,String)
,
OADateTime
public static OATime toTime(Object value)
convert(Class,Object,String)
,
OADateTime
public static String toString(Object obj)
convert(Class,Object,String)
public static String toString(Object obj, String fmt)
convert(Class,Object,String)
,
OAString.format(String,String)
public static String toString(double d, String fmt)
OAConverterNumber
,
convert(Class,Object,String)
,
OAString.format(String,String)
public static String toString(double d, boolean bUseDefaultFormat)
public static String toString(double d)
OAConverterNumber
,
convert(Class,Object,String)
public static String toString(long l, String fmt)
OAConverterNumber
,
convert(Class,Object,String)
,
OAString.format(String,String)
public static String toString(long l)
OAConverterNumber
,
convert(Class,Object,String)
public static String toString(long l, boolean bUseDefaultFormat)
public static String toString(char c)
OAConverterCharacter
public static String toString(char c, boolean bUseDefaultFormat)
public static String toString(boolean b, String fmt)
fmt
- format string to determine values for true, false, null. Ex: "true;false;null", "yes;no;maybe"OAConverterBoolean
,
convert(Class,Object,String)
,
OAString.format(String,String)
public static String toString(boolean b, boolean bUseDefaultFormat)
public static String toString(Boolean b, String fmt)
b
- boolean value, can be null if used as "(Boolean) null"fmt
- format string to determine values for true, false, null. Ex: "true;false;null", "yes;no;maybe"OAConverterBoolean
,
convert(Class,Object,String)
,
OAString.format(String,String)
public static String toString(boolean b)
public static void main(String[] args)
Copyright © 1999–2019 ViaOA. All rights reserved.