View Javadoc
1   /*
2    * Copyright 2019-2024 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware;
6   
7   import oshi.annotation.concurrent.Immutable;
8   import oshi.util.FormatUtil;
9   
10  /**
11   * The PhysicalMemory class represents a physical memory device located on a computer system and available to the
12   * operating system.
13   */
14  @Immutable
15  public class PhysicalMemory {
16  
17      private final String bankLabel;
18      private final long capacity;
19      private final long clockSpeed;
20      private final String manufacturer;
21      private final String memoryType;
22      private final String partNumber;
23      private final String serialNumber;
24  
25      public PhysicalMemory(String bankLabel, long capacity, long clockSpeed, String manufacturer, String memoryType,
26              String partNumber, String serialNumber) {
27          this.bankLabel = bankLabel;
28          this.capacity = capacity;
29          this.clockSpeed = clockSpeed;
30          this.manufacturer = manufacturer;
31          this.memoryType = memoryType;
32          this.partNumber = partNumber;
33          this.serialNumber = serialNumber;
34      }
35  
36      /**
37       * The bank and/or slot label.
38       *
39       * @return the bank label
40       */
41      public String getBankLabel() {
42          return bankLabel;
43      }
44  
45      /**
46       * The capacity of memory bank in bytes.
47       *
48       * @return the capacity
49       */
50      public long getCapacity() {
51          return capacity;
52      }
53  
54      /**
55       * The configured memory clock speed in hertz.
56       * <p>
57       * For DDR memory, this is the data transfer rate, which is a multiple of the actual bus clock speed.
58       *
59       * @return the clock speed, if avaialable. If unknown, returns -1.
60       */
61      public long getClockSpeed() {
62          return clockSpeed;
63      }
64  
65      /**
66       * The manufacturer of the physical memory.
67       *
68       * @return the manufacturer
69       */
70      public String getManufacturer() {
71          return manufacturer;
72      }
73  
74      /**
75       * The type of physical memory
76       *
77       * @return the memory type
78       */
79      public String getMemoryType() {
80          return memoryType;
81      }
82  
83      /**
84       * The part number of the physical memory
85       *
86       * @return the part number
87       */
88      public String getPartNumber() {
89          return partNumber;
90      }
91  
92      /**
93       * The serial number of the physical memory
94       *
95       * @return the serial number
96       */
97      public String getSerialNumber() {
98          return serialNumber;
99      }
100 
101     @Override
102     public String toString() {
103         StringBuilder sb = new StringBuilder();
104         sb.append("Bank label: " + getBankLabel());
105         sb.append(", Capacity: " + FormatUtil.formatBytes(getCapacity()));
106         sb.append(", Clock speed: " + FormatUtil.formatHertz(getClockSpeed()));
107         sb.append(", Manufacturer: " + getManufacturer());
108         sb.append(", Memory type: " + getMemoryType());
109         sb.append(", Part number: " + getPartNumber());
110         sb.append(", Serial number: " + getSerialNumber());
111         return sb.toString();
112     }
113 }