/[classpath]/classpath/gnu/java/nio/charset/Provider.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/charset/Provider.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by mkoch, Fri Nov 8 14:05:22 2002 UTC revision 1.2.2.1 by gnu_andrew, Fri Feb 4 09:44:44 2005 UTC
# Line 1  Line 1 
1  /* Provider.java --  /* Provider.java --
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 48  import java.util.Iterator; Line 48  import java.util.Iterator;
48   * {@link Charset#charsetForName} and * {@link Charset#availableCharsets}.   * {@link Charset#charsetForName} and * {@link Charset#availableCharsets}.
49   *   *
50   * @author Jesse Rosenstock   * @author Jesse Rosenstock
51     * @author Robert Schuster (thebohemian@gmx.net)
52   * @see Charset   * @see Charset
53   */   */
54  public final class Provider extends CharsetProvider  public final class Provider extends CharsetProvider
# Line 63  public final class Provider extends Char Line 64  public final class Provider extends Char
64    }    }
65    
66    /**    /**
67     * Map from charset name to charset canonical name.     * Map from charset name to charset canonical name. The strings
68       * are all lower-case to allow case-insensitive retrieval of
69       * Charset instances.
70     */     */
71    private final HashMap canonicalNames;    private final HashMap canonicalNames;
72    
73    /**    /**
74     * Map from canonical name to Charset.     * Map from lower-case canonical name to Charset.
75     * TODO: We may want to use soft references.  We would then need to keep     * TODO: We may want to use soft references.  We would then need to keep
76     * track of the class name to regenerate the object.     * track of the class name to regenerate the object.
77     */     */
# Line 76  public final class Provider extends Char Line 79  public final class Provider extends Char
79    
80    private Provider ()    private Provider ()
81    {    {
     // FIXME: We might need to make the name comparison case insensitive.  
     // Verify this with the Sun JDK.  
82      canonicalNames = new HashMap ();      canonicalNames = new HashMap ();
83      charsets = new HashMap ();      charsets = new HashMap ();
84    
# Line 106  public final class Provider extends Char Line 107  public final class Provider extends Char
107                        .iterator ();                        .iterator ();
108    }    }
109    
110      /**
111       * Returns a Charset instance by converting the given
112       * name to lower-case, looking up the canonical charset
113       * name and finally looking up the Charset with that name.
114       *
115       * <p>The lookup is therefore case-insensitive.</p>
116       *
117       *  @returns The Charset having <code>charsetName</code>
118       *  as its alias or null if no such Charset exist.
119       */
120    public Charset charsetForName (String charsetName)    public Charset charsetForName (String charsetName)
121    {    {
122      return (Charset) charsets.get (canonicalize (charsetName));      return (Charset) charsets.get(canonicalNames.get(charsetName.toLowerCase()));
   }  
   
   private Object canonicalize (String charsetName)  
   {  
     Object o = canonicalNames.get (charsetName);  
     return o == null ? charsetName : o;  
123    }    }
124    
125      /**
126       * Puts a Charset under its canonical name into the 'charsets' map.
127       * Then puts a mapping from all its alias names to the canonical name.
128       *
129       * <p>All names are converted to lower-case</p>.
130       *
131       * @param cs
132       */
133    private void addCharset (Charset cs)    private void addCharset (Charset cs)
134    {    {
135      String canonicalName = cs.name ();      String canonicalName = cs.name().toLowerCase();
136      charsets.put (canonicalName, cs);      charsets.put (canonicalName, cs);
137        
138        /* Adds a mapping between the canonical name
139         * itself making a lookup using that name
140         * no special case.
141         */  
142        canonicalNames.put(canonicalName, canonicalName);
143    
144      for (Iterator i = cs.aliases ().iterator (); i.hasNext (); )      for (Iterator i = cs.aliases ().iterator (); i.hasNext (); )
145        canonicalNames.put (i.next (), canonicalName);        canonicalNames.put (((String) i.next()).toLowerCase(), canonicalName);
146    }    }
147    
148    public static synchronized Provider provider ()    public static synchronized Provider provider ()

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.2.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26