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

org.openstreetmap.atlas.streaming.resource.FileSuffix Maven / Gradle / Ivy

There is a newer version: 7.0.8
Show newest version
package org.openstreetmap.atlas.streaming.resource;

import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

import com.google.common.base.Joiner;

/**
 * @author mgostintsev
 */
public enum FileSuffix
{
    ATLAS(".atlas"),
    CHANGESET(".cs"),
    CSV(".csv"),
    GEO_JSON(".geojson"),
    GZIP(".gz"),
    // extended csv
    EXTENDED(".ext"),
    JSON(".json"),
    NONE(""),
    OSMPBF(".osm.pbf"),
    OSM(".osm"),
    PBF(".pbf"),
    PROTOATLAS(".patlas"),
    TEMPORARY(".tmp"),
    TEXT(".txt"),
    ZIP(".zip"),
    WKT(".wkt"),
    WKB(".wkb");

    private final String suffix;

    public static FileSuffix getEnum(final String value)
    {
        return suffixFor(value).orElseThrow(
                () -> new IllegalArgumentException("No file suffix found for " + value));
    }

    public static Predicate pathFilter(final FileSuffix... listOfSuffixes)
    {
        final String suffix = Joiner.on("").join(listOfSuffixes);
        return path -> path.getFileName().toString().toLowerCase().endsWith(suffix);
    }

    public static Predicate resourceFilter(final FileSuffix... listOfSuffixes)
    {
        final String suffix = Joiner.on("").join(listOfSuffixes);
        return resource -> resource.getName().endsWith(suffix);
    }

    public static Optional suffixFor(final String value)
    {
        final String compareMe = value.toLowerCase();
        return Stream.of(FileSuffix.values())
                .filter(suffix -> compareMe.endsWith(suffix.toString())).findFirst();
    }

    FileSuffix(final String suffix)
    {
        this.suffix = suffix;
    }

    public boolean matches(final Resource resource)
    {
        final Optional foundSuffix = suffixFor(resource.getName());
        return foundSuffix.isPresent() && foundSuffix.get() == this;
    }

    @Override
    public String toString()
    {
        return this.suffix;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy