src/share/classes/sun/font/Font2D.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -89,12 +89,12 @@
      * principal object by which you look up fonts.
      * It means more Hashmaps, but look ups can be quicker because
      * the map will have fewer entries, and there's no need to try to
      * make the Font2D part of the key.
      */
-    protected ConcurrentHashMap<FontStrikeDesc, Reference>
-        strikeCache = new ConcurrentHashMap<FontStrikeDesc, Reference>();
+    protected ConcurrentHashMap<FontStrikeDesc, Reference<FontStrike>>
+        strikeCache = new ConcurrentHashMap<>();
 
     /* Store the last Strike in a Reference object.
      * Similarly to the strike that was stored on a C++ font object,
      * this is an optimisation which helps if multiple clients (ie
      * typically SunGraphics2D instances) are using the same font, then

@@ -103,11 +103,11 @@
      * strike obtained from this Font2D satifies the needs of the next
      * client too.
      * This pre-supposes that a FontStrike is a shareable object, which
      * it should.
      */
-    protected Reference lastFontStrike = new SoftReference(null);
+    protected Reference<FontStrike> lastFontStrike = new SoftReference<>(null);
 
     /*
      * POSSIBLE OPTIMISATION:
      * Array of length 1024 elements of 64 bits indicating if a font
      * contains these. This kind of information can be shared between

@@ -193,11 +193,11 @@
      * this font with the default FRC. It will become the lastStrike and
      * there's a good chance that the next call will be to get exactly that
      * strike.
      */
     public FontStrike getStrike(Font font) {
-        FontStrike strike = (FontStrike)lastFontStrike.get();
+        FontStrike strike = lastFontStrike.get();
         if (strike != null) {
             return strike;
         } else {
             return getStrike(font, DEFAULT_FRC);
         }

@@ -305,21 +305,21 @@
          *
          * If the key isn't in the map, or its reference object has been
          * collected, then we create a new strike, put it in the map and
          * set it to be the last strike.
          */
-        FontStrike strike = (FontStrike)lastFontStrike.get();
+        FontStrike strike = lastFontStrike.get();
         if (strike != null && desc.equals(strike.desc)) {
             //strike.lastlookupTime = System.currentTimeMillis();
             return strike;
         } else {
-            Reference strikeRef = strikeCache.get(desc);
+            Reference<FontStrike> strikeRef = strikeCache.get(desc);
             if (strikeRef != null) {
-                strike = (FontStrike)strikeRef.get();
+                strike = strikeRef.get();
                 if (strike != null) {
                     //strike.lastlookupTime = System.currentTimeMillis();
-                    lastFontStrike = new SoftReference(strike);
+                    lastFontStrike = new SoftReference<>(strike);
                     StrikeCache.refStrike(strike);
                     return strike;
                 }
             }
             /* When we create a new FontStrike instance, we *must*

@@ -358,18 +358,18 @@
             } else {
                 strikeRef = StrikeCache.getStrikeRef(strike);
             }
             strikeCache.put(desc, strikeRef);
             //strike.lastlookupTime = System.currentTimeMillis();
-            lastFontStrike = new SoftReference(strike);
+            lastFontStrike = new SoftReference<>(strike);
             StrikeCache.refStrike(strike);
             return strike;
         }
     }
 
     void removeFromCache(FontStrikeDesc desc) {
-        Reference ref = strikeCache.get(desc);
+        Reference<FontStrike> ref = strikeCache.get(desc);
         if (ref != null) {
             Object o = ref.get();
             if (o == null) {
                 strikeCache.remove(desc);
             }