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;
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());

View File

@ -21,7 +21,7 @@ public class ServerPropertyFile {
if (f == null) throw new IllegalArgumentException("f ne doit pas être null");
file = f;
data = new HashMap<String, Object>();
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;

View File

@ -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);
}
/**

View File

@ -52,7 +52,7 @@ public abstract class AbstractConfig {
BufferedReader reader = new BufferedReader(new FileReader(f));
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null) {
@ -111,8 +111,7 @@ public abstract class AbstractConfig {
public static List<String> splitPermissionsString(String perms) {
if (perms == null || perms.equals("*"))
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;
sql += ";";
SQLElementList<E> elmts = new SQLElementList<E>();
SQLElementList<E> elmts = new SQLElementList<>();
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);
}
else
fields = (SQLFieldMap<E>) fieldsCache.get((Class<E>)getClass());
fields = (SQLFieldMap<E>) fieldsCache.get(getClass());
values = new LinkedHashMap<>(fields.size());
modifiedSinceLastSave = new HashSet<>(fields.size());
@ -188,7 +188,7 @@ public abstract class SQLElement<E extends SQLElement<E>> {
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.");

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) {
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<E> elemClass = (Class<E>) field.getSQLElementType();
Class<E> elemClass = field.getSQLElementType();
try {
E emptyElement = elemClass.newInstance();
emptyElement.set(field, value, false);

View File

@ -32,7 +32,7 @@ public class DistanceUtil {
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");
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);
synchronized (psStorage) {
sendAndGetResponse(packet, responseCondition, packetServer -> {

View File

@ -64,7 +64,7 @@ public abstract class Packet implements ByteSerializable {
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) {
if (!packetTypes.containsKey(data[0]))

View File

@ -8,7 +8,7 @@ import fr.pandacube.java.util.network.server.TCPServer.TCPServerClientConnection
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) {
packetHistory.add(new PacketStat(co, in, size));

View File

@ -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<PacketServer> packetQueue = new LinkedBlockingDeque<PacketServer>();
private BlockingQueue<PacketServer> 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();
}
}

View File

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

View File

@ -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<Character, ChatColor>();
BY_CHAR = new HashMap<>();
for (ChatColor colour : ChatColor.values())
BY_CHAR.put(Character.valueOf(colour.code), colour);
}

View File

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

View File

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

View File

@ -16,7 +16,7 @@ public class TextComponent extends BaseComponent {
private String text;
public static BaseComponent[] fromLegacyText(String message) {
ArrayList<TextComponent> components = new ArrayList<TextComponent>();
ArrayList<TextComponent> 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<BaseComponent>(Arrays.asList(extras)));
setExtra(new ArrayList<>(Arrays.asList(extras)));
}
@Override

View File

@ -22,7 +22,7 @@ public class TranslatableComponent extends BaseComponent {
super(original);
setTranslate(original.getTranslate());
if (original.getWith() != null) {
ArrayList<BaseComponent> temp = new ArrayList<BaseComponent>();
ArrayList<BaseComponent> 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<BaseComponent> temp = new ArrayList<BaseComponent>();
ArrayList<BaseComponent> 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<BaseComponent>();
if (with == null) with = new ArrayList<>();
component.parent = this;
with.add(component);
}