001/**
002 * Copyright (C) 2007-2011, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020package org.dllearner.experiments;
021
022import java.util.List;
023
024import com.jamonapi.MonKey;
025import com.jamonapi.MonKeyItem;
026@SuppressWarnings("all")
027public class MyMonKey  implements MonKey{
028                        
029        
030        
031              private final String summaryLabel; // pageHits for example
032              private Object details; // The actual page name for the detail buffer.  pageHits for example
033              private final String units; // ms. for example
034//            private boolean initializeDetail=true;
035              private Object param;
036//            
037              public MyMonKey(String summaryLabel, String units) {
038                  this(summaryLabel, summaryLabel, units);
039              }
040           
041//            /** Object details can be an Object[], a Collection, or a Java Object.  */
042              public MyMonKey(String summaryLabel, Object details, String units) {
043                  this.summaryLabel = (summaryLabel==null) ? "" : summaryLabel;
044                  this.details = details;
045                  this.units= (units==null) ? "" : units;
046            }
047              
048              public MyMonKey(MonKeyItem keyItem, String units) {
049                  super();
050                  this.summaryLabel = (keyItem==null) ? "" : keyItem.toString();;
051                  this.units= (units==null) ? "" : units;
052                  this.details=keyItem.getDetails();
053              }
054
055              
056              /** Returns the label for the monitor */
057              public String getLabel() {
058                  return summaryLabel;
059              }
060                
061              /** Returns the units for the monitor */
062              public String getUnits() {
063                  return units;
064              }
065              
066                public Object getDetails() {
067                return details;
068         //       return details;
069//                      if (initializeDetail) {
070//                              initializeDetail=false;
071//                              detailLabel+=", "+units;
072//                  (detailLabel==null) ? "" : detailLabel
073//                      }
074//                      
075//                   return detailLabel;
076                }
077            
078        //    
079//          public List getDetails(List list) {
080//              Misc.addTo(list, details);
081//              return list;
082//          }
083                
084                public void setDetails(Object details) {
085                        this.details=details;
086                    
087            }
088              
089              /** Returns any object that has a named key.  In this keys case
090               * 'label' and 'units' makes sense, but any values are acceptible.
091               */
092              public Object getValue(String key) {
093                  if (LABEL_HEADER.equalsIgnoreCase(key))
094                     return getLabel();
095                  else if (UNITS_HEADER.equalsIgnoreCase(key))
096                     return getUnits();
097                  else if ("param".equalsIgnoreCase(key))
098                     return getParam();
099                  else if ("details".equalsIgnoreCase(key))
100                     return getDetails();
101                  else
102                     return null;
103                      
104              }
105              
106              /** 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
107               * in the JAMonBufferListener.
108               * @return
109               */
110              public Object getParam() {
111                  return param;
112              }
113         
114              
115              /** 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
116               * in the JAMonBufferListener.
117               * @return
118               */
119              public void setParam(Object param) {
120                  this.param=param;
121              }
122                
123        /**
124        This method is called automatically by a HashMap when this class is used as a HashMap key.  A Coordinate is
125        considered equal if its x and y variables have the same value.
126        */
127
128          @Override
129        public boolean equals(Object compareKey) {
130
131             return (
132                 compareKey instanceof MyMonKey && 
133                 summaryLabel.equals(((MyMonKey) compareKey).summaryLabel) &&
134                 units.equals(((MyMonKey) compareKey).units)
135                 );
136
137          }
138
139          /** Used when key is put into a Map to look up the monitor */
140          @Override
141          public int hashCode() {
142             return (summaryLabel.hashCode() + units.hashCode());
143           }
144
145            public List getBasicHeader(List header) { 
146                header.add(LABEL_HEADER);
147                return header;
148            }   
149                
150          
151            public List getDisplayHeader(List header) {
152                return getHeader(header);
153            }
154            
155            public List getHeader(List header) {
156                header.add(LABEL_HEADER);
157                header.add(UNITS_HEADER);
158                return header;
159            }   
160            
161            public List getBasicRowData(List rowData) {
162              rowData.add(getLabel()+", "+getUnits());
163              return rowData;
164            }
165            
166
167            
168            public List getRowData(List rowData) {
169              rowData.add(getLabel());
170              rowData.add(getUnits());
171              
172              return rowData;
173            }
174            
175            public List getRowDisplayData(List rowData) {
176                return getRowData(rowData);
177            }
178
179            
180            public String toString() {
181                return new StringBuffer().append("JAMon Label=").append(getLabel()).append(", Units=").append(getUnits()).toString();
182                
183            }
184            
185            public String getRangeKey() {
186                return getUnits();
187            }
188
189                /* (non-Javadoc)
190                 * @see com.jamonapi.MonKeyItem#setInstanceName(java.lang.String)
191                 */
192                @Override
193                public void setInstanceName(String instanceName) {
194                }
195
196                /* (non-Javadoc)
197                 * @see com.jamonapi.MonKeyItem#getInstanceName()
198                 */
199                @Override
200                public String getInstanceName() {
201                        return null;
202                }
203
204                /* (non-Javadoc)
205                 * @see com.jamonapi.MonKey#getSize()
206                 */
207                @Override
208                public int getSize() {
209                        return 0;
210                }
211
212            
213        
214}