MCPcopy Index your code
hub / github.com/oshi/oshi / SystemInfo

Class SystemInfo

oshi-core/src/main/java/oshi/SystemInfo.java:56–152  ·  view source on GitHub ↗

System information. This is the main entry point to OSHI. This object provides getters which instantiate the appropriate platform-specific implementations of oshi.software.os.OperatingSystem (software) and oshi.hardware.HardwareAbstractionLayer (hardware).

Source from the content-addressed store, hash-verified

54 * (software) and {@link oshi.hardware.HardwareAbstractionLayer} (hardware).
55 */
56public class SystemInfo {
57
58 // The platform isn't going to change, and making this static enables easy
59 // access from outside this class
60 private static final PlatformEnum CURRENT_PLATFORM = PlatformEnum.getValue(Platform.getOSType());
61
62 private static final String NOT_SUPPORTED = "Operating system not supported: ";
63
64 private final Supplier<OperatingSystem> os = memoize(SystemInfo::createOperatingSystem);
65
66 private final Supplier<HardwareAbstractionLayer> hardware = memoize(SystemInfo::createHardware);
67
68 /**
69 * Create a new instance of {@link SystemInfo}. This is the main entry point to
70 * OSHI and provides access to cross-platform code.
71 * <p>
72 * Platform-specific Hardware and Software objects are retrieved via memoized
73 * suppliers. To conserve memory at the cost of additional processing time,
74 * create a new version of SystemInfo() for subsequent calls. To conserve
75 * processing time at the cost of additional memory usage, re-use the same
76 * {@link SystemInfo} object for future queries.
77 */
78 public SystemInfo() {
79 // Intentionally empty, here to enable the constructor javadoc.
80 }
81
82 /**
83 * Gets the {@link PlatformEnum} value representing this system.
84 *
85 * @return Returns the current platform
86 */
87 public static PlatformEnum getCurrentPlatform() {
88 return CURRENT_PLATFORM;
89 }
90
91 /**
92 * Creates a new instance of the appropriate platform-specific
93 * {@link oshi.software.os.OperatingSystem}.
94 *
95 * @return A new instance of {@link oshi.software.os.OperatingSystem}.
96 */
97 public OperatingSystem getOperatingSystem() {
98 return os.get();
99 }
100
101 private static OperatingSystem createOperatingSystem() {
102 switch (CURRENT_PLATFORM) {
103 case WINDOWS:
104 return new WindowsOperatingSystem();
105 case LINUX:
106 return new LinuxOperatingSystem();
107 case MACOS:
108 return new MacOperatingSystem();
109 case SOLARIS:
110 return new SolarisOperatingSystem();
111 case FREEBSD:
112 return new FreeBsdOperatingSystem();
113 case AIX:

Callers

nothing calls this directly

Calls 2

getValueMethod · 0.95
memoizeMethod · 0.80

Tested by

no test coverage detected