View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel 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-Excel 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-Excel; 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.office.compound;
22  
23  import org.millscript.commons.util.map.AbstractIBinaryTreeMapNode;
24  import org.millscript.commons.util.map.AbstractITreeMap;
25  
26  import java.util.Comparator;
27  
28  /**
29   * 
30   */
31  public class DirectoryMap extends AbstractITreeMap< String, DirectoryEntry, DirectoryMap.Node > {
32  
33      public static class Node extends AbstractIBinaryTreeMapNode< String, DirectoryEntry > {
34  
35          private final DirectoryEntry directoryEntry;
36  
37          public Node( final AbstractIBinaryTreeMapNode< String, DirectoryEntry > parent, final DirectoryEntry entry ) {
38              super( parent );
39              this.directoryEntry = entry;
40          }
41  
42          public Node( final AbstractIBinaryTreeMapNode< String, DirectoryEntry > parent, final DirectoryEntry[] dir, final int did ) {
43              super( parent );
44              this.directoryEntry = dir[ did ];
45              if ( this.directoryEntry.getLeft() != -1 ) {
46                  this.setLeft( new Node( this, dir, this.directoryEntry.getLeft() ) );
47              }
48              if ( this.directoryEntry.getRight() != -1 ) {
49                  this.setRight( new Node( this, dir, this.directoryEntry.getRight() ) );
50              }
51          }
52  
53          /**
54           * @see org.millscript.commons.util.ITreeMapNode#deepCopy()
55           */
56          @Override
57          public Node deepCopy() {
58              final Node copy = new Node( this.getParent(), this.directoryEntry );
59              if ( this.getLeft() != null ) {
60                  copy.setLeft( this.getLeft().deepCopy() );
61              }
62              if ( this.getRight() != null ) {
63                  copy.setRight( this.getRight().deepCopy() );
64              }
65              return copy;
66          }
67  
68          /**
69           * @see org.millscript.commons.util.Maplet#getKey()
70           */
71          public String getKey() {
72              return this.directoryEntry.getName();
73          }
74  
75          /**
76           * @see org.millscript.commons.util.Maplet#getValue()
77           */
78          public DirectoryEntry getValue() {
79              return this.directoryEntry;
80          }
81          
82      }
83  
84      private Node rootNode;
85  
86      /**
87       * 
88       */
89      public DirectoryMap( final DirectoryEntry[] dir, final int rootDID ) {
90          this.rootNode = new Node( null, dir, rootDID );
91      }
92  
93      /**
94       * @see org.millscript.commons.util.ITreeMap#find(K)
95       */
96      public Node find( final String key ) {
97          return (Node) this.rootNode.find( DirectoryComparator.DIRECTORY_COMPARATOR, key );
98      }
99  
100     /**
101      * @see org.millscript.commons.util.ITreeMap#getComparator()
102      */
103     public Comparator< String > getComparator() {
104         return DirectoryComparator.DIRECTORY_COMPARATOR;
105     }
106 
107     /**
108      * @see org.millscript.commons.util.map.AbstractITreeMap#getRootNode()
109      */
110     public Node getRootNode() {
111         return this.rootNode;
112     }
113 
114 }