Package com.stardog.stark.io
Class SupportedFileFormats<T extends FileFormat>
- java.lang.Object
-
- com.stardog.stark.io.SupportedFileFormats<T>
-
public final class SupportedFileFormats<T extends FileFormat> extends java.lang.Object
Utility class to keep a list of
formats
that are supported by an application.- Since:
- 1.0
- Version:
- 1.0
- Author:
- Michael Grove
-
-
Constructor Summary
Constructors Modifier Constructor Description SupportedFileFormats()
protected
SupportedFileFormats(java.util.Set<T> theFormats, java.util.Map<java.lang.String,T> theAliases)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SupportedFileFormats<T>
add(T theFormat)
Add a new format to the list of supported formatsSupportedFileFormats<T>
alias(java.lang.String theAlias, T theFormat)
Associate an alias for the given formatboolean
contains(T theFormat)
Return whether or not the specific format is supportedvoid
forEach(java.util.function.Consumer<T> theConsumer)
java.util.Optional<T>
forFile(java.nio.file.Path thePath)
Return theformat
for the file denoted by the givenPath
.java.util.Optional<T>
forFileName(java.lang.String thePath)
java.util.Optional<T>
forMime(java.lang.String theMime)
Return theformat
which supports the given mimetypejava.util.Optional<T>
forName(java.lang.String theName)
Return theformat
with the provided name.SupportedFileFormats<T>
only(java.util.function.Predicate<T> thePredicate)
Return a newSupportedFileFormats
which contains only the formats which match the given predicate
-
-
-
Method Detail
-
add
@Nonnull public SupportedFileFormats<T> add(@Nonnull T theFormat)
Add a new format to the list of supported formats- Parameters:
theFormat
- the format to add
-
contains
public boolean contains(@Nonnull T theFormat)
Return whether or not the specific format is supported- Parameters:
theFormat
- the format- Returns:
- `true` if supported, `false` otherwise
-
alias
public SupportedFileFormats<T> alias(@Nonnull java.lang.String theAlias, @Nonnull T theFormat)
Associate an alias for the given format- Parameters:
theAlias
- the aliastheFormat
- the format
-
forFile
@Nonnull public java.util.Optional<T> forFile(@Nonnull java.nio.file.Path thePath)
Return theformat
for the file denoted by the givenPath
.- Parameters:
thePath
- the file to be parsed- Returns:
- the format
- Implementation Notes:
- This will inspect the file extension of the path and attempt to align it with the file extensions registered with all known formats. The default extensions are checked first before all other extensions are checked.
-
forFileName
@Nonnull public java.util.Optional<T> forFileName(@Nonnull java.lang.String thePath)
-
forName
@Nonnull public java.util.Optional<T> forName(@Nonnull java.lang.String theName)
Return theformat
with the provided name.
-
forMime
@Nonnull public java.util.Optional<T> forMime(@Nonnull java.lang.String theMime)
Return theformat
which supports the given mimetype- Parameters:
theMime
- the mimetype- Returns:
- the
format
that supports the mimetype - Implementation Notes:
- The default mimetypes are checked for _all_ formats before the full set of mimetypes for each format are considered.
-
only
@Nonnull public SupportedFileFormats<T> only(@Nonnull java.util.function.Predicate<T> thePredicate)
Return a newSupportedFileFormats
which contains only the formats which match the given predicate- Parameters:
thePredicate
- the predicate for filtering- Returns:
- the new `SupportedFileFormats`
-
forEach
public void forEach(@Nonnull java.util.function.Consumer<T> theConsumer)
-
-