org.unlaxer.Range Maven / Gradle / Ivy
package org.unlaxer;
public class Range{
public final int startIndexInclusive;
public final int endIndexExclusive;
public Range(int startIndexInclusive, int endIndexExclusive) {
super();
this.startIndexInclusive = startIndexInclusive;
this.endIndexExclusive = endIndexExclusive;
}
public Range(int startIndexInclusive) {
super();
this.startIndexInclusive = startIndexInclusive;
this.endIndexExclusive = startIndexInclusive;
}
public Range() {
super();
this.startIndexInclusive = 0;
this.endIndexExclusive = 0;
}
public boolean match(int position){
return position >=startIndexInclusive && position < endIndexExclusive;
}
public RangesRelation relation(Range other){
int otherStart = other.startIndexInclusive;
int otherEnd= other.endIndexExclusive;
if(startIndexInclusive == otherStart && endIndexExclusive == otherEnd){
return RangesRelation.equal;
}else if(startIndexInclusive >= otherStart && endIndexExclusive <= otherEnd){
return RangesRelation.outer;
}else if(startIndexInclusive <= otherStart && endIndexExclusive >= otherEnd){
return RangesRelation.inner;
}else if(startIndexInclusive >= otherEnd || endIndexExclusive <= otherStart){
return RangesRelation.notCrossed;
}
return RangesRelation.crossed;
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy