src/share/classes/java/lang/Character.java

Print this page
rev 4568 : 7088952: Add "BYTES" constant to primitive wrapper classes
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
Reviewed-by: smarks


4392     /**
4393      * Returns the value of this {@code Character} object.
4394      * @return  the primitive {@code char} value represented by
4395      *          this object.
4396      */
4397     public char charValue() {
4398         return value;
4399     }
4400 
4401     /**
4402      * Returns a hash code for this {@code Character}; equal to the result
4403      * of invoking {@code charValue()}.
4404      *
4405      * @return a hash code value for this {@code Character}
4406      */
4407     public int hashCode() {
4408         return (int)value;
4409     }
4410 
4411     /**












4412      * Compares this object against the specified object.
4413      * The result is {@code true} if and only if the argument is not
4414      * {@code null} and is a {@code Character} object that
4415      * represents the same {@code char} value as this object.
4416      *
4417      * @param   obj   the object to compare with.
4418      * @return  {@code true} if the objects are the same;
4419      *          {@code false} otherwise.
4420      */
4421     public boolean equals(Object obj) {
4422         if (obj instanceof Character) {
4423             return value == ((Character)obj).charValue();
4424         }
4425         return false;
4426     }
4427 
4428     /**
4429      * Returns a {@code String} object representing this
4430      * {@code Character}'s value.  The result is a string of
4431      * length 1 whose sole component is the primitive


6955      * mapping, then the {@code char} itself is returned in the
6956      * {@code char[]}.
6957      *
6958      * @param   codePoint   the character (Unicode code point) to be converted.
6959      * @return a {@code char[]} with the uppercased character.
6960      * @since 1.4
6961      */
6962     static char[] toUpperCaseCharArray(int codePoint) {
6963         // As of Unicode 6.0, 1:M uppercasings only happen in the BMP.
6964         assert isBmpCodePoint(codePoint);
6965         return CharacterData.of(codePoint).toUpperCaseCharArray(codePoint);
6966     }
6967 
6968     /**
6969      * The number of bits used to represent a <tt>char</tt> value in unsigned
6970      * binary form, constant {@code 16}.
6971      *
6972      * @since 1.5
6973      */
6974     public static final int SIZE = 16;








6975 
6976     /**
6977      * Returns the value obtained by reversing the order of the bytes in the
6978      * specified <tt>char</tt> value.
6979      *
6980      * @return the value obtained by reversing (or, equivalently, swapping)
6981      *     the bytes in the specified <tt>char</tt> value.
6982      * @since 1.5
6983      */
6984     public static char reverseBytes(char ch) {
6985         return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
6986     }
6987 
6988     /**
6989      * Returns the Unicode name of the specified character
6990      * {@code codePoint}, or null if the code point is
6991      * {@link #UNASSIGNED unassigned}.
6992      * <p>
6993      * Note: if the specified character is not assigned a name by
6994      * the <i>UnicodeData</i> file (part of the Unicode Character




4392     /**
4393      * Returns the value of this {@code Character} object.
4394      * @return  the primitive {@code char} value represented by
4395      *          this object.
4396      */
4397     public char charValue() {
4398         return value;
4399     }
4400 
4401     /**
4402      * Returns a hash code for this {@code Character}; equal to the result
4403      * of invoking {@code charValue()}.
4404      *
4405      * @return a hash code value for this {@code Character}
4406      */
4407     public int hashCode() {
4408         return (int)value;
4409     }
4410 
4411     /**
4412      * Returns a hash code for a {@code char} value; compatible with
4413      * {@code Character.hashCode()}.
4414      *  
4415      * @since 1.8
4416      *
4417      * @return a hash code value for a {@code char} value.
4418      */
4419     public static int hashCode(char value) {
4420         return (int)value;
4421     }
4422 
4423     /**
4424      * Compares this object against the specified object.
4425      * The result is {@code true} if and only if the argument is not
4426      * {@code null} and is a {@code Character} object that
4427      * represents the same {@code char} value as this object.
4428      *
4429      * @param   obj   the object to compare with.
4430      * @return  {@code true} if the objects are the same;
4431      *          {@code false} otherwise.
4432      */
4433     public boolean equals(Object obj) {
4434         if (obj instanceof Character) {
4435             return value == ((Character)obj).charValue();
4436         }
4437         return false;
4438     }
4439 
4440     /**
4441      * Returns a {@code String} object representing this
4442      * {@code Character}'s value.  The result is a string of
4443      * length 1 whose sole component is the primitive


6967      * mapping, then the {@code char} itself is returned in the
6968      * {@code char[]}.
6969      *
6970      * @param   codePoint   the character (Unicode code point) to be converted.
6971      * @return a {@code char[]} with the uppercased character.
6972      * @since 1.4
6973      */
6974     static char[] toUpperCaseCharArray(int codePoint) {
6975         // As of Unicode 6.0, 1:M uppercasings only happen in the BMP.
6976         assert isBmpCodePoint(codePoint);
6977         return CharacterData.of(codePoint).toUpperCaseCharArray(codePoint);
6978     }
6979 
6980     /**
6981      * The number of bits used to represent a <tt>char</tt> value in unsigned
6982      * binary form, constant {@code 16}.
6983      *
6984      * @since 1.5
6985      */
6986     public static final int SIZE = 16;
6987 
6988     /**
6989      * The number of bytes used to represent a {@code char} value in unsigned
6990      * binary form.
6991      *
6992      * @since 1.8
6993      */
6994     public static final int BYTES = SIZE / Byte.SIZE;
6995 
6996     /**
6997      * Returns the value obtained by reversing the order of the bytes in the
6998      * specified <tt>char</tt> value.
6999      *
7000      * @return the value obtained by reversing (or, equivalently, swapping)
7001      *     the bytes in the specified <tt>char</tt> value.
7002      * @since 1.5
7003      */
7004     public static char reverseBytes(char ch) {
7005         return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
7006     }
7007 
7008     /**
7009      * Returns the Unicode name of the specified character
7010      * {@code codePoint}, or null if the code point is
7011      * {@link #UNASSIGNED unassigned}.
7012      * <p>
7013      * Note: if the specified character is not assigned a name by
7014      * the <i>UnicodeData</i> file (part of the Unicode Character