Class Directory

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    it.tidalwave.image.metadata.EXIFDirectoryGenerated, it.tidalwave.image.metadata.IPTCDirectoryGenerated, MakerNote, XMP

    public class Directory
    extends JavaBeanSupport
    implements java.io.Serializable
    This class provides basic support for all kinds of metadata such EXIF, IPTC or maker notes.
    Author:
    Fabrizio Giudici
    See Also:
    Serialized Form
    • Field Detail

      • tagMapByCode

        protected static final java.util.Map<java.lang.String,​Directory.Tag> tagMapByCode
    • Constructor Detail

      • Directory

        public Directory()
        Creates an empty directory.
      • Directory

        public Directory​(@Nonnull
                         java.time.Instant latestModificationTime)
        Creates an empty directory with a given latest modification time.
        Parameters:
        latestModificationTime - the latest modification time
    • Method Detail

      • get

        @Nonnull
        public <T> java.util.Optional<T> get​(@Nonnull
                                             Directory.Tag<T> tag)
        Returns a value given its tag. The result is converted to the standard type of the tag (e.g. an enum).
        Type Parameters:
        T - the static type of the tag
        Parameters:
        tag - the tag to retrieve
        Returns:
        the value
      • get

        @Nonnull
        public <T,​U> java.util.Optional<T> get​(@Nonnull
                                                     Directory.Tag<U> tag,
                                                     @Nonnull
                                                     java.lang.Class<T> asType)
        Returns a value given its tag. The result is converted to the specified type, is possible.
        Type Parameters:
        U - the static type of the tag
        T - the static type of the type to convert
        Parameters:
        tag - the tag to retrieve
        asType - the type to convert the value into
        Returns:
        the value
      • get

        @Nonnull
        public <T> java.util.Optional<T> get​(@Nonnegative
                                             int code,
                                             @Nonnull
                                             java.lang.Class<T> asType)
        Returns a value given its tag. The result is converted to the specified type, is possible.
        Type Parameters:
        T - the static type of the type to convert
        Parameters:
        code - the code of the tag to retrieve
        asType - the type to convert the value into
        Returns:
        the value
      • getRaw

        @CheckForNull
        public java.lang.Object getRaw​(@Nonnegative
                                       int code)
        Returns a value given its tag code. No type conversion is applied.
        Parameters:
        code - the code of the tag to retrieve
        Returns:
        the value (can be null)
      • set

        public void set​(@Nonnull
                        Directory.Tag<?> tag,
                        java.lang.Object value)
        Sets a value for a tag. null and Optional are accepted and eventually unpacked: passing null or an empty Optional is equivalent to a call to remove(int). If the value is different from the previous one, events are fired:
        • the property name
        • empty
        • latestModificationTime
        Parameters:
        tag - the tag to retrieve
        value - the new value
      • setRaw

        public void setRaw​(@Nonnegative
                           int code,
                           java.lang.Object value)
        Sets a raw value, that is without converting any type. null and Optional are accepted and eventually unpacked: passing null or an empty Optional is equivalent to a call to remove(int). This method does not fire events.
        Parameters:
        code - the code of the tag to set
        value - the value
      • contains

        public boolean contains​(@Nonnegative
                                int code)
        Verifies if a value is present.
        Parameters:
        code - the code of the tag
        Returns:
        if the value is present
      • remove

        public void remove​(@Nonnegative
                           int code)
        Removes a value. This method does not fire events.
        Parameters:
        code - the code of the tag to remove
      • getTagInfo

        @Nonnull
        public java.util.Optional<Directory.Tag<?>> getTagInfo​(@Nonnegative
                                                               int tag)
        Returns information about a tag.
        Parameters:
        tag - the tag code
        Returns:
        the tag info
      • getTagCodes

        @Nonnull
        public int[] getTagCodes()
        Returns the tag codes contained in this directory, sorted by code.
        Returns:
        the tag codes
      • getTags

        @Nonnull
        public Directory.Tag[] getTags()
        Returns the tags contained in this directory. Tags are sorted by code.
        Returns:
        the tags
      • forEachTag

        public void forEachTag​(@Nonnull
                               java.util.function.Consumer<Directory.Tag<?>> action)
        Iterates through all the tags calling the provided action.
        Parameters:
        action - the action to call
      • forEachTag

        public void forEachTag​(@Nonnull
                               java.util.function.BiConsumer<Directory.Tag<?>,​java.lang.Object> action)
        Iterates through all the tags and related raw values calling the provided action.
        Parameters:
        action - the action to call
      • forEachTagCode

        public void forEachTagCode​(@Nonnull
                                   java.util.function.IntConsumer action)
        Iterates through all the tag codes calling the provided action.
        Parameters:
        action - the action to call
      • isEmpty

        public boolean isEmpty()
        Checks whether this directory is empty.
        Returns:
        true if this directory doesn't contain any tag
      • getSubDirectoryNames

        @Nonnull
        public java.util.Set<java.lang.String> getSubDirectoryNames()
        Returns the names of the available subdirectories.
        Returns:
        the names of subdirectories
      • getSubDirectory

        @Nonnull
        public java.util.Optional<Directory> getSubDirectory​(@Nonnull
                                                             java.lang.String name)
        Returns a subdirectory given its name.
        Parameters:
        name - the name of the subdirectory
        Returns:
        the subdirectory
      • getLatestModificationTime

        @Nonnull
        public java.time.Instant getLatestModificationTime()
        Returns the latest modification time of this object.
        Returns:
        the latest modification time
      • load

        public void load​(@Nonnull
                         DirectoryLoader loader)
        Loads tags and subdirectories from the given loader.
      • equals

        public final boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • toString

        @Nonnull
        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • touch

        protected void touch()
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toHexString

        @Nonnull
        public java.lang.String toHexString​(@Nonnull
                                            Rational[] array)
        Parameters:
        array -
        Returns:
      • isSubClass

        protected boolean isSubClass​(@Nonnull
                                     java.lang.Class aClass,
                                     @Nonnull
                                     java.lang.String ancestorClassName)
        Returns:
      • formatDateTime

        protected static java.lang.String formatDateTime​(java.time.Instant date)
      • parseDateTime

        protected static java.time.Instant parseDateTime​(java.lang.String string)