View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi;
6   
7   /**
8    * An enumeration of supported operating systems. The order of declaration matches the osType constants in the JNA
9    * Platform class.
10   */
11  public enum PlatformEnum {
12      /**
13       * macOS
14       */
15      MACOS("macOS"),
16      /**
17       * A flavor of Linux
18       */
19      LINUX("Linux"),
20      /**
21       * Microsoft Windows
22       */
23      WINDOWS("Windows"),
24      /**
25       * Solaris (SunOS)
26       */
27      SOLARIS("Solaris"),
28      /**
29       * FreeBSD
30       */
31      FREEBSD("FreeBSD"),
32      /**
33       * OpenBSD
34       */
35      OPENBSD("OpenBSD"),
36      /**
37       * Windows Embedded Compact
38       */
39      WINDOWSCE("Windows CE"),
40      /**
41       * IBM AIX
42       */
43      AIX("AIX"),
44      /**
45       * Android
46       */
47      ANDROID("Android"),
48      /**
49       * GNU operating system
50       */
51      GNU("GNU"),
52      /**
53       * Debian GNU/kFreeBSD
54       */
55      KFREEBSD("kFreeBSD"),
56      /**
57       * NetBSD
58       */
59      NETBSD("NetBSD"),
60      /**
61       * An unspecified system
62       */
63      UNKNOWN("Unknown");
64  
65      private final String name;
66  
67      PlatformEnum(String name) {
68          this.name = name;
69      }
70  
71      /**
72       * Gets the friendly name of the platform
73       *
74       * @return the friendly name of the platform
75       */
76      public String getName() {
77          return this.name;
78      }
79  
80      /**
81       * Gets the friendly name of the specified JNA Platform type
82       *
83       * @param osType The constant returned from JNA's {@link com.sun.jna.Platform#getOSType()} method.
84       * @return the friendly name of the specified JNA Platform type
85       */
86      public static String getName(int osType) {
87          return getValue(osType).getName();
88      }
89  
90      /**
91       * Gets the value corresponding to the specified JNA Platform type
92       *
93       * @param osType The constant returned from JNA's {@link com.sun.jna.Platform#getOSType()} method.
94       * @return the value corresponding to the specified JNA Platform type
95       */
96      public static PlatformEnum getValue(int osType) {
97          if (osType < 0 || osType >= UNKNOWN.ordinal()) {
98              return UNKNOWN;
99          }
100         return values()[osType];
101     }
102 }