public class FileCache extends java.lang.Object implements ImageCache
Modifier and Type | Field and Description |
---|---|
private java.io.File |
cacheDir
The directory where the images are saved.
|
Constructor and Description |
---|
FileCache(java.io.File cacheDir)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
private java.io.File |
getImageFileName(java.lang.String faceName,
int faceChecksum)
Calculates a hashed image name to be used as a file name.
|
javax.swing.ImageIcon |
load(Face face)
Retrieves an image from the cache.
|
private javax.swing.ImageIcon |
load(java.lang.String faceName,
int faceChecksum)
Retrieves an image from the cache.
|
void |
save(Face face,
javax.swing.ImageIcon imageIcon)
Stores an
ImageIcon into the cache. |
void |
save(java.lang.String faceName,
int faceChecksum,
javax.swing.Icon imageIcon)
Stores an
ImageIcon into the cache. |
@NotNull private final java.io.File cacheDir
public FileCache(@NotNull java.io.File cacheDir)
cacheDir
- the directory where the images are saved@NotNull private java.io.File getImageFileName(@NotNull java.lang.String faceName, int faceChecksum)
faceName
- the image name to hashfaceChecksum
- the checksum to hash@Nullable public javax.swing.ImageIcon load(@NotNull Face face)
load
in interface ImageCache
face
- the face to retrievenull
if the cache does not contain the
image@Nullable private javax.swing.ImageIcon load(@NotNull java.lang.String faceName, int faceChecksum)
faceName
- the image name to retrievefaceChecksum
- the checksum to retrievenull
if the cache does not contain the
imagepublic void save(@NotNull Face face, @NotNull javax.swing.ImageIcon imageIcon)
ImageIcon
into the cache.save
in interface ImageCache
face
- the face to saveimageIcon
- the image icon to storepublic void save(@NotNull java.lang.String faceName, int faceChecksum, @NotNull javax.swing.Icon imageIcon)
ImageIcon
into the cache.faceName
- the image name to savefaceChecksum
- the checksum to saveimageIcon
- the image icon to store