de.unibremen.informatik.st.libvcs4j.Revision Maven / Gradle / Ivy
package de.unibremen.informatik.st.libvcs4j;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
/**
* Represents the state of a VCS at a certain point in time.
*/
public interface Revision extends VCSModelElement {
/**
* Returns the id of this revision. Usually, it is the id of the commit
* that yields to this revision. However, a VCS may use a dedicated id to
* identify commits and revisions independently.
*
* @return
* The id of this revision.
*/
String getId();
/**
* @see VCSEngine#getOutput()
*
* @return
* The path to the tracked files and directories.
*/
default Path getOutput() {
return getVCSEngine().getOutput();
}
/**
* Returns all non-VCS-specific files.
*
* @return
* All non-VCS-specific files.
*/
List getFiles();
/**
* Filters the list of files returned by {@link #getFiles()} and returns
* only those whose relative path end with {@code suffix}.
*
* You may use this method to analyze a certain file type only. For
* instance, call {@code getFilesBySuffix(".java")} to get only Java files.
*
* @param suffix
* The suffix used to filter the files.
* @return
* All files whose relative path end with {@code suffix}.
*/
default List getFilesBySuffix(final String suffix) {
return getFiles().stream()
.filter(f -> f.getRelativePath().endsWith(suffix))
.collect(Collectors.toList());
}
/**
* Filters the list of files returned by {@link #getFiles()} and returns
* only those whose relative path start with {@code prefix}.
*
* You may use this method to analyze files located in a certain directory
* only. For instance, call {@code getFilesByPrefix("src/main/java")} to
* get only the files located in "src/main/java".
*
* @param prefix
* The prefix used to filter the files.
* @return
* All files whose relative path start with {@code prefix}.
*/
default List getFilesByPrefix(final String prefix) {
return getFiles().stream()
.filter(f -> f.getRelativePath().startsWith(prefix))
.collect(Collectors.toList());
}
/**
* Filters the list of files returned by {@link #getFiles()} and returns
* only those whose relative path match {@code regex}. Paths are matched
* using {@link String#matches(String)}.
*
* @param regex
* The regular expression used to filter the files.
* @return
* All files whose relative path match match {@code regex}.
*/
default List getFilesByRegex(final String regex) {
return getFiles().stream()
.filter(f -> f.getRelativePath().matches(regex))
.collect(Collectors.toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy