blob: f27ee868aa401bfb7ca8d35f5e7c932874e71fa0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
package org.noreply.fancydress.directory.parser;
import java.util.*;
/**
* Hold entries of a directory section.
*
* This class holds all entries of a directory section. All entries are
* key:value pairs.
*
* The values themselves are not yet parsed, nor is the content
* cryptographically verified.
*
* A <code>DirectoryMessage</code> is made up of instances of this class.
*
* @see org.noreply.fancydress.directory.Directory
* @see DirectoryParser
* @see DirectoryMessage
* @see DirectoryEntry
*/
public class DirectorySection {
/**
* name of this section
*/
private String name;
/**
* List of entries
*/
private ArrayList entries;
/**
* Default constructor.
*
* Creates a new DirectorySection with the name passed as parameter.
*
* @param name name of this section
*/
public DirectorySection(String name) {
this.name = name;
entries = new ArrayList();
}
/**
* Copy constructor.
*
* Creates a new DirectorySection copying all values (recursively) from
* <code>section</code>.
*
* @param section section to copy from.
*/
public DirectorySection(DirectorySection section) {
name = new String(section.name);
entries = new ArrayList();
for (Iterator i = section.entries.iterator(); i.hasNext(); )
entries.add(new DirectoryEntry((DirectoryEntry)i.next()));
}
/**
* Add an entry to this section.
*
* @param entry Entry to add. It is used directly, not copied.
*/
public void addEntry(DirectoryEntry entry) {
entries.add(entry);
}
/**
* Blint a value in order to verify or create a signature.
*
* @param entry Entry to blind.
* @return The number of entries blinded.
*/
public int blindValue(String entry) {
int count = 0;
for (Iterator i = entries.iterator(); i.hasNext(); ) {
DirectoryEntry e = (DirectoryEntry) i.next();
if (e.getName().equals(entry)) {
e.blindValue();
count ++;
}
}
return count;
}
/**
* Return the first entry with that name
*
* @param entry Entry to return.
* @return first DirectoryEntry that matches the name or null.
*/
public DirectoryEntry getEntry(String entry) {
int count = 0;
for (Iterator i = entries.iterator(); i.hasNext(); ) {
DirectoryEntry e = (DirectoryEntry) i.next();
if (e.getName().equals(entry))
return e;
};
return null;
}
/**
* Returns a string representation of this section.
*
* @return a string representation of the object.
*/
public String toString() {
StringBuffer strbuf = new StringBuffer();
strbuf.append("[");
strbuf.append(name);
strbuf.append("]\n");
for (Iterator i = entries.iterator(); i.hasNext(); ) {
Object o = i.next();
strbuf.append(o.toString());
strbuf.append("\n");
}
return strbuf.toString();
}
/**
* Returns the name of this section.
*
* @return name of this section.
*/
public String getName() {
return name;
}
}
|