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: * A simple string key/string value pair.
10: *
11: * @since 1.0
12: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
13: * @version $Id: KeyValuePair.java,v 1.11 2007/04/10 20:06:25 pholser Exp $
14: */
15: final class KeyValuePair {
16: static final String EMPTY = "";
17:
18: final String key;
19: final String value;
20:
21: private KeyValuePair(String key, String value) {
22: this .key = key;
23: this .value = value;
24: }
25:
26: static KeyValuePair parse(String aString) {
27: int indexOfEqualsSign = aString.indexOf('=');
28: if (indexOfEqualsSign == -1)
29: return new KeyValuePair(aString, EMPTY);
30:
31: String aKey = aString.substring(0, indexOfEqualsSign);
32: String aValue;
33:
34: if (indexOfEqualsSign == aString.length() - 1)
35: aValue = EMPTY;
36: else
37: aValue = aString.substring(indexOfEqualsSign + 1);
38:
39: return new KeyValuePair(aKey, aValue);
40: }
41:
42: public String toString() {
43: return key + '=' + value;
44: }
45: }
|