sorry this is the code you should be looking...i forgot to replace the
overlapping spans of same type with null while keeping the longest. and
then of course i have to remove all nulls from the List. I still don't
know how to reason about overlapping spans of different type.
---------------------------------------------------------------------------------------------------------------------
private Span[] untangle(List<Span> allFindings){ //list of spans comes
in sorted
List<Span> problems = new ArrayList<Span>();//all the overlaps
for (int i=1;i<allFindings.size();i++){//start from 1
Span current = allFindings.get(i);
Span previous = allFindings.get(i-1);//safe
if (current.intersects(previous)||current.crosses(previous))
if (current.getType().equals(previous.getType())){//if same type
// Span temp = ((current.length()-previous.length()) > 0) ?
current : previous;
if ((current.length()-previous.length()) > 0){
allFindings.set(i, current); //keep the longest one - current
allFindings.set(i-1, null); //put null in previous's place
}
else
allFindings.set(i, null); //put null in current's place
}
else { //add both as problems
problems.add(current);
problems.add(previous);
}
}
//get rid of potential nulls that came from the above code
allFindings.removeAll(Collections.singleton(null));
if(problems.isEmpty()) //if no problems so far do the usual
return allFindings.toArray(new Span[allFindings.size()]);
else
return sortProblems(allFindings, problems);//don't know what to
do in this method
}
-------------------------------------------------------------------------------------------------------------------------
Jim