prefix
property
+ *
+ * @return The value for the prefix
property
+ */
+
+ Options.Prefix getPrefix() {
+ return prefix;
+ }
+
+/**
+ * Getter method for key
property
+ *
+ * @return The value for the key
property
+ */
+
+ String getKey() {
+ return key;
+ }
+
+/**
+ * Getter method for detail
property
+ *
+ * @return The value for the detail
property
+ */
+
+ boolean useDetail() {
+ return detail;
+ }
+
+/**
+ * Getter method for separator
property
+ *
+ * @return The value for the separator
property
+ */
+
+ Options.Separator getSeparator() {
+ return separator;
+ }
+
+/**
+ * Getter method for value
property
+ *
+ * @return The value for the value
property
+ */
+
+ boolean useValue() {
+ return value;
+ }
+
+/**
+ * Getter method for multiplicity
property
+ *
+ * @return The value for the multiplicity
property
+ */
+
+ Options.Multiplicity getMultiplicity() {
+ return multiplicity;
+ }
+
+/**
+ * Getter method for pattern
property
+ *
+ * @return The value for the pattern
property
+ */
+
+ java.util.regex.Pattern getPattern() {
+ return pattern;
+ }
+
+/**
+ * Get the number of results found for this option, which is number of times the key matched
+ *
+ * @return The number of results
+ */
+
+ public int getResultCount() {
+ if (value) {
+ return values.size();
+ } else {
+ return counter;
+ }
+ }
+
+/**
+ * Get the value with the given index. The index can range between 0 and {@link #getResultCount()} - 1
.
+ * However, only for value options, a non-null
value will be returned. Non-value options always
+ * return null
.
+ *
+ * @param index The index for the desired value + *
+ * @return The option value with the given index + *
+ * @throws IllegalArgumentException If the value for index
is out of bounds
+ */
+
+ public String getResultValue(int index) {
+ if (!value) return null;
+ if (index < 0 || index >= getResultCount()) throw new IllegalArgumentException(CLASS + ": illegal value for index");
+ return values.get(index);
+ }
+
+/**
+ * Get the detail with the given index. The index can range between 0 and {@link #getResultCount()} - 1
.
+ * However, only for value options which take details, a non-null
detail will be returned. Non-value options
+ * and value options which do not take details always return null
.
+ *
+ * @param index The index for the desired value + *
+ * @return The option detail with the given index + *
+ * @throws IllegalArgumentException If the value for index
is out of bounds
+ */
+
+ public String getResultDetail(int index) {
+ if (!detail) return null;
+ if (index < 0 || index >= getResultCount()) throw new IllegalArgumentException(CLASS + ": illegal value for index");
+ return details.get(index);
+ }
+
+/**
+ * Store the data for a match found
+ */
+
+ void addResult(String valueData, String detailData) {
+ if (value) {
+ if (valueData == null) throw new IllegalArgumentException(CLASS + ": valueData may not be null");
+ values.add(valueData);
+ if (detail) {
+ if (detailData == null) throw new IllegalArgumentException(CLASS + ": detailData may not be null");
+ details.add(detailData);
+ }
+ }
+ counter++;
+ }
+
+/**
+ * This is the overloaded {@link Object#toString()} method, and it is provided mainly for debugging
+ * purposes.
+ *
+ * @return A string representing the instance
+ */
+
+ public String toString() {
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("Prefix : ");
+ sb.append(prefix);
+ sb.append('\n');
+ sb.append("Key : ");
+ sb.append(key);
+ sb.append('\n');
+ sb.append("Detail : ");
+ sb.append(detail);
+ sb.append('\n');
+ sb.append("Separator : ");
+ sb.append(separator);
+ sb.append('\n');
+ sb.append("Value : ");
+ sb.append(value);
+ sb.append('\n');
+ sb.append("Multiplicity: ");
+ sb.append(multiplicity);
+ sb.append('\n');
+ sb.append("Pattern : ");
+ sb.append(pattern);
+ sb.append('\n');
+
+ sb.append("Results : ");
+ sb.append(counter);
+ sb.append('\n');
+ if (value) {
+ if (detail) {
+ for (int i = 0; i < values.size(); i++) {
+ sb.append(details.get(i));
+ sb.append(" / ");
+ sb.append(values.get(i));
+ sb.append('\n');
+ }
+ } else {
+ for (int i = 0; i < values.size(); i++) {
+ sb.append(values.get(i));
+ sb.append('\n');
+ }
+ }
+ }
+
+ return sb.toString();
+
+ }
+
+}
+
+
diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/options/OptionSet.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/options/OptionSet.java
new file mode 100644
index 0000000..c320f61
--- /dev/null
+++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/options/OptionSet.java
@@ -0,0 +1,276 @@
+package com.minres.scviewer.e4.application.options;
+
+/**
+ * This class holds the information for a set of options. A set can hold any number of
+ * OptionData
instances which are checked together to determine success or failure.
+ *
+ * The approach to use this class looks like this: + *
+ *
Options.addSet()
(e. g. {@link Options#addSet(String)}) to create
+ * any number of sets required (or just relies on the default set, if only one set is required)
+ * Options.check()
methods, each set can be checked whether the options
+ * that were specified on the command line satisfy its requirements
+ *
+ * @return A list of {@link OptionData} instances defined for this set
+ */
+
+ public java.util.ArrayList
+ * @param key The key for the option
+ *
+ * @return The {@link OptionData} instance
+ *
+ * @throws IllegalArgumentException If the
+ * @param key The key for the option
+ *
+ * @return
+ * @throws IllegalArgumentException If the
+ * @return The value for the
+ * @return The value for the
+ * @return The value for the
+ * @return A list of strings with all data items found
+ */
+
+ public java.util.ArrayList
+ * @return A list of strings with all unmatched items found
+ */
+
+ public java.util.ArrayList
+ * @param key The key for the option
+ *
+ * @return The set instance itself (to support invocation chaining for
+ * @throws IllegalArgumentException If the
+ * @param key The key for the option
+ * @param multiplicity The multiplicity for the option
+ *
+ * @return The set instance itself (to support invocation chaining for
+ * @throws IllegalArgumentException If the
+ * @param key The key for the option
+ * @param separator The separator for the option
+ *
+ * @return The set instance itself (to support invocation chaining for
+ * @throws IllegalArgumentException If the
+ * @param key The key for the option
+ * @param separator The separator for the option
+ * @param multiplicity The multiplicity for the option
+ *
+ * @return The set instance itself (to support invocation chaining for
+ * @throws IllegalArgumentException If the
+ * @param key The key for the option
+ * @param details A boolean indicating whether details are expected for the option
+ * @param separator The separator for the option
+ *
+ * @return The set instance itself (to support invocation chaining for
+ * @throws IllegalArgumentException If the
+ * @param key The key for the option
+ * @param details A boolean indicating whether details are expected for the option
+ * @param separator The separator for the option
+ * @param multiplicity The multiplicity for the option
+ *
+ * @return The set instance itself (to support invocation chaining for
+ * @throws IllegalArgumentException If the
+ * @return The actual separator character
+ */
+
+ char getName() {
+ return c;
+ }
+
+ }
+
+/**
+ * An enum encapsulating the possible prefixes identifying options (and separating them from command line data items)
+ */
+
+ public enum Prefix {
+
+/**
+ * Options start with a "-" (typically on Unix platforms)
+ */
+
+ DASH('-'),
+
+/**
+ * Options start with a "/" (typically on Windows platforms)
+ */
+
+ SLASH('/');
+
+ private char c;
+
+ private Prefix(char c) {
+ this.c = c;
+ }
+
+/**
+ * Return the actual prefix character
+ *
+ * @return The actual prefix character
+ */
+
+ char getName() {
+ return c;
+ }
+
+ }
+
+/**
+ * An enum encapsulating the possible multiplicities for options
+ */
+
+ public enum Multiplicity {
+
+/**
+ * Option needs to occur exactly once
+ */
+
+ ONCE,
+
+/**
+ * Option needs to occur at least once
+ */
+
+ ONCE_OR_MORE,
+
+/**
+ * Option needs to occur either once or not at all
+ */
+
+ ZERO_OR_ONE,
+
+/**
+ * Option can occur any number of times
+ */
+
+ ZERO_OR_MORE;
+
+ }
+
+ private java.util.HashMap
+ * @param args The command line arguments to check
+ * @param prefix The prefix to use for all command line options. It can only be set here for all options at
+ * the same time
+ * @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
+ * @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
+ * @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param prefix The prefix to use for all command line options. It can only be set here for all options at
+ * the same time
+ * @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
+ * @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param prefix The prefix to use for all command line options. It can only be set here for all options at
+ * the same time
+ * @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
+ * @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
+ * @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
+ * @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ *
+ * @throws IllegalArgumentException If
+ * @param args The command line arguments to check
+ * @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If
+ * @param args The command line arguments to check
+ * @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
+ * @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If
+ * @param args The command line arguments to check
+ * @param prefix The prefix to use for all command line options. It can only be set here for all options at
+ * the same time
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param prefix The prefix to use for all command line options. It can only be set here for all options at
+ * @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If either
+ * @param args The command line arguments to check
+ * @param prefix The prefix to use for all command line options. It can only be set here for all options at
+ * the same time
+ * @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
+ * @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
+ *
+ * @throws IllegalArgumentException If either
+ * @return The first set which matches (i. e. the
+ * @param ignoreUnmatched A boolean to select whether unmatched options can be ignored in the checks or not
+ * @param requireDataLast A boolean to indicate whether the data items have to be the last ones on the command line or not
+ *
+ * @return The first set which matches (i. e. the
+ * @param setName The name for the set. This must be a unique identifier
+ * @param minData The minimum number of data items for this set
+ * @param maxData The maximum number of data items for this set
+ *
+ * @return The new
+ * @param setName The name for the set. This must be a unique identifier
+ * @param data The minimum and maximum number of data items for this set
+ *
+ * @return The new
+ * @param setName The name for the set. This must be a unique identifier
+ *
+ * @return The new
+ * @param setName The name for the set to retrieve
+ *
+ * @return The set to retrieve (or
+ * @return The default set
+ */
+
+ public OptionSet getSet() {
+ if (getSet(DEFAULT_SET) == null)
+ addSet(DEFAULT_SET, defaultMinData, defaultMaxData);
+ return getSet(DEFAULT_SET);
+ }
+
+/**
+ * The error messages collected during the last option check (invocation of any of the
+ * @return A string with all collected error messages
+ */
+
+ public String getCheckErrors() {
+ return checkErrors.toString();
+ }
+
+/**
+ * Run the checks for the default set.
+ * @return A boolean indicating whether all checks were successful or not
+ */
+
+ public boolean check() {
+ return check(DEFAULT_SET, false, true);
+ }
+
+/**
+ * Run the checks for the default set.
+ *
+ * @param ignoreUnmatched A boolean to select whether unmatched options can be ignored in the checks or not
+ * @param requireDataLast A boolean to indicate whether the data items have to be the last ones on the command line or not
+ *
+ * @return A boolean indicating whether all checks were successful or not
+ */
+
+ public boolean check(boolean ignoreUnmatched, boolean requireDataLast) {
+ return check(DEFAULT_SET, ignoreUnmatched, requireDataLast);
+ }
+
+/**
+ * Run the checks for the given set.
+ * @param setName The name for the set to check
+ *
+ * @return A boolean indicating whether all checks were successful or not
+ *
+ * @throws IllegalArgumentException If either
+ * @param setName The name for the set to check
+ * @param ignoreUnmatched A boolean to select whether unmatched options can be ignored in the checks or not
+ * @param requireDataLast A boolean to indicate whether the data items have to be the last ones on the command line or not
+ *
+ * @return A boolean indicating whether all checks were successful or not
+ *
+ * @throws IllegalArgumentException If either
+ * @return A string representing the instance
+ */
+
+ public String toString() {
+
+ StringBuffer sb = new StringBuffer();
+
+ for (OptionSet set : optionSets.values()) {
+ sb.append("Set: ");
+ sb.append(set.getSetName());
+ sb.append('\n');
+ for (OptionData data : set.getOptionData()) {
+ sb.append(data.toString());
+ sb.append('\n');
+ }
+ }
+
+ return sb.toString();
+
+ }
+
+}
+
+
diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java
index 7b8ad35..36061ab 100644
--- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java
+++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java
@@ -14,10 +14,10 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -58,19 +58,12 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.MouseWheelListener;
-import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
@@ -87,6 +80,8 @@ import com.minres.scviewer.database.ui.GotoDirection;
import com.minres.scviewer.database.ui.ICursor;
import com.minres.scviewer.database.ui.IWaveformViewer;
import com.minres.scviewer.database.ui.TrackEntry;
+import com.minres.scviewer.database.ui.TrackEntry.ValueDisplay;
+import com.minres.scviewer.database.ui.TrackEntry.WaveDisplay;
import com.minres.scviewer.database.ui.WaveformColors;
import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl;
@@ -95,7 +90,6 @@ import com.minres.scviewer.e4.application.internal.util.IFileChangeListener;
import com.minres.scviewer.e4.application.internal.util.IModificationChecker;
import com.minres.scviewer.e4.application.preferences.DefaultValuesInitializer;
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
-//import com.minres.scviewer.database.swt.internal.WaveformCanvas;
/**
* The Class WaveformViewerPart.
@@ -115,6 +109,10 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
/** The Constant SHOWN_WAVEFORM. */
protected static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM"; //$NON-NLS-1$
+ protected static final String VALUE_DISPLAY = ".VALUE_DISPLAY"; //$NON-NLS-1$
+
+ protected static final String WAVE_DISPLAY = ".WAVE_DISPLAY"; //$NON-NLS-1$
+
/** The Constant SHOWN_CURSOR. */
protected static final String SHOWN_CURSOR = "SHOWN_CURSOR"; //$NON-NLS-1$
@@ -154,7 +152,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
@Inject
ESelectionService selectionService;
- /** The e part service. */
+ /** The part service. */
@Inject
EPartService ePartService;
@@ -344,17 +342,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
case SWT.HOME: return; //TODO: should be handled
case SWT.END: return; //TODO: should be handled
}
-// String string = e.type == SWT.KeyDown ? "DOWN:" : "UP :";
-// string += " stateMask=0x" + Integer.toHexString (e.stateMask) + ","; // SWT.CTRL, SWT.ALT, SWT.SHIFT, SWT.COMMAND
-// string += " keyCode=0x" + Integer.toHexString (e.keyCode) + ",";
-// string += " character=0x" + Integer.toHexString (e.character) ;
-// if (e.keyLocation != 0) {
-// string += " location=";
-// if (e.keyLocation == SWT.LEFT) string += "LEFT";
-// if (e.keyLocation == SWT.RIGHT) string += "RIGHT";
-// if (e.keyLocation == SWT.KEYPAD) string += "KEYPAD";
-// }
-// System.out.println (string);
}
}
@@ -510,7 +497,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
*/
@Inject
@Optional
- public void setPartInput(@Named("input") Object partInput) {
+ public void setPartInput(@Named("input") Object partInput, @Named("config") Object partConfig) {
if (partInput instanceof File) {
filesToLoad = new ArrayListkey
is null
or unknown in this set
+ */
+
+ public OptionData getOption(String key) {
+ if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
+ if (!keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": unknown key: " + key);
+ return keys.get(key);
+ }
+
+/**
+ * Check whether a specific option is set, i. e. whether it was specified at least once on the command line.
+ * true
or false
, depending on the outcome of the check
+ * key
is null
or unknown in this set
+ */
+
+ public boolean isSet(String key) {
+ if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
+ if (!keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": unknown key: " + key);
+ return keys.get(key).getResultCount() > 0 ? true : false;
+ }
+
+/**
+ * Getter method for setName
property
+ * setName
property
+ */
+
+ public String getSetName() {
+ return setName;
+ }
+
+/**
+ * Getter method for minData
property
+ * minData
property
+ */
+
+ public int getMinData() {
+ return minData;
+ }
+
+/**
+ * Getter method for maxData
property
+ * maxData
property
+ */
+
+ public int getMaxData() {
+ return maxData;
+ }
+
+/**
+ * Return the data items found (these are the items on the command line which do not start with the prefix, i. e. non-option arguments)
+ * addOption()
methods)
+ * key
is null
or a key with this name has already been defined
+ */
+
+ public OptionSet addOption(String key) {
+ return addOption(key, defaultMultiplicity);
+ }
+
+/**
+ * Add a non-value option with the given key and multiplicity, and the default prefix
+ * addOption()
methods)
+ * key
is null
or a key with this name has already been defined
+ * or if multiplicity
is null
+ */
+
+ public OptionSet addOption(String key, Options.Multiplicity multiplicity) {
+ return addOption(key, false, Options.Separator.NONE, false, multiplicity);
+ }
+
+/**
+ * Add a value option with the given key and separator, no details, and the default prefix and multiplicity
+ * addOption()
methods)
+ * key
is null
or a key with this name has already been defined
+ * or if separator
is null
+ */
+
+ public OptionSet addOption(String key, Options.Separator separator) {
+ return addOption(key, false, separator, true, defaultMultiplicity);
+ }
+
+/**
+ * Add a value option with the given key, separator, and multiplicity, no details, and the default prefix
+ * addOption()
methods)
+ * key
is null
or a key with this name has already been defined
+ * or if separator
or multiplicity
are null
+ */
+
+ public OptionSet addOption(String key, Options.Separator separator, Options.Multiplicity multiplicity) {
+ return addOption(key, false, separator, true, multiplicity);
+ }
+
+/**
+ *
+ * Add a value option with the given key and separator, possibly details, and the default prefix and multiplicity
+ * addOption()
methods)
+ * key
is null
or a key with this name has already been defined
+ * or if separator
is null
+ */
+
+ public OptionSet addOption(String key, boolean details, Options.Separator separator) {
+ return addOption(key, details, separator, true, defaultMultiplicity);
+ }
+
+/**
+ * Add a value option with the given key, separator, and multiplicity, possibly details, and the default prefix
+ * addOption()
methods)
+ * key
is null
or a key with this name has already been defined
+ * or if separator
or multiplicity
are null
+ */
+
+ public OptionSet addOption(String key, boolean details, Options.Separator separator, Options.Multiplicity multiplicity) {
+ return addOption(key, details, separator, true, multiplicity);
+ }
+
+/**
+ * The master method to add an option. Since there are combinations which are not
+ * acceptable (like a NONE separator and a true value), this method is not public.
+ * Internally, we only supply acceptable combinations.
+ */
+
+ OptionSet addOption(String key,
+ boolean details,
+ Options.Separator separator,
+ boolean value,
+ Options.Multiplicity multiplicity) {
+
+ if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
+ if (multiplicity == null) throw new IllegalArgumentException(CLASS + ": multiplicity may not be null");
+ if (separator == null) throw new IllegalArgumentException(CLASS + ": separator may not be null");
+ if (keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": the key "
+ + key + " has already been defined for this OptionSet");
+
+ OptionData od = new OptionData(prefix, key, details, separator, value, multiplicity);
+ options.add(od);
+ keys.put(key, od);
+
+ return this;
+
+ }
+
+}
+
+
diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/options/Options.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/options/Options.java
new file mode 100644
index 0000000..b7e0282
--- /dev/null
+++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/options/Options.java
@@ -0,0 +1,768 @@
+package com.minres.scviewer.e4.application.options;
+
+/**
+ * The central class for option processing. Sets are identified by their name, but there is also
+ * an anonymous default set, which is very convenient if an application requieres only one set.
+ */
+
+public class Options {
+
+ private final static String CLASS = "Options";
+
+/**
+ * The name used internally for the default set
+ */
+
+ public final static String DEFAULT_SET = "DEFAULT_OPTION_SET";
+
+/**
+ * An enum encapsulating the possible separators between value options and their actual values.
+ */
+
+ public enum Separator {
+
+/**
+ * Separate option and value by ":"
+ */
+
+ COLON(':'),
+
+/**
+ * Separate option and value by "="
+ */
+
+ EQUALS('='),
+
+/**
+ * Separate option and value by blank space
+ */
+
+ BLANK(' '), // Or, more precisely, whitespace (as allowed by the CLI)
+
+/**
+ * This is just a placeholder in case no separator is required (i. e. for non-value options)
+ */
+
+ NONE('D'); // NONE is a placeholder in case no separator is required, 'D' is just an arbitrary dummy value
+
+ private char c;
+
+ private Separator(char c) {
+ this.c = c;
+ }
+
+/**
+ * Return the actual separator character
+ * args
, prefix
, or defaultMultiplicity
+ * is null
- or if the data range values don't make sense
+ */
+
+ public Options(String args[], Prefix prefix, Multiplicity defaultMultiplicity, int defMinData, int defMaxData) {
+
+ if (args == null) throw new IllegalArgumentException(CLASS + ": args may not be null");
+ if (prefix == null) throw new IllegalArgumentException(CLASS + ": prefix may not be null");
+ if (defaultMultiplicity == null) throw new IllegalArgumentException(CLASS + ": defaultMultiplicity may not be null");
+
+ if (defMinData < 0) throw new IllegalArgumentException(CLASS + ": defMinData must be >= 0");
+ if (defMaxData < defMinData) throw new IllegalArgumentException(CLASS + ": defMaxData must be >= defMinData");
+
+ arguments = new String[args.length];
+ int i = 0;
+ for (String s : args)
+ arguments[i++] = s;
+
+ this.prefix = prefix;
+ this.defaultMultiplicity = defaultMultiplicity;
+ this.defaultMinData = defMinData;
+ this.defaultMaxData = defMaxData;
+
+ }
+
+/**
+ * Constructor
+ * args
, prefix
, or defaultMultiplicity
+ * is null
- or if the data range value doesn't make sense
+ */
+
+ public Options(String args[], Prefix prefix, Multiplicity defaultMultiplicity, int data) {
+ this(args, prefix, defaultMultiplicity, data, data);
+ }
+
+/**
+ * Constructor. The default number of data items is set to 0.
+ * args
, prefix
, or defaultMultiplicity
+ * is null
+ */
+
+ public Options(String args[], Prefix prefix, Multiplicity defaultMultiplicity) {
+ this(args, prefix, defaultMultiplicity, 0, 0);
+ }
+
+/**
+ * Constructor. The prefix is set to {@link Prefix#DASH}.
+ * args
or defaultMultiplicity
+ * is null
- or if the data range values don't make sense
+ */
+
+ public Options(String args[], Multiplicity defaultMultiplicity, int defMinData, int defMaxData) {
+ this(args, Prefix.DASH, defaultMultiplicity, defMinData, defMaxData);
+ }
+
+/**
+ * Constructor. The prefix is set to {@link Prefix#DASH}.
+ * args
or defaultMultiplicity
+ * is null
- or if the data range value doesn't make sense
+ */
+
+ public Options(String args[], Multiplicity defaultMultiplicity, int data) {
+ this(args, Prefix.DASH, defaultMultiplicity, data, data);
+ }
+
+/**
+ * Constructor. The prefix is set to {@link Prefix#DASH}, and the default number of data items is set to 0.
+ * args
or defaultMultiplicity
+ * is null
+ */
+
+ public Options(String args[], Multiplicity defaultMultiplicity) {
+ this(args, Prefix.DASH, defaultMultiplicity, 0, 0);
+ }
+
+/**
+ * Constructor. The prefix is set to {@link Prefix#DASH}, the default number of data items is set to 0, and
+ * the multiplicity is set to {@link Multiplicity#ONCE}.
+ * args
is null
+ */
+
+ public Options(String args[]) {
+ this(args, Prefix.DASH, Multiplicity.ONCE);
+ }
+
+/**
+ * Constructor. The prefix is set to {@link Prefix#DASH}, and
+ * the multiplicity is set to {@link Multiplicity#ONCE}.
+ * args
is null
- or if the data range value doesn't make sense
+ */
+
+ public Options(String args[], int data) {
+ this(args, Prefix.DASH, Multiplicity.ONCE, data, data);
+ }
+
+/**
+ * Constructor. The prefix is set to {@link Prefix#DASH}, and
+ * the multiplicity is set to {@link Multiplicity#ONCE}.
+ * args
is null
- or if the data range values don't make sense
+ */
+
+ public Options(String args[], int defMinData, int defMaxData) {
+ this(args, Prefix.DASH, Multiplicity.ONCE, defMinData, defMaxData);
+ }
+
+/**
+ * Constructor. The default number of data items is set to 0, and
+ * the multiplicity is set to {@link Multiplicity#ONCE}.
+ * args
or prefix
is null
+ */
+
+ public Options(String args[], Prefix prefix) {
+ this(args, prefix, Multiplicity.ONCE, 0, 0);
+ }
+
+/**
+ * Constructor. The multiplicity is set to {@link Multiplicity#ONCE}.
+ * args
or prefix
is null
+ * - or if the data range value doesn't make sense
+ */
+
+ public Options(String args[], Prefix prefix, int data) {
+ this(args, prefix, Multiplicity.ONCE, data, data);
+ }
+
+/**
+ * Constructor. The multiplicity is set to {@link Multiplicity#ONCE}.
+ * args
or prefix
is null
+ * - or if the data range values don't make sense
+ */
+
+ public Options(String args[], Prefix prefix, int defMinData, int defMaxData) {
+ this(args, prefix, Multiplicity.ONCE, defMinData, defMaxData);
+ }
+
+/**
+ * Return the (first) matching set. This invocation does not ignore unmatched options and requires that
+ * data items are the last ones on the command line.
+ * check()
method returns true
) - or
+ * null
, if no set matches.
+ */
+
+ public OptionSet getMatchingSet() {
+ return getMatchingSet(false, true);
+ }
+
+/**
+ * Return the (first) matching set.
+ * check()
method returns true
) - or
+ * null
, if no set matches.
+ */
+
+ public OptionSet getMatchingSet(boolean ignoreUnmatched, boolean requireDataLast) {
+ for (String setName : optionSets.keySet())
+ if (check(setName, ignoreUnmatched, requireDataLast))
+ return optionSets.get(setName);
+ return null;
+ }
+
+/**
+ * Add an option set.
+ * Optionset
instance created. This is useful to allow chaining of addOption()
+ * calls right after this method
+ */
+
+ public OptionSet addSet(String setName, int minData, int maxData) {
+ if (setName == null) throw new IllegalArgumentException(CLASS + ": setName may not be null");
+ if (optionSets.containsKey(setName)) throw new IllegalArgumentException(CLASS + ": a set with the name "
+ + setName + " has already been defined");
+ OptionSet os = new OptionSet(prefix, defaultMultiplicity, setName, minData, maxData);
+ optionSets.put(setName, os);
+ return os;
+ }
+
+/**
+ * Add an option set.
+ * Optionset
instance created. This is useful to allow chaining of addOption()
+ * calls right after this method
+ */
+
+ public OptionSet addSet(String setName, int data) {
+ return addSet(setName, data, data);
+ }
+
+/**
+ * Add an option set. The defaults for the number of data items are used.
+ * Optionset
instance created. This is useful to allow chaining of addOption()
+ * calls right after this method
+ */
+
+ public OptionSet addSet(String setName) {
+ return addSet(setName, defaultMinData, defaultMaxData);
+ }
+
+/**
+ * Return an option set - or null
, if no set with the given name exists
+ * null
, if no set with the given name exists)
+ */
+
+ public OptionSet getSet(String setName) {
+ return optionSets.get(setName);
+ }
+
+/**
+ * This returns the (anonymous) default set
+ * check()
methods). This
+ * is useful to determine what was wrong with the command line arguments provided
+ * ignoreUnmatched
is set to false
, and
+ * requireDataLast
is set to true
.
+ * ignoreUnmatched
is set to false
, and
+ * requireDataLast
is set to true
.
+ * setName
is null
, or the set is unknown.
+ */
+
+ public boolean check(String setName) {
+ return check(setName, false, true);
+ }
+
+/**
+ * Run the checks for the given set.
+ * setName
is null
, or the set is unknown.
+ */
+
+ public boolean check(String setName, boolean ignoreUnmatched, boolean requireDataLast) {
+
+ if (setName == null) throw new IllegalArgumentException(CLASS + ": setName may not be null");
+ if (optionSets.get(setName) == null) throw new IllegalArgumentException(CLASS + ": Unknown OptionSet: " + setName);
+
+ checkErrors = new StringBuffer();
+ checkErrors.append("Checking set ");
+ checkErrors.append(setName);
+ checkErrors.append('\n');
+
+//.... Access the data for the set to use
+
+ OptionSet set = optionSets.get(setName);
+ java.util.ArrayList