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 {
16 * Console buffer high and low water marks
18 public static final String CONSOLE_LIMIT_CONSOLE_OUTPUT = "SCLConsole.limitConsoleOutput"; //$NON-NLS-1$
20 public static final String CONSOLE_LOW_WATER_MARK = "SCLConsole.lowWaterMark"; //$NON-NLS-1$
22 public static final String CONSOLE_HIGH_WATER_MARK = "SCLConsole.highWaterMark"; //$NON-NLS-1$
25 * By default console output buffer size is limited.
27 public static final boolean CONSOLE_LIMIT_CONSOLE_OUTPUT_DEFAULT = true;
30 * The console low water mark default value {@value #CONSOLE_LOW_WATER_MARK_DEFAULT_VALUE}.
32 public static final int CONSOLE_LOW_WATER_MARK_DEFAULT_VALUE = 5000000;
35 * The console low water mark default value {@value #CONSOLE_HIGH_WATER_MARK_DEFAULT_VALUE}.
37 public static final int CONSOLE_HIGH_WATER_MARK_DEFAULT_VALUE = highWatermarkForLow(CONSOLE_LOW_WATER_MARK_DEFAULT_VALUE);
40 * The console low water mark maximum value {@value #CONSOLE_LOW_WATER_MARK_MAX_VALUE}.
42 public static final int CONSOLE_LOW_WATER_MARK_MAX_VALUE = 10000000;
44 public static int highWatermarkForLow(int low) {
48 public static final String COMMAND_HISTORY = "COMMAND_HISTORY"; //$NON-NLS-1$
50 private static final String DELIMITER = "¤¤¤¤"; //$NON-NLS-1$
52 public static String join(Collection<String> s, String delimiter) {
53 if (s == null || s.isEmpty()) return ""; //$NON-NLS-1$
54 Iterator<String> iter = s.iterator();
55 StringBuilder builder = new StringBuilder(iter.next());
56 while( iter.hasNext() )
58 builder.append(delimiter).append(iter.next());
60 return builder.toString();
63 public static Deque<String> decodePaths(String recentPathsPref) {
64 Deque<String> result = new LinkedList<String>();
65 for(String s : recentPathsPref.split(DELIMITER)) result.add(s);
69 public static String encodePaths(Collection<String> recentPaths) {
70 return join(recentPaths, DELIMITER);
73 public static <T> void removeDuplicates(Iterable<String> iter) {
75 Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
76 for (Iterator<String> it = iter.iterator(); it.hasNext();) {
77 String path = it.next();
78 if (!dups.add(path)) {