Skip to content

Commit

Permalink
Small Java code cleanup (scream3r#88)
Browse files Browse the repository at this point in the history
Use JDK5+ foreach
Remove redundant conditionals

Co-authored-by: Tomas Nieboer <[email protected]>
  • Loading branch information
Omnieboer and Tomas Nieboer committed Apr 30, 2021
1 parent bf356a4 commit 28de0f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 67 deletions.
26 changes: 13 additions & 13 deletions src/main/java/jssc/SerialPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,16 @@ public String readHexString(int byteCount) throws SerialPortException {
public String readHexString(int byteCount, String separator) throws SerialPortException {
checkPortOpened("readHexString()");
String[] strBuffer = readHexStringArray(byteCount);
String returnString = "";
StringBuilder returnString = new StringBuilder();
boolean insertSeparator = false;
for(String value : strBuffer){
if(insertSeparator){
returnString += separator;
returnString.append(separator);
}
returnString += value;
returnString.append(value);
insertSeparator = true;
}
return returnString;
return returnString.toString();
}

/**
Expand Down Expand Up @@ -1108,9 +1108,9 @@ 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 {
Expand Down Expand Up @@ -1160,9 +1160,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;
Expand Down Expand Up @@ -1202,10 +1202,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:
Expand Down
63 changes: 9 additions & 54 deletions src/main/java/jssc/SerialPortEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,107 +86,62 @@ public int getEventValue() {
* Method returns true if event of type <b>"RXCHAR"</b> 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 <b>"RXFLAG"</b> 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 <b>"TXEMPTY"</b> 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 <b>"CTS"</b> 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 <b>"DSR"</b> 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 <b>"RLSD"</b> 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 <b>"BREAK"</b> 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 <b>"ERR"</b> 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 <b>"RING"</b> is received and otherwise false
*/
public boolean isRING() {
if(eventType == RING){
return true;
}
else {
return false;
}
return eventType == RING;
}
}

0 comments on commit 28de0f5

Please sign in to comment.