01: /*
02: * ValueLogElement.java
03: *
04: * Created on October 8, 2002, 2:38 PM
05: */
06:
07: package org.netbeans.performance.spi;
08:
09: import org.netbeans.performance.spi.html.*;
10:
11: /**A log element that supplies a value derived from whatever
12: * text it wraps.
13: *
14: * @author Tim Boudreau
15: */
16: public abstract class ValueLogElement extends AbstractLogElement
17: implements Valued {
18: protected Object value = null;
19:
20: /** Do nothing constructor for subclassers. */
21: protected ValueLogElement() {
22: }
23:
24: /** Creates a new instance of ValueLogElement, using the passed
25: * String as the thing to be parsed to find the value
26: * on demand.
27: */
28: public ValueLogElement(String s) {
29: super (s);
30: }
31:
32: /**Creates a new instances of ValueLogElement, using the
33: * passed arguments as the value. Instances created
34: * by this constructor will <i>not</i> ever call the parse()
35: * method - it is assumed the code that created them set
36: * the values correctly.
37: */
38: protected ValueLogElement(Object value) {
39: super ();
40: this .value = value;
41: parsed = true;
42: }
43:
44: public synchronized Object getValue() {
45: checkParsed();
46: return value;
47: }
48:
49: /**Get a string representation of the object. If the <code>line</code>
50: * instance variable from AbstractLogElement is null, uses the <code>value</code>
51: * field by calling toString() on it.
52: */
53: public String toString() {
54: String result = super .toString();
55: if (result == null)
56: result = value.toString();
57: return result;
58: }
59:
60: public int hashCode() {
61: checkParsed();
62: if (value != null) {
63: return value.hashCode() ^ 37;
64: } else {
65: return 0;
66: }
67: }
68:
69: public boolean equals(Object o) {
70: checkParsed();
71: return (o.getClass() == ValueLogElement.class)
72: && ((ValueLogElement) o).value == value;
73: }
74:
75: public HTML toHTML() {
76: checkParsed();
77: return new HTMLTextItem(value.toString());
78: }
79: }
|