Résolutions de tous les messages d'avertissement et d'informations d'Eclipse à propos du code

This commit is contained in:
Marc Baloup 2016-10-17 00:03:04 +02:00
parent 4ae06be523
commit dd47b2b392
18 changed files with 57 additions and 60 deletions

View File

@ -122,7 +122,7 @@ public class GifDecoder {
// //
delay = -1; delay = -1;
if ((n >= 0) && (n < frameCount)) { if ((n >= 0) && (n < frameCount)) {
delay = ((GifFrame) frames.get(n)).delay; delay = frames.get(n).delay;
} }
return delay; return delay;
} }
@ -234,7 +234,7 @@ public class GifDecoder {
int sx = i * iw; // start of line in source int sx = i * iw; // start of line in source
while (dx < dlim) { while (dx < dlim) {
// map color and insert in destination // map color and insert in destination
int index = ((int) pixels[sx++]) & 0xff; int index = (pixels[sx++]) & 0xff;
int c = act[index]; int c = act[index];
if (c != 0) { if (c != 0) {
dest[dx] = c; dest[dx] = c;
@ -253,7 +253,7 @@ public class GifDecoder {
public BufferedImage getFrame(int n) { public BufferedImage getFrame(int n) {
BufferedImage im = null; BufferedImage im = null;
if ((n >= 0) && (n < frameCount)) { if ((n >= 0) && (n < frameCount)) {
im = ((GifFrame) frames.get(n)).image; im = frames.get(n).image;
} }
return im; return im;
} }
@ -284,13 +284,13 @@ public class GifDecoder {
status = STATUS_FORMAT_ERROR; status = STATUS_FORMAT_ERROR;
} }
} }
} else {
status = STATUS_OPEN_ERROR;
}
try { try {
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {
} }
} else {
status = STATUS_OPEN_ERROR;
}
return status; return status;
} }
@ -313,13 +313,13 @@ public class GifDecoder {
status = STATUS_FORMAT_ERROR; status = STATUS_FORMAT_ERROR;
} }
} }
} else {
status = STATUS_OPEN_ERROR;
}
try { try {
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {
} }
} else {
status = STATUS_OPEN_ERROR;
}
return status; return status;
} }
@ -410,7 +410,7 @@ public class GifDecoder {
break; break;
bi = 0; bi = 0;
} }
datum += (((int) block[bi]) & 0xff) << bits; datum += ((block[bi]) & 0xff) << bits;
bits += 8; bits += 8;
bi++; bi++;
count--; count--;
@ -450,7 +450,7 @@ public class GifDecoder {
pixelStack[top++] = suffix[code]; pixelStack[top++] = suffix[code];
code = prefix[code]; code = prefix[code];
} }
first = ((int) suffix[code]) & 0xff; first = (suffix[code]) & 0xff;
// Add a new string to the string table, // Add a new string to the string table,
@ -563,9 +563,9 @@ public class GifDecoder {
int i = 0; int i = 0;
int j = 0; int j = 0;
while (i < ncolors) { while (i < ncolors) {
int r = ((int) c[j++]) & 0xff; int r = (c[j++]) & 0xff;
int g = ((int) c[j++]) & 0xff; int g = (c[j++]) & 0xff;
int b = ((int) c[j++]) & 0xff; int b = (c[j++]) & 0xff;
tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b; tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
} }
} }
@ -746,8 +746,8 @@ public class GifDecoder {
readBlock(); readBlock();
if (block[0] == 1) { if (block[0] == 1) {
// loop count sub-block // loop count sub-block
int b1 = ((int) block[1]) & 0xff; int b1 = (block[1]) & 0xff;
int b2 = ((int) block[2]) & 0xff; int b2 = (block[2]) & 0xff;
loopCount = (b2 << 8) | b1; loopCount = (b2 << 8) | b1;
} }
} while ((blockSize > 0) && !err()); } while ((blockSize > 0) && !err());

View File

