com.limegroup.gnutella.xml
Class LimeXMLReplyCollection

java.lang.Object
  extended bycom.limegroup.gnutella.xml.LimeXMLReplyCollection

public class LimeXMLReplyCollection
extends java.lang.Object

Stores a schema and a list of replies corresponding to that schema.

So when a search comes in, we only have to look at the set of replies that correspond to the schema of the query. Locking: Never obtain a this' monitor PRIOR to obtaining that of the FileManager.


Field Summary
static int BAD_ID3
           
static int FAILED_ALBUM
           
static int FAILED_ARTIST
           
static int FAILED_COMMENT
           
static int FAILED_GENRE
           
static int FAILED_TITLE
           
static int FAILED_TRACK
           
static int FAILED_YEAR
           
static int FILE_DEFECTIVE
           
static int HASH_FAILED
           
static int NORMAL
           
static int RW_ERROR
           
 
Constructor Summary
LimeXMLReplyCollection(FileDesc[] fds, java.lang.String URI, boolean audio)
          Creates a new LimeXMLReplyCollection.
 
Method Summary
 void addReply(FileDesc fd, LimeXMLDocument replyDoc)
          Adds a reply into the mainMap of this collection.
 int getCount()
          Returns the amount of items in this collection.
 LimeXMLDocument getDocForHash(URN hash)
          Returns the LimeXMLDocument associated with this hash.
protected  java.util.List getKeyWords()
          Gets a list of keywords from all the documents in this collection.
 java.util.List getMatchingReplies(LimeXMLDocument query)
          Returns all documents that match the particular query.
 java.lang.String getSchemaURI()
          Returns the schema URI of this collection.
 boolean isAudio()
          Returns whether or not this reply collection is for audio files.
 int mp3ToDisk(java.lang.String mp3FileName, LimeXMLDocument doc)
          Writes this mp3 file to disk, using the XML in the doc.
 boolean removeDoc(FileDesc fd)
          Removes the document associated with this FileDesc from this collection, as well as removing it from the FileDesc.
 LimeXMLDocument replaceDoc(FileDesc fd, LimeXMLDocument newDoc)
          Replaces the document in the map with a newer LimeXMLDocument.
 boolean write()
          Simply write() out the mainMap to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL

public static final int NORMAL
See Also:
Constant Field Values

FILE_DEFECTIVE

public static final int FILE_DEFECTIVE
See Also:
Constant Field Values

RW_ERROR

public static final int RW_ERROR
See Also:
Constant Field Values

BAD_ID3

public static final int BAD_ID3
See Also:
Constant Field Values

FAILED_TITLE

public static final int FAILED_TITLE
See Also:
Constant Field Values

FAILED_ARTIST

public static final int FAILED_ARTIST
See Also:
Constant Field Values

FAILED_ALBUM

public static final int FAILED_ALBUM
See Also:
Constant Field Values

FAILED_YEAR

public static final int FAILED_YEAR
See Also:
Constant Field Values

FAILED_COMMENT

public static final int FAILED_COMMENT
See Also:
Constant Field Values

FAILED_TRACK

public static final int FAILED_TRACK
See Also:
Constant Field Values

FAILED_GENRE

public static final int FAILED_GENRE
See Also:
Constant Field Values

HASH_FAILED

public static final int HASH_FAILED
See Also:
Constant Field Values
Constructor Detail

LimeXMLReplyCollection

public LimeXMLReplyCollection(FileDesc[] fds,
                              java.lang.String URI,
                              boolean audio)
Creates a new LimeXMLReplyCollection. The reply collection will retain only those XMLDocs that match the given schema URI.

Parameters:
fds - The list of shared FileDescs.
URI - This collection's schema URI
audio - Whether this is a collection of audio files.
Method Detail

getKeyWords

protected java.util.List getKeyWords()
Gets a list of keywords from all the documents in this collection.

delegates to the individual documents and collates the list


getSchemaURI

public java.lang.String getSchemaURI()
Returns the schema URI of this collection.


addReply

public void addReply(FileDesc fd,
                     LimeXMLDocument replyDoc)
Adds a reply into the mainMap of this collection. Also adds this LimeXMLDocument to the list of documents the FileDesc knows about.


getCount

public int getCount()
Returns the amount of items in this collection.


isAudio

public boolean isAudio()
Returns whether or not this reply collection is for audio files.


getDocForHash

public LimeXMLDocument getDocForHash(URN hash)
Returns the LimeXMLDocument associated with this hash. May return null if the hash is not found.


getMatchingReplies

public java.util.List getMatchingReplies(LimeXMLDocument query)
Returns all documents that match the particular query. If no documents match, this returns an empty list. This goes through the following methodology: 1) Looks in the index trie to determine if ANY of the values in the query's document match. If they do, adds the document to a set of possible matches. A set is used so the same document is not added multiple times. 2) If no documents matched, returns an empty list. 3) Iterates through the possible matching documents and does a fine-grained matchup, using XML-specific matching techniques. 4) Returns an empty list if nothing matched or a list of the matching documents.


replaceDoc

public LimeXMLDocument replaceDoc(FileDesc fd,
                                  LimeXMLDocument newDoc)
Replaces the document in the map with a newer LimeXMLDocument.

Returns:
the older document, which is being replaced. Can be null.

removeDoc

public boolean removeDoc(FileDesc fd)
Removes the document associated with this FileDesc from this collection, as well as removing it from the FileDesc.


write

public boolean write()
Simply write() out the mainMap to disk.


mp3ToDisk

public int mp3ToDisk(java.lang.String mp3FileName,
                     LimeXMLDocument doc)
Writes this mp3 file to disk, using the XML in the doc.