Fix naming issues in RxtxChannelConfig / Format cleanup

This commit is contained in:
Trustin Lee 2013-01-10 13:24:36 +09:00
parent 0c3732cad5
commit 4528c793ba
2 changed files with 19 additions and 27 deletions

View File

@ -15,8 +15,9 @@
*/
package io.netty.transport.rxtx;
import static io.netty.transport.rxtx.RxtxChannelOptions.*;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import io.netty.buffer.BufType;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelConfig;
@ -30,9 +31,7 @@ import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.nio.channels.NotYetConnectedException;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import static io.netty.transport.rxtx.RxtxChannelOptions.*;
/**
* A channel to a serial device using the RXTX library.
@ -111,9 +110,9 @@ public class RxtxChannel extends AbstractOioByteChannel {
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(
config().getOption(BAUD_RATE),
config().getOption(DATA_BITS).getValue(),
config().getOption(STOP_BITS).getValue(),
config().getOption(PARITY_BIT).getValue()
config().getOption(DATA_BITS).value(),
config().getOption(STOP_BITS).value(),
config().getOption(PARITY_BIT).value()
);
serialPort.setDTR(config().getOption(DTR));
serialPort.setRTS(config().getOption(RTS));

View File

@ -15,14 +15,13 @@
*/
package io.netty.transport.rxtx;
import static io.netty.transport.rxtx.RxtxChannelOptions.*;
import gnu.io.SerialPort;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig;
import java.util.Map;
import gnu.io.SerialPort;
import static io.netty.transport.rxtx.RxtxChannelOptions.*;
/**
* A configuration class for RXTX device connections.
@ -49,17 +48,17 @@ public class RxtxChannelConfig extends DefaultChannelConfig {
this.value = value;
}
public int getValue() {
public int value() {
return value;
}
public static Stopbits ofValue(int value) {
public static Stopbits valueOf(int value) {
for (Stopbits stopbit : Stopbits.values()) {
if (stopbit.value == value) {
return stopbit;
}
}
throw new IllegalArgumentException("Unknown value for Stopbits: " + value + '.');
throw new IllegalArgumentException("unknown " + Stopbits.class.getSimpleName() + " value: " + value);
}
}
@ -87,17 +86,17 @@ public class RxtxChannelConfig extends DefaultChannelConfig {
this.value = value;
}
public int getValue() {
public int value() {
return value;
}
public static Databits ofValue(int value) {
public static Databits valueOf(int value) {
for (Databits databit : Databits.values()) {
if (databit.value == value) {
return databit;
}
}
throw new IllegalArgumentException("Unknown value for Databits: " + value + '.');
throw new IllegalArgumentException("unknown " + Databits.class.getSimpleName() + " value: " + value);
}
}
@ -131,30 +130,25 @@ public class RxtxChannelConfig extends DefaultChannelConfig {
this.value = value;
}
public int getValue() {
public int value() {
return value;
}
public static Paritybit ofValue(int value) {
public static Paritybit valueOf(int value) {
for (Paritybit paritybit : Paritybit.values()) {
if (paritybit.value == value) {
return paritybit;
}
}
throw new IllegalArgumentException("Unknown value for paritybit: " + value + '.');
throw new IllegalArgumentException("unknown " + Paritybit.class.getSimpleName() + " value: " + value);
}
}
private volatile int baudrate = 115200;
private volatile boolean dtr;
private volatile boolean rts;
private volatile Stopbits stopbits = Stopbits.STOPBITS_1;
private volatile Databits databits = Databits.DATABITS_8;
private volatile Paritybit paritybit = Paritybit.NONE;
public RxtxChannelConfig(RxtxChannel channel) {
@ -163,8 +157,7 @@ public class RxtxChannelConfig extends DefaultChannelConfig {
@Override
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(super.getOptions(),
BAUD_RATE, DTR, RTS, STOP_BITS, DATA_BITS, PARITY_BIT);
return getOptions(super.getOptions(), BAUD_RATE, DTR, RTS, STOP_BITS, DATA_BITS, PARITY_BIT);
}
@SuppressWarnings("unchecked")