jdk/src/java.base/share/classes/java/util/Observable.java
author smarks
Thu, 28 Apr 2016 14:29:09 -0700
changeset 37682 faf3ae8eefc7
parent 32108 aa5490a167ee
child 44421 3ab80e087775
permissions -rw-r--r--
8154801: deprecate Observer and Observable Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
37682
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
     2
 * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This class represents an observable object, or "data"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * in the model-view paradigm. It can be subclassed to represent an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * object that the application wants to have observed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * An observable object can have one or more observers. An observer
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
    34
 * may be any object that implements interface {@code Observer}. After an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * observable instance changes, an application calling the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
    36
 * {@code Observable}'s {@code notifyObservers} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * causes all of its observers to be notified of the change by a call
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
    38
 * to their {@code update} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The order in which notifications will be delivered is unspecified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The default implementation provided in the Observable class will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * notify Observers in the order in which they registered interest, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * subclasses may change this order, use no guaranteed order, deliver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * notifications on separate threads, or may guarantee that their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * subclass follows this order, as they choose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
10350
6d009f117062 4748706: typos in java.util.Observable documentation
darcy
parents: 5506
diff changeset
    47
 * Note that this notification mechanism has nothing to do with threads
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
    48
 * and is completely separate from the {@code wait} and {@code notify}
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
    49
 * mechanism of class {@code Object}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * When an observable object is newly created, its set of observers is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * empty. Two observers are considered the same if and only if the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
    53
 * {@code equals} method returns true for them.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author  Chris Warth
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see     java.util.Observable#notifyObservers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see     java.util.Observable#notifyObservers(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see     java.util.Observer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 14342
diff changeset
    60
 * @since   1.0
37682
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    61
 *
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    62
 * @deprecated
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    63
 * This class and the {@link Observer} interface have been deprecated.
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    64
 * The event model supported by {@code Observer} and {@code Observable}
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    65
 * is quite limited, the order of notifications delivered by
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    66
 * {@code Observable} is unspecified, and state changes are not in
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    67
 * one-for-one correspondence with notifications.
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    68
 * For a richer event model, consider using the
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    69
 * {@link java.beans} package.  For reliable and ordered
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    70
 * messaging among threads, consider using one of the concurrent data
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    71
 * structures in the {@link java.util.concurrent} package.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
37682
faf3ae8eefc7 8154801: deprecate Observer and Observable
smarks
parents: 32108
diff changeset
    73
@Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
public class Observable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private boolean changed = false;
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 10350
diff changeset
    76
    private Vector<Observer> obs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /** Construct an Observable with zero Observers. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public Observable() {
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 10350
diff changeset
    81
        obs = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Adds an observer to the set of observers for this object, provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * that it is not the same as some observer already in the set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The order in which notifications will be delivered to multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * observers is not specified. See the class comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param   o   an observer to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @throws NullPointerException   if the parameter o is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public synchronized void addObserver(Observer o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (o == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (!obs.contains(o)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            obs.addElement(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Deletes an observer from the set of observers of this object.
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   103
     * Passing {@code null} to this method will have no effect.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param   o   the observer to be deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public synchronized void deleteObserver(Observer o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        obs.removeElement(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * If this object has changed, as indicated by the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   112
     * {@code hasChanged} method, then notify all of its observers
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   113
     * and then call the {@code clearChanged} method to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * indicate that this object has no longer changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p>
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   116
     * Each observer has its {@code update} method called with two
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   117
     * arguments: this observable object and {@code null}. In other
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * words, this method is equivalent to:
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   119
     * <blockquote>{@code
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   120
     * notifyObservers(null)}</blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @see     java.util.Observable#clearChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see     java.util.Observable#hasChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void notifyObservers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        notifyObservers(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * If this object has changed, as indicated by the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   132
     * {@code hasChanged} method, then notify all of its observers
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   133
     * and then call the {@code clearChanged} method to indicate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * that this object has no longer changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <p>
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   136
     * Each observer has its {@code update} method called with two
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   137
     * arguments: this observable object and the {@code arg} argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param   arg   any object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see     java.util.Observable#clearChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @see     java.util.Observable#hasChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void notifyObservers(Object arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * a temporary array buffer, used as a snapshot of the state of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * current Observers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        Object[] arrLocal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            /* We don't want the Observer doing callbacks into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
             * arbitrary code while holding its own Monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
             * The code where we extract each Observable from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
             * the Vector and store the state of the Observer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
             * needs synchronization, but notifying observers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
             * does not (should not).  The worst result of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
             * potential race-condition here is that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
             * 1) a newly-added Observer will miss a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
             *   notification in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
             * 2) a recently unregistered Observer will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
             *   wrongly notified when it doesn't care
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (!changed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            arrLocal = obs.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            clearChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        for (int i = arrLocal.length-1; i>=0; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            ((Observer)arrLocal[i]).update(this, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Clears the observer list so that this object no longer has any observers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public synchronized void deleteObservers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        obs.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   182
     * Marks this {@code Observable} object as having been changed; the
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   183
     * {@code hasChanged} method will now return {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    protected synchronized void setChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        changed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Indicates that this object has no longer changed, or that it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * already notified all of its observers of its most recent change,
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   192
     * so that the {@code hasChanged} method will now return {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * This method is called automatically by the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   194
     * {@code notifyObservers} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @see     java.util.Observable#notifyObservers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see     java.util.Observable#notifyObservers(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected synchronized void clearChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        changed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Tests if this object has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   206
     * @return  {@code true} if and only if the {@code setChanged}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *          method has been called more recently than the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   208
     *          {@code clearChanged} method on this object;
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   209
     *          {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see     java.util.Observable#clearChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see     java.util.Observable#setChanged()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public synchronized boolean hasChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return changed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 25859
diff changeset
   218
     * Returns the number of observers of this {@code Observable} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return  the number of observers of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public synchronized int countObservers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return obs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
}