1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }