Fix some warnings
authorNiki Roo <niki@nikiroo.be>
Fri, 26 Jan 2018 10:51:02 +0000 (11:51 +0100)
committerNiki Roo <niki@nikiroo.be>
Fri, 26 Jan 2018 10:51:02 +0000 (11:51 +0100)
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/data/MetaData.java
src/be/nikiroo/fanfix/data/Story.java
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/output/InfoCover.java
src/be/nikiroo/fanfix/reader/BasicReader.java
src/be/nikiroo/fanfix/test/Test.java

index f413a2d66e95ce296d8d7d1388103b98c41e7722..354541219f0db8c433f79192b608f6373538244d 100644 (file)
@@ -309,8 +309,8 @@ public class Main {
                        case VERSION:
                                System.out
                                                .println(String.format("Fanfix version %s"
-                                                               + "\nhttps://github.com/nikiroo/fanfix/"
-                                                               + "\n\tWritten by Nikiroo",
+                                                               + "%nhttps://github.com/nikiroo/fanfix/"
+                                                               + "%n\tWritten by Nikiroo",
                                                                Version.getCurrentVersion()));
                                updates.ok(); // we consider it read
                                break;
index d72b55732adde9098b98914968f0196c3abc0562..53525fdc58726eee7bd274dc10b5e4adf7568516 100644 (file)
@@ -380,8 +380,41 @@ public class MetaData implements Cloneable, Comparable<MetaData> {
 
        @Override
        public int compareTo(MetaData o) {
-               String oUuid = o == null ? null : o.getUuid();
-               return getUuid().compareTo(oUuid);
+               if (o == null) {
+                       return 1;
+               }
+
+               String uuid = getUuid();
+               String oUuid = o.getUuid();
+
+               if (uuid == null) {
+                       uuid = "";
+               }
+
+               if (oUuid == null) {
+                       oUuid = "";
+               }
+
+               return uuid.compareTo(oUuid);
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (!(obj instanceof MetaData)) {
+                       return false;
+               }
+
+               return compareTo((MetaData) obj) == 0;
+       }
+
+       @Override
+       public int hashCode() {
+               String uuid = getUuid();
+               if (uuid == null) {
+                       uuid = "" + title + author + source;
+               }
+
+               return uuid.hashCode();
        }
 
        @Override
index fd4f2a8d15258f1f973b12252089d7bc52b24fda..f4b653a273fba147a7e8049e66db18af56130bf5 100644 (file)
@@ -72,13 +72,13 @@ public class Story implements Iterable<Chapter>, Cloneable {
                        title = meta.getTitle();
                }
 
-               String tags = "";
+               StringBuilder tags = new StringBuilder();
                if (meta != null && meta.getTags() != null) {
                        for (String tag : meta.getTags()) {
-                               if (!tags.isEmpty()) {
-                                       tags += ", ";
+                               if (tags.length() > 0) {
+                                       tags.append(", ");
                                }
-                               tags += tag;
+                               tags.append(tag);
                        }
                }
 
@@ -108,11 +108,12 @@ public class Story implements Iterable<Chapter>, Cloneable {
 
                        cover = size + cover;
                }
+
                return String.format(
                                "Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
                                                + "Resume: [%s]\nCover: [%s]", title, meta == null ? ""
                                                : meta.getAuthor(), meta == null ? "" : meta.getDate(),
-                               tags, resume, cover);
+                               tags.toString(), resume, cover);
        }
 
        @Override
index 4cdfb944e0cd7b62bdbdedadac580cefa61f895b..5e0ad40097f8add91f78d73cf1cf61b3334c53e7 100644 (file)
@@ -128,7 +128,7 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       protected void invalidateInfo(String luid) {
+       protected synchronized void invalidateInfo(String luid) {
                stories = null;
                sourceCovers = new HashMap<String, Image>();
        }
index 1e6ccd3363f49cf210e45c28ea2a66d5fa3eae2e..9227d3e440d9f9371506c160813b9827c029c851 100644 (file)
@@ -14,11 +14,13 @@ public class InfoCover {
        public static void writeInfo(File targetDir, String targetName,
                        MetaData meta) throws IOException {
                File info = new File(targetDir, targetName + ".info");
-               BufferedWriter infoWriter = new BufferedWriter(new OutputStreamWriter(
-                               new FileOutputStream(info), "UTF-8"));
 
-               if (meta != null) {
-                       try {
+               BufferedWriter infoWriter = null;
+               try {
+                       infoWriter = new BufferedWriter(new OutputStreamWriter(
+                                       new FileOutputStream(info), "UTF-8"));
+
+                       if (meta != null) {
                                String tags = "";
                                if (meta.getTags() != null) {
                                        for (String tag : meta.getTags()) {
@@ -57,7 +59,9 @@ public class InfoCover {
                                writeMeta(infoWriter, "CREATION_DATE", meta.getCreationDate());
                                writeMeta(infoWriter, "FAKE_COVER",
                                                Boolean.toString(meta.isFakeCover()));
-                       } finally {
+                       }
+               } finally {
+                       if (infoWriter != null) {
                                infoWriter.close();
                        }
                }
index e9100e2e036a2bb7456bf0ab7be4670de9d87186..74a99c4005dfe45a89b3dd8b1be97e6757a8fa38 100644 (file)
@@ -71,7 +71,7 @@ public abstract class BasicReader implements Reader {
        }
 
        @Override
-       public MetaData getMeta() {
+       public synchronized MetaData getMeta() {
                return meta;
        }
 
index 3ff9a7ab8d139ad3e42c46f9caed8d504021f5e7..c5d852d397c5c746a6f2cd34b161b030aaa0496f 100644 (file)
@@ -47,12 +47,17 @@ public class Test extends TestLauncher {
                tmpCache.delete();
                tmpCache.mkdir();
 
-               FileOutputStream out = new FileOutputStream(new File(tmpConfig,
-                               "config.properties"));
-               Properties props = new Properties();
-               props.setProperty("CACHE_DIR", tmpCache.getAbsolutePath());
-               props.store(out, null);
-               out.close();
+               FileOutputStream out = null;
+               try {
+                       out = new FileOutputStream(new File(tmpConfig, "config.properties"));
+                       Properties props = new Properties();
+                       props.setProperty("CACHE_DIR", tmpCache.getAbsolutePath());
+                       props.store(out, null);
+               } finally {
+                       if (out != null) {
+                               out.close();
+                       }
+               }
 
                ConfigBundle config = new ConfigBundle();
                Bundles.setDirectory(tmpConfig.getAbsolutePath());