private boolean in(List<String> cycle, Set<List<String>> cycles) { List<String> superCycle = new ArrayList<>(cycle); superCycle.remove(superCycle.size() - 1); superCycle.addAll(cycle); for (List<String> foundCycle: cycles) { if (foundCycle.size() == cycle.size() && Collections.indexOfSubList(superCycle, foundCycle) != -1) return true; } return false; }
public static int findArray(Integer[] array, Integer[] subArray) { return Collections.indexOfSubList(Arrays.asList(array), Arrays.asList(subArray)); }
public static void assertGeneratedClassContains(File output, String[] codeFragment) { assertTrue("Code fragment \"" + join(codeFragment) + "\" should be in file " + output.getAbsolutePath(), Collections.indexOfSubList(Arrays.asList(getContents(output)), Arrays.asList(codeFragment)) != -1); }
public static void assertGeneratedClassDoesNotContain(File output, String[] codeFragment) { assertTrue("Code fragment \"" + join(codeFragment) + "\" should not be in file " + output.getAbsolutePath(), Collections.indexOfSubList(Arrays.asList(getContents(output)), Arrays.asList(codeFragment)) == -1); }
int startIdx = Collections.indexOfSubList(arrayList, subSetArrayList); if (-1 != startIdx) { int endIdx = startIdx + subSetArrayList.size() - 1; }
private boolean isSubChain ( final List<ViewInstanceDescriptor> descriptors ) { if ( this.currentChain == null || this.currentChain.isEmpty () ) { return false; } final int idx = Collections.indexOfSubList ( this.currentChain, descriptors ); return idx >= 0; }
int a [] = {4,2,1,4,2,1}; if(Collections.indexOfSubList(list, Arrays.asList(a))!=-1){ return true; } return false
Byte[] needle = { 68, 73, 67, 77 }; Byte[] hayStack = { 00, 01, 68, 73, 67, 77, 11, 45 }; location = Collections.indexOfSubList(Arrays.asList(hayStack), Arrays.asList(needle)); // location now equals 2
public static boolean arraysMatch(int[] array1, int[] array2) { return Collections.indexOfSubList( Arrays.asList(ArrayUtils.toObject(ArrayUtils.addAll(array2, array2))), Arrays.asList(ArrayUtils.toObject(array1)) ) != -1; }
List<Integer> nums = new ArrayList<>(); List<Integer> target = new ArrayList<>(Arrays.asList(new int[]{1, 3, 1})); for (int i : array) { if (i == 3 || i == 1) { nums.add(i); } } return Collections.indexOfSubList(nums, target) >= 0;
public static boolean arraysMatch(int[] array1, int[] array2) { int[] combined = new int[array2.length * 2]; System.arraycopy(array2, 0, combined, 0, array2.length); System.arraycopy(array2, 0, combined, array2.length, array2.length); return Collections.indexOfSubList(Arrays.asList(combined), Arrays.asList(array1)) != -1; }
public static boolean arraysMatch(int[] array1, int[] array2) { List<Integer> combined = new ArrayList<>(array2.length * 2); List<Integer> array2List = Arrays.asList(array2); combined.addAll(array2List); combined.addAll(array2List); return Collections.indexOfSubList(combined, Arrays.asList(array1)) != -1; }
List arrlistsrc = new ArrayList(); List arrlisttarget = new ArrayList(); arrlistsrc.add("A"); arrlistsrc.add("B"); arrlistsrc.add("C"); arrlisttarget.add("A"); arrlisttarget.add("C"); int index = Collections.indexOfSubList(arrlistsrc, arrlisttarget); // this will be -1
List<Byte> fileArr = new ArrayList(Arrays.asList(new Byte[]{1, 2, 3, 4, 5, 6})); List<Byte> toReplace = Arrays.asList(new Byte[]{3, 4}); List<Byte> replacing = Arrays.asList(new Byte[]{13, 14, 15, 16, 17, 18}); int idx = Collections.indexOfSubList(fileArr, toReplace); if (idx >= 0) { List<Byte> window = fileArr.subList(idx, idx + toReplace.size()); window.clear(); window.addAll(replacing); } System.out.println(fileArr); [1, 2, 13, 14, 15, 16, 17, 18, 5, 6]
@Override protected boolean matchesSafely(final List<T> items, final Description mismatchDescription) { final boolean hasSubsequence = Collections.indexOfSubList(items, expectedElements) != -1; if (!hasSubsequence) { mismatchDescription.appendText("input was ").appendValueList("[", ",", "]", items); } return hasSubsequence; }
int firstIndex = Collections.indexOfSubList(source, target); if (firstIndex == -1 ){ // the sublist doesn't exist } int lastIndex = Collections.lastIndexOfSubList(source, target);
public static void removeAllSubList(List<?> list, List<?> subList) { // find first occurrence of the subList in the list, O(nm) int i = Collections.indexOfSubList(list, subList); // if found if (i != -1) { // bulk remove, O(m) list.subList(i, i + subList.size()).clear(); // recurse with the rest of the list removeAllSubList(list.subList(i, list.size()), subList); } }
private static boolean subs(int[] array, int[] subsequence) { return Collections.indexOfSubList(toList(array), toList(subsequence)) >= 0; } private static List<Integer> toList(int[] array) { List<Integer> list = new ArrayList<>(array.length); for (int num : array) { list.add(num); } return list; }
private ExecutionState evaluateActions(IData<List<String>> data) { List<String> actions = Collections.emptyList(); if (data != null && data.getResult() != null) { actions = data.getResult(); } if (isActionEmpty(actions) || Collections.indexOfSubList(actions, this.actions) > -1) { return SUCCESS; } else { return FAIL; } }
private ExecutionState evaluateInputExpressions(IData<String> data) { List<Expression> inputExpressions = Collections.emptyList(); if (data != null && data.getResult() != null) { inputExpressions = expressionProvider.parseExpressions(data.getResult()); } if (isInputEmpty(inputExpressions) || Collections.indexOfSubList(inputExpressions, expressions) > -1) { return SUCCESS; } else { return FAIL; } }