01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.persistence;
19:
20: import de.finix.contelligent.exception.ContelligentException;
21:
22: public class NumberConstraint {
23:
24: public static final Relation GREATER = new Relation(">");
25:
26: public static final Relation LESS = new Relation("<");
27:
28: public static final Relation LESS_OR_EQUAL = new Relation("<=");
29:
30: public static final Relation GREATER_OR_EQUAL = new Relation(">=");
31:
32: public static final Relation EQUAL = new Relation("=");
33:
34: public static final Relation NOT_EQUAL = new Relation("<>");
35:
36: public static final Relation[] validRelations = new Relation[] {
37: GREATER, LESS, LESS_OR_EQUAL, GREATER_OR_EQUAL, EQUAL,
38: NOT_EQUAL };
39:
40: private final Relation relation;
41:
42: private final Number value;
43:
44: public NumberConstraint(Relation relation, Number value) {
45: this .relation = relation;
46: this .value = value;
47: }
48:
49: public NumberConstraint(String relationString, Number value)
50: throws ContelligentException {
51: this (parseRelation(relationString), value);
52: }
53:
54: public static Relation parseRelation(String s)
55: throws ContelligentException {
56: for (int i = 0; i < validRelations.length; i++) {
57: if (validRelations[i].relationString.equals(s)) {
58: return validRelations[i];
59: }
60: }
61: throw new ContelligentException("Cannot convert '" + s
62: + "' into a relation!");
63: }
64:
65: public String getRelation() {
66: return relation.relationString;
67: }
68:
69: public Object getConstraintValue() {
70: return value;
71: }
72:
73: static private class Relation {
74: final String relationString;
75:
76: Relation(String relationString) {
77: this.relationString = relationString;
78: }
79: }
80:
81: }
|