use of com.dexels.navajo.document.types.Money in project navajo by Dexels.
the class UtilsMoneyTest method testAddLongAndMoney.
@Test
public void testAddLongAndMoney() {
Long a = 15L;
Money b = new Money(10);
Money result = (Money) Utils.add(a, b, "ToLong(15) + ToMoney(10)");
assertEquals(new Money(25), result);
}
use of com.dexels.navajo.document.types.Money in project navajo by Dexels.
the class UtilsMoneyTest method testSubtractTwoMoneys.
// SUBTRACT
@Test
public void testSubtractTwoMoneys() {
Money a = new Money(15);
Money b = new Money(10);
Money result = (Money) Utils.subtract(a, b, "ToMoney(15) - ToMoney(10)");
assertEquals(new Money(5), result);
}
use of com.dexels.navajo.document.types.Money in project navajo by Dexels.
the class UtilsMoneyTest method testSubtractMoneyAndInteger.
@Test
public void testSubtractMoneyAndInteger() {
Money a = new Money(15);
Integer b = 10;
Money result = (Money) Utils.subtract(a, b, "ToMoney(15) - 10");
assertEquals(new Money(5), result);
}
use of com.dexels.navajo.document.types.Money in project navajo by Dexels.
the class UtilsMoneyTest method testSubtractMoneyAndDouble.
@Test
public void testSubtractMoneyAndDouble() {
Money a = new Money(15);
Double b = 10.0;
Money result = (Money) Utils.subtract(a, b, "ToMoney(15) - 10.0");
assertEquals(new Money(5), result);
}
use of com.dexels.navajo.document.types.Money in project navajo by Dexels.
the class BasePropertyImpl method getTypedValue.
/**
* Get the value of a property as a Java object.
*
* @return
*/
@Override
public final Object getTypedValue() {
if (getType().equals(Property.STRING_PROPERTY)) {
return getValue();
}
if (getType().equals(Property.BOOLEAN_PROPERTY)) {
if (getValue() != null && !getValue().equals("")) {
return Boolean.valueOf(getValue().equalsIgnoreCase("true"));
} else {
return null;
}
}
if (getType().equals(EXPRESSION_LITERAL_PROPERTY)) {
if (getValue() != null && !getValue().equals("")) {
return new NavajoExpression(getValue());
} else {
return null;
}
}
if (getType().equals(EXPRESSION_PROPERTY)) {
if (evaluatedValue == null) {
evaluatedValue = getEvaluatedValue();
return evaluatedValue;
} else {
return evaluatedValue;
}
}
if (getType().equals(Property.PERCENTAGE_PROPERTY)) {
if (getValue() != null) {
return new Percentage(getValue());
} else {
return null;
}
}
if (getType().equals(Property.MONEY_PROPERTY)) {
if (getValue() == null || "".equals(getValue())) {
return new Money((Double) null, getSubType());
}
String val = getValue();
NumberFormat fn = NumberFormat.getNumberInstance(Locale.US);
Number parse;
try {
parse = fn.parse(val);
} catch (ParseException e) {
return null;
}
return new Money(parse.doubleValue(), getSubType());
} else if (getType().equals(Property.CLOCKTIME_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
try {
return new ClockTime(getValue(), getSubType());
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.STOPWATCHTIME_PROPERTY)) {
try {
return new StopwatchTime(getValue(), getSubType());
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.DATE_PROPERTY) || getType().equals(Property.TIMESTAMP_PROPERTY)) {
if (getValue() == null || getValue().equals("") || getValue().equals("null")) {
return null;
}
if (myDate != null) {
return myDate;
}
// Try in order from most specific to least specific
try {
return timestampFormat.get().parse(getValue());
} catch (Exception ex) {
try {
return dateFormat4.get().parse(getValue());
} catch (Exception ex2) {
try {
return dateFormat1.get().parse(getValue());
} catch (Exception ex3) {
try {
return dateFormat2.get().parse(getValue());
} catch (Exception ex4) {
try {
Long l = Long.parseLong(getValue());
Date d = new java.util.Date();
d.setTime(l);
return d;
} catch (Exception e5) {
logger.info("Sorry I really can't parse that date: {}", getValue());
return null;
}
}
}
}
}
} else if (getType().equals(Property.INTEGER_PROPERTY)) {
if (getValue() == null || getValue().equals("") || getValue().trim().equals("null")) {
return null;
}
try {
return Integer.valueOf(Integer.parseInt(getValue().trim()));
} catch (NumberFormatException ex3) {
logger.info("Numberformat exception...: {}", getValue().trim());
return null;
}
} else if (getType().equals(Property.LONG_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
try {
// Added a trim. Frank.
return Long.valueOf(Long.parseLong(getValue().trim()));
} catch (NumberFormatException ex3) {
logger.info("Numberformat exception...");
return null;
}
} else if (getType().equals(Property.FLOAT_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
String v = getValue();
String w = v;
// Sometimes the number formatting creates
if (v.indexOf(',') != -1) {
w = v.replaceAll(",", "");
}
Double d;
try {
d = Double.valueOf(Double.parseDouble(w));
} catch (NumberFormatException ex) {
logger.info("Can not format double with: {}", w);
return null;
}
return d;
} else if (getType().equals(Property.BINARY_PROPERTY)) {
try {
return myBinary;
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.SELECTION_PROPERTY)) {
return getAllSelectedSelections();
} else if (getType().equals(Property.TIPI_PROPERTY)) {
return tipiProperty;
} else if (getType().equals(Property.LIST_PROPERTY)) {
if (tipiProperty != null || myValue == null) {
return tipiProperty;
}
try {
if (myValue.indexOf('[') == 0) {
// Parse back into a list
String stripped = myValue.substring(1, myValue.length() - 1);
tipiProperty = Arrays.asList(stripped.split(", "));
return tipiProperty;
} else if (myValue.length() > 0) {
logger.info("Failed to parse {} as a list!", myValue);
}
} catch (Exception e) {
logger.warn("Exception on parsing {} as a list!", myValue, e);
}
return null;
} else if (getType().equals(Property.BINARY_DIGEST_PROPERTY)) {
return new BinaryDigest(getValue());
} else if (getType().equals(Property.COORDINATE_PROPERTY)) {
try {
return new Coordinate(myValue);
} catch (Exception e) {
logger.error("Cannot create Coordinate Property: ", e);
}
}
return getValue();
}
Aggregations