From 90130e98e6249f93a1a16ac7d80a478363d5d3f7 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 4 May 2017 22:17:50 +0200 Subject: [PATCH] Performed code review and Javadoc review. --- src/fr/devinsy/util/rss/RSSCache.java | 68 ++++++++++++++++------ src/fr/devinsy/util/rss/RSSElement.java | 46 +++++++++++++-- src/fr/devinsy/util/rss/RSSWriter.java | 43 +++++++++++++- test/fr/devinsy/util/rss/RSSCacheTest.java | 13 +++-- 4 files changed, 139 insertions(+), 31 deletions(-) diff --git a/src/fr/devinsy/util/rss/RSSCache.java b/src/fr/devinsy/util/rss/RSSCache.java index ca88126..e0be83b 100644 --- a/src/fr/devinsy/util/rss/RSSCache.java +++ b/src/fr/devinsy/util/rss/RSSCache.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-rss. @@ -20,20 +20,22 @@ package fr.devinsy.util.rss; import java.util.HashMap; import java.util.Locale; +import java.util.Map; import fr.devinsy.util.strings.StringList; /** + * The Class RSSCache. * * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class RSSCache { private static RSSCache instance = new RSSCache(); - private HashMap cache; + private Map cache; /** - * + * Instantiates a new RSS cache. */ private RSSCache() { @@ -41,21 +43,30 @@ public class RSSCache } /** + * Gets the. * - * @param key - * @param locale - * @return + * @param name + * the name + * @return the string */ public String get(final String name) { - return get(name, Locale.ROOT); + String result; + + result = get(name, Locale.ROOT); + + // + return result; } /** + * Gets the. * * @param name + * the name * @param locale - * @return + * the locale + * @return the string */ public String get(final String name, final Locale locale) { @@ -63,7 +74,7 @@ public class RSSCache if (name == null) { - throw new NullPointerException("name is null."); + throw new IllegalArgumentException("name is null."); } else if (locale == null) { @@ -79,14 +90,18 @@ public class RSSCache } } + // return result; } /** + * Key. * * @param name + * the name * @param locale - * @return + * the locale + * @return the string */ private String key(final String name, final Locale locale) { @@ -106,16 +121,20 @@ public class RSSCache } /** + * Put. * - * @param key + * @param name + * the name * @param locale + * the locale * @param rss + * the rss */ public void put(final String name, final Locale locale, final String rss) { if (name == null) { - throw new NullPointerException("name is null."); + throw new IllegalArgumentException("Name is null."); } else if (locale == null) { @@ -128,10 +147,12 @@ public class RSSCache } /** + * Put. * * @param name - * @param locale + * the name * @param rss + * the rss */ public void put(final String name, final String rss) { @@ -139,8 +160,10 @@ public class RSSCache } /** + * Removes the. * * @param name + * the name */ public void remove(final String name) { @@ -148,14 +171,18 @@ public class RSSCache } /** + * Removes the. * * @param name + * the name + * @param locale + * the locale */ public void remove(final String name, final Locale locale) { if (name == null) { - throw new NullPointerException("key is null."); + throw new IllegalArgumentException("Name is null."); } else { @@ -164,8 +191,10 @@ public class RSSCache } /** + * Sets the oudated. * - * @param key + * @param name + * the new oudated */ public void setOudated(final String name) { @@ -179,8 +208,11 @@ public class RSSCache } /** + * Subkeys. * - * @param key + * @param name + * the name + * @return the string list */ public StringList subkeys(final String name) { @@ -203,12 +235,12 @@ public class RSSCache } /** + * Instance. * - * @return + * @return the RSS cache */ public static RSSCache instance() { return instance; } - } diff --git a/src/fr/devinsy/util/rss/RSSElement.java b/src/fr/devinsy/util/rss/RSSElement.java index c4b6290..0534fa7 100644 --- a/src/fr/devinsy/util/rss/RSSElement.java +++ b/src/fr/devinsy/util/rss/RSSElement.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-rss. @@ -21,20 +21,25 @@ package fr.devinsy.util.rss; import org.joda.time.DateTime; /** + * The Class RSSElement. * * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class RSSElement { public static final String DATE_PATTERN = "dd MMM YYYY hh:mm:ss Z"; + private String name; private String value; private String[] attributes; /** + * Instantiates a new RSS element. * * @param name + * the name * @param value + * the value */ public RSSElement(final String name, final DateTime value) { @@ -51,9 +56,12 @@ public class RSSElement } /** + * Instantiates a new RSS element. * * @param name + * the name * @param value + * the value */ public RSSElement(final String name, final long value) { @@ -63,9 +71,14 @@ public class RSSElement } /** + * Instantiates a new RSS element. * * @param name + * the name * @param value + * the value + * @param attributes + * the attributes */ public RSSElement(final String name, final long value, final String... attributes) { @@ -75,9 +88,12 @@ public class RSSElement } /** + * Instantiates a new RSS element. * * @param name + * the name * @param value + * the value */ public RSSElement(final String name, final String value) { @@ -87,9 +103,14 @@ public class RSSElement } /** + * Instantiates a new RSS element. * * @param name + * the name * @param value + * the value + * @param attributes + * the attributes */ public RSSElement(final String name, final String value, final String... attributes) { @@ -98,14 +119,20 @@ public class RSSElement this.attributes = attributes; } + /** + * Gets the attributes. + * + * @return the attributes + */ public String[] getAttributes() { return this.attributes; } /** + * Gets the name. * - * @return + * @return the name */ public String getName() { @@ -113,28 +140,37 @@ public class RSSElement } /** + * Gets the value. * - * @return + * @return the value */ public String getValue() { return this.value; } + /** + * Sets the attributes. + * + * @param attributes + * the new attributes + */ public void setAttributes(final String[] attributes) { this.attributes = attributes; } /** + * Sets the name. * * @param name + * the new name */ public void setName(final String name) { if (name == null) { - throw new NullPointerException("name is null"); + throw new IllegalArgumentException("name is null"); } else { @@ -143,8 +179,10 @@ public class RSSElement } /** + * Sets the value. * * @param value + * the new value */ public void setValue(final String value) { diff --git a/src/fr/devinsy/util/rss/RSSWriter.java b/src/fr/devinsy/util/rss/RSSWriter.java index fbe367c..3bcc56c 100644 --- a/src/fr/devinsy/util/rss/RSSWriter.java +++ b/src/fr/devinsy/util/rss/RSSWriter.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2013-2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-rss. @@ -28,6 +28,7 @@ import java.io.Writer; import fr.devinsy.util.xml.XMLWriter; /** + * The Class RSSWriter. * * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ @@ -36,10 +37,14 @@ public class RSSWriter private XMLWriter out; /** + * Instantiates a new RSS writer. * * @param file - * @throws FileNotFoundException + * the file * @throws UnsupportedEncodingException + * the unsupported encoding exception + * @throws FileNotFoundException + * the file not found exception */ public RSSWriter(final File file) throws UnsupportedEncodingException, FileNotFoundException { @@ -48,9 +53,12 @@ public class RSSWriter } /** + * Instantiates a new RSS writer. * * @param target + * the target * @throws UnsupportedEncodingException + * the unsupported encoding exception */ public RSSWriter(final OutputStream target) throws UnsupportedEncodingException { @@ -59,9 +67,12 @@ public class RSSWriter } /** + * Instantiates a new RSS writer. * * @param target + * the target * @throws UnsupportedEncodingException + * the unsupported encoding exception */ public RSSWriter(final Writer target) throws UnsupportedEncodingException { @@ -70,7 +81,10 @@ public class RSSWriter } /** + * Close. * + * @throws IOException + * Signals that an I/O exception has occurred. */ public void close() throws IOException { @@ -83,7 +97,10 @@ public class RSSWriter } /** + * Flush. * + * @throws IOException + * Signals that an I/O exception has occurred. */ public void flush() throws IOException { @@ -94,7 +111,16 @@ public class RSSWriter } /** + * Write channel. * + * @param title + * the title + * @param link + * the link + * @param description + * the description + * @param elements + * the elements */ public void writeChannel(final String title, final String link, final String description, final RSSElement... elements) { @@ -117,8 +143,10 @@ public class RSSWriter } /** + * Write comment. * * @param comment + * the comment */ public void writeComment(final String comment) { @@ -126,7 +154,16 @@ public class RSSWriter } /** + * Write item. * + * @param title + * the title + * @param link + * the link + * @param description + * the description + * @param elements + * the elements */ public void writeItem(final String title, final String link, final String description, final RSSElement... elements) { @@ -162,7 +199,7 @@ public class RSSWriter } /** - * + * Write RSS header. */ private void writeRSSHeader() { diff --git a/test/fr/devinsy/util/rss/RSSCacheTest.java b/test/fr/devinsy/util/rss/RSSCacheTest.java index b4b0b15..05d31ee 100644 --- a/test/fr/devinsy/util/rss/RSSCacheTest.java +++ b/test/fr/devinsy/util/rss/RSSCacheTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2014,2017 Christian Pierre MOMON * * This file is part of Devinsy-rss. @@ -25,15 +25,16 @@ import org.junit.Before; import org.junit.Test; /** + * The Class RSSCacheTest. * - * @author Christian P. Momon + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class RSSCacheTest { - static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(RSSCacheTest.class); + public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(RSSCacheTest.class); /** - * + * Before. */ @Before public void before() @@ -43,8 +44,8 @@ public class RSSCacheTest } /** - * - */ + * Test 01. + */ @Test public void test01() {