1 package org.apache.commons.jcs3.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.jcs3.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;
35
36 /** the data */
37 private V data;
38
39 /**
40 * Constructor
41 *
42 * @param name
43 * @param data
44 */
45 public StatElement(final String name, final V data)
46 {
47 this.name = name;
48 this.data = data;
49 }
50
51 /**
52 * Get the name of the stat element, ex. HitCount
53 * <p>
54 * @return the stat element name
55 */
56 @Override
57 public String getName()
58 {
59 return name;
60 }
61
62 /**
63 * @param name
64 */
65 @Override
66 public void setName( final String name )
67 {
68 this.name = name;
69 }
70
71 /**
72 * Get the data, ex. for hit count you would get a value for some number.
73 * <p>
74 * @return data
75 */
76 @Override
77 public V getData()
78 {
79 return data;
80 }
81
82 /**
83 * Set the data for this element.
84 * <p>
85 * @param data
86 */
87 @Override
88 public void setData( final V data )
89 {
90 this.data = data;
91 }
92
93 /**
94 * @return a readable string.
95 */
96 @Override
97 public String toString()
98 {
99 final StringBuilder buf = new StringBuilder();
100 buf.append( name ).append(" = ").append( data );
101 return buf.toString();
102 }
103 }