1 32 33 package com.jeantessier.commandline; 34 35 38 public abstract class CommandLineSwitchBase implements CommandLineSwitch { 39 private Object defaultValue; 40 protected Object value; 41 private boolean present; 42 private boolean mandatory; 43 44 public CommandLineSwitchBase() { 45 this(null, false); 46 } 47 48 public CommandLineSwitchBase(Object defaultValue) { 49 this(defaultValue, false); 50 } 51 52 public CommandLineSwitchBase(boolean mandatory) { 53 this(null, mandatory); 54 } 55 56 public CommandLineSwitchBase(Object defaultValue, boolean mandatory) { 57 this.defaultValue = defaultValue; 58 this.mandatory = mandatory; 59 60 this.value = null; 61 62 isPresent(false); 63 } 64 65 public Object getDefaultValue() { 66 return defaultValue; 67 } 68 69 public Object getValue() { 70 Object result = defaultValue; 71 72 if (value != null) { 73 result = value; 74 } 75 76 return result; 77 } 78 79 public void setValue(Object value) { 80 this.value = value; 81 82 isPresent(true); 83 } 84 85 public boolean isPresent() { 86 return present; 87 } 88 89 protected void isPresent(boolean present) { 90 this.present = present; 91 } 92 93 public boolean isMandatory() { 94 return mandatory; 95 } 96 97 public String toString() { 98 return getValue().toString(); 99 } 100 } 101 | Popular Tags |