View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2004 Open World Ltd
4   // Copyright (C) 2005 Kevin Rogers
5   //
6   // This file is part of MillScript.
7   //
8   // MillScript is free software; you can redistribute it and/or modify it under
9   // the terms of the GNU General Public License as published by the Free
10  // Software Foundation; either version 2 of the License, or (at your option)
11  // any later version.
12  //
13  // MillScript is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  // more details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA  02111-1307  USA
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          // We use 0 and 1 as the indexes here, although the millscript user will
66          // be using 1 and 2. The 1-indexing is handled in ListMap.java.
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 }