1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info:  http://www.jrobin.org
6  * Project Lead:  Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003-2005, by Sasa Markovic.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * Developers:    Sasa Markovic (saxon@jrobin.org)
15  *
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25
26 package org.jrobin.core;
27
28 import java.io.IOException;
29
30 class RrdString extends RrdPrimitive {
31     private String cache;
32
33     RrdString(RrdUpdater updater, boolean isConstant) throws IOException {
34         super(updater, RrdPrimitive.RRD_STRING, isConstant);
35     }
36
37     RrdString(RrdUpdater updater) throws IOException {
38         this(updater, false);
39     }
40
41     void set(String value) throws IOException {
42         if (!isCachingAllowed()) {
43             writeString(value);
44         }
45         // caching allowed
46         else if (cache == null || !cache.equals(value)) {
47             // update cache
48             writeString(cache = value);
49         }
50     }
51
52     String get() throws IOException {
53         return (cache != null) ? cache : readString();
54     }
55 }
56