]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/Preferences.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / Preferences.java
1 package org.simantics.team.ui;
2
3 import java.util.Deque;
4 import java.util.Iterator;
5 import java.util.LinkedList;
6 import java.util.Set;
7 import java.util.TreeSet;
8
9 import org.eclipse.ui.IMemento;
10 import org.simantics.utils.ui.workbench.StringMemento;
11
12 public final class Preferences {
13     public static final String CURRENT_TEAM_FOLDER = "CURRENT_TEAM_FOLDER";
14     public static final String RECENT_TEAM_FOLDERS = "RECENT_TEAM_FOLDERS";
15     private static final String TAG_PATH = "path";
16     private static final String ATTR_NAME = "name";
17     public static Deque<String> decodePaths(String recentPathsPref) {
18         Deque<String> result = new LinkedList<String>();
19         try {
20             StringMemento sm = new StringMemento(recentPathsPref);
21             for (IMemento m : sm.getChildren(TAG_PATH)) {
22                 String name = m.getString(ATTR_NAME);
23                 if (name != null && !name.isEmpty())
24                     result.add(name);
25             }
26         } catch (IllegalArgumentException e) {
27         }
28         return result;
29     }
30     public static String encodePaths(Deque<String> recentPaths) {
31         StringMemento sm = new StringMemento();
32         for (String path : recentPaths) {
33             IMemento m = sm.createChild(TAG_PATH);
34             m.putString(ATTR_NAME, path);
35         }
36         return sm.toString();
37     }
38     public static <T> void removeDuplicates(Iterable<String> iter) {
39         // Remove duplicates
40         Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
41         for (Iterator<String> it = iter.iterator(); it.hasNext();) {
42             String path = it.next();
43             if (!dups.add(path)) {
44                 it.remove();
45             }
46         }
47     }
48
49 }