Skip to content

Commit 15907ae

Browse files
committed
PrefService: make String arg always name, not key
Passing a raw key is never what we want. The name needs to be synthesized with the class name. Otherwise the raw key is stored in the _package_ node, and not actually associated with the specified class. This is a quasi-breaking change, in that certain kinds of persisted preferences from previous will be lost. But the behavior was confusing and inconsistent and problematic as it was, and needed to be fixed.
1 parent 8021b11 commit 15907ae

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/main/java/org/scijava/prefs/DefaultPrefService.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,20 @@ public void clearAll() {
147147
}
148148

149149
@Override
150-
public void clear(final Class<?> prefClass, final String key) {
151-
prefs(prefClass).clear(key);
150+
public void clear(final Class<?> prefClass, final String name) {
151+
prefs(prefClass).clear(key(prefClass, name));
152152
}
153153

154154
@Override
155-
public void remove(final Class<?> prefClass, final String key) {
156-
prefs(prefClass).remove(key);
155+
public void remove(final Class<?> prefClass, final String name) {
156+
prefs(prefClass).remove(key(prefClass, name));
157157
}
158158

159159
@Override
160160
public void putMap(final Class<?> prefClass, final Map<String, String> map,
161-
final String key)
161+
final String name)
162162
{
163-
prefs(prefClass).node(key).putMap(map);
163+
prefs(prefClass).node(key(prefClass, name)).putMap(map);
164164
}
165165

166166
@Override
@@ -169,9 +169,9 @@ public void putMap(final Class<?> prefClass, final Map<String, String> map) {
169169
}
170170

171171
@Override
172-
public Map<String, String> getMap(final Class<?> prefClass, final String key)
172+
public Map<String, String> getMap(final Class<?> prefClass, final String name)
173173
{
174-
return prefs(prefClass).node(key).getMap();
174+
return prefs(prefClass).node(key(prefClass, name)).getMap();
175175
}
176176

177177
@Override
@@ -181,9 +181,9 @@ public Map<String, String> getMap(final Class<?> prefClass) {
181181

182182
@Override
183183
public void putList(final Class<?> prefClass, final List<String> list,
184-
final String key)
184+
final String name)
185185
{
186-
prefs(prefClass).node(key).putList(list);
186+
prefs(prefClass).node(key(prefClass, name)).putList(list);
187187
}
188188

189189
@Override
@@ -192,8 +192,8 @@ public void putList(final Class<?> prefClass, final List<String> list) {
192192
}
193193

194194
@Override
195-
public List<String> getList(final Class<?> prefClass, final String key) {
196-
return prefs(prefClass).node(key).getList();
195+
public List<String> getList(final Class<?> prefClass, final String name) {
196+
return prefs(prefClass).node(key(prefClass, name)).getList();
197197
}
198198

199199
@Override
@@ -202,13 +202,13 @@ public List<String> getList(final Class<?> prefClass) {
202202
}
203203

204204
@Override
205-
public Iterable<String> getIterable(final Class<?> prefClass, final String key) {
206-
return prefs(prefClass).node(key).getIterable();
205+
public Iterable<String> getIterable(final Class<?> prefClass, final String name) {
206+
return prefs(prefClass).node(key(prefClass, name)).getIterable();
207207
}
208208

209209
@Override
210-
public void putIterable(final Class<?> prefClass, final Iterable<String> iterable, final String key) {
211-
prefs(prefClass).node(key).node(key).putIterable(iterable);
210+
public void putIterable(final Class<?> prefClass, final Iterable<String> iterable, final String name) {
211+
prefs(prefClass).node(key(prefClass, name)).putIterable(iterable);
212212
}
213213

214214
// -- Deprecated methods --

src/main/java/org/scijava/prefs/PrefService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public interface PrefService extends SciJavaService {
7979
/**
8080
* Clears the node indexed under the given class.
8181
*/
82-
void clear(Class<?> prefClass, String key);
82+
void clear(Class<?> prefClass, String name);
8383

8484
/** Removes the node. */
85-
void remove(Class<?> prefClass, String key);
85+
void remove(Class<?> prefClass, String name);
8686

8787
/**
8888
* Puts a Map into the preferences, indexed under the specified class.
8989
*/
90-
void putMap(Class<?> prefClass, Map<String, String> map, String key);
90+
void putMap(Class<?> prefClass, Map<String, String> map, String name);
9191

9292
/**
9393
* Puts a Map into the preferences, indexed under the given class.
@@ -97,23 +97,23 @@ public interface PrefService extends SciJavaService {
9797
/**
9898
* Gets a map from the preferences, indexed under the specified class.
9999
*/
100-
Map<String, String> getMap(Class<?> prefClass, String key);
100+
Map<String, String> getMap(Class<?> prefClass, String name);
101101

102102
/** Gets a Map from the preferences. */
103103
Map<String, String> getMap(Class<?> prefClass);
104104

105105
/**
106106
* Puts a list into the preferences, indexed under the specified class.
107107
*/
108-
void putList(Class<?> prefClass, List<String> list, String key);
108+
void putList(Class<?> prefClass, List<String> list, String name);
109109

110110
/** Puts a list into the preferences. */
111111
void putList(Class<?> prefClass, List<String> list);
112112

113113
/**
114114
* Gets a List from the preferences, indexed under the specified class.
115115
*/
116-
List<String> getList(Class<?> prefClass, String key);
116+
List<String> getList(Class<?> prefClass, String name);
117117

118118
/**
119119
* Gets a List from the preferences. Returns an empty list if nothing in
@@ -124,12 +124,12 @@ public interface PrefService extends SciJavaService {
124124
/**
125125
* Puts an iterable into the preferences.
126126
*/
127-
void putIterable(Class<?> prefClass, Iterable<String> iterable, String key);
127+
void putIterable(Class<?> prefClass, Iterable<String> iterable, String name);
128128

129129
/**
130130
* Gets an iterable from the preferences.
131131
*/
132-
Iterable<String> getIterable(Class<?> prefClass, String key);
132+
Iterable<String> getIterable(Class<?> prefClass, String name);
133133

134134
// -- Deprecated methods --
135135

0 commit comments

Comments
 (0)