AbstractWebPreferences.java
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.mumfrey.webprefs;
import java.util.Set;
import java.util.UUID;
import com.mumfrey.webprefs.interfaces.IWebPreferences;
/**
* Common base class for online/offline web preferences
*/
abstract class AbstractWebPreferences implements IWebPreferences
{
/**
* Our UUID
*/
protected final String uuid;
/**
* True if we are a private settings set
*/
protected final boolean isPrivate;
protected final boolean isReadOnly;
AbstractWebPreferences(UUID uuid, boolean isPrivate, boolean isReadOnly)
{
this(uuid.toString(), isPrivate, isReadOnly);
}
AbstractWebPreferences(String uuid, boolean isPrivate, boolean isReadOnly)
{
this.uuid = uuid;
this.isPrivate = isPrivate;
this.isReadOnly = isReadOnly;
}
void onTick()
{
// stub for subclasses
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences#getUUID()
*/
@Override
public final String getUUID()
{
return this.uuid;
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences#isPrivate()
*/
@Override
public final boolean isPrivate()
{
return this.isPrivate;
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences#isReadOnly()
*/
@Override
public final boolean isReadOnly()
{
return this.isReadOnly;
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences
* #request(java.lang.String)
*/
@Override
public void request(String key)
{
WebPreferences.validateKey(key);
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences
* #request(java.lang.String[])
*/
@Override
public void request(String... keys)
{
if (keys == null || keys.length < 1) return;
if (keys.length == 1) this.request(keys[0]);
for (String key : keys)
{
this.request(key);
}
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences
* #request(java.util.Set)
*/
@Override
public void request(Set<String> keys)
{
if (keys == null || keys.size() < 1) return;
for (String key : keys)
{
this.request(key);
}
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences#commit(boolean)
*/
@Override
public void commit(boolean force)
{
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences
* #set(java.lang.String, java.lang.String)
*/
@Override
public void set(String key, String value)
{
WebPreferences.validateKey(key);
}
/* (non-Javadoc)
* @see com.mumfrey.webprefs.interfaces.IWebPreferences
* #remove(java.lang.String)
*/
@Override
public void remove(String key)
{
this.set(key, "");
}
}