View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware.common;
6   
7   import static oshi.util.Memoizer.memoize;
8   
9   import java.util.function.Supplier;
10  
11  import oshi.annotation.concurrent.Immutable;
12  import oshi.hardware.Baseboard;
13  import oshi.hardware.ComputerSystem;
14  import oshi.hardware.Firmware;
15  
16  /**
17   * Computer System data.
18   */
19  @Immutable
20  public abstract class AbstractComputerSystem implements ComputerSystem {
21  
22      private final Supplier<Firmware> firmware = memoize(this::createFirmware);
23  
24      private final Supplier<Baseboard> baseboard = memoize(this::createBaseboard);
25  
26      @Override
27      public Firmware getFirmware() {
28          return firmware.get();
29      }
30  
31      /**
32       * Instantiates the platform-specific {@link Firmware} object
33       *
34       * @return platform-specific {@link Firmware} object
35       */
36      protected abstract Firmware createFirmware();
37  
38      @Override
39      public Baseboard getBaseboard() {
40          return baseboard.get();
41      }
42  
43      /**
44       * Instantiates the platform-specific {@link Baseboard} object
45       *
46       * @return platform-specific {@link Baseboard} object
47       */
48      protected abstract Baseboard createBaseboard();
49  
50      @Override
51      public String toString() {
52          StringBuilder sb = new StringBuilder();
53          sb.append("manufacturer=").append(getManufacturer()).append(", ");
54          sb.append("model=").append(getModel()).append(", ");
55          sb.append("serial number=").append(getSerialNumber()).append(", ");
56          sb.append("uuid=").append(getHardwareUUID());
57          return sb.toString();
58      }
59  }