| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package joptsimple.util; |
| 7 | |
|
| 8 | |
import joptsimple.internal.Strings; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
public final class KeyValuePair { |
| 21 | |
public final String key; |
| 22 | |
public final String value; |
| 23 | |
|
| 24 | 548 | private KeyValuePair( String key, String value ) { |
| 25 | 548 | this.key = key; |
| 26 | 548 | this.value = value; |
| 27 | 548 | } |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public static KeyValuePair valueOf( String stringRepresentation ) { |
| 38 | 550 | int equalsIndex = stringRepresentation.indexOf( '=' ); |
| 39 | 548 | if ( equalsIndex == -1 ) |
| 40 | 378 | return new KeyValuePair( stringRepresentation, Strings.EMPTY ); |
| 41 | |
|
| 42 | 170 | String aKey = stringRepresentation.substring( 0, equalsIndex ); |
| 43 | |
String aValue; |
| 44 | |
|
| 45 | 170 | if ( equalsIndex == stringRepresentation.length() - 1 ) |
| 46 | 2 | aValue = Strings.EMPTY; |
| 47 | |
else |
| 48 | 168 | aValue = stringRepresentation.substring( equalsIndex + 1 ); |
| 49 | |
|
| 50 | 170 | return new KeyValuePair( aKey, aValue ); |
| 51 | |
} |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public boolean equals( Object that ) { |
| 57 | 676 | if ( this == that ) |
| 58 | 168 | return true; |
| 59 | |
|
| 60 | 508 | if ( !( that instanceof KeyValuePair ) ) |
| 61 | 0 | return false; |
| 62 | |
|
| 63 | 508 | KeyValuePair other = (KeyValuePair) that; |
| 64 | 508 | return key.equals( other.key ) && value.equals( other.value ); |
| 65 | |
} |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
public int hashCode() { |
| 71 | 180 | return key.hashCode() ^ value.hashCode(); |
| 72 | |
} |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
public String toString() { |
| 78 | 2 | return key + '=' + value; |
| 79 | |
} |
| 80 | |
} |