01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.mandarax.lib.date;
19:
20: import java.util.Calendar;
21: import org.mandarax.kernel.Term;
22: import org.mandarax.kernel.Session;
23:
24: /**
25: * Abstract superclass for binary date (better: calendar) predicates.
26: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
27: * @version 3.4 <7 March 05>
28: * @since 1.4
29: */
30: public abstract class BinaryDatePredicate extends
31: org.mandarax.lib.AbstractPredicate {
32:
33: private static Class[] structure = { Calendar.class, Calendar.class };
34:
35: /**
36: * Get the structure of the function.
37: * @return the structure of the function
38: */
39: public Class[] getStructure() {
40: return structure;
41: }
42:
43: /**
44: * Perform the predicate using an array of terms as parameters.
45: * @return the result of the computation
46: * @param parameter an array of terms
47: * @param session a session object
48: * @throws java.lang.UnsupportedOperationException
49: * @throws java.lang.IllegalArgumentException
50: */
51: public Object perform(Term[] parameter, Session session)
52: throws IllegalArgumentException,
53: UnsupportedOperationException {
54: Calendar c1, c2 = null;
55:
56: try {
57: c1 = (Calendar) (parameter[0].resolve(session));
58: c2 = (Calendar) (parameter[1].resolve(session));
59: } catch (Exception x) {
60: throw new IllegalArgumentException();
61: }
62:
63: return new Boolean(compute(c1, c2));
64: }
65:
66: /**
67: * Compare calendars.
68: * @return the result
69: * @param c1 a date
70: * @param c2 another date
71: */
72: protected abstract boolean compute(Calendar c1, Calendar c2);
73: }
|