Package limn.backend

Record Class Platform

java.lang.Object
java.lang.Record
limn.backend.Platform
Record Components:
os - the operating system family
arch - the processor architecture the JVM was built for, normalized: x86_64, aarch64, or whatever os.arch said, lower-cased, when it is neither

public record Platform(Platform.Os os, String arch) extends Record
The operating system and processor architecture this JVM runs on, answered once and from one place.

Every module has something it does differently per platform: which modifier a menu accelerator means, whether a window may carry an icon, where the system fonts live, which native library directory to load from, whether the JVM has to be started on the first thread. Each of those used to read os.name for itself, and spelled the test its own way — startsWith("Mac") here, contains("mac") there, and a contains("win") that only failed to match Darwin because the macOS test happened to come first on the same line. This is the one reading, so that a platform added or a spelling corrected is a change in one file.

It answers about the JVM, never about the machine. An x86_64 JVM under Rosetta on an Apple Silicon Mac reports os.arch=x86_64 and can load only an x86_64 library; asking the hardware would find arm64, hand the JVM a library it cannot map, and produce an UnsatisfiedLinkError that names no cause. The same holds for a 32-bit JVM on a 64-bit Windows install. So the architecture here is what the JVM says it is.

of(String, String) is the reading as a pure function of the two property values, so that every branch a caller takes can be tested on a machine that is not that platform.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The operating system families the toolkit tells apart.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a Platform record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the arch record component.
    static Platform
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
     
    boolean
     
    boolean
     
    static Platform
    of(String osName, String osArch)
    The platform a given os.name and os.arch describe.
    os()
    Returns the value of the os record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Platform

      public Platform(Platform.Os os, String arch)
      Creates an instance of a Platform record class.
      Parameters:
      os - the value for the os record component
      arch - the value for the arch record component
  • Method Details

    • current

      public static Platform current()
      Returns:
      the platform this JVM is running on, read once from the system properties
    • of

      public static Platform of(String osName, String osArch)
      The platform a given os.name and os.arch describe.

      The family is matched by substring of the lower-cased name, macOS first: mac or darwin, then win, then linux or nux. The order matters once — Darwin contains win — and this is the only place it has to be right. The architecture folds the two spellings each of the common ones has (amd64/x86_64, arm64/aarch64) into one, and passes any other through lower-cased rather than pretending to know it.

      Parameters:
      osName - what System.getProperty("os.name") answered; never null
      osArch - what System.getProperty("os.arch") answered; never null
      Returns:
      the platform they describe
    • isMacOs

      public boolean isMacOs()
      Returns:
      whether this is macOS
    • isWindows

      public boolean isWindows()
      Returns:
      whether this is Windows
    • isLinux

      public boolean isLinux()
      Returns:
      whether this is Linux
    • 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.
    • os

      public Platform.Os os()
      Returns the value of the os record component.
      Returns:
      the value of the os record component
    • arch

      public String arch()
      Returns the value of the arch record component.
      Returns:
      the value of the arch record component