com.limegroup.gnutella.altlocs
Class AlternateLocationCollection

java.lang.Object
  extended bycom.limegroup.gnutella.altlocs.AlternateLocationCollection
All Implemented Interfaces:
AlternateLocationCollector, HTTPHeaderValue

public final class AlternateLocationCollection
extends java.lang.Object
implements HTTPHeaderValue, AlternateLocationCollector

This class holds a collection of AlternateLocation instances, providing type safety for alternate location data.

See Also:
AlternateLocation

Method Summary
 boolean add(AlternateLocation al)
          Adds a new AlternateLocation to the list.
 int addAll(AlternateLocationCollection alc)
          Implements the AlternateLocationCollector interface.
 void clear()
           
 boolean contains(AlternateLocation loc)
           
static AlternateLocationCollection create(URN sha1)
          Factory constructor for creating a new AlternateLocationCollection for this URN.
static AlternateLocationCollection createCollectionFromHttpValue(java.lang.String value)
          Creates a new AlternateLocationCollection with all alternate locations contained in the given comma-delimited HTTP header value string.
 boolean equals(java.lang.Object o)
           
 int getAltLocsSize()
          Number of alternate locations this collector is holding
 URN getSHA1Urn()
          Returns the SHA1 for this AlternateLocationCollection.
 boolean hasAlternateLocations()
          Returns whether or not this AlternateLocationCollector has any alternate locations.
 java.lang.String httpStringValue()
          Implements the HTTPHeaderValue interface.
 java.util.Iterator iterator()
           
 boolean remove(AlternateLocation al)
          Removes this AlternateLocation from the active locations and adds it to the removed locations.
 java.lang.String toString()
          Overrides Object.toString to print out all of the alternate locations for this collection of alternate locations.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static AlternateLocationCollection create(URN sha1)
Factory constructor for creating a new AlternateLocationCollection for this URN.

Parameters:
sha1 - the SHA1 URN for this collection
Returns:
a new AlternateLocationCollection instance for this SHA1

createCollectionFromHttpValue

public static AlternateLocationCollection createCollectionFromHttpValue(java.lang.String value)
Creates a new AlternateLocationCollection with all alternate locations contained in the given comma-delimited HTTP header value string. The returned AlternateLocationCollection may be empty.

Parameters:
value - the HTTP header value containing alternate locations
Returns:
a new AlternateLocationCollection with any valid AlternateLocations from the HTTP string, or null if no valid locations could be found
Throws:
NullPointerException - if value is null

getSHA1Urn

public URN getSHA1Urn()
Returns the SHA1 for this AlternateLocationCollection.

Specified by:
getSHA1Urn in interface AlternateLocationCollector
Returns:
the SHA1 URN for this collection

add

public boolean add(AlternateLocation al)
Adds a new AlternateLocation to the list. If the alternate location is already present in the collection, it's count will be incremented. Implements the AlternateLocationCollector interface.

Specified by:
add in interface AlternateLocationCollector
Parameters:
al - the AlternateLocation to add
Returns:
true if added, false otherwise.
Throws:
IllegalArgumentException - if the AlternateLocation being added does not have a SHA1 urn or if the SHA1 urn does not match the urn for this collection

remove

public boolean remove(AlternateLocation al)
Removes this AlternateLocation from the active locations and adds it to the removed locations.

Specified by:
remove in interface AlternateLocationCollector

addAll

public int addAll(AlternateLocationCollection alc)
Implements the AlternateLocationCollector interface. Adds the specified AlternateLocationCollection to this collection. Note that to avoid deadlocks, the given AlternateLocationCollection is cloned first

Specified by:
addAll in interface AlternateLocationCollector
Parameters:
alc - the AlternateLocationCollection to add
Throws:
NullPointerException - if alc is null
IllegalArgumentException - if the SHA1 of the collection to add does not match the collection of this

clear

public void clear()

hasAlternateLocations

public boolean hasAlternateLocations()
Description copied from interface: AlternateLocationCollector
Returns whether or not this AlternateLocationCollector has any alternate locations.

Specified by:
hasAlternateLocations in interface AlternateLocationCollector
Returns:
true if this AlternateLocationCollector has 1 or more alternate locations, false otherwise

contains

public boolean contains(AlternateLocation loc)
Returns:
true is this contains loc

httpStringValue

public java.lang.String httpStringValue()
Implements the HTTPHeaderValue interface. This adds randomness to the order in which alternate locations are reported and only reports 10 locations.

Specified by:
httpStringValue in interface HTTPHeaderValue
Returns:
an HTTP-compliant string of alternate locations, delimited by commas, or the empty string if there are no alternate locations to report

getAltLocsSize

public int getAltLocsSize()
Description copied from interface: AlternateLocationCollector
Number of alternate locations this collector is holding

Specified by:
getAltLocsSize in interface AlternateLocationCollector

iterator

public java.util.Iterator iterator()

toString

public java.lang.String toString()
Overrides Object.toString to print out all of the alternate locations for this collection of alternate locations.

Returns:
the string representation of all alternate locations in this collection

equals

public boolean equals(java.lang.Object o)