src/share/classes/java/lang/Short.java

Print this page




 153      * int)} method. The result is a {@code Short} object that
 154      * represents the {@code short} value specified by the string.
 155      *
 156      * <p>In other words, this method returns a {@code Short} object
 157      * equal to the value of:
 158      *
 159      * <blockquote>
 160      *  {@code new Short(Short.parseShort(s, radix))}
 161      * </blockquote>
 162      *
 163      * @param s         the string to be parsed
 164      * @param radix     the radix to be used in interpreting {@code s}
 165      * @return          a {@code Short} object holding the value
 166      *                  represented by the string argument in the
 167      *                  specified radix.
 168      * @throws          NumberFormatException If the {@code String} does
 169      *                  not contain a parsable {@code short}.
 170      */
 171     public static Short valueOf(String s, int radix)
 172         throws NumberFormatException {
 173         return new Short(parseShort(s, radix));
 174     }
 175 
 176     /**
 177      * Returns a {@code Short} object holding the
 178      * value given by the specified {@code String}. The argument
 179      * is interpreted as representing a signed decimal
 180      * {@code short}, exactly as if the argument were given to
 181      * the {@link #parseShort(java.lang.String)} method. The result is
 182      * a {@code Short} object that represents the
 183      * {@code short} value specified by the string.
 184      *
 185      * <p>In other words, this method returns a {@code Short} object
 186      * equal to the value of:
 187      *
 188      * <blockquote>
 189      *  {@code new Short(Short.parseShort(s))}
 190      * </blockquote>
 191      *
 192      * @param s the string to be parsed
 193      * @return  a {@code Short} object holding the value


 265      * "{@code #}", or leading zero) is parsed as by the {@code
 266      * Short.parseShort} method with the indicated radix (10, 16, or
 267      * 8).  This sequence of characters must represent a positive
 268      * value or a {@link NumberFormatException} will be thrown.  The
 269      * result is negated if first character of the specified {@code
 270      * String} is the minus sign.  No whitespace characters are
 271      * permitted in the {@code String}.
 272      *
 273      * @param     nm the {@code String} to decode.
 274      * @return    a {@code Short} object holding the {@code short}
 275      *            value represented by {@code nm}
 276      * @throws    NumberFormatException  if the {@code String} does not
 277      *            contain a parsable {@code short}.
 278      * @see java.lang.Short#parseShort(java.lang.String, int)
 279      */
 280     public static Short decode(String nm) throws NumberFormatException {
 281         int i = Integer.decode(nm);
 282         if (i < MIN_VALUE || i > MAX_VALUE)
 283             throw new NumberFormatException(
 284                     "Value " + i + " out of range from input " + nm);
 285         return (short)i;
 286     }
 287 
 288     /**
 289      * The value of the {@code Short}.
 290      *
 291      * @serial
 292      */
 293     private final short value;
 294 
 295     /**
 296      * Constructs a newly allocated {@code Short} object that
 297      * represents the specified {@code short} value.
 298      *
 299      * @param value     the value to be represented by the
 300      *                  {@code Short}.
 301      */
 302     public Short(short value) {
 303         this.value = value;
 304     }
 305 


 362 
 363     /**
 364      * Returns the value of this {@code Short} as a
 365      * {@code double}.
 366      */
 367     public double doubleValue() {
 368         return (double)value;
 369     }
 370 
 371     /**
 372      * Returns a {@code String} object representing this
 373      * {@code Short}'s value.  The value is converted to signed
 374      * decimal representation and returned as a string, exactly as if
 375      * the {@code short} value were given as an argument to the
 376      * {@link java.lang.Short#toString(short)} method.
 377      *
 378      * @return  a string representation of the value of this object in
 379      *          base&nbsp;10.
 380      */
 381     public String toString() {
 382         return String.valueOf((int)value);
 383     }
 384 
 385     /**
 386      * Returns a hash code for this {@code Short}; equal to the result
 387      * of invoking {@code intValue()}.
 388      *
 389      * @return a hash code value for this {@code Short}
 390      */
 391     public int hashCode() {
 392         return (int)value;
 393     }
 394 
 395     /**
 396      * Compares this object to the specified object.  The result is
 397      * {@code true} if and only if the argument is not
 398      * {@code null} and is a {@code Short} object that
 399      * contains the same {@code short} value as this object.
 400      *
 401      * @param obj       the object to compare with
 402      * @return          {@code true} if the objects are the same;




 153      * int)} method. The result is a {@code Short} object that
 154      * represents the {@code short} value specified by the string.
 155      *
 156      * <p>In other words, this method returns a {@code Short} object
 157      * equal to the value of:
 158      *
 159      * <blockquote>
 160      *  {@code new Short(Short.parseShort(s, radix))}
 161      * </blockquote>
 162      *
 163      * @param s         the string to be parsed
 164      * @param radix     the radix to be used in interpreting {@code s}
 165      * @return          a {@code Short} object holding the value
 166      *                  represented by the string argument in the
 167      *                  specified radix.
 168      * @throws          NumberFormatException If the {@code String} does
 169      *                  not contain a parsable {@code short}.
 170      */
 171     public static Short valueOf(String s, int radix)
 172         throws NumberFormatException {
 173         return valueOf(parseShort(s, radix));
 174     }
 175 
 176     /**
 177      * Returns a {@code Short} object holding the
 178      * value given by the specified {@code String}. The argument
 179      * is interpreted as representing a signed decimal
 180      * {@code short}, exactly as if the argument were given to
 181      * the {@link #parseShort(java.lang.String)} method. The result is
 182      * a {@code Short} object that represents the
 183      * {@code short} value specified by the string.
 184      *
 185      * <p>In other words, this method returns a {@code Short} object
 186      * equal to the value of:
 187      *
 188      * <blockquote>
 189      *  {@code new Short(Short.parseShort(s))}
 190      * </blockquote>
 191      *
 192      * @param s the string to be parsed
 193      * @return  a {@code Short} object holding the value


 265      * "{@code #}", or leading zero) is parsed as by the {@code
 266      * Short.parseShort} method with the indicated radix (10, 16, or
 267      * 8).  This sequence of characters must represent a positive
 268      * value or a {@link NumberFormatException} will be thrown.  The
 269      * result is negated if first character of the specified {@code
 270      * String} is the minus sign.  No whitespace characters are
 271      * permitted in the {@code String}.
 272      *
 273      * @param     nm the {@code String} to decode.
 274      * @return    a {@code Short} object holding the {@code short}
 275      *            value represented by {@code nm}
 276      * @throws    NumberFormatException  if the {@code String} does not
 277      *            contain a parsable {@code short}.
 278      * @see java.lang.Short#parseShort(java.lang.String, int)
 279      */
 280     public static Short decode(String nm) throws NumberFormatException {
 281         int i = Integer.decode(nm);
 282         if (i < MIN_VALUE || i > MAX_VALUE)
 283             throw new NumberFormatException(
 284                     "Value " + i + " out of range from input " + nm);
 285         return valueOf((short)i);
 286     }
 287 
 288     /**
 289      * The value of the {@code Short}.
 290      *
 291      * @serial
 292      */
 293     private final short value;
 294 
 295     /**
 296      * Constructs a newly allocated {@code Short} object that
 297      * represents the specified {@code short} value.
 298      *
 299      * @param value     the value to be represented by the
 300      *                  {@code Short}.
 301      */
 302     public Short(short value) {
 303         this.value = value;
 304     }
 305 


 362 
 363     /**
 364      * Returns the value of this {@code Short} as a
 365      * {@code double}.
 366      */
 367     public double doubleValue() {
 368         return (double)value;
 369     }
 370 
 371     /**
 372      * Returns a {@code String} object representing this
 373      * {@code Short}'s value.  The value is converted to signed
 374      * decimal representation and returned as a string, exactly as if
 375      * the {@code short} value were given as an argument to the
 376      * {@link java.lang.Short#toString(short)} method.
 377      *
 378      * @return  a string representation of the value of this object in
 379      *          base&nbsp;10.
 380      */
 381     public String toString() {
 382         return Integer.toString((int)value);
 383     }
 384 
 385     /**
 386      * Returns a hash code for this {@code Short}; equal to the result
 387      * of invoking {@code intValue()}.
 388      *
 389      * @return a hash code value for this {@code Short}
 390      */
 391     public int hashCode() {
 392         return (int)value;
 393     }
 394 
 395     /**
 396      * Compares this object to the specified object.  The result is
 397      * {@code true} if and only if the argument is not
 398      * {@code null} and is a {@code Short} object that
 399      * contains the same {@code short} value as this object.
 400      *
 401      * @param obj       the object to compare with
 402      * @return          {@code true} if the objects are the same;