Java Code Examples for java.util.Collections.indexOfSubList()

The following are Jave code examples for showing how to use indexOfSubList() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: n4js   File: URIPropertyMatcher.java   View Source Code Vote up 6 votes
@Override
public boolean matches(Issue issue) {
	URI actualValue = getActualValue.apply(issue);
	if (actualValue == null)
		return false;

	List<String> actualSegments = actualValue.segmentsList();
	List<String> expectedSegments = expectedPattern.segmentsList();

	switch (mode) {
	case StartsWith:
		return Collections.indexOfSubList(actualSegments, expectedSegments) == 0;
	case EndsWith:
		return Collections.lastIndexOfSubList(actualSegments, expectedSegments) == actualSegments.size()
				- expectedSegments.size();
	case Equals:
		return actualSegments.equals(expectedSegments);
	}

	throw new IllegalStateException("Unknown URI property matching mode: " + mode);
}
 
Example 2
Project: deisotoper   File: Deisotoper.java   View Source Code Vote up 6 votes
private static List<PeakList> checkForContainingAndRemoveWrongSets(List<PeakList> listOfPeakLists) {
    List<PeakList> tempListOfPeakLists = new ArrayList<>(listOfPeakLists);

    for (PeakList peakList1 : listOfPeakLists) {
        for (PeakList peakList2 : listOfPeakLists) {
            if (peakList1.equals(peakList2)) {
                continue;
            }
            if (Collections.indexOfSubList(peakList1.getPeakList(), peakList2.getPeakList()) != -1) {
                if (peakList1.size() > peakList2.size()) {
                    tempListOfPeakLists.remove(peakList2);
                } else if (peakList1.size() < peakList2.size()) {
                    tempListOfPeakLists.remove(peakList1);
                }
            }
        }
    }

    tempListOfPeakLists = checkIfRemovedCorrectly(tempListOfPeakLists);

    return tempListOfPeakLists;
}
 
Example 3
Project: neoscada   File: BreadcrumbNavigator.java   View Source Code Vote up 5 votes
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;
}
 
Example 4
Project: kafka-0.11.0.0-src-with-comment   File: StickyAssignor.java   View Source Code Vote up 5 votes
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;
}
 
Example 5
Project: openjdk-jdk10   File: AnnotationDefaultNewlineTest.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    ToolBox tb = new ToolBox();
    new JavacTask(tb).sources(TestSrc).run();

    List<String> res = new JavapTask(tb)
            .options("-v")
            .classes("AnnotationDefault.class")
            .run()
            .getOutputLines(Task.OutputKind.DIRECT);

    List<String> goldenList = tb.split(ExpectedSubstring, "\n");
    Boolean found = Collections.indexOfSubList(res, goldenList) > -1;

    Assert.check(found, "expected output not found: " + ExpectedSubstring);
}
 
Example 6
Project: openjdk-jdk10   File: InvisibleParameterAnnotationsTest.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    ToolBox tb = new ToolBox();
    new JavacTask(tb).sources(TestSrc).run();

    List<String> res = new JavapTask(tb)
            .options("-v")
            .classes("Sample.class")
            .run()
            .getOutputLines(Task.OutputKind.DIRECT);

    List<String> expectedList = tb.split(ExpectedSubstring, "\n");
    Boolean found = Collections.indexOfSubList(res, expectedList) > -1;
    Assert.check(found, "expected output not found: " + ExpectedSubstring);
}
 
Example 7
Project: openjdk-jdk10   File: TestSearchPaths.java   View Source Code Vote up 4 votes
void checkPath(StandardLocation l, Mode m, List<File> expect) {
    List<File> files = getLocation(l);
    if (files == null) {
        error("location is unset: " + l);
        return;
    }

    switch (m) {
        case EQUALS:
            if (!Objects.equals(files, expect)) {
                error("location does not match the expected files: " + l);
                out.println("found:  " + files);
                out.println("expect: " + expect);
            }
            break;

        case CONTAINS:
            int containsIndex = Collections.indexOfSubList(files, expect);
            if (containsIndex == -1) {
                error("location does not contain the expected files: " + l);
                out.println("found:  " + files);
                out.println("expect: " + expect);
            }
        break;

        case STARTS_WITH:
            int startsIndex = Collections.indexOfSubList(files, expect);
            if (startsIndex != 0) {
                error("location does not start with the expected files: " + l);
                out.println("found:  " + files);
                out.println("expect: " + expect);
            }
        break;

        case ENDS_WITH:
            int endsIndex = Collections.lastIndexOfSubList(files, expect);
            if (endsIndex != files.size() - expect.size()) {
                error("location does not end with the expected files: " + l);
                out.println("found:  " + files);
                out.println("expect: " + expect);
            }
        break;

    }
}