001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.mandarax.examples.crm.domainmodel;
019:
020: /**
021: * Represents customers. Note that there are some method to get the turnover.
022: * These methods are used as functions to build the knowledge base.
023: * (rules like: if the turnover of a customer in the last 6 month was more than
024: * 500$ then ..".
025: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
026: * @version 3.4 <7 March 05>
027: * @since 1.2
028: */
029: public class Customer extends BusinessObject {
030:
031: private int id = 0;
032: private String firstName = "?";
033: private String name = "?";
034: public static Customer ROBERT_MUSIL = new Customer(1, "Robert",
035: "Musil");
036: public static Customer KURT_VONNEGUT = new Customer(2, "Kurt",
037: "Vonnegut");
038: public static Customer GRAHAM_GREENE = new Customer(3, "Graham",
039: "Greene");
040: public static Customer THOMAS_MANN = new Customer(4, "Thomas",
041: "Mann");
042: public static Customer UMBERTO_ECO = new Customer(5, "Umberto",
043: "Eco");
044: public static Customer LUDWIG_WITTGENSTEIN = new Customer(6,
045: "Ludwig", "Wittgenstein");
046: public static Customer[] ALL = { ROBERT_MUSIL, KURT_VONNEGUT,
047: GRAHAM_GREENE, THOMAS_MANN, UMBERTO_ECO,
048: LUDWIG_WITTGENSTEIN };
049:
050: /**
051: * Constructor.
052: */
053: public Customer() {
054: super ();
055: }
056:
057: /**
058: * Constructor.
059: * @param anId int
060: * @param aFirstName java.lang.String
061: * @param aName java.lang.String
062: */
063: public Customer(int anId, String aFirstName, String aName) {
064: super ();
065:
066: id = anId;
067: firstName = aFirstName;
068: name = aName;
069: }
070:
071: /**
072: * Get the first name.
073: * @return java.lang.String
074: */
075: public String getFirstName() {
076: return firstName;
077: }
078:
079: /**
080: * Get the id.
081: * @return int
082: */
083: public int getId() {
084: return id;
085: }
086:
087: /**
088: * Set the id.
089: * @param id the id
090: */
091: public void setId(int id) {
092: this .id = id;
093: }
094:
095: /**
096: * Get the name.
097: * @return java.lang.String
098: */
099: public String getName() {
100: return name;
101: }
102:
103: /**
104: * Get the turnover during the last months.
105: * @return double
106: * @param month int
107: */
108: public double getTurnover(int month) {
109: // WARNING: pure dummy data - would probably be fetched from a DB in a real project (using a GROUP BY query)
110: // this method is used as JFunction, see Oryx for another flavor of this example that uses SQLFunctions wrapping
111: // SQL queries on a CUSTOMER_TRANSACTION table
112: if (month > 10) {
113: if (id == 1)
114: return 80;
115: else if (id == 2)
116: return 100;
117: else if (id == 3)
118: return 150;
119: else if (id == 4)
120: return 220;
121: else if (id == 5)
122: return 300;
123: else if (id == 6)
124: return 420;
125: }
126: return 1000;
127: }
128:
129: /**
130: * Get the turnover in the last numberOfMonth
131: * using the kind of payment.
132: * @return double
133: * @param month int
134: * @param kop KindOfPayment
135: */
136: public double getTurnover(int month, KindOfPayment kop) {
137: // WARNING: pure dummy data - would probably be fetched from a DB in a real project (using a GROUP BY query)
138: // this method is used as JFunction, see Oryx for another flavor of this example that uses SQLFunctions wrapping
139: // SQL queries on a CUSTOMER_TRANSACTION table
140: if (month > 10) {
141: if (id == 1)
142: return 50;
143: else if (id == 2)
144: return 50;
145: else if (id == 3)
146: return 100;
147: else if (id == 4)
148: return 220;
149: else if (id == 5)
150: return 200;
151: else if (id == 6)
152: return 300;
153: }
154: return 1000;
155: }
156:
157: /**
158: * Set the first name.
159: * @param aFirstName java.lang.String
160: */
161: public void setFirstName(String aFirstName) {
162: firstName = aFirstName;
163: }
164:
165: /**
166: * Set the name.
167: * @param aName java.lang.String
168: */
169: public void setName(String aName) {
170: name = aName;
171: }
172:
173: /**
174: * COnvert the object to a string.
175: * @return java.lang.String
176: */
177: public String toString() {
178: return firstName + " " + name;
179: }
180:
181: /**
182: * Compares objects.
183: * @return boolean
184: * @param obj java.lang.Object
185: */
186: public boolean equals(Object obj) {
187: return obj != null && (obj instanceof Customer)
188: && ((Customer) obj).id == id;
189: }
190:
191: /**
192: * Get the hash code of the object.
193: * @return int
194: */
195: public int hashCode() {
196: return id;
197: }
198: }
|