1 package org.incava.jagol; 2 3 import java.io.*; 4 import java.util.*; 5 6 7 10 public class BooleanOption extends Option 11 { 12 private Boolean value; 13 14 public BooleanOption(String longName, String description) 15 { 16 this(longName, description, null); 17 } 18 19 public BooleanOption(String longName, String description, Boolean value) 20 { 21 super(longName, description); 22 this.value = value; 23 } 24 25 28 public Boolean getValue() 29 { 30 return value; 31 } 32 33 36 public void setValue(Boolean value) 37 { 38 this.value = value; 39 } 40 41 44 public void setValue(String value) throws InvalidTypeException 45 { 46 tr.Ace.log("value: '" + value + "'"); 47 String lcvalue = value.toLowerCase(); 48 if (lcvalue.equals("yes") || lcvalue.equals("true")) { 49 setValue(Boolean.TRUE); 50 } 51 else if (lcvalue.equals("no") || lcvalue.equals("false")) { 52 setValue(Boolean.FALSE); 53 } 54 else { 55 throw new InvalidTypeException(longName + " expects boolean argument (yes/no/true/false), not '" + value + "'"); 56 } 57 } 58 59 63 public boolean set(String arg, List args) throws OptionException 64 { 65 tr.Ace.log("arg: " + arg + "; args: " + args); 66 67 if (arg.equals("--" + longName)) { 68 setValue(Boolean.TRUE); 70 } 71 else if (arg.equals("--no-" + longName) || arg.equals("--no" + longName)) { 72 setValue(Boolean.FALSE); 74 } 75 else if (shortName != 0 && arg.equals("-" + shortName)) { 76 setValue(Boolean.TRUE); 78 } 79 else { 80 return false; 81 } 82 return true; 83 } 84 85 public String toString() 86 { 87 return value == null ? "" : value.toString(); 88 } 89 90 } 91 | Popular Tags |