net.amygdalum.util.text.CharRangeAccumulator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compilerutils Show documentation
Show all versions of compilerutils Show documentation
Utility classes needed for search and compiler applications
The newest version!
package net.amygdalum.util.text;
import static java.lang.Character.MAX_VALUE;
import static java.lang.Character.MIN_VALUE;
import java.util.List;
import net.amygdalum.util.builders.Lists;
public class CharRangeAccumulator {
private List ranges;
public CharRangeAccumulator() {
ranges = Lists.of(new CharRange(MIN_VALUE, MAX_VALUE));
}
public List getRanges() {
return ranges;
}
public void split(char from, char to) {
for (int i = 0; i < ranges.size(); i++) {
CharRange currentRange = ranges.get(i);
if (currentRange.contains(from) && currentRange.contains(to)) {
i = replace(i, currentRange.splitAround(from, to));
} else if (currentRange.contains(from)) {
i = replace(i, currentRange.splitBefore(from));
} else if (currentRange.contains(to)) {
i = replace(i, currentRange.splitAfter(to));
}
}
}
private int replace(int i, List replacement) {
ranges.remove(i);
ranges.addAll(i, replacement);
return i + replacement.size() - 1;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy