From 426c849d6da685585fb3660bc4bcc51b132ccaad Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:12:40 +0200 Subject: [PATCH 1/7] use keyword 'final' for members if possible --- src/main/java/jssc/SerialNativeAccess.java | 2 +- src/main/java/org/scream3r/jssc/SerialPort.java | 4 ++-- src/main/java/org/scream3r/jssc/SerialPortEvent.java | 6 +++--- src/main/java/org/scream3r/jssc/SerialPortException.java | 6 +++--- .../java/org/scream3r/jssc/SerialPortTimeoutException.java | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/jssc/SerialNativeAccess.java b/src/main/java/jssc/SerialNativeAccess.java index f8c163695..3158dc1d7 100644 --- a/src/main/java/jssc/SerialNativeAccess.java +++ b/src/main/java/jssc/SerialNativeAccess.java @@ -37,7 +37,7 @@ public class SerialNativeAccess { private int osType = -1; - private static SerialNativeInterface sni = new SerialNativeInterface(); + private static final SerialNativeInterface sni = new SerialNativeInterface(); private static SerialNativeAccess instance = null; public static SerialNativeAccess getInstance() { diff --git a/src/main/java/org/scream3r/jssc/SerialPort.java b/src/main/java/org/scream3r/jssc/SerialPort.java index 613dce389..12ebf1d62 100644 --- a/src/main/java/org/scream3r/jssc/SerialPort.java +++ b/src/main/java/org/scream3r/jssc/SerialPort.java @@ -35,10 +35,10 @@ */ public class SerialPort { - private SerialNativeInterface serialInterface; + private final SerialNativeInterface serialInterface; private SerialPortEventListener eventListener; private long portHandle; - private String portName; + private final String portName; private boolean portOpened = false; private boolean maskAssigned = false; private boolean eventListenerAdded = false; diff --git a/src/main/java/org/scream3r/jssc/SerialPortEvent.java b/src/main/java/org/scream3r/jssc/SerialPortEvent.java index badb83755..dc1f0d846 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortEvent.java +++ b/src/main/java/org/scream3r/jssc/SerialPortEvent.java @@ -30,9 +30,9 @@ */ public class SerialPortEvent { - private String portName; - private int eventType; - private int eventValue; + private final String portName; + private final int eventType; + private final int eventValue; public static final int RXCHAR = 1; public static final int RXFLAG = 2; diff --git a/src/main/java/org/scream3r/jssc/SerialPortException.java b/src/main/java/org/scream3r/jssc/SerialPortException.java index 8b3ad647e..3f2431de8 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortException.java +++ b/src/main/java/org/scream3r/jssc/SerialPortException.java @@ -63,9 +63,9 @@ public class SerialPortException extends Exception { */ final public static String TYPE_INCORRECT_SERIAL_PORT = "Incorrect serial port"; - private String portName; - private String methodName; - private String exceptionType; + private final String portName; + private final String methodName; + private final String exceptionType; public SerialPortException(String portName, String methodName, String exceptionType){ super("Port name - " + portName + "; Method name - " + methodName + "; Exception type - " + exceptionType + "."); diff --git a/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java b/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java index 5fb013b3d..d65a1b31c 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java +++ b/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java @@ -32,9 +32,9 @@ public class SerialPortTimeoutException extends Exception { final static long serialVersionUID = -1584357967321684324l; - private String portName; - private String methodName; - private int timeoutValue; + private final String portName; + private final String methodName; + private final int timeoutValue; public SerialPortTimeoutException(String portName, String methodName, int timeoutValue) { super("Port name - " + portName + "; Method name - " + methodName + "; Serial port operation timeout (" + timeoutValue + " ms)."); From aed4a133bb3cdd40f1ca68934cea02e4a578c429 Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:17:34 +0200 Subject: [PATCH 2/7] remove redundant if statements --- .../java/org/scream3r/jssc/SerialPort.java | 42 ++----------- .../org/scream3r/jssc/SerialPortEvent.java | 63 +++---------------- 2 files changed, 15 insertions(+), 90 deletions(-) diff --git a/src/main/java/org/scream3r/jssc/SerialPort.java b/src/main/java/org/scream3r/jssc/SerialPort.java index 12ebf1d62..9b209965f 100644 --- a/src/main/java/org/scream3r/jssc/SerialPort.java +++ b/src/main/java/org/scream3r/jssc/SerialPort.java @@ -267,24 +267,14 @@ public boolean setEventsMask(int mask) throws SerialPortException { SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_SOLARIS || SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X){//since 0.9.0 linuxMask = mask; - if(mask > 0){ - maskAssigned = true; - } - else { - maskAssigned = false; - } + maskAssigned = mask > 0; return true; } boolean returnValue = serialInterface.setEventsMask(portHandle, mask); if(!returnValue){ throw new SerialPortException(portName, "setEventsMask()", SerialPortException.TYPE_CANT_SET_MASK); } - if(mask > 0){ - maskAssigned = true; - } - else { - maskAssigned = false; - } + maskAssigned = mask > 0; return returnValue; } @@ -905,12 +895,7 @@ public int[] getLinesStatus() throws SerialPortException { */ public boolean isCTS() throws SerialPortException { checkPortOpened("isCTS()"); - if(serialInterface.getLinesStatus(portHandle)[0] == 1){ - return true; - } - else { - return false; - } + return serialInterface.getLinesStatus(portHandle)[0] == 1; } /** @@ -922,12 +907,7 @@ public boolean isCTS() throws SerialPortException { */ public boolean isDSR() throws SerialPortException { checkPortOpened("isDSR()"); - if(serialInterface.getLinesStatus(portHandle)[1] == 1){ - return true; - } - else { - return false; - } + return serialInterface.getLinesStatus(portHandle)[1] == 1; } /** @@ -939,12 +919,7 @@ public boolean isDSR() throws SerialPortException { */ public boolean isRING() throws SerialPortException { checkPortOpened("isRING()"); - if(serialInterface.getLinesStatus(portHandle)[2] == 1){ - return true; - } - else { - return false; - } + return serialInterface.getLinesStatus(portHandle)[2] == 1; } /** @@ -956,12 +931,7 @@ public boolean isRING() throws SerialPortException { */ public boolean isRLSD() throws SerialPortException { checkPortOpened("isRLSD()"); - if(serialInterface.getLinesStatus(portHandle)[3] == 1){ - return true; - } - else { - return false; - } + return serialInterface.getLinesStatus(portHandle)[3] == 1; } /** diff --git a/src/main/java/org/scream3r/jssc/SerialPortEvent.java b/src/main/java/org/scream3r/jssc/SerialPortEvent.java index dc1f0d846..cbd0e4ca8 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortEvent.java +++ b/src/main/java/org/scream3r/jssc/SerialPortEvent.java @@ -86,107 +86,62 @@ public int getEventValue() { * Method returns true if event of type "RXCHAR" is received and otherwise false */ public boolean isRXCHAR() { - if(eventType == RXCHAR){ - return true; - } - else { - return false; - } + return eventType == RXCHAR; } /** * Method returns true if event of type "RXFLAG" is received and otherwise false */ public boolean isRXFLAG() { - if(eventType == RXFLAG){ - return true; - } - else { - return false; - } + return eventType == RXFLAG; } /** * Method returns true if event of type "TXEMPTY" is received and otherwise false */ public boolean isTXEMPTY() { - if(eventType == TXEMPTY){ - return true; - } - else { - return false; - } + return eventType == TXEMPTY; } /** * Method returns true if event of type "CTS" is received and otherwise false */ public boolean isCTS() { - if(eventType == CTS){ - return true; - } - else { - return false; - } + return eventType == CTS; } /** * Method returns true if event of type "DSR" is received and otherwise false */ public boolean isDSR() { - if(eventType == DSR){ - return true; - } - else { - return false; - } + return eventType == DSR; } /** * Method returns true if event of type "RLSD" is received and otherwise false */ public boolean isRLSD() { - if(eventType == RLSD){ - return true; - } - else { - return false; - } + return eventType == RLSD; } /** * Method returns true if event of type "BREAK" is received and otherwise false */ public boolean isBREAK() { - if(eventType == BREAK){ - return true; - } - else { - return false; - } + return eventType == BREAK; } /** * Method returns true if event of type "ERR" is received and otherwise false */ public boolean isERR() { - if(eventType == ERR){ - return true; - } - else { - return false; - } + return eventType == ERR; } /** * Method returns true if event of type "RING" is received and otherwise false */ public boolean isRING() { - if(eventType == RING){ - return true; - } - else { - return false; - } + return eventType == RING; } } From 246a64b0d60848dab7dd94d5205f01aa3e63d10d Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:18:56 +0200 Subject: [PATCH 3/7] remove redundant type arguments (use diamond) --- src/main/java/org/scream3r/jssc/SerialPortList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/scream3r/jssc/SerialPortList.java b/src/main/java/org/scream3r/jssc/SerialPortList.java index 05094a3b4..a7b3d548d 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortList.java +++ b/src/main/java/org/scream3r/jssc/SerialPortList.java @@ -308,7 +308,7 @@ private static String[] getWindowsPortNames(Pattern pattern, Comparator if(portNames == null){ return new String[]{}; } - TreeSet ports = new TreeSet(comparator); + TreeSet ports = new TreeSet<>(comparator); for(String portName : portNames){ if(pattern.matcher(portName).find()){ ports.add(portName); @@ -327,7 +327,7 @@ private static String[] getUnixBasedPortNames(String searchPath, Pattern pattern if(dir.exists() && dir.isDirectory()){ File[] files = dir.listFiles(); if(files.length > 0){ - TreeSet portsTree = new TreeSet(comparator); + TreeSet portsTree = new TreeSet<>(comparator); for(File file : files){ String fileName = file.getName(); if(!file.isDirectory() && !file.isFile() && pattern.matcher(fileName).find()){ From 552a1ceb8e4efbeb1619217b9f0d737038c1c43c Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:28:08 +0200 Subject: [PATCH 4/7] add missing javadoc params --- src/main/java/jssc/SerialNativeAccess.java | 1 + .../java/org/scream3r/jssc/SerialPort.java | 19 +++++++++ .../org/scream3r/jssc/SerialPortEvent.java | 42 +++++++++++++++---- .../scream3r/jssc/SerialPortException.java | 6 +++ .../jssc/SerialPortTimeoutException.java | 6 +++ 5 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/main/java/jssc/SerialNativeAccess.java b/src/main/java/jssc/SerialNativeAccess.java index 3158dc1d7..edfa24409 100644 --- a/src/main/java/jssc/SerialNativeAccess.java +++ b/src/main/java/jssc/SerialNativeAccess.java @@ -232,6 +232,7 @@ private static boolean extractLib(String libFilePath, String osName, String libN /** * Get OS type (OS_LINUX || OS_WINDOWS || OS_SOLARIS) * + * @return * @since 0.8 */ public int getOsType() { diff --git a/src/main/java/org/scream3r/jssc/SerialPort.java b/src/main/java/org/scream3r/jssc/SerialPort.java index 9b209965f..c4ab742e4 100644 --- a/src/main/java/org/scream3r/jssc/SerialPort.java +++ b/src/main/java/org/scream3r/jssc/SerialPort.java @@ -234,6 +234,7 @@ else if(stopBits == 3){ * parameter "PURGE_RXCLEAR | PURGE_TXCLEAR". *
Note: some devices or drivers may not support this function * + * @param flags * @return If the operation is successfully completed, the method returns true, otherwise false. * * @throws SerialPortException @@ -257,6 +258,7 @@ public boolean purgePort(int flags) throws SerialPortException { * For example if messages about data receipt and CTS and DSR status changing * shall be received, it is required to set the mask - "MASK_RXCHAR | MASK_CTS | MASK_DSR" * + * @param mask * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -307,6 +309,7 @@ private int getLinuxMask() { /** * Change RTS line state. Set "true" for switching ON and "false" for switching OFF RTS line * + * @param enabled * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -319,6 +322,7 @@ public boolean setRTS(boolean enabled) throws SerialPortException { /** * Change DTR line state. Set "true" for switching ON and "false" for switching OFF DTR line * + * @param enabled * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -331,6 +335,7 @@ public boolean setDTR(boolean enabled) throws SerialPortException { /** * Write byte array to port * + * @param buffer * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -343,6 +348,7 @@ public boolean writeBytes(byte[] buffer) throws SerialPortException { /** * Write single byte to port * + * @param singleByte * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -357,6 +363,7 @@ public boolean writeByte(byte singleByte) throws SerialPortException { /** * Write String to port * + * @param string * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -371,9 +378,12 @@ public boolean writeString(String string) throws SerialPortException { /** * Write String to port * + * @param string + * @param charsetName * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException + * @throws java.io.UnsupportedEncodingException * * @since 2.8.0 */ @@ -385,6 +395,7 @@ public boolean writeString(String string, String charsetName) throws SerialPortE /** * Write int value (in range from 0 to 255 (0x00 - 0xFF)) to port * + * @param singleInt * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -399,6 +410,7 @@ public boolean writeInt(int singleInt) throws SerialPortException { /** * Write int array (in range from 0 to 255 (0x00 - 0xFF)) to port * + * @param buffer * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -464,6 +476,7 @@ public String readHexString(int byteCount) throws SerialPortException { * Read Hex string from port with setted separator (example if separator is "::": FF::0A::FF) * * @param byteCount count of bytes for reading + * @param separator * * @return byte array with "byteCount" length converted to Hexadecimal String * @@ -619,6 +632,7 @@ public String readHexString(int byteCount, int timeout) throws SerialPortExcepti * Read Hex string from port with setted separator (example if separator is "::": FF::0A::FF) * * @param byteCount count of bytes for reading + * @param separator * @param timeout timeout in milliseconds * * @return byte array with "byteCount" length converted to Hexadecimal String @@ -729,6 +743,7 @@ public String readHexString() throws SerialPortException { /** * Read all available bytes from port like a Hex String with setted separator * + * @param separator * @return If input buffer is empty null will be returned, else byte array with all data from port converted to Hex String * * @throws SerialPortException @@ -812,6 +827,7 @@ public int getOutputBufferBytesCount() throws SerialPortException { * Set flow control mode. For required mode use variables with prefix "FLOWCONTROL_". * Example of hardware flow control mode(RTS/CTS): setFlowControlMode(FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT); * + * @param mask * @return If the operation is successfully completed, the method returns true, otherwise false * * @throws SerialPortException @@ -940,6 +956,7 @@ public boolean isRLSD() throws SerialPortException { * be in charge for handling of occurred events. This method will independently * set the mask in "MASK_RXCHAR" state if it was not set beforehand * + * @param listener * @throws SerialPortException */ public void addEventListener(SerialPortEventListener listener) throws SerialPortException { @@ -952,6 +969,8 @@ public void addEventListener(SerialPortEventListener listener) throws SerialPort * charge for handling of occurred events. Also events mask shall be sent to * this method, to do it use variables with prefix "MASK_" for example "MASK_RXCHAR" * + * @param listener + * @param mask * @see #setEventsMask(int) setEventsMask(int mask) * * @throws SerialPortException diff --git a/src/main/java/org/scream3r/jssc/SerialPortEvent.java b/src/main/java/org/scream3r/jssc/SerialPortEvent.java index cbd0e4ca8..67fb9ddd6 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortEvent.java +++ b/src/main/java/org/scream3r/jssc/SerialPortEvent.java @@ -52,6 +52,8 @@ public SerialPortEvent(String portName, int eventType, int eventValue){ /** * Getting port name which sent the event + * + * @return */ public String getPortName() { return portName; @@ -59,6 +61,8 @@ public String getPortName() { /** * Getting event type + * + * @return */ public int getEventType() { return eventType; @@ -77,69 +81,89 @@ public int getEventType() { *
BREAK - 0
*
RING - state of RING line (0 - OFF, 1 - ON)
*
ERR - mask of errors
+ * + * @return Return the event value. */ public int getEventValue() { return eventValue; } /** - * Method returns true if event of type "RXCHAR" is received and otherwise false + * Test for type RXCHAR + * + * @return Method returns true if event of type "RXCHAR" is received and otherwise false. */ public boolean isRXCHAR() { return eventType == RXCHAR; } /** - * Method returns true if event of type "RXFLAG" is received and otherwise false + * Test for type RXFLAG + * + * @return Method returns true if event of type "RXFLAG" is received and otherwise false */ public boolean isRXFLAG() { return eventType == RXFLAG; } /** - * Method returns true if event of type "TXEMPTY" is received and otherwise false + * Test for type TXEMPTY + * + * @return Method returns true if event of type "TXEMPTY" is received and otherwise false */ public boolean isTXEMPTY() { return eventType == TXEMPTY; } /** - * Method returns true if event of type "CTS" is received and otherwise false + * Test for type CTS + * + * @return Method returns true if event of type "CTS" is received and otherwise false */ public boolean isCTS() { return eventType == CTS; } /** - * Method returns true if event of type "DSR" is received and otherwise false + * Test for type DSR + * + * @return Method returns true if event of type "DSR" is received and otherwise false */ public boolean isDSR() { return eventType == DSR; } /** - * Method returns true if event of type "RLSD" is received and otherwise false + * Test for type RLSD + * + * @return Method returns true if event of type "RLSD" is received and otherwise false */ public boolean isRLSD() { return eventType == RLSD; } /** - * Method returns true if event of type "BREAK" is received and otherwise false + * Test for type BREAK + * + * @return Method returns true if event of type "BREAK" is received and otherwise false */ public boolean isBREAK() { return eventType == BREAK; } /** - * Method returns true if event of type "ERR" is received and otherwise false + * Test for type ERR + * + * @return Method returns true if event of type "ERR" is received and otherwise false */ public boolean isERR() { return eventType == ERR; } /** - * Method returns true if event of type "RING" is received and otherwise false + * Test for type RING + * + * @return Method returns true if event of type "RING" is received and otherwise false */ public boolean isRING() { return eventType == RING; diff --git a/src/main/java/org/scream3r/jssc/SerialPortException.java b/src/main/java/org/scream3r/jssc/SerialPortException.java index 3f2431de8..e773219fe 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortException.java +++ b/src/main/java/org/scream3r/jssc/SerialPortException.java @@ -76,6 +76,8 @@ public SerialPortException(String portName, String methodName, String exceptionT /** * Getting port name during operation with which the exception was called + * + * @return Return the port name. */ public String getPortName(){ return portName; @@ -83,6 +85,8 @@ public String getPortName(){ /** * Getting method name during execution of which the exception was called + * + * @return Return the method name. */ public String getMethodName(){ return methodName; @@ -90,6 +94,8 @@ public String getMethodName(){ /** * Getting exception type + * + * @return Return the exception type. */ public String getExceptionType(){ return exceptionType; diff --git a/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java b/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java index d65a1b31c..87a0fe6a7 100644 --- a/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java +++ b/src/main/java/org/scream3r/jssc/SerialPortTimeoutException.java @@ -45,6 +45,8 @@ public SerialPortTimeoutException(String portName, String methodName, int timeou /** * Getting port name during operation with which the exception was called + * + * @return Return the port name. */ public String getPortName(){ return portName; @@ -52,6 +54,8 @@ public String getPortName(){ /** * Getting method name during execution of which the exception was called + * + * @return Return the method name. */ public String getMethodName(){ return methodName; @@ -59,6 +63,8 @@ public String getMethodName(){ /** * Getting timeout value in millisecond + * + * @return Return the timeout value in milliseconds. */ public int getTimeoutValue(){ return timeoutValue; From d45cb897c29a4a18804c0f449a7f66a46735801b Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:29:08 +0200 Subject: [PATCH 5/7] use switch instead of multiple if statements --- src/main/java/jssc/SerialNativeAccess.java | 60 ++++++++++++---------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/main/java/jssc/SerialNativeAccess.java b/src/main/java/jssc/SerialNativeAccess.java index edfa24409..836570c74 100644 --- a/src/main/java/jssc/SerialNativeAccess.java +++ b/src/main/java/jssc/SerialNativeAccess.java @@ -79,36 +79,40 @@ else if(osName.equals("Mac OS X") || osName.equals("Darwin")){//os.name "Darwin" osName = "mac_os_x"; osType = SerialNativeInterface.OS_MAC_OS_X; }//<- since 0.9.0 - - if(architecture.equals("i386") || architecture.equals("i686")){ - architecture = "x86"; - } - else if(architecture.equals("amd64") || architecture.equals("universal")){//os.arch "universal" since 2.6.0 - architecture = "x86_64"; - } - else if(architecture.equals("arm")) {//since 2.1.0 - String floatStr = "sf"; - if(javaLibPath.toLowerCase().contains("gnueabihf") || javaLibPath.toLowerCase().contains("armhf")){ - floatStr = "hf"; - } - else { - try { - Process readelfProcess = Runtime.getRuntime().exec("readelf -A /proc/self/exe"); - BufferedReader reader = new BufferedReader(new InputStreamReader(readelfProcess.getInputStream())); - String buffer = ""; - while((buffer = reader.readLine()) != null && !buffer.isEmpty()){ - if(buffer.toLowerCase().contains("Tag_ABI_VFP_args".toLowerCase())){ - floatStr = "hf"; - break; + switch (architecture) { + case "i386": + case "i686": + architecture = "x86"; + break; + case "amd64": + case "universal": + //os.arch "universal" since 2.6.0 + architecture = "x86_64"; + break; + case "arm": + //since 2.1.0 + String floatStr = "sf"; + if(javaLibPath.toLowerCase().contains("gnueabihf") || javaLibPath.toLowerCase().contains("armhf")){ + floatStr = "hf"; + } + else { + try { + Process readelfProcess = Runtime.getRuntime().exec("readelf -A /proc/self/exe"); + BufferedReader reader = new BufferedReader(new InputStreamReader(readelfProcess.getInputStream())); + String buffer = ""; + while((buffer = reader.readLine()) != null && !buffer.isEmpty()){ + if(buffer.toLowerCase().contains("Tag_ABI_VFP_args".toLowerCase())){ + floatStr = "hf"; + break; + } } + reader.close(); } - reader.close(); - } - catch (Exception ex) { - //Do nothing - } - } - architecture = "arm" + floatStr; + catch (Exception ex) { + //Do nothing + } + } architecture = "arm" + floatStr; + break; } libFolderPath = libRootFolder + fileSeparator + ".jssc" + fileSeparator + osName; From 62f6449ae3cf0613b42c943eec7bf052cd920e1f Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:32:13 +0200 Subject: [PATCH 6/7] remove unused assignement --- src/main/java/jssc/SerialNativeAccess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/jssc/SerialNativeAccess.java b/src/main/java/jssc/SerialNativeAccess.java index 836570c74..533b6a4e3 100644 --- a/src/main/java/jssc/SerialNativeAccess.java +++ b/src/main/java/jssc/SerialNativeAccess.java @@ -99,7 +99,7 @@ else if(osName.equals("Mac OS X") || osName.equals("Darwin")){//os.name "Darwin" try { Process readelfProcess = Runtime.getRuntime().exec("readelf -A /proc/self/exe"); BufferedReader reader = new BufferedReader(new InputStreamReader(readelfProcess.getInputStream())); - String buffer = ""; + String buffer; while((buffer = reader.readLine()) != null && !buffer.isEmpty()){ if(buffer.toLowerCase().contains("Tag_ABI_VFP_args".toLowerCase())){ floatStr = "hf"; From 443ae6a8020a85fb53f243aaed5ea6037965dd6e Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 Oct 2014 21:36:55 +0200 Subject: [PATCH 7/7] use for-loops when possible --- .../java/org/scream3r/jssc/SerialPort.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/scream3r/jssc/SerialPort.java b/src/main/java/org/scream3r/jssc/SerialPort.java index c4ab742e4..ce79ee8c8 100644 --- a/src/main/java/org/scream3r/jssc/SerialPort.java +++ b/src/main/java/org/scream3r/jssc/SerialPort.java @@ -1097,17 +1097,17 @@ private class EventThread extends Thread { public void run() { while(!threadTerminated){ int[][] eventArray = waitEvents(); - for(int i = 0; i < eventArray.length; i++){ - if(eventArray[i][0] > 0 && !threadTerminated){ - eventListener.serialEvent(new SerialPortEvent(portName, eventArray[i][0], eventArray[i][1])); + for (int[] event : eventArray) { + if (event[0] > 0 && !threadTerminated) { + eventListener.serialEvent(new SerialPortEvent(portName, event[0], event[1])); //FIXME /*if(methodErrorOccurred != null){ - try { - methodErrorOccurred.invoke(eventListener, new Object[]{new SerialPortException("port", "method", "exception")}); - } - catch (Exception ex) { - System.out.println(ex); - } + try { + methodErrorOccurred.invoke(eventListener, new Object[]{new SerialPortException("port", "method", "exception")}); + } + catch (Exception ex) { + System.out.println(ex); + } }*/ } } @@ -1149,9 +1149,9 @@ private class LinuxEventThread extends EventThread { //Need to get initial states public LinuxEventThread(){ int[][] eventArray = waitEvents(); - for(int i = 0; i < eventArray.length; i++){ - int eventType = eventArray[i][0]; - int eventValue = eventArray[i][1]; + for (int[] event : eventArray) { + int eventType = event[0]; + int eventValue = event[1]; switch(eventType){ case INTERRUPT_BREAK: interruptBreak = eventValue; @@ -1191,10 +1191,10 @@ public void run() { int mask = getLinuxMask(); boolean interruptTxChanged = false; int errorMask = 0; - for(int i = 0; i < eventArray.length; i++){ + for (int[] event : eventArray) { boolean sendEvent = false; - int eventType = eventArray[i][0]; - int eventValue = eventArray[i][1]; + int eventType = event[0]; + int eventValue = event[1]; if(eventType > 0 && !super.threadTerminated){ switch(eventType){ case INTERRUPT_BREAK: @@ -1273,10 +1273,10 @@ public void run() { sendEvent = true; } break; - /*case MASK_RXFLAG: + /*case MASK_RXFLAG: //Do nothing at this moment if(((mask & MASK_RXFLAG) == MASK_RXFLAG) && (eventValue > 0)){ - sendEvent = true; + sendEvent = true; } break;*/ case MASK_TXEMPTY: