--- /dev/null
+package org.simantics.team.ui;\r
+\r
+import java.util.Deque;\r
+import java.util.Iterator;\r
+import java.util.LinkedList;\r
+import java.util.Set;\r
+import java.util.TreeSet;\r
+\r
+import org.eclipse.ui.IMemento;\r
+import org.simantics.utils.ui.workbench.StringMemento;\r
+\r
+public final class Preferences {\r
+ public static final String CURRENT_TEAM_FOLDER = "CURRENT_TEAM_FOLDER";\r
+ public static final String RECENT_TEAM_FOLDERS = "RECENT_TEAM_FOLDERS";\r
+ private static final String TAG_PATH = "path";\r
+ private static final String ATTR_NAME = "name";\r
+ public static Deque<String> decodePaths(String recentPathsPref) {\r
+ Deque<String> result = new LinkedList<String>();\r
+ try {\r
+ StringMemento sm = new StringMemento(recentPathsPref);\r
+ for (IMemento m : sm.getChildren(TAG_PATH)) {\r
+ String name = m.getString(ATTR_NAME);\r
+ if (name != null && !name.isEmpty())\r
+ result.add(name);\r
+ }\r
+ } catch (IllegalArgumentException e) {\r
+ }\r
+ return result;\r
+ }\r
+ public static String encodePaths(Deque<String> recentPaths) {\r
+ StringMemento sm = new StringMemento();\r
+ for (String path : recentPaths) {\r
+ IMemento m = sm.createChild(TAG_PATH);\r
+ m.putString(ATTR_NAME, path);\r
+ }\r
+ return sm.toString();\r
+ }\r
+ public static <T> void removeDuplicates(Iterable<String> iter) {\r
+ // Remove duplicates\r
+ Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);\r
+ for (Iterator<String> it = iter.iterator(); it.hasNext();) {\r
+ String path = it.next();\r
+ if (!dups.add(path)) {\r
+ it.remove();\r
+ }\r
+ }\r
+ }\r
+\r
+}\r