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

The following examples show how to use java.util.Collections#indexOfSubList() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: n4js   File: URIPropertyMatcher.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@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
/**
 * if building block can be created during choose-process, return true
 * 
 * @return
 */
private boolean isCreateButtonVisible() {
    if (!canCreate) {
        return false;
    }

    final List<String> limitTypeList = Arrays.asList(this.limitTypes);

    final String[] createAllowed = new String[] { TestFileResource.TYPE_NAME, WikiResource.TYPE_NAME, ImsCPFileResource.TYPE_NAME, SurveyFileResource.TYPE_NAME,
            BlogFileResource.TYPE_NAME, PodcastFileResource.TYPE_NAME, EPTemplateMapResource.TYPE_NAME };

    if (Collections.indexOfSubList(Arrays.asList(createAllowed), limitTypeList) != -1) {
        return true;
    }
    return false;
}
 
Example 3
public static <T> Assertor<Collection> hasExactlyInOrder(final T ... elements) {
    return new Assertor<Collection>() {

        public void assertValue(Collection value) {
            assertEquals(elements.length, value.size());
            
            boolean containsSublist = Collections.indexOfSubList((List<?>) value, Arrays.asList(elements)) != -1;
            assertTrue(
                    "Elements:" +
                    "\n" + 
                    Arrays.toString(elements) + 
                    "\n" +
                    "were not found in collection:" +
                    "\n" +
                    value, containsSublist);
        }
    };
}
 
Example 4
public static <T> Assertor<Collection> hasExactlyInOrder(final T ... elements) {
    return new Assertor<Collection>() {

        public void assertValue(Collection value) {
            assertEquals(elements.length, value.size());
            
            boolean containsSublist = Collections.indexOfSubList((List<?>) value, Arrays.asList(elements)) != -1;
            assertTrue(
                    "Elements:" +
                    "\n" + 
                    Arrays.toString(elements) + 
                    "\n" +
                    "were not found in collection:" +
                    "\n" +
                    value, containsSublist);
        }
    };
}
 
Example 5
Source Project: EDDI   File: InputParser.java    License: Apache License 2.0 6 votes vote down vote up
private List<IDictionary.IFoundWord> lookForPartlyMatch(List<IDictionary.IFoundWord> dictionaryEntries,
                                                        IDictionary.IPhrase phrase) {
    List<IDictionary.IWord> phraseWords = phrase.getWords();
    int startOfMatch = Collections.indexOfSubList(phraseWords, dictionaryEntries);
    if (startOfMatch > -1) {
        //does match
        List<IDictionary.IFoundWord> ret = new LinkedList<>();
        if (startOfMatch > 0) {
            ret.addAll(dictionaryEntries.subList(0, startOfMatch - 1));
        }
        ret.add(createPhrase(phrase, 1.0));
        int rangeOfMatch = startOfMatch + phraseWords.size();
        if (rangeOfMatch < dictionaryEntries.size()) {
            ret.addAll(dictionaryEntries.subList(rangeOfMatch, dictionaryEntries.size()));
        }

        return ret;
    } else {
        // does not match
        return dictionaryEntries;
    }
}
 
Example 6
/**
 * if building block can be imported, return true
 * 
 * @return
 */
private boolean isImportButtonVisible() {
    if (!canImport) {
        return false;
    }

    final List<String> limitTypeList = Arrays.asList(this.limitTypes);

    final String[] importAllowed = new String[] { TestFileResource.TYPE_NAME, WikiResource.TYPE_NAME, ImsCPFileResource.TYPE_NAME, ScormCPFileResource.TYPE_NAME,
            SurveyFileResource.TYPE_NAME, BlogFileResource.TYPE_NAME, PodcastFileResource.TYPE_NAME };

    if (Collections.indexOfSubList(Arrays.asList(importAllowed), limitTypeList) != -1) {
        return true;
    }

    return false;
}
 
Example 7
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 8
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 9
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 10
Source Project: Repeat   File: KeySequence.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check if two {@link KeySequence} collides when applied. Formally, return true
 * if triggering one {@link KeySequence} forces the other to be triggered. To
 * trigger a KeyChain is to press all the keys in the given order (there is no
 * constraint on releasing one key while pressing another).
 */
@Override
public boolean collideWith(KeySeries other) {
	if (getClass() != other.getClass()) {
		throw new IllegalArgumentException("Cannot compare " + getClass() + " with " + other.getClass());
	}

	List<KeyStroke> keys = getKeyStrokes();
	List<KeyStroke> otherKeys = other.getKeyStrokes();
	if (keys.size() > otherKeys.size()) {
		return Collections.indexOfSubList(keys, otherKeys) >= 0;
	} else {
		return Collections.indexOfSubList(otherKeys, keys) >= 0;
	}
}
 
