/** * Conducts a binary search to find the index where Object * should be inserted. */ protected int findInsertionPoint(E o, int low, int high) { while (low <= high) { int mid = (low + high) >>> 1; int delta = compare(get(mid), o); if (delta > 0) { high = mid - 1; } else { low = mid + 1; } } return low; }
@Test void testComparator(){ Comparator<String> comparator = new Comparator<String>() { @Override public int compare(String str1, String str2) { if (str1 == null && str2 == null) { return 0; } if (str1 == null) { return 1; } if (str2 == null) { return -1; } return str2.compareTo(str1); } }; SortedArrayList<String> list = new SortedArrayList<>(comparator); assertNotNull(list.getComparator()); list.add("aaa"); list.add("bbb"); assertEquals(2, list.size()); assertEquals("bbb", list.get(0)); assertEquals("aaa", list.get(1)); } }
/** * Conducts a binary search to find the index where Object * should be inserted. */ protected int findInsertionPoint(final E o, int low, int high) { while (low <= high) { int mid = (low + high) >>> 1; int delta = compare(get(mid), o); if (delta > 0) { high = mid - 1; } else { low = mid + 1; } } return low; }
@Test void testRandom() { int total = 100000; ArrayList<String> randomList = new ArrayList<>(); for (int i = 0; i < total; i++) { randomList.add(RandomString.get().random(20, 'a', 'z')); } SortedArrayList<String> sortedList = new SortedArrayList<>(randomList); Collections.sort(randomList); for (int i = 0; i < total; i++) { assertEquals(randomList.get(i), sortedList.get(i)); } }
@Test void testList2() { SortedArrayList<String> list = new SortedArrayList<>(); list.add("bbb"); list.add("aaa"); assertEquals(2, list.size()); assertEquals("aaa", list.get(0)); assertEquals("bbb", list.get(1)); list.add("aa"); assertEquals(3, list.size()); assertEquals("aa", list.get(0)); list.add("a"); assertEquals(4, list.size()); assertEquals("a", list.get(0)); assertEquals(1, list.findInsertionPoint("a")); }
/** * Returns chunk <code>deep</code> of a path at <code>index</code>. */ protected String get(int index, int deep) { return list.get(index).actionPathChunks[deep]; }
/** * Conducts a binary search to find the index where Object * should be inserted. */ protected int findInsertionPoint(final E o, int low, int high) { while (low <= high) { int mid = (low + high) >>> 1; int delta = compare(get(mid), o); if (delta > 0) { high = mid - 1; } else { low = mid + 1; } } return low; }
/** * Conducts a binary search to find the index where Object * should be inserted. */ protected int findInsertionPoint(E o, int low, int high) { while (low <= high) { int mid = (low + high) >>> 1; int delta = compare(get(mid), o); if (delta > 0) { high = mid - 1; } else { low = mid + 1; } } return low; }
protected int matchChunk(String chunk, int chunkNdx, int macroNdx, int low, int high) { for (int i = low; i <= high; i++) { ActionConfigSet set = list.get(i); // check if there is a macro on this chunk position if (macroNdx >= set.actionPathMacros.length) { continue; } ActionConfigSet.PathMacro macro = set.actionPathMacros[macroNdx]; if (macro.ndx != chunkNdx) { continue; } // match macro if (chunk.startsWith(macro.left) == false) { continue; } if (chunk.endsWith(macro.right) == false) { continue; } // match value if (macro.pattern != null) { String value = chunk.substring(macro.left.length(), chunk.length() - macro.right.length()); if (macro.pattern.matcher(value).matches() == false) { continue; } } // macro found return i; } return -1; }
list.add(set); } else { set = list.get(ndx);
ActionConfigSet set = list.get(low); ActionConfig cfg = set.lookup(method);