1 /*
2 * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
69 * <p>
70 * The general contract of {@code hashCode} is:
71 * <ul>
72 * <li>Whenever it is invoked on the same object more than once during
73 * an execution of a Java application, the {@code hashCode} method
74 * must consistently return the same integer, provided no information
75 * used in {@code equals} comparisons on the object is modified.
76 * This integer need not remain consistent from one execution of an
77 * application to another execution of the same application.
78 * <li>If two objects are equal according to the {@code equals(Object)}
79 * method, then calling the {@code hashCode} method on each of
80 * the two objects must produce the same integer result.
81 * <li>It is <em>not</em> required that if two objects are unequal
82 * according to the {@link java.lang.Object#equals(java.lang.Object)}
83 * method, then calling the {@code hashCode} method on each of the
84 * two objects must produce distinct integer results. However, the
85 * programmer should be aware that producing distinct integer results
86 * for unequal objects may improve the performance of hash tables.
87 * </ul>
88 * <p>
89 * As much as is reasonably practical, the hashCode method defined by
90 * class {@code Object} does return distinct integers for distinct
91 * objects. (This is typically implemented by converting the internal
92 * address of the object into an integer, but this implementation
93 * technique is not required by the
94 * Java™ programming language.)
95 *
96 * @return a hash code value for this object.
97 * @see java.lang.Object#equals(java.lang.Object)
98 * @see java.lang.System#identityHashCode
99 */
100 public native int hashCode();
101
102 /**
103 * Indicates whether some other object is "equal to" this one.
104 * <p>
105 * The {@code equals} method implements an equivalence relation
106 * on non-null object references:
107 * <ul>
108 * <li>It is <i>reflexive</i>: for any non-null reference value
109 * {@code x}, {@code x.equals(x)} should return
110 * {@code true}.
111 * <li>It is <i>symmetric</i>: for any non-null reference values
112 * {@code x} and {@code y}, {@code x.equals(y)}
113 * should return {@code true} if and only if
114 * {@code y.equals(x)} returns {@code true}.
327 * ante - that is, to the situation as of the time that the {@code wait}
328 * method was invoked. Thread <var>T</var> then returns from the
329 * invocation of the {@code wait} method. Thus, on return from the
330 * {@code wait} method, the synchronization state of the object and of
331 * thread {@code T} is exactly as it was when the {@code wait} method
332 * was invoked.
333 * <p>
334 * A thread can also wake up without being notified, interrupted, or
335 * timing out, a so-called <i>spurious wakeup</i>. While this will rarely
336 * occur in practice, applications must guard against it by testing for
337 * the condition that should have caused the thread to be awakened, and
338 * continuing to wait if the condition is not satisfied. In other words,
339 * waits should always occur in loops, like this one:
340 * <pre>
341 * synchronized (obj) {
342 * while (<condition does not hold>)
343 * obj.wait(timeout);
344 * ... // Perform action appropriate to condition
345 * }
346 * </pre>
347 * (For more information on this topic, see Section 3.2.3 in Doug Lea's
348 * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
349 * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
350 * Language Guide" (Addison-Wesley, 2001).
351 *
352 * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
353 * interrupted} by any thread before or while it is waiting, then an
354 * {@code InterruptedException} is thrown. This exception is not
355 * thrown until the lock status of this object has been restored as
356 * described above.
357 *
358 * <p>
359 * Note that the {@code wait} method, as it places the current thread
360 * into the wait set for this object, unlocks only this object; any
361 * other objects on which the current thread may be synchronized remain
362 * locked while the thread waits.
363 * <p>
364 * This method should only be called by a thread that is the owner
365 * of this object's monitor. See the {@code notify} method for a
366 * description of the ways in which a thread can become the owner of
367 * a monitor.
368 *
369 * @param timeout the maximum time to wait in milliseconds.
370 * @throws IllegalArgumentException if the value of timeout is
|
1 /*
2 * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
69 * <p>
70 * The general contract of {@code hashCode} is:
71 * <ul>
72 * <li>Whenever it is invoked on the same object more than once during
73 * an execution of a Java application, the {@code hashCode} method
74 * must consistently return the same integer, provided no information
75 * used in {@code equals} comparisons on the object is modified.
76 * This integer need not remain consistent from one execution of an
77 * application to another execution of the same application.
78 * <li>If two objects are equal according to the {@code equals(Object)}
79 * method, then calling the {@code hashCode} method on each of
80 * the two objects must produce the same integer result.
81 * <li>It is <em>not</em> required that if two objects are unequal
82 * according to the {@link java.lang.Object#equals(java.lang.Object)}
83 * method, then calling the {@code hashCode} method on each of the
84 * two objects must produce distinct integer results. However, the
85 * programmer should be aware that producing distinct integer results
86 * for unequal objects may improve the performance of hash tables.
87 * </ul>
88 * <p>
89 * As much as is reasonably practical, the hashCode method defined
90 * by class {@code Object} does return distinct integers for
91 * distinct objects. (The hashCode may or may not be implemented
92 * as some function of an object's memory address at some point
93 * in time.)
94 *
95 * @return a hash code value for this object.
96 * @see java.lang.Object#equals(java.lang.Object)
97 * @see java.lang.System#identityHashCode
98 */
99 public native int hashCode();
100
101 /**
102 * Indicates whether some other object is "equal to" this one.
103 * <p>
104 * The {@code equals} method implements an equivalence relation
105 * on non-null object references:
106 * <ul>
107 * <li>It is <i>reflexive</i>: for any non-null reference value
108 * {@code x}, {@code x.equals(x)} should return
109 * {@code true}.
110 * <li>It is <i>symmetric</i>: for any non-null reference values
111 * {@code x} and {@code y}, {@code x.equals(y)}
112 * should return {@code true} if and only if
113 * {@code y.equals(x)} returns {@code true}.
326 * ante - that is, to the situation as of the time that the {@code wait}
327 * method was invoked. Thread <var>T</var> then returns from the
328 * invocation of the {@code wait} method. Thus, on return from the
329 * {@code wait} method, the synchronization state of the object and of
330 * thread {@code T} is exactly as it was when the {@code wait} method
331 * was invoked.
332 * <p>
333 * A thread can also wake up without being notified, interrupted, or
334 * timing out, a so-called <i>spurious wakeup</i>. While this will rarely
335 * occur in practice, applications must guard against it by testing for
336 * the condition that should have caused the thread to be awakened, and
337 * continuing to wait if the condition is not satisfied. In other words,
338 * waits should always occur in loops, like this one:
339 * <pre>
340 * synchronized (obj) {
341 * while (<condition does not hold>)
342 * obj.wait(timeout);
343 * ... // Perform action appropriate to condition
344 * }
345 * </pre>
346 *
347 * (For more information on this topic, see section 14.2,
348 * Condition Queues, in Brian Goetz and others'"Java Concurrency in
349 * Practice" (Addison-Wesley, 2006) or Item 69 in Joshua Bloch's
350 * "Effective Java (Second Edition)" (Addison-Wesley, 2008).
351 *
352 * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
353 * interrupted} by any thread before or while it is waiting, then an
354 * {@code InterruptedException} is thrown. This exception is not
355 * thrown until the lock status of this object has been restored as
356 * described above.
357 *
358 * <p>
359 * Note that the {@code wait} method, as it places the current thread
360 * into the wait set for this object, unlocks only this object; any
361 * other objects on which the current thread may be synchronized remain
362 * locked while the thread waits.
363 * <p>
364 * This method should only be called by a thread that is the owner
365 * of this object's monitor. See the {@code notify} method for a
366 * description of the ways in which a thread can become the owner of
367 * a monitor.
368 *
369 * @param timeout the maximum time to wait in milliseconds.
370 * @throws IllegalArgumentException if the value of timeout is
|