Class SupportedFileFormats<T extends FileFormat>


  • 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 formats
      SupportedFileFormats<T> alias​(java.lang.String theAlias, T theFormat)
      Associate an alias for the given format
      boolean contains​(T theFormat)
      Return whether or not the specific format is supported
      void forEach​(java.util.function.Consumer<T> theConsumer)  
      java.util.Optional<T> forFile​(java.nio.file.Path thePath)
      Return the format for the file denoted by the given Path.
      java.util.Optional<T> forFileName​(java.lang.String thePath)  
      java.util.Optional<T> forMime​(java.lang.String theMime)
      Return the format which supports the given mimetype
      java.util.Optional<T> forName​(java.lang.String theName)
      Return the format with the provided name.
      SupportedFileFormats<T> only​(java.util.function.Predicate<T> thePredicate)
      Return a new SupportedFileFormats which contains only the formats which match the given predicate
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SupportedFileFormats

        public SupportedFileFormats()
      • SupportedFileFormats

        protected SupportedFileFormats​(java.util.Set<T> theFormats,
                                       java.util.Map<java.lang.String,​T> theAliases)
    • 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 alias
        theFormat - the format
      • forFile

        @Nonnull
        public java.util.Optional<T> forFile​(@Nonnull
                                             java.nio.file.Path thePath)
        Return the format for the file denoted by the given Path.
        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 the format with the provided name.
        Parameters:
        theName - the name of the format
        Returns:
        the format
        Implementation Notes:
        Format names, and function inputs, are normalized to all caps before matching and a small set of common aliases are used.
      • forMime

        @Nonnull
        public java.util.Optional<T> forMime​(@Nonnull
                                             java.lang.String theMime)
        Return the format 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 new SupportedFileFormats 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)