001package org.apache.commons.jcs3.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.jcs3.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;
035
036    /** the data */
037    private V data;
038
039    /**
040     * Constructor
041     *
042     * @param name
043     * @param data
044     */
045    public StatElement(final String name, final V data)
046    {
047        this.name = name;
048        this.data = data;
049    }
050
051    /**
052     * Get the name of the stat element, ex. HitCount
053     * <p>
054     * @return the stat element name
055     */
056    @Override
057    public String getName()
058    {
059        return name;
060    }
061
062    /**
063     * @param name
064     */
065    @Override
066    public void setName( final String name )
067    {
068        this.name = name;
069    }
070
071    /**
072     * Get the data, ex. for hit count you would get a value for some number.
073     * <p>
074     * @return data
075     */
076    @Override
077    public V getData()
078    {
079        return data;
080    }
081
082    /**
083     * Set the data for this element.
084     * <p>
085     * @param data
086     */
087    @Override
088    public void setData( final V data )
089    {
090        this.data = data;
091    }
092
093    /**
094     * @return a readable string.
095     */
096    @Override
097    public String toString()
098    {
099        final StringBuilder buf = new StringBuilder();
100        buf.append( name ).append(" = ").append( data );
101        return buf.toString();
102    }
103}