All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.klojang.templates.x.ClassPathResolver Maven / Gradle / Ivy

The newest version!
package org.klojang.templates.x;

import org.klojang.templates.PathResolver;

import java.io.InputStream;

public final class ClassPathResolver implements PathResolver {

    private final Class clazz;

    public ClassPathResolver(Class clazz) {
        this.clazz = clazz;
    }

    @Override
    public boolean isValidPath(String path) {
        return clazz.getResource(path) != null;
    }

    @Override
    public InputStream resolve(String path) {
        return clazz.getResourceAsStream(path);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (obj instanceof ClassPathResolver cpr) {
            return clazz.getPackage() == cpr.clazz.getPackage();
        }
        return false;
    }

    @Override
    public int hashCode() {
        return clazz.getPackage().hashCode();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy