001package org.apache.commons.jcs.engine.stats; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.jcs.engine.stats.behavior.IStatElement; 023 024/** 025 * This is a stat data holder. 026 */ 027public class StatElement<V> 028 implements IStatElement<V> 029{ 030 /** Don't change */ 031 private static final long serialVersionUID = -2982373725267618092L; 032 033 /** name of the stat */ 034 private String name = null; 035 036 /** the data */ 037 private V data = null; 038 039 /** 040 * Constructor 041 * 042 * @param name 043 * @param data 044 */ 045 public StatElement(String name, V data) 046 { 047 super(); 048 this.name = name; 049 this.data = data; 050 } 051 052 /** 053 * Get the name of the stat element, ex. HitCount 054 * <p> 055 * @return the stat element name 056 */ 057 @Override 058 public String getName() 059 { 060 return name; 061 } 062 063 /** 064 * @param name 065 */ 066 @Override 067 public void setName( String name ) 068 { 069 this.name = name; 070 } 071 072 /** 073 * Get the data, ex. for hit count you would get a value for some number. 074 * <p> 075 * @return data 076 */ 077 @Override 078 public V getData() 079 { 080 return data; 081 } 082 083 /** 084 * Set the data for this element. 085 * <p> 086 * @param data 087 */ 088 @Override 089 public void setData( V data ) 090 { 091 this.data = data; 092 } 093 094 /** 095 * @return a readable string. 096 */ 097 @Override 098 public String toString() 099 { 100 StringBuilder buf = new StringBuilder(); 101 buf.append( name ).append(" = ").append( data ); 102 return buf.toString(); 103 } 104}