src/java.base/share/classes/java/lang/Character.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8076112 Sdiff src/java.base/share/classes/java/lang

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

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.util.Arrays;
  29 import java.util.Map;
  30 import java.util.HashMap;
  31 import java.util.Locale;
  32 


  33 /**
  34  * The {@code Character} class wraps a value of the primitive
  35  * type {@code char} in an object. An object of type
  36  * {@code Character} contains a single field whose type is
  37  * {@code char}.
  38  * <p>
  39  * In addition, this class provides several methods for determining
  40  * a character's category (lowercase letter, digit, etc.) and for converting
  41  * characters from uppercase to lowercase and vice versa.
  42  * <p>
  43  * Character information is based on the Unicode Standard, version 6.2.0.
  44  * <p>
  45  * The methods and data of class {@code Character} are defined by
  46  * the information in the <i>UnicodeData</i> file that is part of the
  47  * Unicode Character Database maintained by the Unicode
  48  * Consortium. This file specifies various properties including name
  49  * and general category for every defined Unicode code point or
  50  * character range.
  51  * <p>
  52  * The file and its description are available from the Unicode Consortium at:


4552         }
4553     }
4554 
4555     /**
4556      * Returns a <tt>Character</tt> instance representing the specified
4557      * <tt>char</tt> value.
4558      * If a new <tt>Character</tt> instance is not required, this method
4559      * should generally be used in preference to the constructor
4560      * {@link #Character(char)}, as this method is likely to yield
4561      * significantly better space and time performance by caching
4562      * frequently requested values.
4563      *
4564      * This method will always cache values in the range {@code
4565      * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
4566      * cache other values outside of this range.
4567      *
4568      * @param  c a char value.
4569      * @return a <tt>Character</tt> instance representing <tt>c</tt>.
4570      * @since  1.5
4571      */

4572     public static Character valueOf(char c) {
4573         if (c <= 127) { // must cache
4574             return CharacterCache.cache[(int)c];
4575         }
4576         return new Character(c);
4577     }
4578 
4579     /**
4580      * Returns the value of this {@code Character} object.
4581      * @return  the primitive {@code char} value represented by
4582      *          this object.
4583      */

4584     public char charValue() {
4585         return value;
4586     }
4587 
4588     /**
4589      * Returns a hash code for this {@code Character}; equal to the result
4590      * of invoking {@code charValue()}.
4591      *
4592      * @return a hash code value for this {@code Character}
4593      */
4594     @Override
4595     public int hashCode() {
4596         return Character.hashCode(value);
4597     }
4598 
4599     /**
4600      * Returns a hash code for a {@code char} value; compatible with
4601      * {@code Character.hashCode()}.
4602      *
4603      * @since 1.8


7164      */
7165     public static final int SIZE = 16;
7166 
7167     /**
7168      * The number of bytes used to represent a {@code char} value in unsigned
7169      * binary form.
7170      *
7171      * @since 1.8
7172      */
7173     public static final int BYTES = SIZE / Byte.SIZE;
7174 
7175     /**
7176      * Returns the value obtained by reversing the order of the bytes in the
7177      * specified <tt>char</tt> value.
7178      *
7179      * @param ch The {@code char} of which to reverse the byte order.
7180      * @return the value obtained by reversing (or, equivalently, swapping)
7181      *     the bytes in the specified <tt>char</tt> value.
7182      * @since 1.5
7183      */

