src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/util/KeyValuePair.java
changeset 50428 8c88df2e8a78
parent 47216 71c04702a3d5
equal deleted inserted replaced
50427:b06f330492cd 50428:8c88df2e8a78
    29  * However, the following notice accompanied the original version of this
    29  * However, the following notice accompanied the original version of this
    30  * file:
    30  * file:
    31  *
    31  *
    32  * The MIT License
    32  * The MIT License
    33  *
    33  *
    34  * Copyright (c) 2004-2014 Paul R. Holser, Jr.
    34  * Copyright (c) 2004-2015 Paul R. Holser, Jr.
    35  *
    35  *
    36  * Permission is hereby granted, free of charge, to any person obtaining
    36  * Permission is hereby granted, free of charge, to any person obtaining
    37  * a copy of this software and associated documentation files (the
    37  * a copy of this software and associated documentation files (the
    38  * "Software"), to deal in the Software without restriction, including
    38  * "Software"), to deal in the Software without restriction, including
    39  * without limitation the rights to use, copy, modify, merge, publish,
    39  * without limitation the rights to use, copy, modify, merge, publish,
    58 import static jdk.internal.joptsimple.internal.Strings.*;
    58 import static jdk.internal.joptsimple.internal.Strings.*;
    59 
    59 
    60 /**
    60 /**
    61  * <p>A simple string key/string value pair.</p>
    61  * <p>A simple string key/string value pair.</p>
    62  *
    62  *
    63  * <p>This is useful as an argument type for options whose values take on the form <kbd>key=value</kbd>, such as JVM
    63  * <p>This is useful as an argument type for options whose values take on the form {@code key=value}, such as JVM
    64  * command line system properties.</p>
    64  * command line system properties.</p>
    65  *
    65  *
    66  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
    66  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
    67  */
    67  */
    68 public final class KeyValuePair {
    68 public final class KeyValuePair {
    73         this.key = key;
    73         this.key = key;
    74         this.value = value;
    74         this.value = value;
    75     }
    75     }
    76 
    76 
    77     /**
    77     /**
    78      * Parses a string assumed to be of the form <kbd>key=value</kbd> into its parts.
    78      * Parses a string assumed to be of the form {@code key=value} into its parts.
    79      *
    79      *
    80      * @param asString key-value string
    80      * @param asString key-value string
    81      * @return a key-value pair
    81      * @return a key-value pair
    82      * @throws NullPointerException if {@code stringRepresentation} is {@code null}
    82      * @throws NullPointerException if {@code stringRepresentation} is {@code null}
    83      */
    83      */
    84     public static KeyValuePair valueOf( String asString ) {
    84     public static KeyValuePair valueOf( String asString ) {
    85         int equalsIndex = asString.indexOf( '=' );
    85         int equalsIndex = asString.indexOf( '=' );
    86         if ( equalsIndex == -1 )
    86         if ( equalsIndex == -1 )
    87             return new KeyValuePair( asString, EMPTY );
    87             return new KeyValuePair( asString, null );
    88 
    88 
    89         String aKey = asString.substring( 0, equalsIndex );
    89         String aKey = asString.substring( 0, equalsIndex );
    90         String aValue = equalsIndex == asString.length() - 1 ? EMPTY : asString.substring( equalsIndex + 1 );
    90         String aValue = equalsIndex == asString.length() - 1 ? EMPTY : asString.substring( equalsIndex + 1 );
    91 
    91 
    92         return new KeyValuePair( aKey, aValue );
    92         return new KeyValuePair( aKey, aValue );