1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.millscript.millscript.datatypes;
23
24 import org.millscript.millscript.alert.Alerts;
25
26 import java.util.AbstractList;
27 import java.util.Map;
28
29 /**
30 * This class implements a List, based on a <code>Map.Entry</code>, so it will
31 * be a list with two values.
32 *
33 * @deprecated As of MillScript 10.2.0, this functionallity has been subsumed
34 * by the MillScript-Util project and it's Map API, see
35 * {@link org.millscript.commons.util.list.IMapletList}.
36 */
37 @Deprecated
38 public final class MapEntryList extends AbstractList< Object > {
39
40 /**
41 * The backing Map.Entry for this list.
42 */
43 private final Map.Entry< Object, Object > maplet;
44
45 /**
46 * Constructs a new MapEntryList backed by the specified Map.Entry.
47 *
48 * @param m the backing Map.Entry for this list
49 */
50 public MapEntryList( final Map.Entry< Object, Object > m ) {
51 this.maplet = m;
52 }
53
54 /**
55 * @see java.util.Collection#size()
56 */
57 @Override
58 public int size() { return 2; }
59
60 /**
61 * @see java.util.List#get(int)
62 */
63 @Override
64 public Object get( final int n ) {
65
66
67 if ( n == 0 ) {
68 return maplet.getKey();
69 } else if ( n == 1 ) {
70 return maplet.getValue();
71 } else {
72 throw(
73 Alerts.eval(
74 "Index out of range",
75 "Maplets can only be indexed by 1 or 2"
76 ).
77 culprit( "index", new Integer( n ) ).
78 culprit( "pair", this ).
79 mishap()
80 );
81 }
82 }
83
84 /**
85 * @see java.util.List#set(int, java.lang.Object)
86 */
87 @Override
88 public Object set( final int n, final Object val ) {
89 if ( n == 2 ) {
90 return maplet.setValue( val );
91 } else {
92 throw(
93 Alerts.eval(
94 "Index out of range",
95 "Only the second field of a Maplet can be updated"
96 ).
97 culprit( "index", new Integer( n ) ).
98 culprit( "maplet", maplet ).
99 mishap()
100 );
101 }
102 }
103
104 }