KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > Mem


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19
20 package sync4j.framework.core;
21
22 /**
23  * This class represents the <Mem> tag as defined by the SyncML r
24  * epresentation specifications.
25  *
26  * @author Stefano Fornari
27  *
28  * @version $Id: Mem.java,v 1.4 2005/03/02 20:57:37 harrie Exp $
29  */

30 public final class Mem
31 implements java.io.Serializable JavaDoc {
32     
33     // ------------------------------------------------------------ Private data
34

35     private Boolean JavaDoc sharedMem;
36     private long freeMem ;
37     private long freeID ;
38     
39     // ------------------------------------------------------------ Constructors
40

41     /**
42      * For serialization purposes
43      */

44     protected Mem(){}
45     
46     /**
47      * Creates a new Mem object from memory characteristics.
48      *
49      * @param sharedMem is the datastore memory shared
50      * @param freeMem free memory size in bytes (>= 0)
51      * @param freeID number of available item IDs (>= 0)
52      *
53      */

54     public Mem(final boolean sharedMem, final long freeMem, final long freeID) {
55         setFreeMem(freeMem);
56         setFreeID(freeID);
57         this.sharedMem = (sharedMem) ? new Boolean JavaDoc(sharedMem) : null;
58     }
59     
60     // ---------------------------------------------------------- Public methods
61

62     /**
63      * Returns the memoryShared status
64      *
65      * @return <i>true</i> if the datastore memory is shared, <i>false</i> otherwise
66      *
67      */

68     public boolean isSharedMem() {
69         return (sharedMem != null);
70     }
71     
72     /**
73      * Sets the memoryShared status
74      *
75      * @param sharedMem the new memoryShared status
76      */

77     public void setSharedMem(Boolean JavaDoc sharedMem) {
78         this.sharedMem = (sharedMem.booleanValue()) ? sharedMem : null;
79     }
80     
81     /**
82      * Gets the Boolean shared memory property
83      *
84      * @return sharedMem the Boolean shared memory property
85      */

86     public Boolean JavaDoc getSharedMem() {
87         if (!sharedMem.booleanValue()) {
88             return null;
89         }
90         return sharedMem;
91     }
92     
93     /**
94      * Returns the freeMem property (in bytes)
95      *
96      * @return the freeMem property
97      *
98      */

99     public long getFreeMem() {
100         return freeMem;
101     }
102     
103     /**
104      * Sets the freeMem property.
105      *
106      * @param freeMem the freeMem value (>= 0)
107      *
108      * @throws IllegalArgumentException if freeMEmory is < 0
109      */

110     public void setFreeMem(long freeMem) {
111         if (freeMem < 0) {
112             throw new IllegalArgumentException JavaDoc("freeMem cannot be < 0)");
113         }
114         this.freeMem = freeMem;
115     }
116     
117     /**
118      * Returns the number of available item IDs (>= 0)
119      *
120      * @return the number of available item IDs (>= 0)
121      *
122      */

123     public long getFreeID() {
124         return freeID;
125     }
126     
127     /**
128      * Sets the freeID property.
129      *
130      * @param freeID the freeIDCount value (>= 0)
131      *
132      * @throws IllegalArgumentException if freeIDCount is < 0
133      */

134     public void setFreeID(long freeID) {
135         if (freeID < 0) {
136             throw new IllegalArgumentException JavaDoc("freeID cannot be < 0)");
137         }
138         this.freeID = freeID;
139     }
140 }
141
Popular Tags