1 package org.apache.commons.jcs.engine.stats;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.jcs.engine.stats.behavior.IStatElement;
23
24 /**
25 * This is a stat data holder.
26 */
27 public class StatElement<V>
28 implements IStatElement<V>
29 {
30 /** Don't change */
31 private static final long serialVersionUID = -2982373725267618092L;
32
33 /** name of the stat */
34 private String name = null;
35
36 /** the data */
37 private V data = null;
38
39 /**
40 * Constructor
41 *
42 * @param name
43 * @param data
44 */
45 public StatElement(String name, V data)
46 {
47 super();
48 this.name = name;
49 this.data = data;
50 }
51
52 /**
53 * Get the name of the stat element, ex. HitCount
54 * <p>
55 * @return the stat element name
56 */
57 @Override
58 public String getName()
59 {
60 return name;
61 }
62
63 /**
64 * @param name
65 */
66 @Override
67 public void setName( String name )
68 {
69 this.name = name;
70 }
71
72 /**
73 * Get the data, ex. for hit count you would get a value for some number.
74 * <p>
75 * @return data
76 */
77 @Override
78 public V getData()
79 {
80 return data;
81 }
82
83 /**
84 * Set the data for this element.
85 * <p>
86 * @param data
87 */
88 @Override
89 public void setData( V data )
90 {
91 this.data = data;
92 }
93
94 /**
95 * @return a readable string.
96 */
97 @Override
98 public String toString()
99 {
100 StringBuilder buf = new StringBuilder();
101 buf.append( name ).append(" = ").append( data );
102 return buf.toString();
103 }
104 }