@Test public void testLastItemSmallerLinear() throws InvalidMarkupException { VirtualCharSequence vcs = new XmlToStringWrapper(new NodeList()); int[] l = new int[]{1, 5, 7, 9}; assert (vcs.lastItemSmallerLinear(l, 2, 3, 4, true) == 0); assert (vcs.lastItemSmallerLinear(l, 2, 3, 4, false) == 0); assert (vcs.lastItemSmallerLinear(l, 2, 3, 4, true) == 0); assert (vcs.lastItemSmallerLinear(l, 2, 3, 4, true) == 0); assert (vcs.lastItemSmallerLinear(l, 5, 0, 4, false) == 0); l = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, 13, 14, 15}; assert (vcs.lastItemSmallerLinear(l, 12, 12, 16, false) == 11); assert (vcs.lastItemSmallerLinear(l, 12, 12, 16, true) == 11); l = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1}; assert (vcs.lastItemSmallerLinear(l, 15, 15, 16, false) == 14); l = new int[]{0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26}; assert (vcs.lastItemSmallerLinear(l, 0, 0, 27, false) == -1); assert (vcs.lastItemSmallerLinear(l, 0, 0, 27, true) == 0); l = new int[]{0, 1, 2, 3, 4, 5, 5, 5, 5, 9, 10, 11, 12, 13, 14, -1}; assert (vcs.lastItemSmallerLinear(l, 5, 15, 16, true) == 8); assert (vcs.lastItemSmallerLinear(l, 6, 15, 16, false) == 8); assert (vcs.lastItemSmallerLinear(l, 5, 0, 16, true) == 8); assert (vcs.lastItemSmallerLinear(l, 6, 0, 16, false) == 8); assert (vcs.lastItemSmallerLinear(l, 5, 7, 16, true) == 8); assert (vcs.lastItemSmallerLinear(l, 6, 7, 16, false) == 8); assert (vcs.lastItemSmallerLinear(l, 5, 2000, 16, true) == 8); assert (vcs.lastItemSmallerLinear(l, 6, -1000, 16, false) == 8); }
protected int lastItemSmallerLinear(int[] l, int value, int startAt, int endAt, boolean orEqual) { if (startAt > endAt) startAt = endAt; if (startAt < 0) startAt = 0; assert (endAt <= l.length); int lastIx = -1; for (int i = startAt; i < endAt; i++) { int val = l[i]; if (val == -1) continue; if (orEqual) { if (val <= value) lastIx = i; else if (lastIx > -1) return lastIx; } else { if (val < value) lastIx = i; else if (lastIx > -1) return lastIx; } } if (lastIx == -1) { for (int i = startAt - 1; i >= 0; i--) { int val = l[i]; if (val == -1) continue; if (orEqual && val <= value) return i; if (!orEqual && val < value) return i; } } return lastIx; }
VirtualCharSequence implements CharSequence { protected int lastItemSmallerLinear(int[] l, int value, int startAt, int endAt, boolean orEqual) { if (startAt > endAt) startAt = endAt; if (startAt < 0) startAt = 0; assert (endAt <= l.length); int lastIx = -1; for (int i = startAt; i < endAt; i++) { int val = l[i]; if (val == -1) continue; if (orEqual) { if (val <= value) lastIx = i; else if (lastIx > -1) return lastIx; } else { if (val < value) lastIx = i; else if (lastIx > -1) return lastIx; } } if (lastIx == -1) { for (int i = startAt - 1; i >= 0; i--) { int val = l[i]; if (val == -1) continue; if (orEqual && val <= value) return i; if (!orEqual && val < value) return i; } } return lastIx; } }
VirtualCharSequence implements CharSequence { protected int lastItemSmallerLinear(int[] l, int value, int startAt, int endAt, boolean orEqual) { if (startAt > endAt) startAt = endAt; if (startAt < 0) startAt = 0; assert (endAt <= l.length); int lastIx = -1; for (int i = startAt; i < endAt; i++) { int val = l[i]; if (val == -1) continue; if (orEqual) { if (val <= value) lastIx = i; else if (lastIx > -1) return lastIx; } else { if (val < value) lastIx = i; else if (lastIx > -1) return lastIx; } } if (lastIx == -1) { for (int i = startAt - 1; i >= 0; i--) { int val = l[i]; if (val == -1) continue; if (orEqual && val <= value) return i; if (!orEqual && val < value) return i; } } return lastIx; } VirtualCharSequence(List<ITextToken> textTokens);  VirtualCharSequence(List<ITextToken> textTokens, boolean decodeEntities); }
VirtualCharSequence implements CharSequence { protected int lastItemSmallerLinear(int[] l, int value, int startAt, int endAt, boolean orEqual) { if (startAt > endAt) startAt = endAt; if (startAt < 0) startAt = 0; assert (endAt <= l.length); int lastIx = -1; for (int i = startAt; i < endAt; i++) { int val = l[i]; if (val == -1) continue; if (orEqual) { if (val <= value) lastIx = i; else if (lastIx > -1) return lastIx; } else { if (val < value) lastIx = i; else if (lastIx > -1) return lastIx; } } if (lastIx == -1) { for (int i = startAt - 1; i >= 0; i--) { int val = l[i]; if (val == -1) continue; if (orEqual && val <= value) return i; if (!orEqual && val < value) return i; } } return lastIx; } VirtualCharSequence(List<ITextToken> textTokens);  VirtualCharSequence(List<ITextToken> textTokens, boolean decodeEntities); List<String> getComponentStrings(); ITextToken getTokenAt(int index); char charAt(int index); VirtualCharSequence setCharAt(int index, char c); int length(); CharSequence subSequence(int start, int end); int indexOf(String s, int fromIndex); String toString(); void insert(int start, String newText); void delete(int start, int length); VirtualCharSequence replace(int start, int length, String newText); VirtualCharSequence replace(int start, int length, String newText, boolean snapNext); void replaceSmart(int start, int length, String newText); void replaceSmart(int start, int length, String newText, int secondsTimeout, boolean enableLineOptimization); void flattenArea(int start, int length); static String quoteReplacement(String s); VirtualCharSequence replaceAll(Pattern p, String replacement, boolean smartMerging); VirtualCharSequence replaceAll(String regex, String replacement, boolean smartMerging); int replaceMatch(Matcher m, String replacement, boolean smartMerging); VirtualCharSequence trimStart(); VirtualCharSequence trimEnd(); VirtualCharSequence trim(); VirtualCharSequence append(String newText); }
VirtualCharSequence implements CharSequence { protected int lastItemSmallerLinear(int[] l, int value, int startAt, int endAt, boolean orEqual) { if (startAt > endAt) startAt = endAt; if (startAt < 0) startAt = 0; assert (endAt <= l.length); int lastIx = -1; for (int i = startAt; i < endAt; i++) { int val = l[i]; if (val == -1) continue; if (orEqual) { if (val <= value) lastIx = i; else if (lastIx > -1) return lastIx; } else { if (val < value) lastIx = i; else if (lastIx > -1) return lastIx; } } if (lastIx == -1) { for (int i = startAt - 1; i >= 0; i--) { int val = l[i]; if (val == -1) continue; if (orEqual && val <= value) return i; if (!orEqual && val < value) return i; } } return lastIx; } VirtualCharSequence(List<ITextToken> textTokens);  VirtualCharSequence(List<ITextToken> textTokens, boolean decodeEntities); List<String> getComponentStrings(); ITextToken getTokenAt(int index); char charAt(int index); VirtualCharSequence setCharAt(int index, char c); int length(); CharSequence subSequence(int start, int end); int indexOf(String s, int fromIndex); String toString(); void insert(int start, String newText); void delete(int start, int length); VirtualCharSequence replace(int start, int length, String newText); VirtualCharSequence replace(int start, int length, String newText, boolean snapNext); void replaceSmart(int start, int length, String newText); void replaceSmart(int start, int length, String newText, int secondsTimeout, boolean enableLineOptimization); void flattenArea(int start, int length); static String quoteReplacement(String s); VirtualCharSequence replaceAll(Pattern p, String replacement, boolean smartMerging); VirtualCharSequence replaceAll(String regex, String replacement, boolean smartMerging); int replaceMatch(Matcher m, String replacement, boolean smartMerging); VirtualCharSequence trimStart(); VirtualCharSequence trimEnd(); VirtualCharSequence trim(); VirtualCharSequence append(String newText); public HashSet<String> deletedText; }