in src/prettify/parser/Util.java [222:261]
public static List<Object> removeDuplicates(List<Object> decorations, String source) {
if (decorations == null) {
throw new NullPointerException("argument 'decorations' cannot be null");
}
if (source == null) {
throw new NullPointerException("argument 'source' cannot be null");
}
if ((decorations.size() & 0x1) != 0) {
throw new IllegalArgumentException("the size of argument 'decorations' should be a multiple of 2");
}
List<Object> returnList = new ArrayList<Object>();
// use TreeMap to remove entrys with same pos
Map<Integer, Object> orderedMap = new TreeMap<Integer, Object>();
for (int i = 0, iEnd = decorations.size(); i < iEnd; i += 2) {
orderedMap.put((Integer) decorations.get(i), decorations.get(i + 1));
}
// remove adjacent style
String previousStyle = null;
for (Integer pos : orderedMap.keySet()) {
String style = (String) orderedMap.get(pos);
if (previousStyle != null && previousStyle.equals(style)) {
continue;
}
returnList.add(pos);
returnList.add(style);
previousStyle = style;
}
// remove last zero length tag
int returnListSize = returnList.size();
if (returnListSize >= 4 && returnList.get(returnListSize - 2).equals(source.length())) {
returnList.remove(returnListSize - 2);
returnList.remove(returnListSize - 2);
}
return returnList;
}