@ -21,7 +21,7 @@ public class ServerPropertyFile {
if (f == null) throw new IllegalArgumentException("f ne doit pas être null"); if (f == null) throw new IllegalArgumentException("f ne doit pas être null");
file = f; file = f;
data = new HashMap<String, Object>(); data = new HashMap<>();
data.put("name", "default_name"); data.put("name", "default_name");
data.put("memory", "512M"); data.put("memory", "512M");
data.put("javaArgs", ""); data.put("javaArgs", "");
@ -63,9 +63,7 @@ public class ServerPropertyFile {
} }
public boolean save() { public boolean save() {
BufferedWriter out = null; try (BufferedWriter out = new BufferedWriter(new FileWriter(file, false))) {
try {
out = new BufferedWriter(new FileWriter(file, false));
String jsonStr = new Gson().toJson(data); String jsonStr = new Gson().toJson(data);
@ -76,10 +74,6 @@ public class ServerPropertyFile {
return true; return true;
} catch (IOException e) { } catch (IOException e) {
Log.severe(e); Log.severe(e);
} finally {
try {
out.close();
} catch (Exception e) {}
} }
return false; return false;

View File

@ -2,8 +2,8 @@ package fr.pandacube.java.util;
public class StringUtil { public class StringUtil {
public static String formatDouble(double d) { public static String formatDouble(double d) {
if (d == (long) d) return String.format("%d", (long) d); if (d == (long) d)
else return String.format("%d", (long) d);
return String.valueOf(d); return String.valueOf(d);
} }

View File

@ -52,7 +52,7 @@ public abstract class AbstractConfig {
BufferedReader reader = new BufferedReader(new FileReader(f)); BufferedReader reader = new BufferedReader(new FileReader(f));
List<String> lines = new ArrayList<String>(); List<String> lines = new ArrayList<>();
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
@ -111,7 +111,6 @@ public abstract class AbstractConfig {
public static List<String> splitPermissionsString(String perms) { public static List<String> splitPermissionsString(String perms) {
if (perms == null || perms.equals("*")) if (perms == null || perms.equals("*"))
return null; return null;
else
return getSplittedString(perms, ";"); return getSplittedString(perms, ";");
} }

View File

@ -193,7 +193,7 @@ public final class ORM {
if (offset != null) sql += " OFFSET " + offset; if (offset != null) sql += " OFFSET " + offset;
sql += ";"; sql += ";";
SQLElementList<E> elmts = new SQLElementList<E>(); SQLElementList<E> elmts = new SQLElementList<>();
PreparedStatement ps = connection.getNativeConnection().prepareStatement(sql); PreparedStatement ps = connection.getNativeConnection().prepareStatement(sql);

View File

@ -58,7 +58,7 @@ public abstract class SQLElement<E extends SQLElement<E>> {
fieldsCache.put((Class<E>)getClass(), fields); fieldsCache.put((Class<E>)getClass(), fields);
} }
else else
fields = (SQLFieldMap<E>) fieldsCache.get((Class<E>)getClass()); fields = (SQLFieldMap<E>) fieldsCache.get(getClass());
values = new LinkedHashMap<>(fields.size()); values = new LinkedHashMap<>(fields.size());
modifiedSinceLastSave = new HashSet<>(fields.size()); modifiedSinceLastSave = new HashSet<>(fields.size());
@ -188,7 +188,7 @@ public abstract class SQLElement<E extends SQLElement<E>> {
return modifiedSinceLastSave.contains(field.name); return modifiedSinceLastSave.contains(field.name);
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "resource" })
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

@ -47,8 +47,10 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
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") if (field != null && field.name == "id")
throw new IllegalArgumentException("Can't modify id field in a SQLElementList"); throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
if (field == null)
throw new IllegalArgumentException("field can't be null");
Class<E> elemClass = (Class<E>) field.getSQLElementType(); Class<E> elemClass = field.getSQLElementType();
try { try {
E emptyElement = elemClass.newInstance(); E emptyElement = elemClass.newInstance();
emptyElement.set(field, value, false); emptyElement.set(field, value, false);

View File

@ -32,7 +32,7 @@ public class DistanceUtil {
return distanceToString(meterDist, precision, DistanceUnit.M, DistanceUnit.KM); return distanceToString(meterDist, precision, DistanceUnit.M, DistanceUnit.KM);
} }
public enum DistanceUnit implements Comparable<DistanceUnit> { 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"); 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; private final double multiplicator;

View File

@ -164,7 +164,7 @@ public class TCPClient extends Thread implements Closeable {
} }
public PacketServer sendAndWaitForResponse(PacketClient packet, Predicate<PacketServer> responseCondition, boolean avoidListener) throws IOException, InterruptedException { public PacketServer sendAndWaitForResponse(PacketClient packet, Predicate<PacketServer> responseCondition) throws IOException, InterruptedException {
AtomicReference<PacketServer> psStorage = new AtomicReference<>(null); AtomicReference<PacketServer> psStorage = new AtomicReference<>(null);
synchronized (psStorage) { synchronized (psStorage) {
sendAndGetResponse(packet, responseCondition, packetServer -> { sendAndGetResponse(packet, responseCondition, packetServer -> {

View File

@ -64,7 +64,7 @@ public abstract class Packet implements ByteSerializable {
public static final Charset CHARSET = Pandacube.NETWORK_CHARSET; public static final Charset CHARSET = Pandacube.NETWORK_CHARSET;
private static Map<Byte, Class<? extends Packet>> packetTypes = new HashMap<Byte, Class<? extends Packet>>(); private static Map<Byte, Class<? extends Packet>> packetTypes = new HashMap<>();
public static Packet constructPacket(byte[] data) { public static Packet constructPacket(byte[] data) {
if (!packetTypes.containsKey(data[0])) if (!packetTypes.containsKey(data[0]))

View File

@ -8,7 +8,7 @@ import fr.pandacube.java.util.network.server.TCPServer.TCPServerClientConnection
public class BandwidthCalculation { public class BandwidthCalculation {
private List<PacketStat> packetHistory = new LinkedList<PacketStat>(); private List<PacketStat> packetHistory = new LinkedList<>();
public synchronized void addPacket(TCPServerClientConnection co, boolean in, long size) { public synchronized void addPacket(TCPServerClientConnection co, boolean in, long size) {
packetHistory.add(new PacketStat(co, in, size)); packetHistory.add(new PacketStat(co, in, size));

View File

@ -75,6 +75,7 @@ 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);
@ -96,7 +97,7 @@ public class TCPServer extends Thread implements Closeable {
} }
public class TCPServerClientConnection extends Thread { public class TCPServerClientConnection extends Thread {
private Socket socket; private Socket cSocket;
private InputStream in; private InputStream in;
private OutputStream out; private OutputStream out;
private SocketAddress address; private SocketAddress address;
@ -108,10 +109,10 @@ public class TCPServer extends Thread implements Closeable {
public TCPServerClientConnection(Socket s, int coId) throws IOException { public TCPServerClientConnection(Socket s, int coId) throws IOException {
super("TCPSv " + socketName + " Conn#" + coId + " In"); super("TCPSv " + socketName + " Conn#" + coId + " In");
setDaemon(true); setDaemon(true);
socket = s; cSocket = s;
in = socket.getInputStream(); in = cSocket.getInputStream();
out = socket.getOutputStream(); out = cSocket.getOutputStream();
address = new InetSocketAddress(socket.getInetAddress(), socket.getPort()); address = new InetSocketAddress(cSocket.getInetAddress(), cSocket.getPort());
try { try {
listener.onClientConnect(TCPServer.this, this); listener.onClientConnect(TCPServer.this, this);
} catch(Exception e) { } catch(Exception e) {
@ -125,7 +126,7 @@ public class TCPServer extends Thread implements Closeable {
public void run() { public void run() {
try { try {
byte[] code = new byte[1]; byte[] code = new byte[1];
while (!socket.isClosed() && in.read(code) != -1) { while (!cSocket.isClosed() && in.read(code) != -1) {
byte[] sizeB = new byte[4]; byte[] sizeB = new byte[4];
if (in.read(sizeB) != 4) throw new IOException("Socket " + address + " closed"); 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() { public void close() {
if (socket.isClosed()) return; if (cSocket.isClosed()) return;
try { try {
listener.onClientDisconnect(TCPServer.this, this); listener.onClientDisconnect(TCPServer.this, this);
@ -252,7 +253,7 @@ public class TCPServer extends Thread implements Closeable {
try { try {
Thread.sleep(200); Thread.sleep(200);
socket.close(); cSocket.close();
if (!Thread.currentThread().equals(outThread)) send(new PacketServer((byte) 0) { if (!Thread.currentThread().equals(outThread)) send(new PacketServer((byte) 0) {
@Override public void serializeToByteBuffer(ByteBuffer buffer) {} @Override public void serializeToByteBuffer(ByteBuffer buffer) {}
@Override public void deserializeFromByteBuffer(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 class TCPServerConnectionOutputThread extends Thread {
private BlockingQueue<PacketServer> packetQueue = new LinkedBlockingDeque<PacketServer>(); private BlockingQueue<PacketServer> packetQueue = new LinkedBlockingDeque<>();
public TCPServerConnectionOutputThread(int coId) { public TCPServerConnectionOutputThread(int coId) {
super("TCPSv " + socketName + " Conn#" + coId + " Out"); super("TCPSv " + socketName + " Conn#" + coId + " Out");
@ -277,7 +278,7 @@ public class TCPServer extends Thread implements Closeable {
@Override @Override
public void run() { public void run() {
try { try {
while (!socket.isClosed()) { while (!cSocket.isClosed()) {
PacketServer packet = packetQueue.poll(1, TimeUnit.SECONDS); PacketServer packet = packetQueue.poll(1, TimeUnit.SECONDS);
byte[] data; byte[] data;
if (packet != null) { if (packet != null) {
@ -306,7 +307,7 @@ public class TCPServer extends Thread implements Closeable {
public String toString() { public String toString() {
return new ToStringBuilder(this) return new ToStringBuilder(this)
.append("thread", getName()) .append("thread", getName())
.append("socket", socket).toString(); .append("socket", cSocket).toString();
} }
} }

View File

@ -11,7 +11,7 @@ public class NetworkAPIListener implements Runnable {
private int port = 0; private int port = 0;
String pass; String pass;
private ServerSocket serverSocket; private ServerSocket serverSocket;
private HashMap<String, AbstractRequestExecutor> requestExecutors = new HashMap<String, AbstractRequestExecutor>(); private HashMap<String, AbstractRequestExecutor> requestExecutors = new HashMap<>();
private String name; private String name;
private NAPIExecutionHandler nAPIExecutionHandler; private NAPIExecutionHandler nAPIExecutionHandler;
@ -47,6 +47,7 @@ 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

@ -75,7 +75,7 @@ public enum ChatColor {
static { static {
STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]"); STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
BY_CHAR = new HashMap<Character, ChatColor>(); BY_CHAR = new HashMap<>();
for (ChatColor colour : ChatColor.values()) for (ChatColor colour : ChatColor.values())
BY_CHAR.put(Character.valueOf(colour.code), colour); BY_CHAR.put(Character.valueOf(colour.code), colour);
} }

View File

@ -119,7 +119,7 @@ public abstract class BaseComponent {
} }
public void addExtra(BaseComponent component) { public void addExtra(BaseComponent component) {
if (extra == null) extra = new ArrayList<BaseComponent>(); if (extra == null) extra = new ArrayList<>();
component.parent = this; component.parent = this;
extra.add(component); extra.add(component);
} }

View File

@ -10,7 +10,7 @@ import net.md_5.bungee.api.ChatColor;
public class ComponentBuilder { public class ComponentBuilder {
private TextComponent current; private TextComponent current;
private final List<BaseComponent> parts = new ArrayList<BaseComponent>(); private final List<BaseComponent> parts = new ArrayList<>();
public ComponentBuilder(ComponentBuilder original) { public ComponentBuilder(ComponentBuilder original) {
current = new TextComponent(original.current); current = new TextComponent(original.current);

View File

@ -16,7 +16,7 @@ public class TextComponent extends BaseComponent {
private String text; private String text;
public static BaseComponent[] fromLegacyText(String message) { public static BaseComponent[] fromLegacyText(String message) {
ArrayList<TextComponent> components = new ArrayList<TextComponent>(); ArrayList<TextComponent> components = new ArrayList<>();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
TextComponent component = new TextComponent(); TextComponent component = new TextComponent();
Matcher matcher = url.matcher(message); Matcher matcher = url.matcher(message);
@ -103,7 +103,7 @@ public class TextComponent extends BaseComponent {
public /* varargs */ TextComponent(BaseComponent... extras) { public /* varargs */ TextComponent(BaseComponent... extras) {
setText(""); setText("");
setExtra(new ArrayList<BaseComponent>(Arrays.asList(extras))); setExtra(new ArrayList<>(Arrays.asList(extras)));
} }
@Override @Override

View File

@ -22,7 +22,7 @@ public class TranslatableComponent extends BaseComponent {
super(original); super(original);
setTranslate(original.getTranslate()); setTranslate(original.getTranslate());
if (original.getWith() != null) { if (original.getWith() != null) {
ArrayList<BaseComponent> temp = new ArrayList<BaseComponent>(); ArrayList<BaseComponent> temp = new ArrayList<>();
for (BaseComponent baseComponent : original.getWith()) for (BaseComponent baseComponent : original.getWith())
temp.add(baseComponent.duplicate()); temp.add(baseComponent.duplicate());
setWith(temp); setWith(temp);
@ -31,7 +31,7 @@ public class TranslatableComponent extends BaseComponent {
public /* varargs */ TranslatableComponent(String translate, Object... with) { public /* varargs */ TranslatableComponent(String translate, Object... with) {
setTranslate(translate); setTranslate(translate);
ArrayList<BaseComponent> temp = new ArrayList<BaseComponent>(); ArrayList<BaseComponent> temp = new ArrayList<>();
for (Object w : with) { for (Object w : with) {
if (w instanceof String) { if (w instanceof String) {
temp.add(new TextComponent((String) w)); temp.add(new TextComponent((String) w));
@ -58,7 +58,7 @@ public class TranslatableComponent extends BaseComponent {
} }
public void addWith(BaseComponent component) { public void addWith(BaseComponent component) {
if (with == null) with = new ArrayList<BaseComponent>(); if (with == null) with = new ArrayList<>();
component.parent = this; component.parent = this;
with.add(component); with.add(component);
} }