From dd47b2b3924d8fa6dc62ced2af71ea5e4599a9b0 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Mon, 17 Oct 2016 00:03:04 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9solutions=20de=20tous=20les=20messages?= =?UTF-8?q?=20d'avertissement=20et=20d'informations=20d'Eclipse=20=C3=A0?= =?UTF-8?q?=20propos=20du=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/pandacube/java/util/GifDecoder.java | 36 +++++++++---------- .../java/util/ServerPropertyFile.java | 10 ++---- src/fr/pandacube/java/util/StringUtil.java | 6 ++-- .../java/util/config/AbstractConfig.java | 5 ++- .../pandacube/java/util/db/sql_tools/ORM.java | 2 +- .../java/util/db/sql_tools/SQLElement.java | 4 +-- .../util/db/sql_tools/SQLElementList.java | 4 ++- .../java/util/measurement/DistanceUtil.java | 2 +- .../java/util/network/client/TCPClient.java | 2 +- .../java/util/network/packet/Packet.java | 2 +- .../network/server/BandwidthCalculation.java | 2 +- .../java/util/network/server/TCPServer.java | 23 ++++++------ .../server/NetworkAPIListener.java | 3 +- src/net/md_5/bungee/api/ChatColor.java | 2 +- .../md_5/bungee/api/chat/BaseComponent.java | 2 +- .../bungee/api/chat/ComponentBuilder.java | 2 +- .../md_5/bungee/api/chat/TextComponent.java | 4 +-- .../api/chat/TranslatableComponent.java | 6 ++-- 18 files changed, 57 insertions(+), 60 deletions(-) diff --git a/src/fr/pandacube/java/util/GifDecoder.java b/src/fr/pandacube/java/util/GifDecoder.java index dd1bad1..2bdf614 100644 --- a/src/fr/pandacube/java/util/GifDecoder.java +++ b/src/fr/pandacube/java/util/GifDecoder.java @@ -122,7 +122,7 @@ public class GifDecoder { // delay = -1; if ((n >= 0) && (n < frameCount)) { - delay = ((GifFrame) frames.get(n)).delay; + delay = frames.get(n).delay; } return delay; } @@ -234,7 +234,7 @@ public class GifDecoder { int sx = i * iw; // start of line in source while (dx < dlim) { // map color and insert in destination - int index = ((int) pixels[sx++]) & 0xff; + int index = (pixels[sx++]) & 0xff; int c = act[index]; if (c != 0) { dest[dx] = c; @@ -253,7 +253,7 @@ public class GifDecoder { public BufferedImage getFrame(int n) { BufferedImage im = null; if ((n >= 0) && (n < frameCount)) { - im = ((GifFrame) frames.get(n)).image; + im = frames.get(n).image; } return im; } @@ -284,13 +284,13 @@ public class GifDecoder { status = STATUS_FORMAT_ERROR; } } + try { + is.close(); + } catch (IOException e) { + } } else { status = STATUS_OPEN_ERROR; } - try { - is.close(); - } catch (IOException e) { - } return status; } @@ -313,13 +313,13 @@ public class GifDecoder { status = STATUS_FORMAT_ERROR; } } + try { + is.close(); + } catch (IOException e) { + } } else { status = STATUS_OPEN_ERROR; } - try { - is.close(); - } catch (IOException e) { - } return status; } @@ -410,7 +410,7 @@ public class GifDecoder { break; bi = 0; } - datum += (((int) block[bi]) & 0xff) << bits; + datum += ((block[bi]) & 0xff) << bits; bits += 8; bi++; count--; @@ -450,7 +450,7 @@ public class GifDecoder { pixelStack[top++] = suffix[code]; code = prefix[code]; } - first = ((int) suffix[code]) & 0xff; + first = (suffix[code]) & 0xff; // Add a new string to the string table, @@ -563,9 +563,9 @@ public class GifDecoder { int i = 0; int j = 0; while (i < ncolors) { - int r = ((int) c[j++]) & 0xff; - int g = ((int) c[j++]) & 0xff; - int b = ((int) c[j++]) & 0xff; + int r = (c[j++]) & 0xff; + int g = (c[j++]) & 0xff; + int b = (c[j++]) & 0xff; tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b; } } @@ -746,8 +746,8 @@ public class GifDecoder { readBlock(); if (block[0] == 1) { // loop count sub-block - int b1 = ((int) block[1]) & 0xff; - int b2 = ((int) block[2]) & 0xff; + int b1 = (block[1]) & 0xff; + int b2 = (block[2]) & 0xff; loopCount = (b2 << 8) | b1; } } while ((blockSize > 0) && !err()); diff --git a/src/fr/pandacube/java/util/ServerPropertyFile.java b/src/fr/pandacube/java/util/ServerPropertyFile.java index ad80c76..83a855b 100644 --- a/src/fr/pandacube/java/util/ServerPropertyFile.java +++ b/src/fr/pandacube/java/util/ServerPropertyFile.java @@ -21,7 +21,7 @@ public class ServerPropertyFile { if (f == null) throw new IllegalArgumentException("f ne doit pas être null"); file = f; - data = new HashMap(); + data = new HashMap<>(); data.put("name", "default_name"); data.put("memory", "512M"); data.put("javaArgs", ""); @@ -63,9 +63,7 @@ public class ServerPropertyFile { } public boolean save() { - BufferedWriter out = null; - try { - out = new BufferedWriter(new FileWriter(file, false)); + try (BufferedWriter out = new BufferedWriter(new FileWriter(file, false))) { String jsonStr = new Gson().toJson(data); @@ -76,10 +74,6 @@ public class ServerPropertyFile { return true; } catch (IOException e) { Log.severe(e); - } finally { - try { - out.close(); - } catch (Exception e) {} } return false; diff --git a/src/fr/pandacube/java/util/StringUtil.java b/src/fr/pandacube/java/util/StringUtil.java index fff9e1d..665c56b 100644 --- a/src/fr/pandacube/java/util/StringUtil.java +++ b/src/fr/pandacube/java/util/StringUtil.java @@ -2,9 +2,9 @@ package fr.pandacube.java.util; public class StringUtil { public static String formatDouble(double d) { - if (d == (long) d) return String.format("%d", (long) d); - else - return String.valueOf(d); + if (d == (long) d) + return String.format("%d", (long) d); + return String.valueOf(d); } /** diff --git a/src/fr/pandacube/java/util/config/AbstractConfig.java b/src/fr/pandacube/java/util/config/AbstractConfig.java index b6c4709..d7f7a59 100644 --- a/src/fr/pandacube/java/util/config/AbstractConfig.java +++ b/src/fr/pandacube/java/util/config/AbstractConfig.java @@ -52,7 +52,7 @@ public abstract class AbstractConfig { BufferedReader reader = new BufferedReader(new FileReader(f)); - List lines = new ArrayList(); + List lines = new ArrayList<>(); String line; while ((line = reader.readLine()) != null) { @@ -111,8 +111,7 @@ public abstract class AbstractConfig { public static List splitPermissionsString(String perms) { if (perms == null || perms.equals("*")) return null; - else - return getSplittedString(perms, ";"); + return getSplittedString(perms, ";"); } diff --git a/src/fr/pandacube/java/util/db/sql_tools/ORM.java b/src/fr/pandacube/java/util/db/sql_tools/ORM.java index c3aaf72..4f6b6ba 100644 --- a/src/fr/pandacube/java/util/db/sql_tools/ORM.java +++ b/src/fr/pandacube/java/util/db/sql_tools/ORM.java @@ -193,7 +193,7 @@ public final class ORM { if (offset != null) sql += " OFFSET " + offset; sql += ";"; - SQLElementList elmts = new SQLElementList(); + SQLElementList elmts = new SQLElementList<>(); PreparedStatement ps = connection.getNativeConnection().prepareStatement(sql); diff --git a/src/fr/pandacube/java/util/db/sql_tools/SQLElement.java b/src/fr/pandacube/java/util/db/sql_tools/SQLElement.java index 6ea43b6..6a16af7 100644 --- a/src/fr/pandacube/java/util/db/sql_tools/SQLElement.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLElement.java @@ -58,7 +58,7 @@ public abstract class SQLElement> { fieldsCache.put((Class)getClass(), fields); } else - fields = (SQLFieldMap) fieldsCache.get((Class)getClass()); + fields = (SQLFieldMap) fieldsCache.get(getClass()); values = new LinkedHashMap<>(fields.size()); modifiedSinceLastSave = new HashSet<>(fields.size()); @@ -188,7 +188,7 @@ public abstract class SQLElement> { return modifiedSinceLastSave.contains(field.name); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "resource" }) public void save() throws ORMException { if (!isValidForSave()) throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved."); diff --git a/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java b/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java index e082cfe..1723eb5 100644 --- a/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java +++ b/src/fr/pandacube/java/util/db/sql_tools/SQLElementList.java @@ -47,8 +47,10 @@ public class SQLElementList> extends ArrayList { public synchronized void setCommon(SQLField field, T value) { if (field != null && field.name == "id") throw new IllegalArgumentException("Can't modify id field in a SQLElementList"); + if (field == null) + throw new IllegalArgumentException("field can't be null"); - Class elemClass = (Class) field.getSQLElementType(); + Class elemClass = field.getSQLElementType(); try { E emptyElement = elemClass.newInstance(); emptyElement.set(field, value, false); diff --git a/src/fr/pandacube/java/util/measurement/DistanceUtil.java b/src/fr/pandacube/java/util/measurement/DistanceUtil.java index 3f1ba6a..ce93eba 100644 --- a/src/fr/pandacube/java/util/measurement/DistanceUtil.java +++ b/src/fr/pandacube/java/util/measurement/DistanceUtil.java @@ -32,7 +32,7 @@ public class DistanceUtil { return distanceToString(meterDist, precision, DistanceUnit.M, DistanceUnit.KM); } - public enum DistanceUnit implements Comparable { + public enum DistanceUnit { NM(0.000000001, "nm"), µM(0.000001, "µm"), MM(0.001, "mm"), CM(0.01, "cm"), M(1, "m"), KM(1000, "km"); private final double multiplicator; diff --git a/src/fr/pandacube/java/util/network/client/TCPClient.java b/src/fr/pandacube/java/util/network/client/TCPClient.java index ad2a385..6331bfc 100644 --- a/src/fr/pandacube/java/util/network/client/TCPClient.java +++ b/src/fr/pandacube/java/util/network/client/TCPClient.java @@ -164,7 +164,7 @@ public class TCPClient extends Thread implements Closeable { } - public PacketServer sendAndWaitForResponse(PacketClient packet, Predicate responseCondition, boolean avoidListener) throws IOException, InterruptedException { + public PacketServer sendAndWaitForResponse(PacketClient packet, Predicate responseCondition) throws IOException, InterruptedException { AtomicReference psStorage = new AtomicReference<>(null); synchronized (psStorage) { sendAndGetResponse(packet, responseCondition, packetServer -> { diff --git a/src/fr/pandacube/java/util/network/packet/Packet.java b/src/fr/pandacube/java/util/network/packet/Packet.java index 2d192a9..e987b58 100644 --- a/src/fr/pandacube/java/util/network/packet/Packet.java +++ b/src/fr/pandacube/java/util/network/packet/Packet.java @@ -64,7 +64,7 @@ public abstract class Packet implements ByteSerializable { public static final Charset CHARSET = Pandacube.NETWORK_CHARSET; - private static Map> packetTypes = new HashMap>(); + private static Map> packetTypes = new HashMap<>(); public static Packet constructPacket(byte[] data) { if (!packetTypes.containsKey(data[0])) diff --git a/src/fr/pandacube/java/util/network/server/BandwidthCalculation.java b/src/fr/pandacube/java/util/network/server/BandwidthCalculation.java index c39d295..81c9e26 100644 --- a/src/fr/pandacube/java/util/network/server/BandwidthCalculation.java +++ b/src/fr/pandacube/java/util/network/server/BandwidthCalculation.java @@ -8,7 +8,7 @@ import fr.pandacube.java.util.network.server.TCPServer.TCPServerClientConnection public class BandwidthCalculation { - private List packetHistory = new LinkedList(); + private List packetHistory = new LinkedList<>(); public synchronized void addPacket(TCPServerClientConnection co, boolean in, long size) { packetHistory.add(new PacketStat(co, in, size)); diff --git a/src/fr/pandacube/java/util/network/server/TCPServer.java b/src/fr/pandacube/java/util/network/server/TCPServer.java index 3076712..a6f042e 100644 --- a/src/fr/pandacube/java/util/network/server/TCPServer.java +++ b/src/fr/pandacube/java/util/network/server/TCPServer.java @@ -75,6 +75,7 @@ public class TCPServer extends Thread implements Closeable { try { while (true) { + @SuppressWarnings("resource") Socket socketClient = socket.accept(); socketClient.setSendBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE); socketClient.setSoTimeout(Pandacube.NETWORK_TIMEOUT); @@ -96,7 +97,7 @@ public class TCPServer extends Thread implements Closeable { } public class TCPServerClientConnection extends Thread { - private Socket socket; + private Socket cSocket; private InputStream in; private OutputStream out; private SocketAddress address; @@ -108,10 +109,10 @@ public class TCPServer extends Thread implements Closeable { public TCPServerClientConnection(Socket s, int coId) throws IOException { super("TCPSv " + socketName + " Conn#" + coId + " In"); setDaemon(true); - socket = s; - in = socket.getInputStream(); - out = socket.getOutputStream(); - address = new InetSocketAddress(socket.getInetAddress(), socket.getPort()); + cSocket = s; + in = cSocket.getInputStream(); + out = cSocket.getOutputStream(); + address = new InetSocketAddress(cSocket.getInetAddress(), cSocket.getPort()); try { listener.onClientConnect(TCPServer.this, this); } catch(Exception e) { @@ -125,7 +126,7 @@ public class TCPServer extends Thread implements Closeable { public void run() { try { byte[] code = new byte[1]; - while (!socket.isClosed() && in.read(code) != -1) { + while (!cSocket.isClosed() && in.read(code) != -1) { byte[] sizeB = new byte[4]; if (in.read(sizeB) != 4) throw new IOException("Socket " + address + " closed"); @@ -241,7 +242,7 @@ public class TCPServer extends Thread implements Closeable { } public void close() { - if (socket.isClosed()) return; + if (cSocket.isClosed()) return; try { listener.onClientDisconnect(TCPServer.this, this); @@ -252,7 +253,7 @@ public class TCPServer extends Thread implements Closeable { try { Thread.sleep(200); - socket.close(); + cSocket.close(); if (!Thread.currentThread().equals(outThread)) send(new PacketServer((byte) 0) { @Override public void serializeToByteBuffer(ByteBuffer buffer) {} @Override public void deserializeFromByteBuffer(ByteBuffer buffer) {} @@ -263,7 +264,7 @@ public class TCPServer extends Thread implements Closeable { } private class TCPServerConnectionOutputThread extends Thread { - private BlockingQueue packetQueue = new LinkedBlockingDeque(); + private BlockingQueue packetQueue = new LinkedBlockingDeque<>(); public TCPServerConnectionOutputThread(int coId) { super("TCPSv " + socketName + " Conn#" + coId + " Out"); @@ -277,7 +278,7 @@ public class TCPServer extends Thread implements Closeable { @Override public void run() { try { - while (!socket.isClosed()) { + while (!cSocket.isClosed()) { PacketServer packet = packetQueue.poll(1, TimeUnit.SECONDS); byte[] data; if (packet != null) { @@ -306,7 +307,7 @@ public class TCPServer extends Thread implements Closeable { public String toString() { return new ToStringBuilder(this) .append("thread", getName()) - .append("socket", socket).toString(); + .append("socket", cSocket).toString(); } } diff --git a/src/fr/pandacube/java/util/network_api/server/NetworkAPIListener.java b/src/fr/pandacube/java/util/network_api/server/NetworkAPIListener.java index 7f9cc7c..a6b7ee6 100644 --- a/src/fr/pandacube/java/util/network_api/server/NetworkAPIListener.java +++ b/src/fr/pandacube/java/util/network_api/server/NetworkAPIListener.java @@ -11,7 +11,7 @@ public class NetworkAPIListener implements Runnable { private int port = 0; String pass; private ServerSocket serverSocket; - private HashMap requestExecutors = new HashMap(); + private HashMap requestExecutors = new HashMap<>(); private String name; private NAPIExecutionHandler nAPIExecutionHandler; @@ -47,6 +47,7 @@ public class NetworkAPIListener implements Runnable { try { // réception des connexion client while (!serverSocket.isClosed()) { + @SuppressWarnings("resource") Socket socketClient = serverSocket.accept(); nAPIExecutionHandler.handleRun(new PacketExecutor(socketClient, this)); } diff --git a/src/net/md_5/bungee/api/ChatColor.java b/src/net/md_5/bungee/api/ChatColor.java index b800067..d188932 100644 --- a/src/net/md_5/bungee/api/ChatColor.java +++ b/src/net/md_5/bungee/api/ChatColor.java @@ -75,7 +75,7 @@ public enum ChatColor { static { STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]"); - BY_CHAR = new HashMap(); + BY_CHAR = new HashMap<>(); for (ChatColor colour : ChatColor.values()) BY_CHAR.put(Character.valueOf(colour.code), colour); } diff --git a/src/net/md_5/bungee/api/chat/BaseComponent.java b/src/net/md_5/bungee/api/chat/BaseComponent.java index 92027f9..5b7978f 100644 --- a/src/net/md_5/bungee/api/chat/BaseComponent.java +++ b/src/net/md_5/bungee/api/chat/BaseComponent.java @@ -119,7 +119,7 @@ public abstract class BaseComponent { } public void addExtra(BaseComponent component) { - if (extra == null) extra = new ArrayList(); + if (extra == null) extra = new ArrayList<>(); component.parent = this; extra.add(component); } diff --git a/src/net/md_5/bungee/api/chat/ComponentBuilder.java b/src/net/md_5/bungee/api/chat/ComponentBuilder.java index 3ca8835..766146c 100644 --- a/src/net/md_5/bungee/api/chat/ComponentBuilder.java +++ b/src/net/md_5/bungee/api/chat/ComponentBuilder.java @@ -10,7 +10,7 @@ import net.md_5.bungee.api.ChatColor; public class ComponentBuilder { private TextComponent current; - private final List parts = new ArrayList(); + private final List parts = new ArrayList<>(); public ComponentBuilder(ComponentBuilder original) { current = new TextComponent(original.current); diff --git a/src/net/md_5/bungee/api/chat/TextComponent.java b/src/net/md_5/bungee/api/chat/TextComponent.java index 62086e0..e013c03 100644 --- a/src/net/md_5/bungee/api/chat/TextComponent.java +++ b/src/net/md_5/bungee/api/chat/TextComponent.java @@ -16,7 +16,7 @@ public class TextComponent extends BaseComponent { private String text; public static BaseComponent[] fromLegacyText(String message) { - ArrayList components = new ArrayList(); + ArrayList components = new ArrayList<>(); StringBuilder builder = new StringBuilder(); TextComponent component = new TextComponent(); Matcher matcher = url.matcher(message); @@ -103,7 +103,7 @@ public class TextComponent extends BaseComponent { public /* varargs */ TextComponent(BaseComponent... extras) { setText(""); - setExtra(new ArrayList(Arrays.asList(extras))); + setExtra(new ArrayList<>(Arrays.asList(extras))); } @Override diff --git a/src/net/md_5/bungee/api/chat/TranslatableComponent.java b/src/net/md_5/bungee/api/chat/TranslatableComponent.java index f2e1dbc..d5d7f11 100644 --- a/src/net/md_5/bungee/api/chat/TranslatableComponent.java +++ b/src/net/md_5/bungee/api/chat/TranslatableComponent.java @@ -22,7 +22,7 @@ public class TranslatableComponent extends BaseComponent { super(original); setTranslate(original.getTranslate()); if (original.getWith() != null) { - ArrayList temp = new ArrayList(); + ArrayList temp = new ArrayList<>(); for (BaseComponent baseComponent : original.getWith()) temp.add(baseComponent.duplicate()); setWith(temp); @@ -31,7 +31,7 @@ public class TranslatableComponent extends BaseComponent { public /* varargs */ TranslatableComponent(String translate, Object... with) { setTranslate(translate); - ArrayList temp = new ArrayList(); + ArrayList temp = new ArrayList<>(); for (Object w : with) { if (w instanceof String) { temp.add(new TextComponent((String) w)); @@ -58,7 +58,7 @@ public class TranslatableComponent extends BaseComponent { } public void addWith(BaseComponent component) { - if (with == null) with = new ArrayList(); + if (with == null) with = new ArrayList<>(); component.parent = this; with.add(component); }