Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: juju/reattore/util/MapOfLists.java


1   /*  Reattore HTTP Server
2   
3       Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  
19      $Id: MapOfLists.java,v 1.2 2003/03/05 05:06:16 michaelh Exp $
20  */
21  package juju.reattore.util;
22  
23  import java.util.*;
24  
25  /** Indexed set of Lists.
26   */
27  public class MapOfLists {
28  
29      private Map top = new LinkedHashMap();
30  
31      private List subGet(Object key) {
32          List ret = (List)top.get(key);
33  
34          if (ret == null) {
35              ret = new ArrayList();
36              top.put(key, ret);
37          }
38  
39          return ret;
40      }
41  
42      /** Adds a new element to the List identified by 'obj'
43  
44          @param key List key
45          @param obj Object to add.
46      */
47      public void add(Object key, Object obj) {
48          subGet(key).add(obj);
49      }
50  
51      /** All of the lists in order created.
52          
53          @return Set of Map.Entry
54      */
55      public Set entrySet() {
56          return top.entrySet();
57      }
58  
59      /** Fetch a list by key.
60  
61          @param key List key
62          @return    The list for the key.
63      */
64      public List get(Object key) {
65          return subGet(key);
66      }
67  }
68