jdk/src/share/classes/java/util/logging/Level.java
changeset 20745 3d2e35965c56
parent 19795 6c628e165476
child 23010 6dadb192ad81
--- a/jdk/src/share/classes/java/util/logging/Level.java	Wed Oct 09 15:19:56 2013 +0200
+++ b/jdk/src/share/classes/java/util/logging/Level.java	Wed Oct 09 06:24:42 2013 -0700
@@ -204,6 +204,12 @@
      * @throws NullPointerException if the name is null
      */
     protected Level(String name, int value, String resourceBundleName) {
+        this(name, value, resourceBundleName, true);
+    }
+
+    // private constructor to specify whether this instance should be added
+    // to the KnownLevel list from which Level.parse method does its look up
+    private Level(String name, int value, String resourceBundleName, boolean visible) {
         if (name == null) {
             throw new NullPointerException();
         }
@@ -212,7 +218,9 @@
         this.resourceBundleName = resourceBundleName;
         this.localizedLevelName = resourceBundleName == null ? name : null;
         this.cachedLocale = null;
-        KnownLevel.add(this);
+        if (visible) {
+            KnownLevel.add(this);
+        }
     }
 
     /**
@@ -465,7 +473,7 @@
         // Finally, look for a known level with the given localized name,
         // in the current default locale.
         // This is relatively expensive, but not excessively so.
-        level = KnownLevel.findByLocalizedName(name);
+        level = KnownLevel.findByLocalizedLevelName(name);
         if (level != null) {
             return level.levelObject;
         }
@@ -521,13 +529,14 @@
         private static Map<String, List<KnownLevel>> nameToLevels = new HashMap<>();
         private static Map<Integer, List<KnownLevel>> intToLevels = new HashMap<>();
         final Level levelObject;     // instance of Level class or Level subclass
-        final Level mirroredLevel;   // instance of Level class
+        final Level mirroredLevel;   // mirror of the custom Level
         KnownLevel(Level l) {
             this.levelObject = l;
             if (l.getClass() == Level.class) {
                 this.mirroredLevel = l;
             } else {
-                this.mirroredLevel = new Level(l.name, l.value, l.resourceBundleName);
+                // this mirrored level object is hidden
+                this.mirroredLevel = new Level(l.name, l.value, l.resourceBundleName, false);
             }
         }
 
@@ -585,20 +594,6 @@
             return null;
         }
 
-        // Returns a KnownLevel with the given localized name matching
-        // by calling the Level.getLocalizedName() method
-        static synchronized KnownLevel findByLocalizedName(String name) {
-            for (List<KnownLevel> levels : nameToLevels.values()) {
-                for (KnownLevel l : levels) {
-                    String lname = l.levelObject.getLocalizedName();
-                    if (name.equals(lname)) {
-                        return l;
-                    }
-                }
-            }
-            return null;
-        }
-
         static synchronized KnownLevel matches(Level l) {
             List<KnownLevel> list = nameToLevels.get(l.name);
             if (list != null) {