Class HardwareInfo

java.lang.Object
com.iizix.os.HardwareInfo

public class HardwareInfo extends Object
Hardware information class using "OSHI".
Author:
Christopher Mindus
  • Field Details

  • Method Details

    • getInstance

      public static HardwareInfo getInstance()
      Gets the instance.
    • platformOf

      public static String platformOf(String osName)
      Classifies the name of an operating system, as the Java system property os.name gives it, as a platform.
      Parameters:
      osName - The name, null or blank for an unknown platform.
      Returns:
      One of the PLATFORM_ constants.
    • platformOf

      public static String platformOf(Map<String,String> hardwareMap)
      Gets the platform a hardware map names in its PLATFORM_KEY entry.
      Parameters:
      hardwareMap - The map, null for none.
      Returns:
      The platform; PLATFORM_UNKNOWN when the map names none or one that is not a PLATFORM_ constant (a client built before the lists, or a modified one).
    • allowedEnvironmentNames

      public static Set<String> allowedEnvironmentNames(String platform)
      Gets the environment variables allowed into the hardware map on a platform.
      Parameters:
      platform - The platform, a PLATFORM_ constant.
      Returns:
      The names, empty for an unknown platform; never null, never modifiable.
    • isAllowedEnvironmentName

      public static boolean isAllowedEnvironmentName(String platform, String name)
      Tells whether an environment variable is allowed into the hardware map on a platform.
      Parameters:
      platform - The platform.
      name - The variable's name, null for none.
      Returns:
      true when it is on the platform's list.
    • isAllowedSystemPropertyName

      public static boolean isAllowedSystemPropertyName(String platform, String name)
      Tells whether a Java system property is allowed into the hardware map on a platform: on a known platform the shared ones, which describe the Java runtime, the operating system, the encodings and the locale (StringMapProp.isSharedSystemProperty(String)); none on an unknown platform.
      Parameters:
      platform - The platform.
      name - The property's name, null for none.
      Returns:
      true when it is allowed.
    • isAllowedEntry

      public static boolean isAllowedEntry(String platform, String name)
      Tells whether an entry of the hardware map is allowed on a platform: an Env- entry whose variable is on the platform's list, a SysProp- entry whose property is shared, and every other entry (the hardware itself).
      Parameters:
      platform - The platform.
      name - The entry's name, null for none.
      Returns:
      true when it is allowed.
    • retainAllowedEntries

      public static int retainAllowedEntries(Map<String,String> hardwareMap)
      Removes from a hardware map every Env- and SysProp- entry that the platform the map names does not allow: what the License Server does with a map it receives, so that a client built before the lists, or a modified one, cannot fill its table. A map that names no platform keeps none of them.
      Parameters:
      hardwareMap - The map, null for none.
      Returns:
      The number of entries removed.
    • getProperties

      public LinkedHashMap<String,String> getProperties()
      Gets the map of all hardware properties.
      Returns:
      The linked hash map.
    • toString

      public String toString()
      Outputs the info as a string.
      Overrides:
      toString in class Object
      Returns:
      A debug string.
    • get

      public String get(HardwareIdentication info, boolean fresh, boolean update, String... ipAddresses)
      Gets the information as specified by the hardware information.
      Parameters:
      info - The hardware information to return.
      fresh - Flag indicating the information must be fresh (in case hardware has changed).
      update - Flag to update refreshed information.
      ipAddresses - Only these addresses will be included. If the list is empty, all are included.

      This list of addresses is only used for for:
      - HardwareIdentication.HostAddressesIPv4,
      - HardwareIdentication.HostNamesWithDomain, and
      - HardwareIdentication.HostNames.

      Note: the flags "fresh" and "update" are not used if you specify a specific list of IP addresses.

      Returns:
      The string formatted according to specification of the "info".