/* * Arguments.java * * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard * * This file is part of BEAST. * See the NOTICE file distributed with this work for additional * information regarding copyright ownership and licensing. * * BEAST is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * BEAST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BEAST; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ package dr.app.util; import java.util.StringTokenizer; import java.util.Arrays; import java.util.ArrayList; public class Arguments { public static final String ARGUMENT_CHARACTER = "-"; public static class ArgumentException extends Exception { /** * */ private static final long serialVersionUID = -3229759954341228233L; public ArgumentException() { super(); } public ArgumentException(String message) { super(message); } } public static class Option { public Option(String label, String description) { this.label = label; this.description = description; } String label; String description; boolean isAvailable = false; } public static class StringOption extends Option { /** * @param label Option name: * @param tag Descriptive name of option argument. * Example - tag "file-name" will show '-save ' in the usage. * @param description */ public StringOption(String label, String tag, String description) { super(label, description); this.tag = tag; } public StringOption(String label, String[] options, boolean caseSensitive, String description) { super(label, description); this.options = options; this.caseSensitive = caseSensitive; } String[] options = null; String tag = null; boolean caseSensitive = false; String value = null; } public static class IntegerOption extends Option { public IntegerOption(String label, String description) { super(label, description); } public IntegerOption(String label, int minValue, int maxValue, String description) { super(label, description); this.minValue = minValue; this.maxValue = maxValue; } int minValue = Integer.MIN_VALUE; int maxValue = Integer.MAX_VALUE; int value = 0; } public static class IntegerArrayOption extends IntegerOption { public IntegerArrayOption(String label, String description) { this(label, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, description); } public IntegerArrayOption(String label, int count, String description) { this(label, count, Integer.MIN_VALUE, Integer.MAX_VALUE, description); } public IntegerArrayOption(String label, int minValue, int maxValue, String description) { this(label, 0, minValue, maxValue, description); } public IntegerArrayOption(String label, int count, int minValue, int maxValue, String description) { super(label, minValue, maxValue, description); this.count = count; } int count; int[] values = null; } public static class LongOption extends Option { public LongOption(String label, String description) { super(label, description); } public LongOption(String label, long minValue, long maxValue, String description) { super(label, description); this.minValue = minValue; this.maxValue = maxValue; } long minValue = Long.MIN_VALUE; long maxValue = Long.MAX_VALUE; long value = 0; } public static class RealOption extends Option { public RealOption(String label, String description) { super(label, description); } public RealOption(String label, double minValue, double maxValue, String description) { super(label, description); this.minValue = minValue; this.maxValue = maxValue; } double minValue = Double.NEGATIVE_INFINITY; double maxValue = Double.POSITIVE_INFINITY; double value = 0; } public static class RealArrayOption extends RealOption { // public RealArrayOption(String label, String description) { // this(label, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, description); // } // A count of -1 means any length public RealArrayOption(String label, int count, String description) { this(label, count, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, description); } // public RealArrayOption(String label, double minValue, double maxValue, String description) { // this(label, 0, minValue, maxValue, description); // } public RealArrayOption(String label, int count, double minValue, double maxValue, String description) { super(label, minValue, maxValue, description); this.count = count; } private int count; double[] values = null; } /** * Parse a list of arguments ready for accessing */ public Arguments(Option[] options) { this.options = options; } public Arguments(Option[] options, boolean caseSensitive) { this.options = options; this.caseSensitive = caseSensitive; } public void addOption(String label, String description, String positionLabel) { ArrayList