Fixed the equals methods + more refactoring

This commit is contained in:
Maschell 2017-03-31 16:47:06 +02:00
parent 1c98eaffbb
commit d0e7928ed2
6 changed files with 27 additions and 16 deletions

View File

@ -92,7 +92,7 @@ public abstract class Controller implements Runnable {
public byte[] getLatestData() {
if (latestData == null) {
return new byte[0];
}else{
} else {
byte[] data = this.latestData.clone();
this.latestData = null;
return data;
@ -183,7 +183,7 @@ public abstract class Controller implements Runnable {
if (identifier == null) {
if (other.identifier != null) return false;
} else if (!identifier.equals(other.identifier)) return false;
return (type != other.type);
return (type == other.type);
}
@Synchronized("rumbleLock")

View File

@ -100,7 +100,7 @@ public class LinuxDevInputController extends Controller implements Runnable {
if (value == 0) {
// Clear bit with button number
buttonState &= ~(1 << number);
}else{
} else {
// Set bit with button number
buttonState |= (1 << number);
}

View File

@ -30,6 +30,7 @@ import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.Synchronized;
import net.ash.HIDToVPADNetworkClient.util.HandleFoundry;
import net.ash.HIDToVPADNetworkClient.util.Settings;
@ -46,8 +47,9 @@ public class NetworkHIDDevice {
@Getter private final int hidHandle = HandleFoundry.next();
private Object readCommandLock = new Object();
@Getter(AccessLevel.PRIVATE) private final List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
private final Object readCommandLock = new Object();
private final Object pullCommandsLock = new Object();
private final List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) private ReadCommand latestRead;
public NetworkHIDDevice(short vid, short pid) {
@ -55,10 +57,12 @@ public class NetworkHIDDevice {
this.pid = pid;
}
@Synchronized("commands")
private void addCommand(DeviceCommand command) {
this.commands.add(command);
}
@Synchronized("commands")
private void clearCommands() {
this.commands.clear();
}
@ -85,17 +89,24 @@ public class NetworkHIDDevice {
protected Collection<? extends DeviceCommand> getCommandList() {
List<DeviceCommand> commands = new ArrayList<DeviceCommand>();
commands.addAll(getCommands());
DeviceCommand lastRead;
synchronized (pullCommandsLock) {
commands.addAll(getCommands());
clearCommands();
}
synchronized (readCommandLock) {
if ((lastRead = getLatestRead()) != null) {
DeviceCommand lastRead = getLatestRead();
if (lastRead != null) {
commands.add(lastRead);
setLatestRead(null);
}
}
clearCommands();
return commands;
}
@Synchronized("commands")
private List<DeviceCommand> getCommands() {
return commands;
}
@ -113,6 +124,6 @@ public class NetworkHIDDevice {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
NetworkHIDDevice other = (NetworkHIDDevice) obj;
return (hidHandle != other.hidHandle);
return (hidHandle == other.hidHandle);
}
}

View File

@ -57,9 +57,9 @@ public final class NetworkManager implements Runnable {
}
public void addHIDDevice(NetworkHIDDevice device) {
if (!getDevices().contains(device)) {
if (!devices.contains(device)) {
synchronized (devices) {
getDevices().add(device);
devices.add(device);
}
}
}

View File

@ -40,8 +40,7 @@ import net.ash.HIDToVPADNetworkClient.util.Settings;
@Log
final class TCPClient {
private final Object lock = new Object();
@Getter
private static TCPClient instance = new TCPClient();
@Getter private static TCPClient instance = new TCPClient();
private Socket sock;
private DataInputStream in;
private DataOutputStream out;

View File

@ -27,6 +27,7 @@ import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
final class UDPClient {
private final DatagramSocket sock;
private final InetAddress host;