1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.util.prefs;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.abstracthorizon.aequo.util.Preferences;
19
20
21
22
23
24
25 public class Recent {
26
27
28 public static final int MAX_RECENT = 10;
29
30
31
32
33
34
35 public static List<String> allRecent(Preferences prefs, String name) {
36 ArrayList<String> result = new ArrayList<String>();
37
38 for (int i = 1; i <= MAX_RECENT; i++) {
39 String f = prefs.getProperty(name + "." + i);
40 if (f != null) {
41 result.add(f);
42 }
43 }
44
45 return result;
46 }
47
48
49
50
51
52
53
54
55 public static boolean writeNew(Preferences prefs, String name, String value) {
56 for (int i = 1; i <= MAX_RECENT; i++) {
57 String f = prefs.getProperty(name + "." + i);
58 if (value.equals(f)) {
59 return false;
60 }
61 }
62
63 for (int i = MAX_RECENT; i > 1; i--) {
64 String f = prefs.getProperty(name + "." + (i - 1));
65 if (f != null) {
66 prefs.setProperty(name + "." + i, f);
67 }
68 }
69 prefs.setProperty(name + ".1", value);
70 return true;
71 }
72 }