1 23 24 29 30 package com.sun.appserv.management.j2ee.statistics; 31 32 import java.io.Serializable ; 33 34 import java.util.Set ; 35 import java.util.Map ; 36 import java.util.HashMap ; 37 import java.util.Iterator ; 38 import java.util.Collections ; 39 40 import javax.management.openmbean.CompositeData ; 41 42 import javax.management.j2ee.statistics.Statistic ; 43 44 import com.sun.appserv.management.util.j2ee.J2EEUtil; 45 import com.sun.appserv.management.util.misc.MapUtil; 46 47 50 public class MapStatisticImpl implements MapStatistic, Serializable 51 { 52 static final long serialVersionUID = -5921306849633125922L; 53 54 final Map <String ,Object > mItems; 55 56 58 public 59 MapStatisticImpl( final Map <String ,?> map ) 60 { 61 mItems = new HashMap <String ,Object >( map ); 62 } 63 64 66 public 67 MapStatisticImpl( final Statistic statistic ) 68 { 69 if ( statistic instanceof MapStatistic ) 70 { 71 mItems = new HashMap <String ,Object >(); 72 73 mItems.putAll( ((MapStatistic)statistic).asMap() ); 74 } 75 else 76 { 77 mItems = J2EEUtil.statisticToMap( statistic ); 78 } 79 } 80 81 84 public final long 85 getlong( final String name ) 86 { 87 final Object value = getValue( name ); 88 89 if ( ! (value instanceof Long ) ) 90 { 91 throw new IllegalArgumentException ( 92 "MapStatisticImpl.getLong: expecting Long for " + name + 93 ", got " + value + " of class " + value.getClass() + 94 ", all values: " + toString() ); 95 96 } 97 98 return( ((Long )value).longValue() ); 99 } 100 101 104 public final int 105 getint( final String name ) 106 { 107 return( ((Integer )getValue( name )).intValue() ); 108 } 109 110 111 114 public final String 115 getString( final String name ) 116 { 117 return( (String )getValue( name ) ); 118 } 119 120 121 124 public final Object 125 getValue( final String name ) 126 { 127 final Object value = mItems.get( name ); 128 129 if ( value == null && ! mItems.containsKey( name ) ) 130 { 131 throw new IllegalArgumentException ( name ); 132 } 133 134 return( value ); 135 } 136 137 138 139 142 public String 143 getDescription() 144 { 145 return( getString( "Description" ) ); 146 } 147 148 149 152 public long 153 getLastSampleTime() 154 { 155 return( getlong( "LastSampleTime" ) ); 156 } 157 158 161 public String 162 getName() 163 { 164 return( getString( "Name" ) ); 165 } 166 167 170 public String 171 setName( final String newName ) 172 { 173 if ( newName == null || newName.length() == 0 ) 174 { 175 throw new IllegalArgumentException (); 176 } 177 178 final String oldName = getName(); 179 180 mItems.put( "Name", newName ); 181 182 return( oldName ); 183 } 184 185 188 public long 189 getStartTime() 190 { 191 return( getlong( "StartTime" ) ); 192 } 193 194 195 198 public String 199 getUnit() 200 { 201 return( getString( "Unit" ) ); 202 } 203 204 212 public Set 213 valueNames() 214 { 215 return( Collections.unmodifiableSet( mItems.keySet() ) ); 216 } 217 218 219 public Map <String ,Object > 220 asMap() 221 { 222 return( Collections.unmodifiableMap( mItems ) ); 223 } 224 225 public String 226 toString() 227 { 228 return( MapUtil.toString( mItems ) ); 229 } 230 231 public int 232 hashCode() 233 { 234 return mItems.hashCode(); 235 } 236 237 public boolean 238 equals( final Object rhs ) 239 { 240 boolean equals = false; 241 242 if ( rhs instanceof MapStatistic ) 243 { 244 equals = MapUtil.mapsEqual( asMap(), ((MapStatistic)rhs).asMap() ); 245 } 246 return( equals ); 247 } 248 } 249 250 251 252 253 254 | Popular Tags |