
com.atlassian.clover.util.trie.FilePathPrefixTree Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clover Show documentation
Show all versions of clover Show documentation
Clover is an award winning code coverage and testing tool for Java and Groovy.
It integrates easily with Maven, Ant, Grails, Eclipse and IntelliJ IDEA
as well as with continuous integration servers such as Bamboo, Jenkins or Hudson.
Note: before Clover 4.0 this artifact was named com.cenqua.clover:clover.
The newest version!
package com.atlassian.clover.util.trie;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.List;
import java.util.StringTokenizer;
import static org.openclover.util.Lists.newArrayList;
/**
* Prefix tree working on file paths
*/
public class FilePathPrefixTree extends PrefixTree {
public static class FileKeySequence extends KeySequence {
public FileKeySequence(@NotNull final File file) {
super(filePathToSequence(file));
}
@NotNull
protected static List filePathToSequence(@NotNull final File path) {
final List sequence = newArrayList();
final StringTokenizer tokenizer = new StringTokenizer(path.getAbsolutePath(), File.separator);
while (tokenizer.hasMoreTokens()) {
sequence.add(tokenizer.nextToken());
}
return sequence;
}
}
private static final String EMPTY_KEY = "";
/**
* Create empty prefix tree with no value in the root node.
*/
public FilePathPrefixTree() {
super(NodeFactoryImpl.HASH_MAP_BACKED, EMPTY_KEY, null);
}
/**
* Create empty prefix tree with a specified value
in the root node.
*/
public FilePathPrefixTree(@Nullable final V value) {
super(NodeFactoryImpl.HASH_MAP_BACKED, EMPTY_KEY, value);
}
public void add(@NotNull final File filePath, @Nullable final V value) {
add(new FileKeySequence(filePath), value);
}
@Nullable
public Node find(@NotNull final File filePath) {
return find(new FileKeySequence(filePath));
}
@NotNull
public Node findNearest(@NotNull final File filePath) {
return findNearest(new FileKeySequence(filePath));
}
@Nullable
public Node findNearestWithValue(@NotNull final File filePath) {
return findNearestWithValue(new FileKeySequence(filePath));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy