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

name.remal.gradle_plugins.toolkit.cache.ToolkitCacheKeyNormalizer Maven / Gradle / Ivy

There is a newer version: 0.69.7
Show newest version
package name.remal.gradle_plugins.toolkit.cache;

import static name.remal.gradle_plugins.toolkit.FileUtils.normalizeFile;
import static name.remal.gradle_plugins.toolkit.PathUtils.normalizePath;

import java.io.File;
import java.nio.file.Path;

@FunctionalInterface
public interface ToolkitCacheKeyNormalizer {

    Key normalizeKey(Key key) throws Throwable;


    default ToolkitCacheKeyNormalizer then(ToolkitCacheKeyNormalizer other) {
        return key -> {
            key = this.normalizeKey(key);
            key = other.normalizeKey(key);
            return key;
        };
    }


    @SuppressWarnings("unchecked")
    static  ToolkitCacheKeyNormalizer defaultToolkitCacheKeyNormalizer() {
        return key -> {
            if (key instanceof Path) {
                return (Key) normalizePath((Path) key);
            } else if (key instanceof File) {
                return (Key) normalizeFile((File) key);
            } else {
                return key;
            }
        };
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy