01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.workflow;
21:
22: /**
23: * Represents a contextual artifact, which can be any Object, useful for making
24: * a Decision. Facts are key-value pairs, where the key is a String (message
25: * key) and the value is an arbitrary Object. Generally, the supplied object's
26: * {@link #toString()} method should return a human-readable String. Facts are
27: * immutable objects.
28: *
29: * @author Andrew Jaquith
30: * @since 2.5
31: */
32: public final class Fact {
33: private final String m_key;
34:
35: private final Object m_obj;
36:
37: /**
38: * Constructs a new Fact with a supplied message key and value.
39: *
40: * @param messageKey
41: * the "name" of this fact, which should be an i18n message key
42: * @param value
43: * the object to associate with the name
44: */
45: public Fact(String messageKey, Object value) {
46: if (messageKey == null || value == null) {
47: throw new IllegalArgumentException(
48: "Fact message key or value parameters must not be null.");
49: }
50: m_key = messageKey;
51: m_obj = value;
52: }
53:
54: /**
55: * Returns this Fact's name, as represented an i18n message key.
56: * @return the message key
57: */
58: public String getMessageKey() {
59: return m_key;
60: }
61:
62: /**
63: * Returns this Fact's value.
64: * @return the value object
65: */
66: public Object getValue() {
67: return m_obj;
68: }
69:
70: /**
71: * Two Facts are considered equal if their message keys and value objects are equal.
72: * @param obj the object to test
73: * @return <code>true</code> if logically equal, <code>false</code> if not
74: */
75: public boolean equals(Object obj) {
76: if (!(obj instanceof Fact)) {
77: return false;
78: }
79:
80: Fact f = (Fact) obj;
81: return m_key.equals(f.m_key) && m_obj.equals(f.m_obj);
82: }
83:
84: /**
85: * {@inheritDoc}
86: */
87: public int hashCode() {
88: return m_key.hashCode() + 41 * m_obj.hashCode();
89: }
90:
91: /**
92: * Returns a String representation of this Fact.
93: * @return the representation
94: */
95: public String toString() {
96: return "[Fact:" + m_obj.toString() + "]";
97: }
98: }
|