PATH  Documentation > Mac OS X > Foundation Reference: Java



Table of Contents

NSRange


Inherits from:
Object
Implements:
Cloneable
Package:
com.apple.yellow.foundation


Class Description


An NSRange represents a range, a measurement of a segment of something linear, such as a byte stream. An NSRange has two primary values, a location and a length. The methods of NSRange give access to these values, convert between NSRanges and their string representations, test and compare ranges, and create ranges based on operations involving the union, intersection, and subtraction of two ranges.




Constants


NSRange provides the following constant as a convenience; you can use it to compare values returned by some NSRange methods:


Constant Type Description
ZeroRange NSRange An NSRange set to zero in location and length.



Method Types


Constructors
NSRange
Accessing range elements
length
location
locationInRange
Manipulating ranges
clone
rangeByIntersectingRange
rangeByUnioningRange
subtractRange
Testing ranges
equals
hashCode
intersectsRange
isEmpty
isEqualToRange
isSubrangeOfRange
maxRange
Converting between strings and NSRanges
fromString
toString


Constructors



NSRange

public NSRange()

Returns an empty NSRange.

public NSRange( int location, int length)

Initializes the NSRange with the range elements of location and length; it throws an IllegalArgumentException if either integer is negative.

public NSRange(NSRange aRange)

Initializes the new NSRange with the location and length values of aRange; this constructor is used in cloning the receiver.


Static Methods



fromString

public static NSRange fromString(String rangeAsString)

Creates an NSRange from the string rangeAsString, which must be of the form "{loc,len}" where loc is a number representing the starting location of the range and len is the range's length. Throws an IllegalArgumentException if the string is improperly formatted.

See Also: toString




Instance Methods



clone

public Object clone()

Description forthcoming.

equals

public boolean equals(Object otherObject)

Returns whether otherObject is an NSRange and is equal in location and length to the receiver.

See Also: isEqualToRange, isSubrangeOfRange



hashCode

public int hashCode()

Provide an appropriate hash code useful for storing the receiver in a hash-based data structure. This value is the sum of the receiver's location and length.

intersectsRange

public boolean intersectsRange(NSRange aRange)

Returns whether the range aRange intersects the receiver.

See Also: rangeByIntersectingRange



isEmpty

public boolean isEmpty()

Returns whether the length of the receiver is zero.

See Also: maxRange



isEqualToRange

public boolean isEqualToRange(NSRange aRange)

Returns whether the range aRange is equal in both location and length to the receiver.

See Also: equals, isSubrangeOfRange



isSubrangeOfRange

public boolean isSubrangeOfRange(NSRange aRange)

Returns whether the receiver's end points match or fall within those of range aRange.

See Also: intersectsRange



length

public int length()

Returns the length of the receiver from its starting location.

See Also: location



location

public int location()

Returns the starting location of the receiver.

See Also: length



locationInRange

public boolean locationInRange(int aLocation)

Returns whether the location aLocation comes after or matches the starting location and comes before the ending location of the receiver.

See Also: intersectsRange, location



maxRange

public int maxRange()

Returns the extent of the receiver (its starting location plus its length). This number is one greater than the last location in the range.

See Also: isEmpty, length, location



rangeByIntersectingRange

public NSRange rangeByIntersectingRange(NSRange aRange)

Returns an NSRange that is the intersection of aRange and the receiver. If the ranges do not intersect, returns an empty range (see isEmpty).

See Also: rangeByUnioningRange, subtractRange



rangeByUnioningRange

public NSRange rangeByUnioningRange(NSRange aRange)

Returns an NSRange that is the union of aRange and the receiver (a range constructed from the lowest starting location and the highest ending location of both NSRanges).

See Also: rangeByIntersectingRange, subtractRange



subtractRange

public void subtractRange( NSRange otherRange, NSMutableRange resultRange1, NSMutableRange resultRange2)

Returns the ranges resulting from the subtraction of otherRange from the receiver by modifying the mutable ranges resultRange1 and resultRange2 (provided by the caller). Either or both of the result ranges might be empty when this method returns.

See Also: isSubrangeOfRange



toString

public String toString()

Returns a String representing the receiver in the form "{loc,len}" where loc is the starting location of the range and len is its length.

See Also: fromString




Table of Contents