7184     public static char reverseBytes(char ch) {
7185         return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
7186     }
7187 
7188     /**
7189      * Returns the Unicode name of the specified character
7190      * {@code codePoint}, or null if the code point is
7191      * {@link #UNASSIGNED unassigned}.
7192      * <p>
7193      * Note: if the specified character is not assigned a name by
7194      * the <i>UnicodeData</i> file (part of the Unicode Character
7195      * Database maintained by the Unicode Consortium), the returned
7196      * name is the same as the result of expression.
7197      *
7198      * <blockquote>{@code
7199      *     Character.UnicodeBlock.of(codePoint).toString().replace('_', ' ')
7200      *     + " "
7201      *     + Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH);
7202      *
7203      * }</blockquote>




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.util.Arrays;
  29 import java.util.Map;
  30 import java.util.HashMap;
  31 import java.util.Locale;
  32 
  33 import jdk.internal.HotSpotIntrinsicCandidate;
  34 
  35 /**
  36  * The {@code Character} class wraps a value of the primitive
  37  * type {@code char} in an object. An object of type
  38  * {@code Character} contains a single field whose type is
  39  * {@code char}.
  40  * <p>
  41  * In addition, this class provides several methods for determining
  42  * a character's category (lowercase letter, digit, etc.) and for converting
  43  * characters from uppercase to lowercase and vice versa.
  44  * <p>
  45  * Character information is based on the Unicode Standard, version 6.2.0.
  46  * <p>
  47  * The methods and data of class {@code Character} are defined by
  48  * the information in the <i>UnicodeData</i> file that is part of the
  49  * Unicode Character Database maintained by the Unicode
  50  * Consortium. This file specifies various properties including name
  51  * and general category for every defined Unicode code point or
  52  * character range.
  53  * <p>
  54  * The file and its description are available from the Unicode Consortium at:


4554         }
4555     }
4556 
4557     /**
4558      * Returns a <tt>Character</tt> instance representing the specified
4559      * <tt>char</tt> value.
4560      * If a new <tt>Character</tt> instance is not required, this method
4561      * should generally be used in preference to the constructor
4562      * {@link #Character(char)}, as this method is likely to yield
4563      * significantly better space and time performance by caching
4564      * frequently requested values.
4565      *
4566      * This method will always cache values in the range {@code
4567      * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
4568      * cache other values outside of this range.
4569      *
4570      * @param  c a char value.
4571      * @return a <tt>Character</tt> instance representing <tt>c</tt>.
4572      * @since  1.5
4573      */
4574     @HotSpotIntrinsicCandidate
4575     public static Character valueOf(char c) {
4576         if (c <= 127) { // must cache
4577             return CharacterCache.cache[(int)c];
4578         }
4579         return new Character(c);
4580     }
4581 
4582     /**
4583      * Returns the value of this {@code Character} object.
4584      * @return  the primitive {@code char} value represented by
4585      *          this object.
4586      */
4587     @HotSpotIntrinsicCandidate
4588     public char charValue() {
4589         return value;
4590     }
4591 
4592     /**
4593      * Returns a hash code for this {@code Character}; equal to the result
4594      * of invoking {@code charValue()}.
4595      *
4596      * @return a hash code value for this {@code Character}
4597      */
4598     @Override
4599     public int hashCode() {
4600         return Character.hashCode(value);
4601     }
4602 
4603     /**
4604      * Returns a hash code for a {@code char} value; compatible with
4605      * {@code Character.hashCode()}.
4606      *
4607      * @since 1.8


7168      */
7169     public static final int SIZE = 16;
7170 
7171     /**
7172      * The number of bytes used to represent a {@code char} value in unsigned
7173      * binary form.
7174      *
7175      * @since 1.8
7176      */
7177     public static final int BYTES = SIZE / Byte.SIZE;
7178 
7179     /**
7180      * Returns the value obtained by reversing the order of the bytes in the
7181      * specified <tt>char</tt> value.
7182      *
7183      * @param ch The {@code char} of which to reverse the byte order.
7184      * @return the value obtained by reversing (or, equivalently, swapping)
7185      *     the bytes in the specified <tt>char</tt> value.
7186      * @since 1.5
7187      */
7188     @HotSpotIntrinsicCandidate
7189     public static char reverseBytes(char ch) {
7190         return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
7191     }
7192 
7193     /**
7194      * Returns the Unicode name of the specified character
7195      * {@code codePoint}, or null if the code point is
7196      * {@link #UNASSIGNED unassigned}.
7197      * <p>
7198      * Note: if the specified character is not assigned a name by
7199      * the <i>UnicodeData</i> file (part of the Unicode Character
7200      * Database maintained by the Unicode Consortium), the returned
7201      * name is the same as the result of expression.
7202      *
7203      * <blockquote>{@code
7204      *     Character.UnicodeBlock.of(codePoint).toString().replace('_', ' ')
7205      *     + " "
7206      *     + Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH);
7207      *
7208      * }</blockquote>


src/java.base/share/classes/java/lang/Character.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File