Format Java files with google-java-format Change-Id: Ie86467706af6de66e8a698fa5a7ab74102194f43
diff --git a/src/main/java/com/googlesource/gerrit/plugins/support/annotations/PluginDataPath.java b/src/main/java/com/googlesource/gerrit/plugins/support/annotations/PluginDataPath.java index 7530a12..c1b2d31 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/support/annotations/PluginDataPath.java +++ b/src/main/java/com/googlesource/gerrit/plugins/support/annotations/PluginDataPath.java
@@ -16,25 +16,22 @@ package com.googlesource.gerrit.plugins.support.annotations; -import com.google.inject.BindingAnnotation; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import com.google.inject.BindingAnnotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Local path where a plugin can store its own private data. - * <p> - * A plugin or extension may receive this string by Guice injection to discover - * a path where it can store configuration or other data that is private. - * Differently from the Gerrit @PluginData annotation, this automatically - * convert any underlying @PluginData annotation to a Path, regardless of - * the version of Gerrit used. + * + * <p>A plugin or extension may receive this string by Guice injection to discover a path where it + * can store configuration or other data that is private. Differently from the Gerrit @PluginData + * annotation, this automatically convert any underlying @PluginData annotation to a Path, + * regardless of the version of Gerrit used. */ @Target({ElementType.PARAMETER, ElementType.FIELD}) @Retention(RUNTIME) @BindingAnnotation -public @interface PluginDataPath { -} +public @interface PluginDataPath {}
diff --git a/src/main/java/org/jutils/jhardware/HardwareInfo.java b/src/main/java/org/jutils/jhardware/HardwareInfo.java index f185183..b0ae428 100644 --- a/src/main/java/org/jutils/jhardware/HardwareInfo.java +++ b/src/main/java/org/jutils/jhardware/HardwareInfo.java
@@ -17,85 +17,79 @@ import java.util.Set; import org.jutils.jhardware.info.HardwareFactory; import org.jutils.jhardware.info.InfoType; -import org.jutils.jhardware.model.BiosInfo; -import org.jutils.jhardware.model.DisplayInfo; -import org.jutils.jhardware.model.GraphicsCardInfo; import org.jutils.jhardware.model.MemoryInfo; -import org.jutils.jhardware.model.MotherboardInfo; import org.jutils.jhardware.model.NetworkInfo; import org.jutils.jhardware.model.OSInfo; import org.jutils.jhardware.model.ProcessorInfo; /** - * Static class that allows to query for Hardware details.<p> - * Each method return the information related with a different component - * (CPU, memory, motherboard....). There are some important data that comes - * typed in the response. This is the information that is common in different - * system. The complete and specific information is returned in a Map. - * + * Static class that allows to query for Hardware details. + * + * <p>Each method return the information related with a different component (CPU, memory, + * motherboard....). There are some important data that comes typed in the response. This is the + * information that is common in different system. The complete and specific information is returned + * in a Map. + * * @author Javier Garcia Alonso */ public class HardwareInfo { - - /** - * Hide constructor - */ - private HardwareInfo() { - } - - /** - * Gets information related with CPU - * - * @return object with typed common data and a map with full data - */ - public static ProcessorInfo getProcessorInfo() { - return (ProcessorInfo)HardwareFactory.get(InfoType.PROCESSOR).getInfo(); - } - - /** - * Gets information related with memory - * - * @return object with typed common data and a map with full data - */ - public static MemoryInfo getMemoryInfo() { - return (MemoryInfo)HardwareFactory.get(InfoType.MEMORY).getInfo(); - } - - /** - * Gets information related with the Operating System - * - * @return object with typed common data and a map with full data - */ - public static OSInfo getOSInfo() { - return (OSInfo)HardwareFactory.get(InfoType.OS).getInfo(); - } - - /** - * Gets information related with the Network - * - * @return object with typed common data and a map with full data - */ - public static NetworkInfo getNetworkInfo() { - return (NetworkInfo)HardwareFactory.get(InfoType.NETWORK).getInfo(); - } - - public static void main(String [] args) { - ProcessorInfo info = HardwareInfo.getProcessorInfo(); - System.out.println("Cache size: " + info.getCacheSize()); - System.out.println("Family: " + info.getFamily()); - System.out.println("Speed (Mhz): " + info.getMhz()); - System.out.println("Model: " + info.getModel()); - System.out.println("Model name: " + info.getModelName()); - System.out.println("Number of cores: " + info.getNumCores()); - System.out.println("Stepping: " + info.getStepping()); - System.out.println("Temperature: " + info.getTemperature()); - System.out.println("Vendor Id: " + info.getVendorId()); - - Set<Map.Entry<String, String>> fullInfos = info.getFullInfo().entrySet(); + /** Hide constructor */ + private HardwareInfo() {} - for(Map.Entry<String, String> fullInfo: fullInfos) { - System.out.println(fullInfo.getKey() + ": " + fullInfo.getValue()); - } + /** + * Gets information related with CPU + * + * @return object with typed common data and a map with full data + */ + public static ProcessorInfo getProcessorInfo() { + return (ProcessorInfo) HardwareFactory.get(InfoType.PROCESSOR).getInfo(); + } + + /** + * Gets information related with memory + * + * @return object with typed common data and a map with full data + */ + public static MemoryInfo getMemoryInfo() { + return (MemoryInfo) HardwareFactory.get(InfoType.MEMORY).getInfo(); + } + + /** + * Gets information related with the Operating System + * + * @return object with typed common data and a map with full data + */ + public static OSInfo getOSInfo() { + return (OSInfo) HardwareFactory.get(InfoType.OS).getInfo(); + } + + /** + * Gets information related with the Network + * + * @return object with typed common data and a map with full data + */ + public static NetworkInfo getNetworkInfo() { + return (NetworkInfo) HardwareFactory.get(InfoType.NETWORK).getInfo(); + } + + public static void main(String[] args) { + ProcessorInfo info = HardwareInfo.getProcessorInfo(); + + System.out.println("Cache size: " + info.getCacheSize()); + System.out.println("Family: " + info.getFamily()); + System.out.println("Speed (Mhz): " + info.getMhz()); + System.out.println("Model: " + info.getModel()); + System.out.println("Model name: " + info.getModelName()); + System.out.println("Number of cores: " + info.getNumCores()); + System.out.println("Stepping: " + info.getStepping()); + System.out.println("Temperature: " + info.getTemperature()); + System.out.println("Vendor Id: " + info.getVendorId()); + + Set<Map.Entry<String, String>> fullInfos = info.getFullInfo().entrySet(); + + for (Map.Entry<String, String> fullInfo : fullInfos) { + System.out.println(fullInfo.getKey() + ": " + fullInfo.getValue()); } + } }
diff --git a/src/main/java/org/jutils/jhardware/info/HardwareFactory.java b/src/main/java/org/jutils/jhardware/info/HardwareFactory.java index a041b42..1c9678e 100644 --- a/src/main/java/org/jutils/jhardware/info/HardwareFactory.java +++ b/src/main/java/org/jutils/jhardware/info/HardwareFactory.java
@@ -26,32 +26,29 @@ */ public class HardwareFactory { - /** - * Hide constructor - */ - private HardwareFactory() { - } + /** Hide constructor */ + private HardwareFactory() {} - public static HardwareInfo get(InfoType type) { - if (OSDetector.isUnix()) { - return getUnixInfo(type); - } else { - throw new UnsupportedOperationException("Your Operating System is not supported"); - } + public static HardwareInfo get(InfoType type) { + if (OSDetector.isUnix()) { + return getUnixInfo(type); + } else { + throw new UnsupportedOperationException("Your Operating System is not supported"); } + } - private static HardwareInfo getUnixInfo(InfoType type) { - switch (type) { - case PROCESSOR: - return new UnixProcessorInfo(); - case MEMORY: - return new UnixMemoryInfo(); - case OS: - return new UnixOSInfo(); - case NETWORK: - return new UnixNetworkInfo(); - default: - throw new IllegalArgumentException("Type of hardware not supported: " + type); - } + private static HardwareInfo getUnixInfo(InfoType type) { + switch (type) { + case PROCESSOR: + return new UnixProcessorInfo(); + case MEMORY: + return new UnixMemoryInfo(); + case OS: + return new UnixOSInfo(); + case NETWORK: + return new UnixNetworkInfo(); + default: + throw new IllegalArgumentException("Type of hardware not supported: " + type); } + } }
diff --git a/src/main/java/org/jutils/jhardware/info/HardwareInfo.java b/src/main/java/org/jutils/jhardware/info/HardwareInfo.java index e2d95db..f6f536b 100644 --- a/src/main/java/org/jutils/jhardware/info/HardwareInfo.java +++ b/src/main/java/org/jutils/jhardware/info/HardwareInfo.java
@@ -17,9 +17,9 @@ /** * Interface that represents a group of hardware information (cpu, memory, motherboard...) - * + * * @author Javier Garcia Alonso */ public interface HardwareInfo { - ComponentInfo getInfo(); + ComponentInfo getInfo(); }
diff --git a/src/main/java/org/jutils/jhardware/info/InfoType.java b/src/main/java/org/jutils/jhardware/info/InfoType.java index 81238bd..ecb4980 100644 --- a/src/main/java/org/jutils/jhardware/info/InfoType.java +++ b/src/main/java/org/jutils/jhardware/info/InfoType.java
@@ -15,12 +15,12 @@ /** * The type of information to retrieve - * + * * @author Javier Garcia Alonso */ public enum InfoType { - PROCESSOR, - MEMORY, - OS, - NETWORK + PROCESSOR, + MEMORY, + OS, + NETWORK }
diff --git a/src/main/java/org/jutils/jhardware/info/memory/AbstractMemoryInfo.java b/src/main/java/org/jutils/jhardware/info/memory/AbstractMemoryInfo.java index b7acd3f..150d5d2 100644 --- a/src/main/java/org/jutils/jhardware/info/memory/AbstractMemoryInfo.java +++ b/src/main/java/org/jutils/jhardware/info/memory/AbstractMemoryInfo.java
@@ -19,31 +19,28 @@ /** * Information related to Memory - * + * * @author Javier Garcia Alonso */ -public abstract class AbstractMemoryInfo implements HardwareInfo { +public abstract class AbstractMemoryInfo implements HardwareInfo { - /** - * - * @return - */ - @Override - public MemoryInfo getInfo() { - return buildFromDataMap(parseInfo()); + /** @return */ + @Override + public MemoryInfo getInfo() { + return buildFromDataMap(parseInfo()); + } + + protected abstract Map<String, String> parseInfo(); + + protected MemoryInfo buildFromDataMap(Map<String, String> dataMap) { + MemoryInfo info = new MemoryInfo(); + info.setFullInfo(dataMap); + if (dataMap != null && !dataMap.isEmpty()) { + info.setAvailableMemory(dataMap.get("MemAvailable")); + info.setFreeMemory(dataMap.get("MemFree")); + info.setTotalMemory(dataMap.get("MemTotal")); } - - protected abstract Map<String, String> parseInfo(); - - protected MemoryInfo buildFromDataMap(Map<String, String> dataMap) { - MemoryInfo info = new MemoryInfo(); - info.setFullInfo(dataMap); - if (dataMap != null && !dataMap.isEmpty()) { - info.setAvailableMemory(dataMap.get("MemAvailable")); - info.setFreeMemory(dataMap.get("MemFree")); - info.setTotalMemory(dataMap.get("MemTotal")); - } - - return info; - } + + return info; + } }
diff --git a/src/main/java/org/jutils/jhardware/info/memory/unix/UnixMemoryInfo.java b/src/main/java/org/jutils/jhardware/info/memory/unix/UnixMemoryInfo.java index 2075c89..55dd118 100644 --- a/src/main/java/org/jutils/jhardware/info/memory/unix/UnixMemoryInfo.java +++ b/src/main/java/org/jutils/jhardware/info/memory/unix/UnixMemoryInfo.java
@@ -14,40 +14,41 @@ package org.jutils.jhardware.info.memory.unix; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.jutils.jhardware.info.memory.AbstractMemoryInfo; import org.jutils.jhardware.util.HardwareInfoUtils; -import java.util.List; /** * Information related to Memory - * + * * @author Javier Garcia Alonso */ public final class UnixMemoryInfo extends AbstractMemoryInfo { - private static final String MEMINFO = "/proc/meminfo"; - - private static String getMemoryData(){ - List<String> streamMemoryInfo = HardwareInfoUtils.readFile(MEMINFO); - final StringBuilder buffer = new StringBuilder(); + private static final String MEMINFO = "/proc/meminfo"; - for (String line: streamMemoryInfo) { - buffer.append(line).append("\r\n"); - } - - return buffer.toString(); + private static String getMemoryData() { + List<String> streamMemoryInfo = HardwareInfoUtils.readFile(MEMINFO); + final StringBuilder buffer = new StringBuilder(); + + for (String line : streamMemoryInfo) { + buffer.append(line).append("\r\n"); } - @Override - protected Map<String, String> parseInfo() { - Map<String, String> memoryDataMap = new HashMap<>(); - String[] dataStringLines = getMemoryData().split("\\r?\\n"); + return buffer.toString(); + } - for (final String dataLine : dataStringLines) { - String[] dataStringInfo = dataLine.split(":"); - memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : ""); - } + @Override + protected Map<String, String> parseInfo() { + Map<String, String> memoryDataMap = new HashMap<>(); + String[] dataStringLines = getMemoryData().split("\\r?\\n"); - return memoryDataMap; - } + for (final String dataLine : dataStringLines) { + String[] dataStringInfo = dataLine.split(":"); + memoryDataMap.put( + dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : ""); + } + + return memoryDataMap; + } }
diff --git a/src/main/java/org/jutils/jhardware/info/network/AbstractNetworkInfo.java b/src/main/java/org/jutils/jhardware/info/network/AbstractNetworkInfo.java index 6142737..d8f166d 100644 --- a/src/main/java/org/jutils/jhardware/info/network/AbstractNetworkInfo.java +++ b/src/main/java/org/jutils/jhardware/info/network/AbstractNetworkInfo.java
@@ -22,44 +22,41 @@ /** * Information related to Network - * + * * @author Javier Garcia Alonso */ -public abstract class AbstractNetworkInfo implements HardwareInfo { +public abstract class AbstractNetworkInfo implements HardwareInfo { - /** - * - * @return - */ - @Override - public NetworkInfo getInfo() { - return buildFromDataMap(parseInfo()); + /** @return */ + @Override + public NetworkInfo getInfo() { + return buildFromDataMap(parseInfo()); + } + + protected abstract Map<String, String> parseInfo(); + + protected NetworkInfo buildFromDataMap(Map<String, String> dataMap) { + NetworkInfo info = new NetworkInfo(); + + List<NetworkInterfaceInfo> interfacesList = new ArrayList<>(); + if (!dataMap.isEmpty()) { + int interfacesLength = Integer.parseInt(dataMap.get("interfacesLength")); + for (int i = 1; i <= interfacesLength; i++) { + NetworkInterfaceInfo interfaceInfo = new NetworkInterfaceInfo(); + interfaceInfo.setName(dataMap.get("interface_" + i)); + interfaceInfo.setType(dataMap.get("type_" + i)); + interfaceInfo.setIpv4(dataMap.get("ipv4_" + i)); + interfaceInfo.setIpv6(dataMap.get("ipv6_" + i)); + interfaceInfo.setReceivedPackets(dataMap.get("received_packets_" + i)); + interfaceInfo.setTransmittedPackets(dataMap.get("transmitted_packets_" + i)); + interfaceInfo.setReceivedBytes(dataMap.get("received_bytes_" + i)); + interfaceInfo.setTransmittedBytes(dataMap.get("transmitted_bytes_" + i)); + interfacesList.add(interfaceInfo); + } } - - protected abstract Map<String, String> parseInfo(); - - protected NetworkInfo buildFromDataMap(Map<String, String> dataMap) { - NetworkInfo info = new NetworkInfo(); - - List<NetworkInterfaceInfo> interfacesList = new ArrayList<>(); - if (!dataMap.isEmpty()) { - int interfacesLength = Integer.parseInt(dataMap.get("interfacesLength")); - for (int i = 1; i<=interfacesLength; i++) { - NetworkInterfaceInfo interfaceInfo = new NetworkInterfaceInfo(); - interfaceInfo.setName(dataMap.get("interface_" + i)); - interfaceInfo.setType(dataMap.get("type_" + i)); - interfaceInfo.setIpv4(dataMap.get("ipv4_" + i)); - interfaceInfo.setIpv6(dataMap.get("ipv6_" + i)); - interfaceInfo.setReceivedPackets(dataMap.get("received_packets_" + i)); - interfaceInfo.setTransmittedPackets(dataMap.get("transmitted_packets_" + i)); - interfaceInfo.setReceivedBytes(dataMap.get("received_bytes_" + i)); - interfaceInfo.setTransmittedBytes(dataMap.get("transmitted_bytes_" + i)); - interfacesList.add(interfaceInfo); - } - } - - info.setNetworkInterfaces(interfacesList); - - return info; - } + + info.setNetworkInterfaces(interfacesList); + + return info; + } }
diff --git a/src/main/java/org/jutils/jhardware/info/network/unix/UnixNetworkInfo.java b/src/main/java/org/jutils/jhardware/info/network/unix/UnixNetworkInfo.java index 9e152e0..959751c 100644 --- a/src/main/java/org/jutils/jhardware/info/network/unix/UnixNetworkInfo.java +++ b/src/main/java/org/jutils/jhardware/info/network/unix/UnixNetworkInfo.java
@@ -23,63 +23,74 @@ * * @author Javier Garcia Alonso */ -public final class UnixNetworkInfo extends AbstractNetworkInfo { +public final class UnixNetworkInfo extends AbstractNetworkInfo { - private static String getNetworkData() { - return HardwareInfoUtils.executeCommand("ifconfig", "-a"); - } + private static String getNetworkData() { + return HardwareInfoUtils.executeCommand("ifconfig", "-a"); + } - @Override - protected Map<String, String> parseInfo() { - Map<String, String> networkDataMap = new HashMap<>(); + @Override + protected Map<String, String> parseInfo() { + Map<String, String> networkDataMap = new HashMap<>(); - String networkData = getNetworkData(); - - if (networkData != null) { - String[] dataStringLines = networkData.split("\\r?\\n"); + String networkData = getNetworkData(); - int count = 0; - for (final String dataLine : dataStringLines) { - if (!dataLine.startsWith(" ")) { - count++; - networkDataMap.put("interface_" + count, HardwareInfoUtils.extractText(dataLine, "([^\\s]+)")); - networkDataMap.put("type_" + count, HardwareInfoUtils.extractText(dataLine, "Link encap:(.+?) ")); - } else { - updateNetworkData(networkDataMap, count, dataLine); - } - } - networkDataMap.put("interfacesLength", String.valueOf(count)); + if (networkData != null) { + String[] dataStringLines = networkData.split("\\r?\\n"); + + int count = 0; + for (final String dataLine : dataStringLines) { + if (!dataLine.startsWith(" ")) { + count++; + networkDataMap.put( + "interface_" + count, HardwareInfoUtils.extractText(dataLine, "([^\\s]+)")); + networkDataMap.put( + "type_" + count, HardwareInfoUtils.extractText(dataLine, "Link encap:(.+?) ")); + } else { + updateNetworkData(networkDataMap, count, dataLine); } - - return networkDataMap; + } + networkDataMap.put("interfacesLength", String.valueOf(count)); } - private static void updateNetworkData(Map<String, String> networkDataMap, int count, String dataLine) { - String lineType = HardwareInfoUtils.extractText(dataLine, "([^\\s]+)"); - if (null != lineType) { - switch (lineType) { - case "inet": - networkDataMap.put("ipv4_" + count, HardwareInfoUtils.extractText(dataLine, "addr:(.+?) ")); - break; - case "inet6": - networkDataMap.put("ipv6_" + count, HardwareInfoUtils.extractText(dataLine, "addr:(.+?) ")); - break; - case "RX": - if (dataLine.trim().startsWith("RX packets")) { - networkDataMap.put("received_packets_" + count, HardwareInfoUtils.extractText(dataLine, "packets:(.+?) ")); - } else { - networkDataMap.put("received_bytes_" + count, HardwareInfoUtils.extractText(dataLine, "RX bytes:(.+?) ")); - networkDataMap.put("transmitted_bytes_" + count, HardwareInfoUtils.extractText(dataLine, "TX bytes:(.+?) ")); - } - break; - case "TX": - networkDataMap.put("transmitted_packets_" + count, HardwareInfoUtils.extractText(dataLine, "packets:(.+?) ")); - break; - default: - break; - } - } - } + return networkDataMap; + } - + private static void updateNetworkData( + Map<String, String> networkDataMap, int count, String dataLine) { + String lineType = HardwareInfoUtils.extractText(dataLine, "([^\\s]+)"); + if (null != lineType) { + switch (lineType) { + case "inet": + networkDataMap.put( + "ipv4_" + count, HardwareInfoUtils.extractText(dataLine, "addr:(.+?) ")); + break; + case "inet6": + networkDataMap.put( + "ipv6_" + count, HardwareInfoUtils.extractText(dataLine, "addr:(.+?) ")); + break; + case "RX": + if (dataLine.trim().startsWith("RX packets")) { + networkDataMap.put( + "received_packets_" + count, + HardwareInfoUtils.extractText(dataLine, "packets:(.+?) ")); + } else { + networkDataMap.put( + "received_bytes_" + count, + HardwareInfoUtils.extractText(dataLine, "RX bytes:(.+?) ")); + networkDataMap.put( + "transmitted_bytes_" + count, + HardwareInfoUtils.extractText(dataLine, "TX bytes:(.+?) ")); + } + break; + case "TX": + networkDataMap.put( + "transmitted_packets_" + count, + HardwareInfoUtils.extractText(dataLine, "packets:(.+?) ")); + break; + default: + break; + } + } + } }
diff --git a/src/main/java/org/jutils/jhardware/info/os/AbstractOSInfo.java b/src/main/java/org/jutils/jhardware/info/os/AbstractOSInfo.java index c37afb3..6df71e0 100644 --- a/src/main/java/org/jutils/jhardware/info/os/AbstractOSInfo.java +++ b/src/main/java/org/jutils/jhardware/info/os/AbstractOSInfo.java
@@ -19,33 +19,30 @@ /** * Information related to Operating System - * + * * @author Javier Garcia Alonso */ -public abstract class AbstractOSInfo implements HardwareInfo { +public abstract class AbstractOSInfo implements HardwareInfo { - /** - * - * @return - */ - @Override - public OSInfo getInfo() { - return buildFromDataMap(parseInfo()); + /** @return */ + @Override + public OSInfo getInfo() { + return buildFromDataMap(parseInfo()); + } + + protected abstract Map<String, String> parseInfo(); + + protected OSInfo buildFromDataMap(Map<String, String> dataMap) { + OSInfo info = new OSInfo(); + info.setFullInfo(dataMap); + + if (dataMap != null && !dataMap.isEmpty()) { + info.setName(dataMap.get("Name")); + info.setManufacturer(dataMap.get("Manufacturer")); + info.setVersion(dataMap.get("Version")); + info.setLastBootTime(dataMap.get("LastBootTime")); } - - protected abstract Map<String, String> parseInfo(); - - protected OSInfo buildFromDataMap(Map<String, String> dataMap) { - OSInfo info = new OSInfo(); - info.setFullInfo(dataMap); - - if (dataMap != null && !dataMap.isEmpty()) { - info.setName(dataMap.get("Name")); - info.setManufacturer(dataMap.get("Manufacturer")); - info.setVersion(dataMap.get("Version")); - info.setLastBootTime(dataMap.get("LastBootTime")); - } - - return info; - } + + return info; + } }
diff --git a/src/main/java/org/jutils/jhardware/info/os/unix/UnixOSInfo.java b/src/main/java/org/jutils/jhardware/info/os/unix/UnixOSInfo.java index f892eb8..4af6fd9 100644 --- a/src/main/java/org/jutils/jhardware/info/os/unix/UnixOSInfo.java +++ b/src/main/java/org/jutils/jhardware/info/os/unix/UnixOSInfo.java
@@ -32,84 +32,86 @@ */ public final class UnixOSInfo extends AbstractOSInfo { - private static final String OS_RELEASE = "/etc/os-release"; - private static final String LINE_BREAK_REGEX = "\\r?\\n"; + private static final String OS_RELEASE = "/etc/os-release"; + private static final String LINE_BREAK_REGEX = "\\r?\\n"; - private static String getOSLsbReleaseData() { - String fullData = ""; + private static String getOSLsbReleaseData() { + String fullData = ""; - fullData += HardwareInfoUtils.executeCommand("lsb_release", "-a"); + fullData += HardwareInfoUtils.executeCommand("lsb_release", "-a"); - return fullData; + return fullData; + } + + private static String getOSStartTimeData() { + String fullData = ""; + + fullData += HardwareInfoUtils.executeCommand("last", "-x"); + + return fullData; + } + + private static String getOSReleaseData() { + List<String> streamProcessorInfo = HardwareInfoUtils.readFile(OS_RELEASE); + final StringBuilder buffer = new StringBuilder(); + + for (String line : streamProcessorInfo) { + buffer.append(line).append("\r\n"); } - private static String getOSStartTimeData() { - String fullData = ""; + return buffer.toString(); + } - fullData += HardwareInfoUtils.executeCommand("last", "-x"); + @Override + protected Map<String, String> parseInfo() { + Map<String, String> osDataMap = new HashMap<>(); - return fullData; + String lsbRelease = getOSLsbReleaseData(); + String[] dataStringLines = lsbRelease.split(LINE_BREAK_REGEX); + + for (final String dataLine : dataStringLines) { + String[] dataStringInfo = dataLine.split(":"); + osDataMap.put( + dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : ""); } - private static String getOSReleaseData() { - List<String> streamProcessorInfo = HardwareInfoUtils.readFile(OS_RELEASE); - final StringBuilder buffer = new StringBuilder(); + String osRelease = getOSReleaseData(); + dataStringLines = osRelease.split(LINE_BREAK_REGEX); - for(String line: streamProcessorInfo) { - buffer.append(line).append("\r\n"); - } - - return buffer.toString(); + for (final String dataLine : dataStringLines) { + String[] dataStringInfo = dataLine.split("="); + osDataMap.put( + HardwareInfoUtils.toCamelCase("OS_" + dataStringInfo[0].trim()), + (dataStringInfo.length == 2) ? dataStringInfo[1].trim().replaceAll("\"", "") : ""); } - @Override - protected Map<String, String> parseInfo() { - Map<String, String> osDataMap = new HashMap<>(); - - String lsbRelease = getOSLsbReleaseData(); - String[] dataStringLines = lsbRelease.split(LINE_BREAK_REGEX); + String startTimeFullData = getOSStartTimeData(); + dataStringLines = startTimeFullData.split(LINE_BREAK_REGEX); - for (final String dataLine : dataStringLines) { - String[] dataStringInfo = dataLine.split(":"); - osDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : ""); - } - - String osRelease = getOSReleaseData(); - dataStringLines = osRelease.split(LINE_BREAK_REGEX); - - for (final String dataLine : dataStringLines) { - String[] dataStringInfo = dataLine.split("="); - osDataMap.put(HardwareInfoUtils.toCamelCase("OS_" + dataStringInfo[0].trim()), - (dataStringInfo.length == 2) ? dataStringInfo[1].trim().replaceAll("\"", "") : ""); - } - - String startTimeFullData = getOSStartTimeData(); - dataStringLines = startTimeFullData.split(LINE_BREAK_REGEX); - - for (final String dataLine : dataStringLines) { - if (dataLine.startsWith("reboot")) { - osDataMap.put("LastBootTime", normalizeBootUpDate(dataLine.substring(39, 55))); - break; - } - } - - //Set named data - osDataMap.put("Manufacturer", osDataMap.get("Distributor ID")); - osDataMap.put("Name", osDataMap.get("Description")); - osDataMap.put("Version", osDataMap.get("Release")); - - return osDataMap; + for (final String dataLine : dataStringLines) { + if (dataLine.startsWith("reboot")) { + osDataMap.put("LastBootTime", normalizeBootUpDate(dataLine.substring(39, 55))); + break; + } } - - private static String normalizeBootUpDate(String rawBootUpdate) { - DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm yyyy", Locale.ENGLISH); - Date returnedDate; - try{ - returnedDate = df.parse(rawBootUpdate + " " + Calendar.getInstance().get(Calendar.YEAR)); - } catch(ParseException pe) { - return rawBootUpdate; - } - - return returnedDate.toString(); + + // Set named data + osDataMap.put("Manufacturer", osDataMap.get("Distributor ID")); + osDataMap.put("Name", osDataMap.get("Description")); + osDataMap.put("Version", osDataMap.get("Release")); + + return osDataMap; + } + + private static String normalizeBootUpDate(String rawBootUpdate) { + DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm yyyy", Locale.ENGLISH); + Date returnedDate; + try { + returnedDate = df.parse(rawBootUpdate + " " + Calendar.getInstance().get(Calendar.YEAR)); + } catch (ParseException pe) { + return rawBootUpdate; } -} \ No newline at end of file + + return returnedDate.toString(); + } +}
diff --git a/src/main/java/org/jutils/jhardware/info/processor/AbstractProcessorInfo.java b/src/main/java/org/jutils/jhardware/info/processor/AbstractProcessorInfo.java index 87eeae5..84247f6 100644 --- a/src/main/java/org/jutils/jhardware/info/processor/AbstractProcessorInfo.java +++ b/src/main/java/org/jutils/jhardware/info/processor/AbstractProcessorInfo.java
@@ -19,34 +19,34 @@ /** * Information related to CPU - * + * * @author Javier Garcia Alonso */ public abstract class AbstractProcessorInfo implements HardwareInfo { - @Override - public ProcessorInfo getInfo() { - return buildFromDataMap(parseInfo()); + @Override + public ProcessorInfo getInfo() { + return buildFromDataMap(parseInfo()); + } + + protected abstract Map<String, String> parseInfo(); + + protected ProcessorInfo buildFromDataMap(Map<String, String> dataMap) { + ProcessorInfo info = new ProcessorInfo(); + info.setFullInfo(dataMap); + + if (dataMap != null && !dataMap.isEmpty()) { + info.setCacheSize(dataMap.get("cache size")); + info.setFamily(dataMap.get("cpu family")); + info.setMhz(dataMap.get("cpu MHz")); + info.setModel(dataMap.get("model")); + info.setModelName(dataMap.get("model name")); + info.setNumCores(dataMap.get("cpu cores")); + info.setStepping(dataMap.get("stepping")); + info.setTemperature(dataMap.get("temperature")); + info.setVendorId(dataMap.get("vendor_id")); } - - protected abstract Map<String, String> parseInfo(); - - protected ProcessorInfo buildFromDataMap(Map<String, String> dataMap) { - ProcessorInfo info = new ProcessorInfo(); - info.setFullInfo(dataMap); - - if (dataMap != null && !dataMap.isEmpty()) { - info.setCacheSize(dataMap.get("cache size")); - info.setFamily(dataMap.get("cpu family")); - info.setMhz(dataMap.get("cpu MHz")); - info.setModel(dataMap.get("model")); - info.setModelName(dataMap.get("model name")); - info.setNumCores(dataMap.get("cpu cores")); - info.setStepping(dataMap.get("stepping")); - info.setTemperature(dataMap.get("temperature")); - info.setVendorId(dataMap.get("vendor_id")); - } - - return info; - } + + return info; + } }
diff --git a/src/main/java/org/jutils/jhardware/info/processor/unix/UnixProcessorInfo.java b/src/main/java/org/jutils/jhardware/info/processor/unix/UnixProcessorInfo.java index 667cd4a..1799297 100644 --- a/src/main/java/org/jutils/jhardware/info/processor/unix/UnixProcessorInfo.java +++ b/src/main/java/org/jutils/jhardware/info/processor/unix/UnixProcessorInfo.java
@@ -14,11 +14,11 @@ package org.jutils.jhardware.info.processor.unix; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.jutils.jhardware.info.processor.AbstractProcessorInfo; import org.jutils.jhardware.util.HardwareInfoUtils; -import java.util.List; /** * Information related to CPU * @@ -26,29 +26,29 @@ */ public final class UnixProcessorInfo extends AbstractProcessorInfo { - private static final String CPUINFO = "/proc/cpuinfo"; + private static final String CPUINFO = "/proc/cpuinfo"; - public static String getProcessorData() { - List<String> streamProcessorInfo = HardwareInfoUtils.readFile(CPUINFO); - final StringBuilder buffer = new StringBuilder(); + public static String getProcessorData() { + List<String> streamProcessorInfo = HardwareInfoUtils.readFile(CPUINFO); + final StringBuilder buffer = new StringBuilder(); - for(String line: streamProcessorInfo) { - buffer.append(line).append("\r\n"); - } - return buffer.toString(); + for (String line : streamProcessorInfo) { + buffer.append(line).append("\r\n"); + } + return buffer.toString(); + } + + @Override + protected Map<String, String> parseInfo() { + Map<String, String> processorDataMap = new HashMap<>(); + String[] dataStringLines = getProcessorData().split("\\r?\\n"); + + for (final String dataLine : dataStringLines) { + String[] dataStringInfo = dataLine.split(":"); + processorDataMap.put( + dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : ""); } - @Override - protected Map<String, String> parseInfo() { - Map<String, String> processorDataMap = new HashMap<>(); - String[] dataStringLines = getProcessorData().split("\\r?\\n"); - - for (final String dataLine : dataStringLines) { - String[] dataStringInfo = dataLine.split(":"); - processorDataMap.put(dataStringInfo[0].trim(), - (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : ""); - } - - return processorDataMap; - } + return processorDataMap; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/BiosInfo.java b/src/main/java/org/jutils/jhardware/model/BiosInfo.java index 7076335..08fc509 100644 --- a/src/main/java/org/jutils/jhardware/model/BiosInfo.java +++ b/src/main/java/org/jutils/jhardware/model/BiosInfo.java
@@ -15,47 +15,43 @@ import java.util.Map; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class BiosInfo implements ComponentInfo { - private String date; - private String manufacturer; - private String version; - - private Map<String, String> fullInfo; + private String date; + private String manufacturer; + private String version; - public String getDate() { - return date; - } + private Map<String, String> fullInfo; - public void setDate(String date) { - this.date = date; - } + public String getDate() { + return date; + } - public String getManufacturer() { - return manufacturer; - } + public void setDate(String date) { + this.date = date; + } - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } + public String getManufacturer() { + return manufacturer; + } - public String getVersion() { - return version; - } + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } - public void setVersion(String version) { - this.version = version; - } - - public Map<String, String> getFullInfo() { - return fullInfo; - } + public String getVersion() { + return version; + } - public void setFullInfo(Map<String, String> fullInfo) { - this.fullInfo = fullInfo; - } - + public void setVersion(String version) { + this.version = version; + } + + public Map<String, String> getFullInfo() { + return fullInfo; + } + + public void setFullInfo(Map<String, String> fullInfo) { + this.fullInfo = fullInfo; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/ComponentInfo.java b/src/main/java/org/jutils/jhardware/model/ComponentInfo.java index d29199d..05628cb 100644 --- a/src/main/java/org/jutils/jhardware/model/ComponentInfo.java +++ b/src/main/java/org/jutils/jhardware/model/ComponentInfo.java
@@ -15,10 +15,5 @@ import java.io.Serializable; -/** - * - * @author Javier Garcia Alonso - */ -public interface ComponentInfo extends Serializable { - -} +/** @author Javier Garcia Alonso */ +public interface ComponentInfo extends Serializable {}
diff --git a/src/main/java/org/jutils/jhardware/model/Display.java b/src/main/java/org/jutils/jhardware/model/Display.java index 56e0808..d33aefd 100644 --- a/src/main/java/org/jutils/jhardware/model/Display.java +++ b/src/main/java/org/jutils/jhardware/model/Display.java
@@ -15,47 +15,42 @@ */ package org.jutils.jhardware.model; -/** - * - * @author javier - */ +/** @author javier */ public class Display { - private String name; - private String currentResolution; - private String refreshRate; - private String[] supportedResolutions; + private String name; + private String currentResolution; + private String refreshRate; + private String[] supportedResolutions; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } - - public String getCurrentResolution() { - return currentResolution; - } + public void setName(String name) { + this.name = name; + } - public void setCurrentResolution(String currentResolution) { - this.currentResolution = currentResolution; - } + public String getCurrentResolution() { + return currentResolution; + } - public String getRefreshRate() { - return refreshRate; - } + public void setCurrentResolution(String currentResolution) { + this.currentResolution = currentResolution; + } - public void setRefreshRate(String refreshRate) { - this.refreshRate = refreshRate; - } + public String getRefreshRate() { + return refreshRate; + } - public String[] getSupportedResolutions() { - return supportedResolutions; - } + public void setRefreshRate(String refreshRate) { + this.refreshRate = refreshRate; + } - public void setSupportedResolutions(String[] supportedResolutions) { - this.supportedResolutions = supportedResolutions; - } - - + public String[] getSupportedResolutions() { + return supportedResolutions; + } + + public void setSupportedResolutions(String[] supportedResolutions) { + this.supportedResolutions = supportedResolutions; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/DisplayInfo.java b/src/main/java/org/jutils/jhardware/model/DisplayInfo.java index 3004b16..838bf3e 100644 --- a/src/main/java/org/jutils/jhardware/model/DisplayInfo.java +++ b/src/main/java/org/jutils/jhardware/model/DisplayInfo.java
@@ -15,18 +15,15 @@ import java.util.List; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class DisplayInfo implements ComponentInfo { - List<Display> displayDevices; + List<Display> displayDevices; - public List<Display> getDisplayDevices() { - return displayDevices; - } + public List<Display> getDisplayDevices() { + return displayDevices; + } - public void setDisplayDevices(List<Display> displayDevices) { - this.displayDevices = displayDevices; - } + public void setDisplayDevices(List<Display> displayDevices) { + this.displayDevices = displayDevices; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/GraphicsCard.java b/src/main/java/org/jutils/jhardware/model/GraphicsCard.java index c6078d1..2e775bb 100644 --- a/src/main/java/org/jutils/jhardware/model/GraphicsCard.java +++ b/src/main/java/org/jutils/jhardware/model/GraphicsCard.java
@@ -15,74 +15,70 @@ */ package org.jutils.jhardware.model; -/** - * - * @author javier - */ +/** @author javier */ public class GraphicsCard { - private String name; - private String manufacturer; - private String chipType; - private String dacType; - private String deviceType; - private String temperature; - private String fanSpeed; + private String name; + private String manufacturer; + private String chipType; + private String dacType; + private String deviceType; + private String temperature; + private String fanSpeed; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public String getManufacturer() { - return manufacturer; - } + public String getManufacturer() { + return manufacturer; + } - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } - public String getChipType() { - return chipType; - } + public String getChipType() { + return chipType; + } - public void setChipType(String chipType) { - this.chipType = chipType; - } + public void setChipType(String chipType) { + this.chipType = chipType; + } - public String getDacType() { - return dacType; - } + public String getDacType() { + return dacType; + } - public void setDacType(String dacType) { - this.dacType = dacType; - } + public void setDacType(String dacType) { + this.dacType = dacType; + } - public String getDeviceType() { - return deviceType; - } + public String getDeviceType() { + return deviceType; + } - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } - public String getTemperature() { - return temperature; - } + public String getTemperature() { + return temperature; + } - public void setTemperature(String temperature) { - this.temperature = temperature; - } + public void setTemperature(String temperature) { + this.temperature = temperature; + } - public String getFanSpeed() { - return fanSpeed; - } + public String getFanSpeed() { + return fanSpeed; + } - public void setFanSpeed(String fanSpeed) { - this.fanSpeed = fanSpeed; - } - + public void setFanSpeed(String fanSpeed) { + this.fanSpeed = fanSpeed; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/GraphicsCardInfo.java b/src/main/java/org/jutils/jhardware/model/GraphicsCardInfo.java index 7b6c195..615965b 100644 --- a/src/main/java/org/jutils/jhardware/model/GraphicsCardInfo.java +++ b/src/main/java/org/jutils/jhardware/model/GraphicsCardInfo.java
@@ -24,14 +24,13 @@ */ public class GraphicsCardInfo implements ComponentInfo { - List<GraphicsCard> graphicsCards; + List<GraphicsCard> graphicsCards; - public List<GraphicsCard> getGraphicsCards() { - return graphicsCards; - } + public List<GraphicsCard> getGraphicsCards() { + return graphicsCards; + } - public void setGraphicsCards(List<GraphicsCard> graphicsCards) { - this.graphicsCards = graphicsCards; - } - + public void setGraphicsCards(List<GraphicsCard> graphicsCards) { + this.graphicsCards = graphicsCards; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/MemoryInfo.java b/src/main/java/org/jutils/jhardware/model/MemoryInfo.java index 6c7fdae..37ac02b 100644 --- a/src/main/java/org/jutils/jhardware/model/MemoryInfo.java +++ b/src/main/java/org/jutils/jhardware/model/MemoryInfo.java
@@ -15,48 +15,43 @@ import java.util.Map; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class MemoryInfo implements ComponentInfo { - private String totalMemory; - private String freeMemory; - private String availableMemory; - - private Map<String, String> fullInfo; + private String totalMemory; + private String freeMemory; + private String availableMemory; - public String getTotalMemory() { - return totalMemory; - } + private Map<String, String> fullInfo; - public void setTotalMemory(String totalMemory) { - this.totalMemory = totalMemory; - } + public String getTotalMemory() { + return totalMemory; + } - public String getFreeMemory() { - return freeMemory; - } + public void setTotalMemory(String totalMemory) { + this.totalMemory = totalMemory; + } - public void setFreeMemory(String freeMemory) { - this.freeMemory = freeMemory; - } + public String getFreeMemory() { + return freeMemory; + } - public String getAvailableMemory() { - return availableMemory; - } + public void setFreeMemory(String freeMemory) { + this.freeMemory = freeMemory; + } - public void setAvailableMemory(String availableMemory) { - this.availableMemory = availableMemory; - } + public String getAvailableMemory() { + return availableMemory; + } - public Map<String, String> getFullInfo() { - return fullInfo; - } + public void setAvailableMemory(String availableMemory) { + this.availableMemory = availableMemory; + } - public void setFullInfo(Map<String, String> fullInfo) { - this.fullInfo = fullInfo; - } - - + public Map<String, String> getFullInfo() { + return fullInfo; + } + + public void setFullInfo(Map<String, String> fullInfo) { + this.fullInfo = fullInfo; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/MotherboardInfo.java b/src/main/java/org/jutils/jhardware/model/MotherboardInfo.java index 2c789bd..1e1afe6 100644 --- a/src/main/java/org/jutils/jhardware/model/MotherboardInfo.java +++ b/src/main/java/org/jutils/jhardware/model/MotherboardInfo.java
@@ -15,48 +15,44 @@ import java.util.Map; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class MotherboardInfo implements ComponentInfo { - private String name; - private String manufacturer; - private String version; + private String name; + private String manufacturer; + private String version; - private Map<String, String> fullInfo; + private Map<String, String> fullInfo; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public String getManufacturer() { - return manufacturer; - } + public String getManufacturer() { + return manufacturer; + } - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } - public Map<String, String> getFullInfo() { - return fullInfo; - } + public Map<String, String> getFullInfo() { + return fullInfo; + } - public void setFullInfo(Map<String, String> fullInfo) { - this.fullInfo = fullInfo; - } + public void setFullInfo(Map<String, String> fullInfo) { + this.fullInfo = fullInfo; + } - public String getVersion() { - return version; - } + public String getVersion() { + return version; + } - public void setVersion(String version) { - this.version = version; - } - + public void setVersion(String version) { + this.version = version; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/NetworkInfo.java b/src/main/java/org/jutils/jhardware/model/NetworkInfo.java index ce2474e..12d9c3d 100644 --- a/src/main/java/org/jutils/jhardware/model/NetworkInfo.java +++ b/src/main/java/org/jutils/jhardware/model/NetworkInfo.java
@@ -15,19 +15,15 @@ import java.util.List; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class NetworkInfo implements ComponentInfo { - private List<NetworkInterfaceInfo> networkInterfaces; + private List<NetworkInterfaceInfo> networkInterfaces; - public List<NetworkInterfaceInfo> getNetworkInterfaces() { - return networkInterfaces; - } + public List<NetworkInterfaceInfo> getNetworkInterfaces() { + return networkInterfaces; + } - public void setNetworkInterfaces(List<NetworkInterfaceInfo> networkInterfaces) { - this.networkInterfaces = networkInterfaces; - } - + public void setNetworkInterfaces(List<NetworkInterfaceInfo> networkInterfaces) { + this.networkInterfaces = networkInterfaces; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/NetworkInterfaceInfo.java b/src/main/java/org/jutils/jhardware/model/NetworkInterfaceInfo.java index 6513652..566b1cf 100644 --- a/src/main/java/org/jutils/jhardware/model/NetworkInterfaceInfo.java +++ b/src/main/java/org/jutils/jhardware/model/NetworkInterfaceInfo.java
@@ -13,81 +13,78 @@ */ package org.jutils.jhardware.model; -/** - * - * @author Javier Garcia Alonso - */ -public class NetworkInterfaceInfo implements ComponentInfo{ - private String name; - private String type; - private String ipv4; - private String ipv6; - private String receivedPackets; - private String transmittedPackets; - private String receivedBytes; - private String transmittedBytes; +/** @author Javier Garcia Alonso */ +public class NetworkInterfaceInfo implements ComponentInfo { + private String name; + private String type; + private String ipv4; + private String ipv6; + private String receivedPackets; + private String transmittedPackets; + private String receivedBytes; + private String transmittedBytes; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } - public String getIpv4() { - return ipv4; - } + public String getIpv4() { + return ipv4; + } - public void setIpv4(String ipv4) { - this.ipv4 = ipv4; - } + public void setIpv4(String ipv4) { + this.ipv4 = ipv4; + } - public String getIpv6() { - return ipv6; - } + public String getIpv6() { + return ipv6; + } - public void setIpv6(String ipv6) { - this.ipv6 = ipv6; - } + public void setIpv6(String ipv6) { + this.ipv6 = ipv6; + } - public String getReceivedPackets() { - return receivedPackets; - } + public String getReceivedPackets() { + return receivedPackets; + } - public void setReceivedPackets(String receivedPackets) { - this.receivedPackets = receivedPackets; - } + public void setReceivedPackets(String receivedPackets) { + this.receivedPackets = receivedPackets; + } - public String getTransmittedPackets() { - return transmittedPackets; - } + public String getTransmittedPackets() { + return transmittedPackets; + } - public void setTransmittedPackets(String transmittedPackets) { - this.transmittedPackets = transmittedPackets; - } + public void setTransmittedPackets(String transmittedPackets) { + this.transmittedPackets = transmittedPackets; + } - public String getReceivedBytes() { - return receivedBytes; - } + public String getReceivedBytes() { + return receivedBytes; + } - public void setReceivedBytes(String receivedBytes) { - this.receivedBytes = receivedBytes; - } + public void setReceivedBytes(String receivedBytes) { + this.receivedBytes = receivedBytes; + } - public String getTransmittedBytes() { - return transmittedBytes; - } + public String getTransmittedBytes() { + return transmittedBytes; + } - public void setTransmittedBytes(String transmittedBytes) { - this.transmittedBytes = transmittedBytes; - } + public void setTransmittedBytes(String transmittedBytes) { + this.transmittedBytes = transmittedBytes; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/OSInfo.java b/src/main/java/org/jutils/jhardware/model/OSInfo.java index d22a5c8..690f27e 100644 --- a/src/main/java/org/jutils/jhardware/model/OSInfo.java +++ b/src/main/java/org/jutils/jhardware/model/OSInfo.java
@@ -15,55 +15,51 @@ import java.util.Map; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class OSInfo implements ComponentInfo { - private String version; - private String lastBootTime; - private String name; - private String manufacturer; - private Map<String, String> fullInfo; + private String version; + private String lastBootTime; + private String name; + private String manufacturer; + private Map<String, String> fullInfo; - public String getVersion() { - return version; - } + public String getVersion() { + return version; + } - public void setVersion(String version) { - this.version = version; - } + public void setVersion(String version) { + this.version = version; + } - public String getLastBootTime() { - return lastBootTime; - } + public String getLastBootTime() { + return lastBootTime; + } - public void setLastBootTime(String lastBootTime) { - this.lastBootTime = lastBootTime; - } + public void setLastBootTime(String lastBootTime) { + this.lastBootTime = lastBootTime; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public String getManufacturer() { - return manufacturer; - } + public String getManufacturer() { + return manufacturer; + } - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } - - public Map<String, String> getFullInfo() { - return fullInfo; - } + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } - public void setFullInfo(Map<String, String> fullInfo) { - this.fullInfo = fullInfo; - } - + public Map<String, String> getFullInfo() { + return fullInfo; + } + + public void setFullInfo(Map<String, String> fullInfo) { + this.fullInfo = fullInfo; + } }
diff --git a/src/main/java/org/jutils/jhardware/model/ProcessorInfo.java b/src/main/java/org/jutils/jhardware/model/ProcessorInfo.java index 092106e..2663fb4 100644 --- a/src/main/java/org/jutils/jhardware/model/ProcessorInfo.java +++ b/src/main/java/org/jutils/jhardware/model/ProcessorInfo.java
@@ -17,99 +17,99 @@ /** * Model that encapsulates processor information - * + * * @author Javier Garcia Alonso */ -public class ProcessorInfo implements ComponentInfo{ - private String vendorId; - private String family; - private String model; - private String modelName; - private String stepping; - private String mhz; - private String cacheSize; - private String numCores; - private String temperature; - - private Map<String, String> fullInfo; +public class ProcessorInfo implements ComponentInfo { + private String vendorId; + private String family; + private String model; + private String modelName; + private String stepping; + private String mhz; + private String cacheSize; + private String numCores; + private String temperature; - public String getVendorId() { - return vendorId; - } + private Map<String, String> fullInfo; - public void setVendorId(String vendorId) { - this.vendorId = vendorId; - } + public String getVendorId() { + return vendorId; + } - public String getFamily() { - return family; - } + public void setVendorId(String vendorId) { + this.vendorId = vendorId; + } - public void setFamily(String family) { - this.family = family; - } + public String getFamily() { + return family; + } - public String getModel() { - return model; - } + public void setFamily(String family) { + this.family = family; + } - public void setModel(String model) { - this.model = model; - } + public String getModel() { + return model; + } - public String getModelName() { - return modelName; - } + public void setModel(String model) { + this.model = model; + } - public void setModelName(String modelName) { - this.modelName = modelName; - } + public String getModelName() { + return modelName; + } - public String getStepping() { - return stepping; - } + public void setModelName(String modelName) { + this.modelName = modelName; + } - public void setStepping(String stepping) { - this.stepping = stepping; - } + public String getStepping() { + return stepping; + } - public String getMhz() { - return mhz; - } + public void setStepping(String stepping) { + this.stepping = stepping; + } - public void setMhz(String mhz) { - this.mhz = mhz; - } + public String getMhz() { + return mhz; + } - public String getCacheSize() { - return cacheSize; - } + public void setMhz(String mhz) { + this.mhz = mhz; + } - public void setCacheSize(String cacheSize) { - this.cacheSize = cacheSize; - } + public String getCacheSize() { + return cacheSize; + } - public String getNumCores() { - return numCores; - } + public void setCacheSize(String cacheSize) { + this.cacheSize = cacheSize; + } - public void setNumCores(String numCores) { - this.numCores = numCores; - } + public String getNumCores() { + return numCores; + } - public String getTemperature() { - return temperature; - } + public void setNumCores(String numCores) { + this.numCores = numCores; + } - public void setTemperature(String temperature) { - this.temperature = temperature; - } + public String getTemperature() { + return temperature; + } - public Map<String, String> getFullInfo() { - return fullInfo; - } + public void setTemperature(String temperature) { + this.temperature = temperature; + } - public void setFullInfo(Map<String, String> fullInfo) { - this.fullInfo = fullInfo; - } + public Map<String, String> getFullInfo() { + return fullInfo; + } + + public void setFullInfo(Map<String, String> fullInfo) { + this.fullInfo = fullInfo; + } }
diff --git a/src/main/java/org/jutils/jhardware/util/HardwareInfoUtils.java b/src/main/java/org/jutils/jhardware/util/HardwareInfoUtils.java index a49e45d..b599e18 100644 --- a/src/main/java/org/jutils/jhardware/util/HardwareInfoUtils.java +++ b/src/main/java/org/jutils/jhardware/util/HardwareInfoUtils.java
@@ -26,125 +26,119 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * - * @author Javier Garcia Alonso - */ +/** @author Javier Garcia Alonso */ public class HardwareInfoUtils { - private static final String CRLF = "\r\n"; + private static final String CRLF = "\r\n"; - private static final String NOT_FOUND = "NOT_FOUND"; + private static final String NOT_FOUND = "NOT_FOUND"; - private static final Logger log = Logger.getLogger(HardwareInfoUtils.class.getName()); - - //Hide constructor - private HardwareInfoUtils() { + private static final Logger log = Logger.getLogger(HardwareInfoUtils.class.getName()); + // Hide constructor + private HardwareInfoUtils() {} + + public static List<String> readFile(String filePath) { + Path path = Paths.get(filePath); + + List<String> fileLines = new ArrayList<>(); + try (BufferedReader reader = new BufferedReader(new FileReader(path.toFile()))) { + String line; + while (null != (line = reader.readLine())) { + fileLines.add(line); + } + } catch (IOException ex) { + log.log(Level.SEVERE, "Unable to read file " + filePath, ex); } - public static List<String> readFile(String filePath) { - Path path = Paths.get(filePath); + return fileLines; + } - List<String> fileLines = new ArrayList<>(); - try(BufferedReader reader = new BufferedReader(new FileReader(path.toFile()))) { - String line; - while(null != (line = reader.readLine())) { - fileLines.add(line); - } - } catch (IOException ex) { - log.log(Level.SEVERE, "Unable to read file " + filePath, ex); + public static String getSingleValueFromFile(String filePath) { + try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { + return reader.readLine(); + } catch (IOException ex) { + log.log(Level.SEVERE, "Unable to read file " + filePath, ex); + return null; + } + } + + public static String executeCommand(String... command) { + String commandOutput = null; + + try { + ProcessBuilder processBuilder = new ProcessBuilder(command); + processBuilder.redirectErrorStream(true); // redirect error stream to output stream + + commandOutput = readData(processBuilder.start()); + } catch (IOException ex) { + Logger.getLogger(HardwareInfoUtils.class.getName()).log(Level.SEVERE, null, ex); + } + + return commandOutput; + } + + private static String readData(Process process) { + StringBuilder commandOutput = new StringBuilder(); + BufferedReader processOutput = null; + + try { + processOutput = new BufferedReader(new InputStreamReader(process.getInputStream())); + + String line; + while ((line = processOutput.readLine()) != null) { + if (!line.isEmpty()) { + commandOutput.append(line).append(CRLF); } - - return fileLines; - } - - public static String getSingleValueFromFile(String filePath) { - try(BufferedReader reader = new BufferedReader(new FileReader(filePath))) { - return reader.readLine(); - } catch (IOException ex) { - log.log(Level.SEVERE, "Unable to read file " + filePath, ex); - return null; + } + } catch (IOException ex) { + Logger.getLogger(HardwareInfoUtils.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + if (processOutput != null) { + processOutput.close(); } + } catch (IOException ioe) { + Logger.getLogger(HardwareInfoUtils.class.getName()).log(Level.SEVERE, null, ioe); + } } - public static String executeCommand(String... command) { - String commandOutput = null; + return commandOutput.toString(); + } - try { - ProcessBuilder processBuilder = new ProcessBuilder(command); - processBuilder.redirectErrorStream(true); // redirect error stream to output stream + public static boolean isSudo() { + return executeCommand("sudo", "-n", "true").length() == 0; + } - commandOutput = readData(processBuilder.start()); - } catch (IOException ex) { - Logger.getLogger(HardwareInfoUtils.class.getName()).log(Level.SEVERE, null, ex); - } + public static String toCamelCase(String s) { + String[] parts = s.split("_"); + String camelCaseString = ""; + for (String part : parts) { + camelCaseString = camelCaseString + toProperCase(part); + } + return camelCaseString; + } - return commandOutput; + private static String toProperCase(String s) { + return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); + } + + public static String removeAllSpaces(String s) { + return s.replaceAll("\\s+", ""); + } + + public static String extractText(String text, String regex) { + if (text.trim().isEmpty()) { + return NOT_FOUND; } - private static String readData(Process process) { - StringBuilder commandOutput = new StringBuilder(); - BufferedReader processOutput = null; + final Pattern pattern = Pattern.compile(regex); + final Matcher matcher = pattern.matcher(text); - try { - processOutput = new BufferedReader(new InputStreamReader(process.getInputStream())); - - String line; - while ((line = processOutput.readLine()) != null) { - if (!line.isEmpty()) { - commandOutput.append(line).append(CRLF); - } - } - } catch (IOException ex) { - Logger.getLogger(HardwareInfoUtils.class.getName()).log(Level.SEVERE, null, ex); - } finally { - try { - if (processOutput != null) { - processOutput.close(); - } - } catch (IOException ioe) { - Logger.getLogger(HardwareInfoUtils.class.getName()).log(Level.SEVERE, null, ioe); - } - } - - return commandOutput.toString(); + matcher.find(); + if (matcher.groupCount() > 0) { + return matcher.group(1); } - - public static boolean isSudo() { - return executeCommand("sudo", "-n", "true").length() == 0; - } - - public static String toCamelCase(String s) { - String[] parts = s.split("_"); - String camelCaseString = ""; - for (String part : parts) { - camelCaseString = camelCaseString + toProperCase(part); - } - return camelCaseString; - } - - private static String toProperCase(String s) { - return s.substring(0, 1).toUpperCase() - + s.substring(1).toLowerCase(); - } - - public static String removeAllSpaces(String s) { - return s.replaceAll("\\s+", ""); - } - - public static String extractText(String text, String regex) { - if (text.trim().isEmpty()) { - return NOT_FOUND; - } - - final Pattern pattern = Pattern.compile(regex); - final Matcher matcher = pattern.matcher(text); - - matcher.find(); - if (matcher.groupCount() > 0) { - return matcher.group(1); - } - return NOT_FOUND; - } + return NOT_FOUND; + } }
diff --git a/src/main/java/org/jutils/jhardware/util/OSDetector.java b/src/main/java/org/jutils/jhardware/util/OSDetector.java index d292627..b08e723 100644 --- a/src/main/java/org/jutils/jhardware/util/OSDetector.java +++ b/src/main/java/org/jutils/jhardware/util/OSDetector.java
@@ -15,31 +15,28 @@ /** * Detects used OS - * + * * @author Javier Garcia Alonso */ public class OSDetector { - private static final String OS = System.getProperty("os.name").toLowerCase(); - - /** - * Hide constructor - */ - private OSDetector() { - } + private static final String OS = System.getProperty("os.name").toLowerCase(); - public static boolean isWindows() { - return OS.contains("win"); - } + /** Hide constructor */ + private OSDetector() {} - public static boolean isMac() { - return OS.contains("mac"); - } + public static boolean isWindows() { + return OS.contains("win"); + } - public static boolean isUnix() { - return OS.contains("nix") || OS.contains("nux") || OS.contains("aix"); - } + public static boolean isMac() { + return OS.contains("mac"); + } - public static boolean isSolaris() { - return OS.contains("sunos"); - } + public static boolean isUnix() { + return OS.contains("nix") || OS.contains("nux") || OS.contains("aix"); + } + + public static boolean isSolaris() { + return OS.contains("sunos"); + } }