Example 11
Source Project: Repeat   File: KeyChain.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check if two {@link KeyChain} will collide when applied. Formally, return
 * true if triggering one KeyChain forces the other to be triggered. To trigger
 * a {@link KeyChain} is to press all the keys in this.keys in the given order,
 * without releasing any key in the process.
 *
 * For example, A + S + D collides with A + S, but not with S + D or D + S Ctrl
 * + Shift + C does not collide with Ctrl + C
 *
 * @param other
 *            other KeyChain to check for collision.
 * @return true if this key chain collides with the other key chain
 */
@Override
public boolean collideWith(KeySeries other) {
	if (getClass() != other.getClass()) {
		throw new IllegalArgumentException("Cannot compare " + getClass() + " with " + other.getClass());
	}

	List<KeyStroke> keys = getKeyStrokes();
	List<KeyStroke> otherKeys = other.getKeyStrokes();
	if (keys.size() > otherKeys.size()) {
		return Collections.indexOfSubList(keys, otherKeys) == 0;
	} else {
		return Collections.indexOfSubList(otherKeys, keys) == 0;
	}
}
 
Example 12
Source Project: EDDI   File: ActionMatcher.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 13
Source Project: bazel   File: BuildViewTestCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Utility method for asserting that a list contains the elements of a
 * sublist. This is useful for checking that a list of arguments contains a
 * particular set of arguments.
 */
protected void assertContainsSublist(String message, List<String> list, List<String> sublist) {
  if (Collections.indexOfSubList(list, sublist) == -1) {
    fail((message == null ? "" : (message + ' '))
        + "expected: <" + list + "> to contain sublist: <" + sublist + ">");
  }
}
 
Example 14
private static String inferPackageNameFromPath(IPath javaFile, IPath workspaceRoot, String[][] srcPrefixes) {
	IPath parentPath = javaFile.removeTrailingSeparator().removeLastSegments(1);
	IPath relativePath = parentPath.makeRelativeTo(workspaceRoot);
	List<String> segments = Arrays.asList(relativePath.segments());
	for (int i = 0; i < srcPrefixes.length; i++) {
		int index = Collections.indexOfSubList(segments, Arrays.asList(srcPrefixes[i]));
		if (index > -1) {
			return String.join(JDTUtils.PERIOD, segments.subList(index + srcPrefixes[i].length, segments.size()));
		}
	}

	return String.join(JDTUtils.PERIOD, segments);
}
 
Example 15
/**
   * if building block can be created during choose-process, return true
   * 
   * @return
   */
  private boolean isCreateButtonVisible() {
if (!canCreate) { return false; }

      final List<String> limitTypeList = Arrays.asList(this.limitTypes);

      final String[] createAllowed = new String[] { TestFileResource.TYPE_NAME, WikiResource.TYPE_NAME, ImsCPFileResource.TYPE_NAME, SurveyFileResource.TYPE_NAME,
              BlogFileResource.TYPE_NAME, PodcastFileResource.TYPE_NAME, EPTemplateMapResource.TYPE_NAME };

if (Collections.indexOfSubList(Arrays.asList(createAllowed), limitTypeList) != -1) { return true; }
      return false;
  }
 
Example 16
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;

    }
}
 
Example 17
Source Project: iec61850bean   File: ClientServerITest.java    License: Apache License 2.0 4 votes vote down vote up
public static int findArray(Byte[] array, Byte[] subArray) {
  return Collections.indexOfSubList(Arrays.asList(array), Arrays.asList(subArray));
}
 
Example 18
Source Project: iec61850bean   File: ClientServerITest2.java    License: Apache License 2.0 4 votes vote down vote up
public static int findArray(Byte[] array, Byte[] subArray) {
  return Collections.indexOfSubList(Arrays.asList(array), Arrays.asList(subArray));
}
 
Example 19
Source Project: modeldb   File: BlobDAORdbImpl.java    License: Apache License 2.0 4 votes vote down vote up
boolean childContains(Set<?> list, Set<?> sublist) {
  return Collections.indexOfSubList(new LinkedList<>(list), new LinkedList<>(sublist)) != -1;
}
 
Example 20
/**
   * if building block can be imported, return true
   * 
   * @return
   */
  private boolean isImportButtonVisible() {
if (!canImport) { return false; }

      final List<String> limitTypeList = Arrays.asList(this.limitTypes);

      final String[] importAllowed = new String[] { TestFileResource.TYPE_NAME, WikiResource.TYPE_NAME, ImsCPFileResource.TYPE_NAME, ScormCPFileResource.TYPE_NAME,
              SurveyFileResource.TYPE_NAME, BlogFileResource.TYPE_NAME, PodcastFileResource.TYPE_NAME };

if (Collections.indexOfSubList(Arrays.asList(importAllowed), limitTypeList) != -1) { return true; }

      return false;
  }