1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }