1 32 33 package com.jeantessier.commandline; 34 35 39 public class OptionalValueSwitch extends CommandLineSwitchBase { 40 public OptionalValueSwitch() { 41 this("", false); 42 } 43 44 public OptionalValueSwitch(String defaultValue) { 45 this(defaultValue, false); 46 } 47 48 public OptionalValueSwitch(boolean mandatory) { 49 this("", mandatory); 50 } 51 52 public OptionalValueSwitch(String defaultValue, boolean mandatory) { 53 super(defaultValue, mandatory); 54 } 55 56 public int parse(String name, String value) throws CommandLineException { 57 int result = 1; 58 59 setValue(value); 60 61 if (value != null) { 62 result++; 63 } 64 65 return result; 66 } 67 68 public void accept(Visitor visitor) { 69 visitor.visitOptionalValueSwitch(this); 70 } 71 } 72 | Popular Tags |