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 = 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();
            }
        }
        mHash.remove(str);
        return null;
    }

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

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

    public static class CacheInfo {
        ConvertCondition mCacheCondition;
        String mFileName;

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

        public String getFilename() {
            return mFileName;
        }

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

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

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

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