Skip to content

Commit

Permalink
Used SortedMap as cache for FS to have consistent order in FS queries
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Feb 13, 2015
1 parent e876fb1 commit ad48493
Showing 1 changed file with 8 additions and 5 deletions.
Expand Up @@ -31,17 +31,20 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
* Cache of all files and dirs. This cache is shared amongst all project modules. Inclusion and
* exclusion patterns are already applied.
*/
public class InputPathCache implements BatchComponent {

private final Map<String, Map<String, InputFile>> inputFileCache = new LinkedHashMap<>();
private final Map<String, Map<String, InputDir>> inputDirCache = new LinkedHashMap<>();
private final Map<String, SortedMap<String, InputFile>> inputFileCache = new LinkedHashMap<>();
private final Map<String, SortedMap<String, InputDir>> inputDirCache = new LinkedHashMap<>();
private final Map<String, Map<String, InputFileMetadata>> inputFileMetadataCache = new LinkedHashMap<>();

public Iterable<InputFile> allFiles() {
Expand Down Expand Up @@ -102,23 +105,23 @@ public InputPathCache remove(String moduleKey, InputDir inputDir) {

public InputPathCache put(String moduleKey, InputFile inputFile) {
if (!inputFileCache.containsKey(moduleKey)) {
inputFileCache.put(moduleKey, new LinkedHashMap<String, InputFile>());
inputFileCache.put(moduleKey, new TreeMap<String, InputFile>());
}
inputFileCache.get(moduleKey).put(inputFile.relativePath(), inputFile);
return this;
}

public synchronized InputPathCache put(String moduleKey, String relativePath, InputFileMetadata metadata) {
if (!inputFileMetadataCache.containsKey(moduleKey)) {
inputFileMetadataCache.put(moduleKey, new LinkedHashMap<String, InputFileMetadata>());
inputFileMetadataCache.put(moduleKey, new HashMap<String, InputFileMetadata>());
}
inputFileMetadataCache.get(moduleKey).put(relativePath, metadata);
return this;
}

public InputPathCache put(String moduleKey, InputDir inputDir) {
if (!inputDirCache.containsKey(moduleKey)) {
inputDirCache.put(moduleKey, new LinkedHashMap<String, InputDir>());
inputDirCache.put(moduleKey, new TreeMap<String, InputDir>());
}
inputDirCache.get(moduleKey).put(inputDir.relativePath(), inputDir);
return this;
Expand Down

0 comments on commit ad48493

Please sign in to comment.