Some code improvement

This commit is contained in:
Marc Baloup 2017-07-05 00:17:41 +02:00
parent 8bc32aaa30
commit 5832e5270d
7 changed files with 15 additions and 14 deletions

View File

@ -24,7 +24,7 @@
<dependency> <dependency>
<groupId>fr.pandacube.bungeecord</groupId> <groupId>fr.pandacube.bungeecord</groupId>
<artifactId>bungeecord-chat</artifactId> <artifactId>bungeecord-chat</artifactId>
<version>1.11-SNAPSHOT</version> <version>1.12-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -58,4 +58,8 @@ public class BiMap<K, V> implements Iterable<Entry<K, V>> {
} }
} }
public int size() {
return map.size();
}
} }

View File

@ -25,9 +25,9 @@ public class PacketD0ServerException extends PacketServer {
} }
public void setException(Exception e) { public void setException(Throwable t) {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw)); t.printStackTrace(new PrintWriter(sw));
exception = sw.toString(); exception = sw.toString();
} }

View File

@ -75,7 +75,6 @@ public class TCPServer extends Thread implements Closeable {
try { try {
while (true) { while (true) {
@SuppressWarnings("resource")
Socket socketClient = socket.accept(); Socket socketClient = socket.accept();
socketClient.setSendBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE); socketClient.setSendBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
socketClient.setSoTimeout(Pandacube.NETWORK_TIMEOUT); socketClient.setSoTimeout(Pandacube.NETWORK_TIMEOUT);
@ -156,11 +155,13 @@ public class TCPServer extends Thread implements Closeable {
executeCallbacks(pc, callbacks); executeCallbacks(pc, callbacks);
} catch (Exception e) { } catch (Throwable e) {
Log.severe("Exception while handling packet. This exception will be sent to the client with PacketServerException packet.", e); Log.severe("Exception while handling packet. This exception will be sent to the client with PacketServerException packet.", e);
PacketD0ServerException packet = new PacketD0ServerException(); PacketD0ServerException packet = new PacketD0ServerException();
packet.setException(e); packet.setException(e);
send(packet); send(packet);
if (e instanceof InterruptedException || e instanceof Error)
throw e;
} }
} }

View File

@ -47,7 +47,6 @@ public class NetworkAPIListener implements Runnable {
try { try {
// réception des connexion client // réception des connexion client
while (!serverSocket.isClosed()) { while (!serverSocket.isClosed()) {
@SuppressWarnings("resource")
Socket socketClient = serverSocket.accept(); Socket socketClient = serverSocket.accept();
nAPIExecutionHandler.handleRun(new PacketExecutor(socketClient, this)); nAPIExecutionHandler.handleRun(new PacketExecutor(socketClient, this));
} }

View File

@ -188,7 +188,7 @@ public abstract class SQLElement<E extends SQLElement<E>> {
return modifiedSinceLastSave.contains(field.name); return modifiedSinceLastSave.contains(field.name);
} }
@SuppressWarnings({ "unchecked", "resource" }) @SuppressWarnings("unchecked")
public void save() throws ORMException { public void save() throws ORMException {
if (!isValidForSave()) if (!isValidForSave())
throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved."); throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved.");

View File

@ -9,6 +9,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@ -45,10 +46,10 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
* @param value la valeur à lui appliquer * @param value la valeur à lui appliquer
*/ */
public synchronized <T> void setCommon(SQLField<E, T> field, T value) { public synchronized <T> void setCommon(SQLField<E, T> field, T value) {
if (field != null && field.name == "id")
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
if (field == null) if (field == null)
throw new IllegalArgumentException("field can't be null"); throw new IllegalArgumentException("field can't be null");
if (field.name == "id")
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
Class<E> elemClass = field.getSQLElementType(); Class<E> elemClass = field.getSQLElementType();
try { try {
@ -132,11 +133,7 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
} }
private List<E> getStoredEl() { private List<E> getStoredEl() {
List<E> listStored = new ArrayList<>(); return stream().filter(SQLElement::isStored).collect(Collectors.toCollection(() -> new ArrayList<>()));
forEach(el -> {
if (el.isStored()) listStored.add(el);
});
return listStored;
} }
public synchronized void removeFromDB() { public synchronized void removeFromDB() {