package com.epson.iprint.apf;

import java.io.File;
import java.util.HashMap;

class ImageSizeConversionCache {
    private HashMap<String, CacheInfo> mHash = new HashMap<>();

    ImageSizeConversionCache() {
    }

    public String getFilename(String str, ConvertCondition convertCondition) {
        CacheInfo cacheInfo = this.mHash.get(str);
        if (cacheInfo == null) {
            return null;
        }
        if (cacheInfo.isValid(convertCondition)) {
            return cacheInfo.getFilename();
        }
        String filename = cacheInfo.getFilename();
        if (filename != null) {
            File file = new File(filename);
            if (file.exists()) {
                file.delete();
            }
        }
        this.mHash.remove(str);
        return null;
    }

    public void setFilename(String str, ConvertCondition convertCondition, String str2) {
        this.mHash.put(str, new CacheInfo(convertCondition, str2));
    }

    public void invalidateCache() {
        this.mHash.clear();
    }

    public static class CacheInfo {
        ConvertCondition mCacheCondition;
        String mFileName;

        public CacheInfo(ConvertCondition convertCondition, String str) {
            this.mCacheCondition = convertCondition;
            this.mFileName = str;
        }

        public String getFilename() {
            return this.mFileName;
        }

        public boolean isValid(ConvertCondition convertCondition) {
            return this.mCacheCondition.myEquals(convertCondition);
        }
    }

    public static class ConvertCondition {
        public int mColorValue;
        public int mHeight;
        public int mWidth;

        public ConvertCondition(int i, int i2, int i3) {
            this.mWidth = i;
            this.mHeight = i2;
            this.mColorValue = i3;
        }

        public boolean myEquals(ConvertCondition convertCondition) {
            return this.mWidth == convertCondition.mWidth && this.mHeight == convertCondition.mHeight && this.mColorValue == convertCondition.mColorValue;
        }
    }
}
