1
|
1 /* HashTree -- Tree in a Hashtable
|
|
2
|
|
3 Digital Image Library servlet components
|
|
4
|
|
5 Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de)
|
|
6
|
|
7 This program is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2 of the License, or (at your
|
|
10 option) any later version.
|
|
11
|
|
12 Please read license.txt for the full details. A copy of the GPL
|
|
13 may be found at http://www.gnu.org/copyleft/lgpl.html
|
|
14
|
|
15 You should have received a copy of the GNU General Public License
|
|
16 along with this program; if not, write to the Free Software
|
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
|
19 */
|
|
20
|
|
21 package digilib.auth;
|
|
22
|
|
23 import java.util.*;
|
|
24
|
|
25 public class HashTree {
|
|
26
|
|
27 private Hashtable table;
|
|
28 private String twigSep = "/";
|
|
29 private String leafSep = ",";
|
|
30
|
|
31 public HashTree() {
|
|
32 table = new Hashtable();
|
|
33 }
|
|
34
|
|
35 public HashTree(Hashtable t, String twig_separator, String leaf_separator) {
|
|
36 table = t;
|
|
37 twigSep = twig_separator;
|
|
38 leafSep = leaf_separator;
|
|
39 optimizeTable();
|
|
40 }
|
|
41
|
|
42 void optimizeTable() {
|
|
43 }
|
|
44
|
|
45 List match(String branch) {
|
|
46 String b = "";
|
|
47 String m;
|
|
48 LinkedList matches = new LinkedList();
|
|
49
|
|
50 // split branch
|
|
51 StringTokenizer twig = new StringTokenizer(branch, twigSep);
|
|
52 // walk branch and check with tree
|
|
53 while (twig.hasMoreTokens()) {
|
|
54 if (b.length() == 0) {
|
|
55 b = twig.nextToken();
|
|
56 } else {
|
|
57 b += twigSep + twig.nextToken();
|
|
58 }
|
|
59 m = (String)table.get(b);
|
|
60 //System.out.println("CHECK: "+b+" = "+m);
|
|
61 if (m != null) {
|
|
62 if (m.indexOf(leafSep) < 0) {
|
|
63 // single leaf
|
|
64 matches.add(m);
|
|
65 } else {
|
|
66 // split leaves
|
|
67 StringTokenizer leaf = new StringTokenizer(m, leafSep);
|
|
68 while (leaf.hasMoreTokens()) {
|
|
69 matches.add(leaf.nextToken());
|
|
70 }
|
|
71 }
|
|
72 }
|
|
73 }
|
|
74 if (matches.size() > 0) {
|
|
75 return matches;
|
|
76 } else {
|
|
77 return null;
|
|
78 }
|
|
79 }
|
|
80 }
|