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.ObjectUtility class to keep a list of
formatsthat are supported by an application.- Since:
- 1.0
- Version:
- 1.0
- Author:
- Michael Grove
-
-
Constructor Summary
Constructors Modifier Constructor Description SupportedFileFormats()protectedSupportedFileFormats(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 formatbooleancontains(T theFormat)Return whether or not the specific format is supportedvoidforEach(java.util.function.Consumer<T> theConsumer)java.util.Optional<T>forFile(java.nio.file.Path thePath)Return theformatfor 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 theformatwhich supports the given mimetypejava.util.Optional<T>forName(java.lang.String theName)Return theformatwith the provided name.SupportedFileFormats<T>only(java.util.function.Predicate<T> thePredicate)Return a newSupportedFileFormatswhich 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 theformatfor 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 theformatwith the provided name.
-
forMime
@Nonnull public java.util.Optional<T> forMime(@Nonnull java.lang.String theMime)
Return theformatwhich supports the given mimetype- Parameters:
theMime- the mimetype- Returns:
- the
formatthat 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 newSupportedFileFormatswhich 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)
-
-