From 566d17f731637df6828bdf32502a0fb123882dbe Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Thu, 9 Oct 2003 11:41:45 +0000 Subject: Initial import --- .../directory/parser/DirectorySection.java | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/org/noreply/fancydress/directory/parser/DirectorySection.java (limited to 'src/org/noreply/fancydress/directory/parser/DirectorySection.java') diff --git a/src/org/noreply/fancydress/directory/parser/DirectorySection.java b/src/org/noreply/fancydress/directory/parser/DirectorySection.java new file mode 100644 index 0000000..f27ee86 --- /dev/null +++ b/src/org/noreply/fancydress/directory/parser/DirectorySection.java @@ -0,0 +1,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 DirectoryMessage 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 + * section. + * + * @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; + } +} -- cgit v1.2.3