use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class Utils method compareDates.
public static final boolean compareDates(Object a, Object b, String compareChar) {
if (b instanceof Integer) {
int offset = ((Integer) b).intValue();
Calendar cal = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
Date today = new Date();
cal.setTime(today);
cal.add(Calendar.YEAR, -offset);
cal2.setTime((Date) a);
today = cal.getTime();
if (compareChar.equals("==")) {
return (compare(cal.get(Calendar.YEAR), cal2.get(Calendar.YEAR), compareChar));
} else {
return (compare(today, (Date) a, compareChar));
}
} else if (b instanceof Date) {
return (compare((Date) a, (Date) b, compareChar));
} else if (b instanceof ClockTime) {
return (compare(((ClockTime) a).dateValue(), ((ClockTime) b).dateValue(), compareChar));
} else if (b == null) {
if (compareChar.equals("==")) {
return a == null;
} else {
return a != null;
}
}
throw new TMLExpressionException("Invalid date comparison (a =" + a + ", b = " + b + ")");
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class Utils method add.
/**
* Generic method to add two objects.
*/
public static final Object add(Object a, Object b, String expression) {
if ((a == null) && (b == null)) {
return null;
} else if (a == null) {
return b;
} else if (b == null) {
return a;
}
if ((a instanceof String) || (b instanceof String)) {
String sA = Utils.getStringValue(a);
String sB = Utils.getStringValue(b);
return sA + sB;
} else if ((a instanceof DatePattern || a instanceof Date) && (b instanceof DatePattern || b instanceof Date)) {
DatePattern dp1 = null;
DatePattern dp2 = null;
if (a instanceof Date) {
dp1 = DatePattern.parseDatePattern((Date) a);
} else {
dp1 = (DatePattern) a;
}
if (b instanceof Date) {
dp2 = DatePattern.parseDatePattern((Date) b);
} else {
dp2 = (DatePattern) b;
}
dp1.add(dp2);
return dp1.getDate();
} else if ((a instanceof Money) || (b instanceof Money)) {
if (!(a instanceof Money || a instanceof Integer || a instanceof Long || a instanceof Double))
throw new TMLExpressionException("Invalid argument for operation: " + a.getClass() + ", expression: " + expression);
if (!(b instanceof Money || b instanceof Integer || b instanceof Long || b instanceof Double))
throw new TMLExpressionException("Invalid argument for operation: " + b.getClass() + ", expression: " + expression);
Money arg1 = (a instanceof Money ? (Money) a : new Money(a));
Money arg2 = (b instanceof Money ? (Money) b : new Money(b));
return new Money(arg1.doubleValue() + arg2.doubleValue());
} else if ((a instanceof Percentage) || (b instanceof Percentage)) {
if (!(a instanceof Percentage || a instanceof Integer || a instanceof Long || a instanceof Double))
throw new TMLExpressionException("Invalid argument for operation: " + a.getClass() + ", expression: " + expression);
if (!(b instanceof Percentage || b instanceof Integer || b instanceof Long || b instanceof Double))
throw new TMLExpressionException("Invalid argument for operation: " + b.getClass() + ", expression: " + expression);
Percentage arg1 = (a instanceof Percentage ? (Percentage) a : new Percentage(a));
Percentage arg2 = (b instanceof Percentage ? (Percentage) b : new Percentage(b));
return new Percentage(arg1.doubleValue() + arg2.doubleValue());
} else if ((a instanceof ClockTime && b instanceof DatePattern)) {
DatePattern dp1 = DatePattern.parseDatePattern(((ClockTime) a).dateValue());
DatePattern dp2 = (DatePattern) b;
dp1.add(dp2);
return new ClockTime(dp1.getDate());
} else if ((b instanceof ClockTime && a instanceof DatePattern)) {
DatePattern dp1 = DatePattern.parseDatePattern(((ClockTime) b).dateValue());
DatePattern dp2 = (DatePattern) a;
dp1.add(dp2);
return new ClockTime(dp1.getDate());
} else if ((a instanceof ClockTime && b instanceof ClockTime)) {
DatePattern dp1 = DatePattern.parseDatePattern(((ClockTime) a).dateValue());
DatePattern dp2 = DatePattern.parseDatePattern(((ClockTime) b).dateValue());
dp1.add(dp2);
return new ClockTime(dp1.getDate());
} else if ((a instanceof Boolean && b instanceof Boolean)) {
Boolean ba = (Boolean) a;
Boolean bb = (Boolean) b;
return Integer.valueOf((ba.booleanValue() ? 1 : 0) + (bb.booleanValue() ? 1 : 0));
} else if (a instanceof Integer) {
int inta = (Integer) a;
if (b instanceof Integer) {
return inta + (Integer) b;
} else if (b instanceof Long) {
return inta + (Long) b;
} else if (b instanceof Double) {
return inta + (Double) b;
}
} else if (a instanceof Long) {
long longa = (Long) a;
if (b instanceof Integer) {
return longa + (Integer) b;
} else if (b instanceof Long) {
return longa + (Long) b;
} else if (b instanceof Double) {
return longa + (Double) b;
}
} else if (a instanceof Double) {
double doublea = (Double) a;
if (b instanceof Integer) {
return doublea + (Integer) b;
} else if (b instanceof Long) {
return doublea + (Long) b;
} else if (b instanceof Double) {
return doublea + (Double) b;
}
}
throw new TMLExpressionException("Addition: Unknown type. " + " expression: " + expression);
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class StandardFunctionsTest method testIsEmpty.
@Test
public void testIsEmpty() {
FunctionInterface fi = fff.getInstance(cl, "IsEmpty");
// Empty String.
fi.reset();
fi.insertStringOperand("");
Object o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.TRUE, o);
// Non Empty String.
fi.reset();
fi.insertStringOperand("aap");
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.FALSE, o);
// Null value.
fi.reset();
fi.insertOperand(Operand.NULL);
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.TRUE, o);
// Empty list
fi.reset();
fi.insertListOperand(new ArrayList<Object>());
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.TRUE, o);
// Non Empty list.
fi.reset();
boolean thing = new ArrayList<String>().add("noot");
fi.insertBooleanOperand(thing);
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.FALSE, o);
// Empty Binary.
fi.reset();
fi.insertBinaryOperand(new Binary());
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.TRUE, o);
// Non Empty Binary.
fi.reset();
fi.insertBinaryOperand(new Binary("aap".getBytes()));
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.FALSE, o);
// Non empty Clocktime.
fi.reset();
fi.insertClockTimeOperand(new ClockTime(new Date()));
o = fi.evaluateWithTypeChecking();
assertNotNull(o);
assertEquals(Boolean.FALSE, o);
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class DateAppendClockTime method testInvalidTypeArguements.
@Test(expected = com.dexels.navajo.expression.api.TMLExpressionException.class)
public void testInvalidTypeArguements() throws Exception {
Date date = new Date();
ClockTime cTime = new ClockTime("11:28");
System.out.println(" ------ Running Valid Parameters case ------ ");
System.out.println("Sending Date :: " + date);
System.out.println("Sending ClockTime :: " + cTime);
da.reset();
da.insertDateOperand(date);
da.insertStringOperand("11:28");
System.out.println(da.evaluate());
da.evaluate();
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class ToMilliseconds method main.
public static void main(String[] args) {
ToMilliseconds ts = new ToMilliseconds();
ts.reset();
System.err.println("Time: " + Calendar.getInstance().getTime());
ts.insertStopwatchOperand(new StopwatchTime("01:22:45:234"));
try {
Object o = ts.evaluate();
System.err.println("Millis: " + ((Integer) o).intValue());
} catch (Exception e) {
e.printStackTrace();
}
ts.reset();
System.err.println("Time: " + Calendar.getInstance().getTime());
ts.insertClockTimeOperand(new ClockTime("01:22"));
try {
Object o = ts.evaluate();
System.err.println("Millis: " + ((Long) o).longValue());
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations