001: package com.jamonapi;
002:
003: /**
004: * <p>A key implmentation for label, and units type monitors.
005: * Note this could also be implemented with the following use of MonKeyBase. This
006: * class predates that one and would not have to use a Map for basic functions
007: * and so MAY be more efficient (this wasn't tested). Using label, and units
008: * is the most common monitor that will be used in most cases.</p>
009: *
010: * <p>This could be implemented like the following.
011: * LinkedHashMap lm=new LinkedHashMap();<br>
012: * lm.put("Label", "mypakcage.myclass");<br>
013: * lm.put(""Units", "ms.");<br>
014: * MonKey mk=new MonKeyBase(lm);<br>
015: *
016: * </p>
017: */
018:
019: //import java.util.Collection;
020: import java.util.List;
021:
022: public class MonKeyImp implements MonKey {
023:
024: private final String summaryLabel; // pageHits for example
025: private Object details; // The actual page name for the detail buffer. pageHits for example
026: private final String units; // ms. for example
027: // private boolean initializeDetail=true;
028: private Object param;
029:
030: public MonKeyImp(String summaryLabel, String units) {
031: this (summaryLabel, summaryLabel, units);
032: }
033:
034: /** Object details can be an Object[], a Collection, or a Java Object. */
035: public MonKeyImp(String summaryLabel, Object details, String units) {
036: this .summaryLabel = (summaryLabel == null) ? "" : summaryLabel;
037: this .details = details;
038: this .units = (units == null) ? "" : units;
039: }
040:
041: public MonKeyImp(MonKeyItem keyItem, String units) {
042: this .summaryLabel = (keyItem == null) ? "" : keyItem.toString();
043: ;
044: this .units = (units == null) ? "" : units;
045: this .details = keyItem.getDetails();
046:
047: }
048:
049: /** Returns the label for the monitor */
050: public String getLabel() {
051: return summaryLabel;
052: }
053:
054: /** Returns the units for the monitor */
055: public String getUnits() {
056: return units;
057: }
058:
059: public Object getDetails() {
060: return details;
061: // return details;
062: // if (initializeDetail) {
063: // initializeDetail=false;
064: // detailLabel+=", "+units;
065: // (detailLabel==null) ? "" : detailLabel
066: // }
067: //
068: // return detailLabel;
069: }
070:
071: //
072: // public List getDetails(List list) {
073: // Misc.addTo(list, details);
074: // return list;
075: // }
076:
077: public void setDetails(Object details) {
078: this .details = details;
079:
080: }
081:
082: /** Returns any object that has a named key. In this keys case
083: * 'label' and 'units' makes sense, but any values are acceptible.
084: */
085: public Object getValue(String key) {
086: if (LABEL_HEADER.equalsIgnoreCase(key))
087: return getLabel();
088: else if (UNITS_HEADER.equalsIgnoreCase(key))
089: return getUnits();
090: else if ("param".equalsIgnoreCase(key))
091: return getParam();
092: else if ("details".equalsIgnoreCase(key))
093: return getDetails();
094: else
095: return null;
096:
097: }
098:
099: /** Used to get any arbitrary Object into the key. It will not be used as part of the key, however it can be retrieved later for example
100: * in the JAMonBufferListener.
101: * @return
102: */
103: public Object getParam() {
104: return param;
105: }
106:
107: /** Used to set any arbitrary Object into the key. It will not be used as part of the key, however it can be retrieved later for example
108: * in the JAMonBufferListener.
109: * @return
110: */
111: public void setParam(Object param) {
112: this .param = param;
113: }
114:
115: /**
116: This method is called automatically by a HashMap when this class is used as a HashMap key. A Coordinate is
117: considered equal if its x and y variables have the same value.
118: */
119:
120: public boolean equals(Object compareKey) {
121:
122: return (compareKey instanceof MonKeyImp
123: && summaryLabel
124: .equals(((MonKeyImp) compareKey).summaryLabel) && units
125: .equals(((MonKeyImp) compareKey).units));
126:
127: }
128:
129: /** Used when key is put into a Map to look up the monitor */
130: public int hashCode() {
131: return (summaryLabel.hashCode() + units.hashCode());
132: }
133:
134: public List getBasicHeader(List header) {
135: header.add(LABEL_HEADER);
136: return header;
137: }
138:
139: public List getDisplayHeader(List header) {
140: return getHeader(header);
141: }
142:
143: public List getHeader(List header) {
144: header.add(LABEL_HEADER);
145: header.add(UNITS_HEADER);
146: return header;
147: }
148:
149: public List getBasicRowData(List rowData) {
150: rowData.add(getLabel() + ", " + getUnits());
151: return rowData;
152: }
153:
154: public List getRowData(List rowData) {
155: rowData.add(getLabel());
156: rowData.add(getUnits());
157:
158: return rowData;
159: }
160:
161: public List getRowDisplayData(List rowData) {
162: return getRowData(rowData);
163: }
164:
165: public String toString() {
166: return new StringBuffer().append("JAMon Label=").append(
167: getLabel()).append(", Units=").append(getUnits())
168: .toString();
169:
170: }
171:
172: public String getRangeKey() {
173: return getUnits();
174: }
175:
176: }
|