net.wotonomy.foundation
Class NSRange

java.lang.Object
  extended by net.wotonomy.foundation.NSRange
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
NSMutableRange

public class NSRange
extends java.lang.Object
implements java.lang.Cloneable

A pure java implementation of NSRange. An NSRange represents a range of numbers having a starting location and spanning a length.

Version:
$Revision: 920 $
Author:
michael@mpowers.net, $Author: cgruber $

Field Summary
protected  int len
           
protected  int loc
           
static NSRange ZeroRange
          An empty range.
 
Constructor Summary
NSRange()
          Default constructor produces an empty range.
NSRange(int location, int length)
          Produces a range with the specified location and length.
NSRange(NSRange aRange)
          Produces a range that has the same location and length as the specified range.
 
Method Summary
 java.lang.Object clone()
          Returns a copy of this range.
 boolean equals(java.lang.Object anObject)
          Returns whether the specified object is equal to this range.
static NSRange fromString(java.lang.String aString)
          Parses a range from a string of the form "{x,y}" where x is the location and y is the length.
 int hashCode()
          Returns a hashCode.
 boolean intersectsRange(NSRange aRange)
          Returns whether the specified range overlaps at any point with this range.
 boolean isEmpty()
          Returns whether this is an empty range, therefore whether the length is zero.
 boolean isEqualToRange(NSRange aRange)
          Returns whether the specified range is equal to this range.
 boolean isSubrangeOfRange(NSRange aRange)
          Returns whether this range is completely contained within the specified range.
 int length()
          Returns the length of this range.
 int location()
          Returns the location of this range.
 boolean locationInRange(int location)
          Returns whether the specified location is contained within this range.
 int maxRange()
          Returns the maximum extent of the range.
 NSRange rangeByIntersectingRange(NSRange aRange)
          Returns the intersection of this range and the specified range, if any.
 NSRange rangeByUnioningRange(NSRange aRange)
          Returns the union of this range and the specified range, if any.
 void subtractRange(NSRange aRange, NSMutableRange firstResult, NSMutableRange secondResult)
          Eliminates any intersections between this range and the specified range.
 java.lang.String toString()
          Returns a string representation of this range.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZeroRange

public static final NSRange ZeroRange
An empty range.


loc

protected int loc

len

protected int len
Constructor Detail

NSRange

public NSRange()
Default constructor produces an empty range.


NSRange

public NSRange(int location,
               int length)
Produces a range with the specified location and length.


NSRange

public NSRange(NSRange aRange)
Produces a range that has the same location and length as the specified range.

Method Detail

location

public int location()
Returns the location of this range.


length

public int length()
Returns the length of this range.


maxRange

public int maxRange()
Returns the maximum extent of the range. This number is one more than the last position in the range.


isEmpty

public boolean isEmpty()
Returns whether this is an empty range, therefore whether the length is zero.


locationInRange

public boolean locationInRange(int location)
Returns whether the specified location is contained within this range.


isEqualToRange

public boolean isEqualToRange(NSRange aRange)
Returns whether the specified range is equal to this range.


equals

public boolean equals(java.lang.Object anObject)
Returns whether the specified object is equal to this range.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hashCode.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of this range.

Overrides:
toString in class java.lang.Object

rangeByUnioningRange

public NSRange rangeByUnioningRange(NSRange aRange)
Returns the union of this range and the specified range, if any. Gaps are filled, so the result is the smallest starting position and the largest ending position.


rangeByIntersectingRange

public NSRange rangeByIntersectingRange(NSRange aRange)
Returns the intersection of this range and the specified range, if any. If no intersection, returns an empty range.


intersectsRange

public boolean intersectsRange(NSRange aRange)
Returns whether the specified range overlaps at any point with this range.


isSubrangeOfRange

public boolean isSubrangeOfRange(NSRange aRange)
Returns whether this range is completely contained within the specified range.


subtractRange

public void subtractRange(NSRange aRange,
                          NSMutableRange firstResult,
                          NSMutableRange secondResult)
Eliminates any intersections between this range and the specified range. This produces two ranges, either of which may be empty. These two ranges are returned by modifying the supplied second and third parameters.


clone

public java.lang.Object clone()
Returns a copy of this range.

Overrides:
clone in class java.lang.Object

fromString

public static NSRange fromString(java.lang.String aString)
Parses a range from a string of the form "{x,y}" where x is the location and y is the length. If not parsable, an IllegalArgumentException is thrown.



Copyright © 2006 null. All Rights Reserved.