View Javadoc

1   // Copyright 2004, FreeHEP.
2   package hep.wired.heprep.representation;
3   
4   import java.util.*;
5   
6   import hep.wired.heprep.services.DrawAs;
7   import hep.wired.util.WiredRegistry;
8   
9   /***
10   * Cache to register and lookup "DrawAs" values.
11   * 
12   * @author Mark Donszelmann
13   * @version $Id: DrawAsCache.java 258 2004-06-08 06:27:49Z duns $
14   */
15  
16  public class DrawAsCache {
17  
18      private transient Map /*<String,DrawAs>*/ drawAs;    
19  
20      public DrawAs lookup(String name) {
21          if (drawAs == null) {
22              // cache all, since lookups on ID would take too much time
23              Collection instances = WiredRegistry.allInstances(DrawAs.class);
24              drawAs = new HashMap(instances.size());
25              for (Iterator i=instances.iterator(); i.hasNext(); ) {
26                  DrawAs value = (DrawAs)i.next();
27                  drawAs.put(value.getKey(), value);
28              }
29          }
30          return (DrawAs)drawAs.get(name);
31      }
32  }