PATH
Documentation >
Mac OS X >
Foundation Reference: Java
- 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
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
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
public Object clone()
Description forthcoming.
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
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.
public boolean intersectsRange(NSRange aRange)
Returns whether the range aRange intersects
the receiver.See Also: rangeByIntersectingRange
public boolean isEmpty()
Returns whether the length of the receiver is
zero.See Also: maxRange
public boolean isEqualToRange(NSRange aRange)
Returns whether the range aRange is
equal in both location and length to the receiver.See
Also: equals, isSubrangeOfRange
public boolean isSubrangeOfRange(NSRange aRange)
Returns whether the receiver's end points
match or fall within those of range aRange.See
Also: intersectsRange
public int length()
Returns the length of the receiver from its
starting location.See Also: location
public int location()
Returns the starting location of the receiver.See
Also: length
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
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
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
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
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
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