org.tranche.hash.span
Class HashSpanCollection

java.lang.Object
  extended by org.tranche.hash.span.HashSpanCollection

public class HashSpanCollection
extends java.lang.Object

Use to manage and make modifications to a group of HashSpans.

Author:
James "Augie" Hill - augman85@gmail.com

Constructor Summary
HashSpanCollection()
          The default constructor.
HashSpanCollection(java.util.Collection<HashSpan> hashSpans)
          The constructor to use for starting with a group of hash spans.
 
Method Summary
 void addAll(java.util.Collection<HashSpan> hashSpans)
          Adds all the hash spans in the given collection to this collection.
static boolean areEqual(java.util.Collection<HashSpan> hashSpans1, java.util.Collection<HashSpan> hashSpans2)
          Determines the given collections of hash spans are equivalent.
 HashSpanCollection clone()
          Creates a clone of this hash span collection.
 boolean equals(java.lang.Object o)
          Returns whether the hash spans contained within this and the given are equivalent.
 java.util.Collection<HashSpan> getHashSpans()
          The hash spans contained within the collection.
 java.util.Collection<HashSpan> getMissingHashSpans()
          Returns a collection of hash spans that represent the ranges of hashes that are required to complete a full hash span.
 boolean isFullHashSpan()
          Whether the collection of hash spans together represent the full range of hashes.
static HashSpan merge(HashSpan hs1, HashSpan hs2)
          Makes one hash span from two.
static void merge(java.util.List<HashSpan> hashSpans)
          Merge a collection of hash spans as much as possible
 void removeAll(java.util.Collection<HashSpan> hashSpans)
          Removes all the hash spans in the given collection from this collection.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashSpanCollection

public HashSpanCollection()

The default constructor.


HashSpanCollection

public HashSpanCollection(java.util.Collection<HashSpan> hashSpans)

The constructor to use for starting with a group of hash spans.

Parameters:
hashSpans - The hash spans to start with.
Method Detail

getHashSpans

public java.util.Collection<HashSpan> getHashSpans()

The hash spans contained within the collection.

Returns:
A collection of hash spans.

addAll

public void addAll(java.util.Collection<HashSpan> hashSpans)

Adds all the hash spans in the given collection to this collection.

Parameters:
hashSpans - A collection of hash spans.

removeAll

public void removeAll(java.util.Collection<HashSpan> hashSpans)

Removes all the hash spans in the given collection from this collection.

Parameters:
hashSpans - A collection of hash spans.

getMissingHashSpans

public java.util.Collection<HashSpan> getMissingHashSpans()

Returns a collection of hash spans that represent the ranges of hashes that are required to complete a full hash span.

Returns:
A collection of hash spans.

isFullHashSpan

public boolean isFullHashSpan()

Whether the collection of hash spans together represent the full range of hashes.

Returns:
Whether the collection of hash spans together represent the full range of hashes.

clone

public HashSpanCollection clone()

Creates a clone of this hash span collection.

Overrides:
clone in class java.lang.Object
Returns:
A new HashSpanCollection object that is equivalent to this one.

equals

public boolean equals(java.lang.Object o)

Returns whether the hash spans contained within this and the given are equivalent.

Overrides:
equals in class java.lang.Object
Parameters:
o - A hash span collection.
Returns:
Whether the hash spans contained within this and the given are equivalent.

merge

public static void merge(java.util.List<HashSpan> hashSpans)

Merge a collection of hash spans as much as possible

Merging consists of taking overlapping hash spans and combining them into a single hash span as much as is possible.

Parameters:
hashSpans - A list of hash spans.

merge

public static HashSpan merge(HashSpan hs1,
                             HashSpan hs2)

Makes one hash span from two.

Given hash spans must overlap or be adjacent.

Parameters:
hs1 - A hash span.
hs2 - A hash span.
Returns:
Null if the hash spans do not overlap and are not adjacent.

areEqual

public static boolean areEqual(java.util.Collection<HashSpan> hashSpans1,
                               java.util.Collection<HashSpan> hashSpans2)

Determines the given collections of hash spans are equivalent.

Parameters:
hashSpans1 - A collection of hash spans.
hashSpans2 - A collection of hash spans.
Returns:
Whether the two given collections of hash spans are equivalent.


This code is free for use both commercially and non-commercially as stated in the project's license