Package io.ocfl.core.model
Class PathBiMap
- java.lang.Object
-
- io.ocfl.core.model.PathBiMap
-
public class PathBiMap extends Object
BiDirection map implementation that focuses on OCFL structures. FileIds are digest values and are case insensitive. A single fileId can map to many paths, but a single path can only map to one fileId.
-
-
Constructor Summary
Constructors Constructor Description PathBiMap()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsFileId(String fileId)
Indicates if the specified fileId is in the mapboolean
containsPath(String path)
Indicates if the specified path is in the mapboolean
equals(Object o)
static PathBiMap
fromFileIdMap(Map<String,Set<String>> map)
Constructs a new PathBiMap from an existing map of fileIds to paths.String
getFileId(String path)
Returns the fileId associated to the path or nullMap<String,Set<String>>
getFileIdToPaths()
Returns an immutable view of the PathBiMap, mapping fileIds to paths.Set<String>
getPaths(String fileId)
Returns all of the paths associated to the fileId, or an empty set.Map<String,String>
getPathToFileId()
Returns an immutable view of the PathBiMap, mapping paths to fileIdsint
hashCode()
void
put(String fileId, String path)
Adds a new fileId => path mappingSet<String>
removeFileId(String fileId)
Removes a fileId from the map.String
removePath(String path)
Removes the path from the map.String
toString()
-
-
-
Method Detail
-
fromFileIdMap
public static PathBiMap fromFileIdMap(Map<String,Set<String>> map)
Constructs a new PathBiMap from an existing map of fileIds to paths.- Parameters:
map
- fileId => paths map- Returns:
- PathBiMap
-
containsFileId
public boolean containsFileId(String fileId)
Indicates if the specified fileId is in the map- Parameters:
fileId
- fileId- Returns:
- true if it's in the map
-
containsPath
public boolean containsPath(String path)
Indicates if the specified path is in the map- Parameters:
path
- path- Returns:
- true if it's in the map
-
put
public void put(String fileId, String path)
Adds a new fileId => path mapping- Parameters:
fileId
- fileIdpath
- path
-
getPaths
public Set<String> getPaths(String fileId)
Returns all of the paths associated to the fileId, or an empty set.- Parameters:
fileId
- fileId- Returns:
- set of paths
-
getFileId
public String getFileId(String path)
Returns the fileId associated to the path or null- Parameters:
path
- path- Returns:
- fileId or null
-
removePath
public String removePath(String path)
Removes the path from the map. If it is the only path associated to a fileId, then the fileId is also removed.- Parameters:
path
- the path to remove- Returns:
- the fileId of the path that was removed or null
-
removeFileId
public Set<String> removeFileId(String fileId)
Removes a fileId from the map. All of its paths are also removed.- Parameters:
fileId
- the fileId to remove- Returns:
- the associated paths
-
getFileIdToPaths
public Map<String,Set<String>> getFileIdToPaths()
Returns an immutable view of the PathBiMap, mapping fileIds to paths.- Returns:
- immutable fileId => paths map
-
getPathToFileId
public Map<String,String> getPathToFileId()
Returns an immutable view of the PathBiMap, mapping paths to fileIds- Returns:
- immutable path => fileId map
-
-