]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/Preferences.java
LabelDecorator.decorateLabel can return null
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / console / Preferences.java
1 package org.simantics.scl.ui.console;
2
3 import java.util.Collection;
4 import java.util.Deque;
5 import java.util.Iterator;
6 import java.util.LinkedList;
7 import java.util.Set;
8 import java.util.TreeSet;
9
10 /**
11  * @author Antti Villberg
12  */
13 public final class Preferences {
14
15     public static final String  COMMAND_HISTORY = "COMMAND_HISTORY";
16
17     private static final String DELIMITER       = "¤¤¤¤";
18
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() )
24         {
25             builder.append(delimiter).append(iter.next());
26         }
27         return builder.toString();
28     }
29     
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);
33         return result;
34     }
35
36     public static String encodePaths(Collection<String> recentPaths) {
37         return join(recentPaths, DELIMITER);
38     }
39
40     public static <T> void removeDuplicates(Iterable<String> iter) {
41         // Remove duplicates
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)) {
46                 it.remove();
47             }
48         }
49     }
50
51 }