src/macosx/classes/com/apple/laf/AquaUtils.java

Print this page




 160 
 161         abstract int getGreyFor(int gray);
 162     }
 163 
 164     abstract static class RecyclableObject<T> {
 165         private SoftReference<T> objectRef;
 166 
 167         T get() {
 168             T referent;
 169             if (objectRef != null && (referent = objectRef.get()) != null) return referent;
 170             referent = create();
 171             objectRef = new SoftReference<T>(referent);
 172             return referent;
 173         }
 174 
 175         protected abstract T create();
 176     }
 177 
 178     abstract static class RecyclableSingleton<T> {
 179         final T get() {
 180             final AppContext appContext = AppContext.getAppContext();
 181             SoftReference<T> ref = (SoftReference<T>) appContext.get(this);
 182             if (ref != null) {
 183                 final T object = ref.get();
 184                 if (object != null) return object;
 185             }
 186             final T object = getInstance();
 187             ref = new SoftReference<T>(object);
 188             appContext.put(this, ref);
 189             return object;
 190         }
 191 
 192         void reset() {
 193             AppContext.getAppContext().remove(this);
 194         }
 195 
 196         abstract T getInstance();
 197     }
 198 
 199     static class RecyclableSingletonFromDefaultConstructor<T> extends RecyclableSingleton<T> {
 200         private final Class<T> clazz;
 201 
 202         RecyclableSingletonFromDefaultConstructor(final Class<T> clazz) {
 203             this.clazz = clazz;
 204         }
 205 
 206         @Override
 207         T getInstance() {
 208             try {
 209                 ReflectUtil.checkPackageAccess(clazz);




 160 
 161         abstract int getGreyFor(int gray);
 162     }
 163 
 164     abstract static class RecyclableObject<T> {
 165         private SoftReference<T> objectRef;
 166 
 167         T get() {
 168             T referent;
 169             if (objectRef != null && (referent = objectRef.get()) != null) return referent;
 170             referent = create();
 171             objectRef = new SoftReference<T>(referent);
 172             return referent;
 173         }
 174 
 175         protected abstract T create();
 176     }
 177 
 178     abstract static class RecyclableSingleton<T> {
 179         final T get() {
 180             return AppContext.getSoftReferenceValue(this, () -> getInstance());









 181         }
 182 
 183         void reset() {
 184             AppContext.getAppContext().remove(this);
 185         }
 186 
 187         abstract T getInstance();
 188     }
 189 
 190     static class RecyclableSingletonFromDefaultConstructor<T> extends RecyclableSingleton<T> {
 191         private final Class<T> clazz;
 192 
 193         RecyclableSingletonFromDefaultConstructor(final Class<T> clazz) {
 194             this.clazz = clazz;
 195         }
 196 
 197         @Override
 198         T getInstance() {
 199             try {
 200                 ReflectUtil.checkPackageAccess(clazz);