Record Class FileType

java.lang.Object
java.lang.Record
edu.cnu.mdi.dialog.FileType
Record Components:
description - user-facing filter description
extensions - accepted extensions, without leading dots

public record FileType(String description, List<String> extensions) extends Record
Describes one file type used by FileDialogs.

Extensions are stored without a leading dot and compared case-insensitively. The first extension is the preferred extension appended by ensureExtension(Path) when a save target has none of the accepted suffixes.

  • Constructor Details

    • FileType

      public FileType(String description, List<String> extensions)
      Validates and defensively copies this file-type definition.
      Throws:
      NullPointerException - if the description, list, or an extension is null
      IllegalArgumentException - if the description is blank, the list is empty, or an extension is blank
  • Method Details

    • of

      public static FileType of(String description, String... extensions)
      Convenience factory accepting varargs extensions.
      Parameters:
      description - user-facing description
      extensions - accepted extensions
      Returns:
      validated file type
    • toSwingFilter

      public FileNameExtensionFilter toSwingFilter()
      Returns:
      Swing chooser filter corresponding to this definition
    • ensureExtension

      public Path ensureExtension(Path path)
      Ensures that a save path has one of the accepted extensions.
      Parameters:
      path - proposed path
      Returns:
      original path when accepted, otherwise a sibling path with the preferred extension appended
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • extensions

      public List<String> extensions()
      Returns the value of the extensions record component.
      Returns:
      the value of the extensions record component