Skip to content

Commit aa8cd49

Browse files
committed
PrefService: eliminate get/putIterable methods
These have now been combined with the get/putList methods: * The putList method accepts any iterable. * Any persisted Iterable is retrievable as a List with getList. Previously, it might have broken backwards compatibility for the putList(Class, List, String) signature to be widened to putList(Class, Iterable, String). But since we deprecated that method in favor of a new and as-yet-unreleased method put(Class, String, List), we can widen it to put(Class, String, Iterable) without guilt.
1 parent 0030059 commit aa8cd49

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void put(final Class<?> c, final String name,
154154

155155
@Override
156156
public void put(final Class<?> c, final String name,
157-
final List<String> value)
157+
final Iterable<String> value)
158158
{
159159
prefs(c).node(key(c, name)).putList(value);
160160
}
@@ -225,15 +225,10 @@ public Iterable<String> getIterable(final Class<?> prefClass, final String name)
225225
return prefs(prefClass).node(key(prefClass, name)).getIterable();
226226
}
227227

228-
@Override
229-
public void putIterable(final Class<?> prefClass, final String name, final Iterable<String> iterable) {
230-
prefs(prefClass).node(key(prefClass, name)).putIterable(iterable);
231-
}
232-
233228
@Deprecated
234229
@Override
235230
public void putIterable(final Class<?> prefClass, final Iterable<String> iterable, final String name) {
236-
putIterable(prefClass, name, iterable);
231+
put(prefClass, name, iterable);
237232
}
238233

239234
// -- Deprecated methods --
@@ -486,13 +481,14 @@ public Map<String, String> getMap() {
486481
return map;
487482
}
488483

489-
public void putList(final List<String> list) {
490-
for (int index = 0; list != null && index < list.size(); index++) {
491-
final Object value = list.get(index);
492-
put("" + index, value);
484+
public void putList(final Iterable<String> list) {
485+
int index = 0;
486+
for (final String value : list) {
487+
put("" + index++, value);
493488
}
494489
}
495490

491+
496492
public List<String> getList() {
497493
final List<String> list = new ArrayList<>();
498494
for (int index = 0; index < Integer.MAX_VALUE; index++) {
@@ -503,13 +499,6 @@ public List<String> getList() {
503499
return list;
504500
}
505501

506-
public void putIterable(final Iterable<String> iterable) {
507-
int index = 0;
508-
for (final String value : iterable) {
509-
put("" + index++, value);
510-
}
511-
}
512-
513502
public Iterable<String> getIterable() {
514503
return new Iterable<String>() {
515504
@Override

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public interface PrefService extends SciJavaService {
7777

7878
void put(Class<?> c, String name, Map<String, String> value);
7979

80-
void put(Class<?> c, String name, List<String> list);
80+
void put(Class<?> c, String name, Iterable<String> list);
8181

8282
void clear(Class<?> c);
8383

@@ -125,11 +125,6 @@ public interface PrefService extends SciJavaService {
125125
@Deprecated
126126
List<String> getList(Class<?> prefClass);
127127

128-
/**
129-
* Puts an iterable into the preferences.
130-
*/
131-
void putIterable(Class<?> prefClass, String name, Iterable<String> iterable);
132-
133128
/**
134129
* Puts an iterable into the preferences.
135130
*/

src/test/java/org/scijava/prefs/PrefServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void testMap() {
160160
}
161161

162162
/**
163-
* Tests {@link PrefService#put(Class, String, List)} and
163+
* Tests {@link PrefService#put(Class, String, Iterable)} and
164164
* {@link PrefService#getList(Class, String)}.
165165
*/
166166
@Test

0 commit comments

Comments
 (0)