Path: blob/master/src/java.desktop/share/classes/sun/java2d/StateTracker.java
41152 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d;2627/**28* This interface is used to track changes to the complex data of an29* object that implements the StateTrackable interface.30* <p>31* The usage pattern for code accessing the trackable data is as follows:32* <pre>33* StateTrackable trackedobject;34* MyInfo cacheddata;35* StateTracker cachetracker;36* public synchronized MyInfo getInfoAbout(StateTrackable obj) {37* if (trackedobject != obj || !cachetracker.isCurrent()) {38* // Note: Always call getStateTracker() before39* // caching any data about the objct...40* cachetracker = obj.getStateTracker();41* cacheddata = calculateInfoFrom(obj);42* trackedobject = obj;43* }44* return cacheddata;45* }46* </pre>47* Note that the sample code above works correctly regardless of the48* {@link StateTrackable.State State} of the complex data of the object,49* but it may be inefficient to store precalculated information about50* an object whose current {@link StateTrackable.State State} is51* {@link StateTrackable.State#UNTRACKABLE UNTRACKABLE}52* and it is unnecessary to perform the {@link #isCurrent} test for53* data whose current {@link StateTrackable.State State} is54* {@link StateTrackable.State#IMMUTABLE IMMUTABLE}.55* Optimizations to the sample code for either or both of those terminal56* States may be of benefit for some use cases, but is left out of the57* example to reduce its complexity.58*59* @see StateTrackable.State60* @since 1.761*/62public interface StateTracker {63/**64* An implementation of the StateTracker interface which65* always returns true.66* This implementation is useful for objects whose current67* {@link StateTrackable.State State} is68* {@link StateTrackable.State#IMMUTABLE IMMUTABLE}.69* @since 1.770*/71public StateTracker ALWAYS_CURRENT = new StateTracker() {72public boolean isCurrent() {73return true;74}75};7677/**78* An implementation of the StateTracker interface which79* always returns false.80* This implementation is useful for objects whose current81* {@link StateTrackable.State State} is82* {@link StateTrackable.State#UNTRACKABLE UNTRACKABLE}.83* This implementation may also be useful for some objects84* whose current {@link StateTrackable.State State} is85* {@link StateTrackable.State#DYNAMIC DYNAMIC}.86* @since 1.787*/88public StateTracker NEVER_CURRENT = new StateTracker() {89public boolean isCurrent() {90return false;91}92};9394/**95* Returns true iff the contents of the complex data of the96* associated StateTrackable object have not changed since97* the time that this StateTracker was returned from its98* getStateTracker() method.99* @see StateTrackable100* @since 1.7101*/102public boolean isCurrent();103}104105106