1 package org.simantics.scl.ui.console;
3 import java.util.Collection;
4 import java.util.Deque;
5 import java.util.Iterator;
6 import java.util.LinkedList;
8 import java.util.TreeSet;
11 * @author Antti Villberg
13 public final class Preferences {
15 public static final String COMMAND_HISTORY = "COMMAND_HISTORY";
17 private static final String DELIMITER = "¤¤¤¤";
19 public static String join(Collection<String> s, String delimiter) {
20 if (s == null || s.isEmpty()) return "";
21 Iterator<String> iter = s.iterator();
22 StringBuilder builder = new StringBuilder(iter.next());
23 while( iter.hasNext() )
25 builder.append(delimiter).append(iter.next());
27 return builder.toString();
30 public static Deque<String> decodePaths(String recentPathsPref) {
31 Deque<String> result = new LinkedList<String>();
32 for(String s : recentPathsPref.split(DELIMITER)) result.add(s);
36 public static String encodePaths(Collection<String> recentPaths) {
37 return join(recentPaths, DELIMITER);
40 public static <T> void removeDuplicates(Iterable<String> iter) {
42 Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
43 for (Iterator<String> it = iter.iterator(); it.hasNext();) {
44 String path = it.next();
45 if (!dups.add(path)) {