org.apache.geronimo.javamail.store.nntp.newsrc
Class Range

java.lang.Object
  extended by org.apache.geronimo.javamail.store.nntp.newsrc.Range

public class Range
extends Object

Represent a single Range in a newsrc file. A Range can be either a single number (start == end) or a span of article numbers.


Constructor Summary
Range(int spot)
          Construct a Range item for a single digit range.
Range(int start, int end)
          Construct a Range item.
 
Method Summary
 boolean abutts(int article)
          Tests if a single point abutts either the start or end of this Range.
 boolean abutts(Range other)
          Test if two ranges exactly abutt each other.
 boolean contains(int target)
          Test if a range contains a point value.
 boolean contains(Range other)
          Test if one range is completely contained within another Range.
 int getEnd()
          Get the ending point for the Range.
 int getStart()
          Get the starting point for the Range.
 boolean greaterThan(int article)
          Test if a point is above the test Range.
 boolean greaterThan(Range other)
          Test if another Range is greater than this Range.
 boolean lessThan(int article)
          Test if a point is below the test Range.
 boolean lessThan(Range other)
          Test if another Range is less than this Range.
 void merge(Range other)
          Merge another Range into this one.
 boolean overlaps(Range other)
          Tests if two ranges overlap
static Range parse(String range)
          Parse a section of a .newsrc range string into a single Range item.
 void save(Writer out)
          Save an individual range element to a newsrc file.
 void setEnd(int end)
          Set the ending point for a Range.
 void setStart(int start)
          Set the starting point for a Range.
 Range split(int location)
          Split a range at a given split point.
 String toString()
          Convert a Range into String form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range(int spot)
Construct a Range item for a single digit range.

Parameters:
spot - The location of the singleton.

Range

public Range(int start,
             int end)
Construct a Range item.

Parameters:
start - The starting point of the Range.
end - The Range end point (which may be equal to the starting point).
Method Detail

parse

public static Range parse(String range)
Parse a section of a .newsrc range string into a single Range item. The range is either a single number, or a pair of numbers separated by a hyphen.

Parameters:
range - The range string.
Returns:
A constructed Range item, or null if there is a parsing error.

getStart

public int getStart()
Get the starting point for the Range.

Returns:
The beginning of the mark range.

setStart

public void setStart(int start)
Set the starting point for a Range.

Parameters:
start - The new start value.

getEnd

public int getEnd()
Get the ending point for the Range.

Returns:
The end of the mark range.

setEnd

public void setEnd(int end)
Set the ending point for a Range.

Parameters:
end - The new end value.

contains

public boolean contains(int target)
Test if a range contains a point value.

Parameters:
target - The article location to test.
Returns:
True if the target is between the start and end values, inclusive.

contains

public boolean contains(Range other)
Test if one range is completely contained within another Range.

Parameters:
other - The other test range.
Returns:
true if the other start and end points are contained within this range.

overlaps

public boolean overlaps(Range other)
Tests if two ranges overlap

Parameters:
other - The other test range.
Returns:
true if the start or end points of either range are contained within the range of the other.

abutts

public boolean abutts(Range other)
Test if two ranges exactly abutt each other.

Parameters:
other - The other Range to test.
Returns:
true if the end of one range abutts the start of the other range.

abutts

public boolean abutts(int article)
Tests if a single point abutts either the start or end of this Range.

Parameters:
article - The point to test.
Returns:
true if test point is equal to start - 1 or end + 1.

lessThan

public boolean lessThan(int article)
Test if a point is below the test Range.

Parameters:
article - The point to test.
Returns:
true if the entire range is less than the test point.

lessThan

public boolean lessThan(Range other)
Test if another Range is less than this Range.

Parameters:
other - The other Range to test.
Returns:
true if the other Range lies completely below this Range.

greaterThan

public boolean greaterThan(int article)
Test if a point is above the test Range.

Parameters:
article - The point to test.
Returns:
true if the entire range is greater than the test point.

greaterThan

public boolean greaterThan(Range other)
Test if another Range is greater than this Range.

Parameters:
other - The other Range to test.
Returns:
true if the other Range lies completely below this Range.

merge

public void merge(Range other)
Merge another Range into this one. Merging will increase the bounds of this Range to encompass the entire span of the two. If the Ranges do not overlap, the newly created range will include the gap between the two.

Parameters:
other - The Range to merge.

split

public Range split(int location)
Split a range at a given split point. Splitting will truncate at the split location - 1 and return a new range beginning at location + 1; This code assumes that the split location is at neither end poing.

Parameters:
location - The split location. Location must be in the range start < location < end.
Returns:
A new Range object for the split portion of the range.

save

public void save(Writer out)
          throws IOException
Save an individual range element to a newsrc file. The range is expressed either as a single number, or a hypenated pair of numbers.

Parameters:
out - The output writer used to save the data.
Throws:
IOException

toString

public String toString()
Convert a Range into String form. Used mostly for debugging.

Overrides:
toString in class Object
Returns:
The String representation of the Range.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.