1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.datatypes;
22
23
24 import java.io.Serializable;
25 import java.util.AbstractMap;
26 import java.util.Set;
27
28 /**
29 * A <code>MapWithDefault</code> implementation that can have a default value,
30 * but no keys or values. This is used in situations where you need to have a
31 * map available, but you will never be able to place keys and values in it. For
32 * instance, this is used by
33 * {@link org.millscript.millscript.functions.GroupFunction} for higher level
34 * defaults on Maps, when creating multi-level groups.
35 *
36 * @deprecated As of MillScript 10.2.0, this functionallity has been subsumed
37 * by the MillScript-Util project and it's Map API, see
38 * {@link org.millscript.commons.util.map.IEmptyMap}.
39 */
40 @Deprecated
41 public class NullMapWithDefault extends AbstractMap implements MapWithDefault, Serializable {
42
43 /**
44 * This is the ID from the release 10.0.0 for future compatibility.
45 */
46 private static final long serialVersionUID = -3189021365453950223L;
47
48 /**
49 * This member holds the default value associated with this map. As a
50 * NullMap cannot hold any proper values, this is the value that will be
51 * seen within MillScript.
52 */
53 private Object def = null;
54
55 /**
56 * Constructs a new NullMap with a default value of <code>null</code>.
57 */
58 NullMapWithDefault() {
59 }
60
61 /**
62 * Constructs a new NullMap with the specified default value.
63 *
64 * @param obj the default object to be returned by this map
65 */
66 NullMapWithDefault( final Object obj ) {
67 def = obj;
68 }
69
70 /**
71 * Constructs a new NullMap with the specified depth and default value. The
72 * depth refers to the number of times you have to index this map to reach
73 * the bottom, hence retrieve the default value. At the top level, the
74 * default value will be another NullMap, with a depth one less than this
75 * level. This default NullMap will have a default value of another NullMap,
76 * with a depth one less again, and so on until the depth is zero, where the
77 * NullMap will have the specified default value.
78 *
79 * @param depth the number of times you have to index this map to the
80 * "bottom"
81 * @param obj the default object to be returned from the bottom of this
82 * map
83 */
84 public NullMapWithDefault( final int depth, final Object obj ) {
85 def = (
86 depth > 1 ?
87 new NullMapWithDefault( depth - 1, obj ) :
88 obj
89 );
90 }
91
92 /**
93 * @see org.millscript.millscript.datatypes.MapWithDefault#getDefault()
94 */
95 public Object getDefault() {
96 return def;
97 }
98
99 /**
100 * @see org.millscript.millscript.datatypes.MapWithDefault#setDefault(java.lang.Object)
101 */
102 public void setDefault( final Object d ) {
103 def = d;
104 }
105
106 /**
107 * Returns a special NullSet, as this map will never contain any values.
108 *
109 * @return a set of no values
110 */
111 @Override
112 public Set entrySet() {
113 return new NullSet();
114 }
115
116 }