01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple;
07:
08: /**
09: * An option specification, which describes options that an option parser recognizes.
10: *
11: * @since 1.0
12: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
13: * @version $Id: OptionSpec.java,v 1.15 2007/04/10 20:06:25 pholser Exp $
14: */
15: abstract class OptionSpec {
16: private final String option;
17: private final String description;
18:
19: /**
20: * Creates an option spec.
21: *
22: * @since 1.0
23: * @param option option string this spec represents
24: */
25: protected OptionSpec(String option) {
26: this (option, "");
27: }
28:
29: /**
30: * Creates an option spec.
31: *
32: * @since 2.1
33: * @param option option string this spec represents
34: * @param description describes the semantics of the option
35: */
36: protected OptionSpec(String option, String description) {
37: this .option = option;
38: this .description = description;
39: }
40:
41: String option() {
42: return option;
43: }
44:
45: String description() {
46: return description;
47: }
48:
49: abstract void handleOption(OptionParser parser,
50: ArgumentList arguments, OptionSet detectedOptions,
51: String detectedArgument);
52:
53: abstract boolean acceptsArguments();
54:
55: abstract boolean requiresArgument();
56:
57: /**
58: * {@inheritDoc}
59: */
60: public boolean equals(Object that) {
61: if (this == that) {
62: return true;
63: }
64:
65: if (that == null || !getClass().equals(that.getClass())) {
66: return false;
67: }
68:
69: OptionSpec other = (OptionSpec) that;
70: return option().equals(other.option());
71: }
72:
73: /**
74: * {@inheritDoc}
75: */
76: public int hashCode() {
77: return option().hashCode();
78: }
79:
80: /**
81: * {@inheritDoc}
82: */
83: public String toString() {
84: return "option '" + option() + "': " + description;
85: }
86:
87: abstract void accept(OptionSpecVisitor visitor);
88: }
|