org.openstreetmap.atlas.streaming.resource.FileSuffix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atlas Show documentation
Show all versions of atlas Show documentation
"Library to load OSM data into an Atlas format"
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;
}
}