From: Niki Roo Date: Fri, 26 Jan 2018 10:51:02 +0000 (+0100) Subject: Fix some warnings X-Git-Tag: fanfix-1.7.0~30 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=9fe3f17729759e933d7687cc2838f7255f2c9283;p=fanfix.git Fix some warnings --- diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index f413a2d..3545412 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -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; diff --git a/src/be/nikiroo/fanfix/data/MetaData.java b/src/be/nikiroo/fanfix/data/MetaData.java index d72b557..53525fd 100644 --- a/src/be/nikiroo/fanfix/data/MetaData.java +++ b/src/be/nikiroo/fanfix/data/MetaData.java @@ -380,8 +380,41 @@ public class MetaData implements Cloneable, Comparable { @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 diff --git a/src/be/nikiroo/fanfix/data/Story.java b/src/be/nikiroo/fanfix/data/Story.java index fd4f2a8..f4b653a 100644 --- a/src/be/nikiroo/fanfix/data/Story.java +++ b/src/be/nikiroo/fanfix/data/Story.java @@ -72,13 +72,13 @@ public class Story implements Iterable, 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, 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 diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index 4cdfb94..5e0ad40 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -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(); } diff --git a/src/be/nikiroo/fanfix/output/InfoCover.java b/src/be/nikiroo/fanfix/output/InfoCover.java index 1e6ccd3..9227d3e 100644 --- a/src/be/nikiroo/fanfix/output/InfoCover.java +++ b/src/be/nikiroo/fanfix/output/InfoCover.java @@ -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(); } } diff --git a/src/be/nikiroo/fanfix/reader/BasicReader.java b/src/be/nikiroo/fanfix/reader/BasicReader.java index e9100e2..74a99c4 100644 --- a/src/be/nikiroo/fanfix/reader/BasicReader.java +++ b/src/be/nikiroo/fanfix/reader/BasicReader.java @@ -71,7 +71,7 @@ public abstract class BasicReader implements Reader { } @Override - public MetaData getMeta() { + public synchronized MetaData getMeta() { return meta; } diff --git a/src/be/nikiroo/fanfix/test/Test.java b/src/be/nikiroo/fanfix/test/Test.java index 3ff9a7a..c5d852d 100644 --- a/src/be/nikiroo/fanfix/test/Test.java +++ b/src/be/nikiroo/fanfix/test/Test.java @@ -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());