View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.commons.util.map;
22  
23  import java.io.Serializable;
24  
25  import org.millscript.commons.util.IList;
26  import org.millscript.commons.util.IMap;
27  import org.millscript.commons.util.MapIterator;
28  import org.millscript.commons.util.Maplet;
29  import org.millscript.commons.util.iterator.NullMapIterator;
30  import org.millscript.commons.util.list.IEmptyList;
31  
32  /**
33   * A <code>Map</code> implementation that can have a default value, but no keys
34   * or values. This is used in situations where you need to have a map
35   * available, but you will never be able to place keys and values in it.
36   */
37  public class IEmptyMap< K, V > extends AbstractIMap< K, V > implements Cloneable, Serializable {
38  
39      /**
40       * This is the ID from the release 0.1.0 for future compatibility.
41       */
42      private static final long serialVersionUID = 7329566302488482806L;
43  
44      /**
45       * The immutable empty map. This is provided for convenience within your
46       * applications, where an immutable empty map is required.
47       */
48      public static final IMap EMPTY_MAP = new IEmptyMap();
49  
50      /**
51       * @see java.lang.Object#clone()
52       */
53      @Override
54      public Object clone() throws CloneNotSupportedException {
55          // Nothing special required for this clone
56          return super.clone();
57      }
58  
59      /**
60       * @see org.millscript.commons.util.IMap#contains(java.lang.Object, java.lang.Object)
61       */
62      public boolean contains( final K key, final V value ) {
63          return false;
64      }
65  
66      /**
67       * @see org.millscript.commons.util.IMap#containsKey(java.lang.Object)
68       */
69      public boolean containsKey( final K key ) {
70          return false;
71      }
72  
73      /**
74       * @see org.millscript.commons.util.IMap#containsValue(java.lang.Object)
75       */
76      public boolean containsValue( final V value ) {
77          return false;
78      }
79  
80      /**
81       * @see org.millscript.commons.util.IMap#get(java.lang.Object)
82       */
83      public V get( final K key ) {
84          return this.getDefault().get( this, key );
85      }
86  
87      /**
88       * @see org.millscript.commons.util.IMap#iterator(boolean)
89       */
90      public MapIterator< K, V > iterator( final boolean share ) {
91          return new NullMapIterator< K, V >();
92      }
93  
94      /**
95       * @see org.millscript.commons.util.map.AbstractIMap#sharedKeyList()
96       */
97      @Override
98      @SuppressWarnings( "unchecked" )
99      protected IList< K > sharedKeyList() {
100         return IEmptyList.EMPTY_LIST;
101     }
102 
103     /**
104      * @see org.millscript.commons.util.map.AbstractIMap#sharedMapletList()
105      */
106     @Override
107     @SuppressWarnings( "unchecked" )
108     protected IList< Maplet< K, V > > sharedMapletList() {
109         return IEmptyList.EMPTY_LIST;
110     }
111 
112     /**
113      * @see org.millscript.commons.util.map.AbstractIMap#sharedValueList()
114      */
115     @Override
116     @SuppressWarnings( "unchecked" )
117     protected IList< V > sharedValueList() {
118         return IEmptyList.EMPTY_LIST;
119     }
120 
121     /**
122      * @see org.millscript.commons.util.IMap#size()
123      */
124     public int size() {
125         return 0;
126     }
127 
128 }