Class FileExtension


  • @Immutable
    public class FileExtension
    extends java.lang.Object
    A file extension with description. A compiler provides list of supported source file extensions with a description, which is then used in emuStudio application when opening a file.

    The file extension should be provided without the starting dot ("."), i.e. "asm" instead of ".asm". The extension is case-sensitive.

    Instances of this class can be compared using .equals() method and also put to hashed collections like HashMap or HashSet. The comparison is performed by extension only.

    • Constructor Summary

      Constructors 
      Constructor Description
      FileExtension​(java.lang.String extension, java.lang.String description)
      Creates new instance of FileExtension.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      java.lang.String getDescription()
      Returns the file-extension description.
      java.lang.String getExtension()
      Returns the file extension.
      int hashCode()  
      static java.lang.String stripKnownExtension​(java.lang.String fileName, java.lang.Iterable<FileExtension> knownExtensions)
      Strip file name extension if the extension belongs to known extensions.
      • Methods inherited from class java.lang.Object

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

      • FileExtension

        public FileExtension​(java.lang.String extension,
                             java.lang.String description)
        Creates new instance of FileExtension.
        Parameters:
        extension - Case-sensitive non-null file extension of the file, without the starting dot (example: "asm", but not ".asm").
        description - Non-null description of the file extension.
        Throws:
        java.lang.NullPointerException - if extension or description is null
    • Method Detail

      • getExtension

        public java.lang.String getExtension()
        Returns the file extension.
        Returns:
        File extension
      • getDescription

        public java.lang.String getDescription()
        Returns the file-extension description.
        Returns:
        file-extension description
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public static java.lang.String stripKnownExtension​(java.lang.String fileName,
                                                           java.lang.Iterable<FileExtension> knownExtensions)
        Strip file name extension if the extension belongs to known extensions.

        The idea is that compilers should generate file with some "output" extension, so the source extension is replaced with it. However, if the source extension is unknown, it should be preserved.

        Parameters:
        fileName - a file name
        knownExtensions - known extensions
        Returns:
        given file name stripped from extension if it belongs to known ones