package com.philisense.www.license;

import java.io.*;

public abstract class AbstractKeyStoreParam implements KeyStoreParam
{
    private final Class clazz;
    private final String resource;
    
    protected AbstractKeyStoreParam(final Class clazz, final String resource) {
        if (null == clazz || null == resource) {
            throw new NullPointerException();
        }
        this.clazz = clazz;
        this.resource = resource;
    }
    
    @Override
    public InputStream getStream() throws IOException {
        final InputStream resourceAsStream = this.clazz.getResourceAsStream(this.resource);
        if (null == resourceAsStream) {
            throw new FileNotFoundException(this.resource);
        }
        return resourceAsStream;
    }
    
    @Override
    public final boolean equals(final Object o) {
        if (!(o instanceof AbstractKeyStoreParam)) {
            return false;
        }
        final AbstractKeyStoreParam abstractKeyStoreParam = (AbstractKeyStoreParam)o;
        return this.clazz.equals(abstractKeyStoreParam.clazz) && this.resource.equals(abstractKeyStoreParam.resource) && this.getAlias().equals(abstractKeyStoreParam.getAlias());
    }
    
    @Override
    public final int hashCode() {
        return 37 * (37 * (37 * 17 + this.clazz.hashCode()) + this.resource.hashCode()) + this.getAlias().hashCode();
    }
}
