View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2004 Open World Ltd
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.millscript.datatypes;
22  
23  
24  import java.io.Serializable;
25  import java.util.Comparator;
26  import java.util.Map;
27  import java.util.SortedMap;
28  import java.util.TreeMap;
29  
30  /**
31   * This interface provides a version of the usual <code>TreeMap</code> that
32   * includes a notion of a default which can be exploited by the MillScript
33   * index operator. Because the default compareTo's can throw
34   * ClassCastExceptions we must take over the Comparator.
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.EBinaryTreeMap}.
39   * @see org.millscript.millscript.datatypes.GeneralComparator
40   */
41  @Deprecated
42  public class TreeMapWithDefault extends TreeMap< Object, Object > implements MapWithDefault< Object, Object >, Serializable {
43  
44      /**
45       * This is the ID from the release 10.0.0 for future compatibility.
46       */
47      private static final long serialVersionUID = 1909162462951110403L;
48  
49      /**
50       * The general comparator we will use for our tree map's with default
51       * values, to avoid unnecessary ClassCastExceptions.
52       */
53      private static GeneralComparator gc = new GeneralComparator();
54  
55      /**
56       * This hash map's default value.
57       */
58      private Object def = null;
59  
60      /**
61       * @see org.millscript.millscript.datatypes.MapWithDefault#getDefault()
62       */
63      public Object getDefault() {
64          return def;
65      }
66  
67      /**
68       * @see org.millscript.millscript.datatypes.MapWithDefault#setDefault(java.lang.Object)
69       */
70      public void setDefault( final Object d ) {
71          def = d;
72      }
73  
74      /**
75       * Constructs a new empty tree map with default, sorted using our default
76       * comparator.
77       */
78      public TreeMapWithDefault() {
79          super( gc );
80      }
81  
82      /**
83       * Constructs a new tree map with default, containing all the mappings in
84       * the specified map, sorted using our default comparator.
85       *
86       * @param m the map to copy into this map
87       */
88      public TreeMapWithDefault( final SortedMap< ?, ? > m ) {
89          super( gc );
90          putAll( m );
91      }
92  
93      /**
94       * Constructs a new empty tree map with default, sorted according to the
95       * specified comparator.
96       *
97       * @param c the compartor to use for sorting this map
98       */
99      public TreeMapWithDefault( final Comparator< Object > c ) {
100         super( c );
101     }
102 
103     /**
104      * Constructs a new tree map with default, containing all the mappings in
105      * the specified map, sorted using our default comparator.
106      *
107      * @param m the map to copy into this map
108      */
109     public TreeMapWithDefault( final Map< ?, ? > m ) {
110         super( gc );
111         putAll( m );
112     }
113 
114 }