* @return the newly created object.
*/
public SelectionRange cloneRange() {
SelectionRange dup = new SelectionRange();
dup.userDataList.addAll(userDataList);
dup.range = range.cloneRange();
return dup;
}
/**
* Returns the list of user data items
*
* @return the list (not a copy, so modifiable)
*/
public List getUserDataList() {
return userDataList;
}
/**
* Adds the contents of the list to user data list.
*
* @param list the list to add
*/
public void addAllUserData(Listlist) {
userDataList.addAll(list);
}
/**
* Checks if this SelectionRange is after the other.
*
* @param other the other range to compare
*
* @return returns <code>true</code> if this range is after
*/
public boolean isAfter(SelectionRange other) {
//compare end of other to start of this
int es = range.compareBoundaryPoints(Range.END_TO_START, other.range);
// -1 if this point before other, 0 if equal, 1 if this after other
return (es >= 0); // other is before this
}
/**
* Checks if this SelectionRange is before the other.
*
* @param other the other range to compare
*
* @return returns <code>true</code> if the other range is after this.
*/
public boolean isBefore(SelectionRange other) {
//compare start of other to end of this
int se = range.compareBoundaryPoints(Range.START_TO_END, other.range);
// -1 if this point before other, 0 if equal, 1 if this after other
return (se <= 0); // other is after this
}
/**
* Checks if this range starts before the other
*
* @param other the other range to compare
*
* @return returns <code>true</code> if this range starts before the other
*/
public boolean startsBefore(SelectionRange other) {
//compare start of other to start of this
int ss = range.compareBoundaryPoints(Range.START_TO_START, other.range);
// -1 if this point before other, 0 if equal, 1 if this after other
return (ss < 0); // if this starts before other
}
/**
* Checks if this range ends after the other
*
* @param other the other range to compare
*
* @return returns <code>true</code> if this range ends before the other
*/
public boolean endsAfter(SelectionRange other) {
//compare end of other to end of this
int ee = range.compareBoundaryPoints(Range.END_TO_END, other.range);
// -1 if this point before other, 0 if equal, 1 if this after other
return (ee > 0); // if this ends after other
}
/**
* Splits this range into two and sets this range as starting after the split.
*
* @param splitPoint the range whose start is the split point
*
* @return returns the range before the split point
*/
public SelectionRange splitBefore(SelectionRange splitPoint) {
SelectionRange before = cloneRange();
before.range.setEnd(splitPoint.range.getStartContainer(), splitPoint.range.getStartOffset());
range.setStart(splitPoint.range.getStartContainer(), splitPoint.range.getStartOffset());
return before;
}
/**