From e28fb2fcee95112c51506a4713933949099efb54 Mon Sep 17 00:00:00 2001 From: jendave Date: Fri, 9 Sep 2011 15:32:27 +0000 Subject: [PATCH] fixed checkstyle --- .../java/treeProperties/PropertyElement.java | 8 +- .../java/treeProperties/PropertyType.java | 6 +- .../java/treeProperties/TreeProperties.java | 142 ++++++++++-------- 3 files changed, 87 insertions(+), 69 deletions(-) diff --git a/src/main/java/treeProperties/PropertyElement.java b/src/main/java/treeProperties/PropertyElement.java index 4fb020683af..ab5762d0629 100644 --- a/src/main/java/treeProperties/PropertyElement.java +++ b/src/main/java/treeProperties/PropertyElement.java @@ -19,26 +19,26 @@ public interface PropertyElement { * * @return a {@link java.lang.String} object. */ - public String getKey(); + String getKey(); /** * Returns the type of the element. * * @return a {@link java.lang.Class} object. */ - public Class getType(); + Class getType(); /** * Returns the value of the element. * * @return a {@link java.lang.Object} object. */ - public Object getValue(); + Object getValue(); /** * Sets the property value as a string. * * @param value a {@link java.lang.String} object. */ - public void setValue(String value); + void setValue(String value); } diff --git a/src/main/java/treeProperties/PropertyType.java b/src/main/java/treeProperties/PropertyType.java index 86baeba0eab..d6e344e9b5d 100644 --- a/src/main/java/treeProperties/PropertyType.java +++ b/src/main/java/treeProperties/PropertyType.java @@ -24,14 +24,14 @@ public interface PropertyType { * * @return a {@link java.lang.String} object. */ - public String getSuffix(); + String getSuffix(); /** * The class that identifies this content type. * * @return a {@link java.lang.Class} object. */ - public Class getType(); + Class getType(); /** * Returns an object for the specified value, in the context of a TreeProperties. @@ -40,5 +40,5 @@ public interface PropertyType { * @param s a {@link java.lang.String} object. * @return a T object. */ - public T toObject(TreeProperties p, String s); + T toObject(TreeProperties p, String s); } diff --git a/src/main/java/treeProperties/TreeProperties.java b/src/main/java/treeProperties/TreeProperties.java index b48e764cef6..2ed1ca2b57a 100644 --- a/src/main/java/treeProperties/TreeProperties.java +++ b/src/main/java/treeProperties/TreeProperties.java @@ -82,19 +82,19 @@ import static java.util.Collections.unmodifiableList; * @see Properties */ public class TreeProperties implements Iterable { - /** Constant suffixes */ - private static final Map> suffixes; - /** Constant types */ - private static final Map, PropertyType> types; + /** Constant suffixes. */ + private static final Map> SUFFIXES; + /** Constant types. */ + private static final Map, PropertyType> TYPES; - /** Constant transparent="transparent-properties" */ - private static final String transparent = "transparent-properties"; - /** Constant child="properties" */ - private static final String child = "properties"; + /** Constant transparent="transparent-properties". */ + private static final String TRANSPARENT = "transparent-properties"; + /** Constant child="properties". */ + private static final String CHILD = "properties"; static { - types = new HashMap, PropertyType>(); - suffixes = new HashMap>(); + TYPES = new HashMap, PropertyType>(); + SUFFIXES = new HashMap>(); PropertyType[] pt = {new FileType()}; for (PropertyType type : pt) { addType(type); @@ -112,9 +112,9 @@ public class TreeProperties implements Iterable { * * @param type a {@link treeProperties.PropertyType} object. */ - public static void addType(PropertyType type) { - types.put(type.getType(), type); - suffixes.put(type.getSuffix(), type); + public static void addType(final PropertyType type) { + TYPES.put(type.getType(), type); + SUFFIXES.put(type.getSuffix(), type); } /** @@ -122,29 +122,29 @@ public class TreeProperties implements Iterable { * * @param type a {@link treeProperties.PropertyType} object. */ - public static void removeType(PropertyType type) { - types.remove(type.getType()); - suffixes.remove(type.getSuffix()); + public static void removeType(final PropertyType type) { + TYPES.remove(type.getType()); + SUFFIXES.remove(type.getSuffix()); } /** - * Delegate to {@link #TreeProperties(File)} with a new {@link File#File(String)} + * Delegate to {@link #TreeProperties(File)} with a new {@link File#File(String)}. * * @param f a {@link java.lang.String} object. * @throws java.io.IOException if any. */ - public TreeProperties(String f) throws IOException { + public TreeProperties(final String f) throws IOException { this(new File(f)); } /** - * Delegate to {@link #TreeProperties(File)} with a new {@link File#File(File, String)} + * Delegate to {@link #TreeProperties(File)} with a new {@link File#File(File, String)}. * * @param parent a {@link java.io.File} object. * @param f a {@link java.lang.String} object. * @throws java.io.IOException if any. */ - public TreeProperties(File parent, String f) throws IOException { + public TreeProperties(final File parent, final String f) throws IOException { this(new File(parent, f)); } @@ -157,11 +157,13 @@ public class TreeProperties implements Iterable { * @param f a {@link java.io.File} object. * @throws java.io.IOException if any. */ - public TreeProperties(File f) throws IOException { - if (f == null) throw new FileNotFoundException("null"); + public TreeProperties(final File f) throws IOException { + if (f == null) { + throw new FileNotFoundException("null"); + } this.path = f.getParentFile(); - instanceTypes = new HashMap, PropertyType>(types); - instanceSuffixes = new HashMap>(suffixes); + instanceTypes = new HashMap, PropertyType>(TYPES); + instanceSuffixes = new HashMap>(SUFFIXES); Properties p = new Properties(); // BufferedReader r = new BufferedReader(new FileReader(f)); @@ -186,13 +188,15 @@ public class TreeProperties implements Iterable { result = value; } else { //suffix - if (parts[1].equals(transparent) || parts[1].equals(child)) { + if (parts[1].equals(TRANSPARENT) || parts[1].equals(CHILD)) { TreeProperties child = new TreeProperties(path, FileType.getPath(value)); exceptions.addAll(child.exceptions); result = child; } else { PropertyType t = instanceSuffixes.get(parts[1]); - if (t == null) throw new IllegalArgumentException("No content type: " + parts[1]); + if (t == null) { + throw new IllegalArgumentException("No content type: " + parts[1]); + } result = t.toObject(this, value); } } @@ -209,7 +213,7 @@ public class TreeProperties implements Iterable { * * @return a {@link java.util.List} object. */ - public List getExceptions() { + public final List getExceptions() { return exceptions; } @@ -219,8 +223,10 @@ public class TreeProperties implements Iterable { * * @throws java.io.IOException if any. */ - public void rethrow() throws IOException { - if (exceptions.isEmpty()) return; + public final void rethrow() throws IOException { + if (exceptions.isEmpty()) { + return; + } StringBuilder sb = new StringBuilder("The following exceptions occurred:"); for (Exception ex : exceptions) { sb.append("\n"); @@ -234,7 +240,7 @@ public class TreeProperties implements Iterable { * * @return a {@link java.io.File} object. */ - public File getPath() { + public final File getPath() { return path; } @@ -244,8 +250,10 @@ public class TreeProperties implements Iterable { * * @param key a {@link java.lang.String} object. */ - private void checkQueryKey(String key) { - if (key.contains("--")) throw new IllegalArgumentException("Invalid key: " + key); + private void checkQueryKey(final String key) { + if (key.contains("--")) { + throw new IllegalArgumentException("Invalid key: " + key); + } } /** @@ -254,7 +262,7 @@ public class TreeProperties implements Iterable { * @param key a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ - public String getProperty(String key) { + public final String getProperty(final String key) { return getProperty(key, String.class); } @@ -264,7 +272,7 @@ public class TreeProperties implements Iterable { * @param key a {@link java.lang.String} object. * @return a {@link java.io.File} object. */ - public File getFile(String key) { + public final File getFile(final String key) { return getProperty(key, File.class); } @@ -274,8 +282,8 @@ public class TreeProperties implements Iterable { * @param key a {@link java.lang.String} object. * @return a {@link treeProperties.TreeProperties} object. */ - public TreeProperties getChildProperties(String key) { - return (TreeProperties) getProperty(key, "--" + child, true); + public final TreeProperties getChildProperties(final String key) { + return (TreeProperties) getProperty(key, "--" + CHILD, true); } /** @@ -284,8 +292,8 @@ public class TreeProperties implements Iterable { * @param key a {@link java.lang.String} object. * @return a {@link treeProperties.TreeProperties} object. */ - public TreeProperties getTransparentProperties(String key) { - return (TreeProperties) getProperty(key, "--" + transparent, true); + public final TreeProperties getTransparentProperties(final String key) { + return (TreeProperties) getProperty(key, "--" + TRANSPARENT, true); } /** @@ -297,10 +305,11 @@ public class TreeProperties implements Iterable { * @param a T object. */ @SuppressWarnings("unchecked") - public T getProperty(String key, Class cls) { + public final T getProperty(final String key, final Class cls) { String suffix; - if (cls == String.class) suffix = ""; - else { + if (cls == String.class) { + suffix = ""; + } else { PropertyType t = instanceTypes.get(cls); suffix = "--" + t.getSuffix(); } @@ -315,18 +324,20 @@ public class TreeProperties implements Iterable { * @param top a boolean. * @return a {@link java.lang.Object} object. */ - private Object getProperty(String key, String suffix, boolean top) { + private Object getProperty(final String key, final String suffix, final boolean top) { checkQueryKey(key); //first, try the key in the current file, as if there were no slash //No subpath - either directly in the properties... Object result; - if ((result = properties.get(key + suffix)) != null) return result; + if ((result = properties.get(key + suffix)) != null) { + return result; + } //...or in a transparent properties //look for all --transparent-properties for (Entry entry : properties.entrySet()) { - if (entry.getKey().endsWith("--" + transparent)) { + if (entry.getKey().endsWith("--" + TRANSPARENT)) { TreeProperties p = (TreeProperties) entry.getValue(); if ((result = p.getProperty(key, suffix, false)) != null) { return result; @@ -342,8 +353,10 @@ public class TreeProperties implements Iterable { while ((index = key.indexOf('/', index + 1)) != -1) { String first = key.substring(0, index), second = key.substring(index + 1); - TreeProperties p = (TreeProperties) getProperty(first, "--" + child, false); - if (p == null) continue; + TreeProperties p = (TreeProperties) getProperty(first, "--" + CHILD, false); + if (p == null) { + continue; + } if ((result = p.getProperty(second, suffix, false)) != null) { return result; } @@ -362,11 +375,9 @@ public class TreeProperties implements Iterable { * * @return a {@link java.util.Iterator} object. */ - public Iterator iterator() { + public final Iterator iterator() { return iterator(""); - } - - ; + }; /** *

iterator.

@@ -374,7 +385,7 @@ public class TreeProperties implements Iterable { * @param prefix a {@link java.lang.String} object. * @return a {@link treeProperties.TreeProperties.TreePropertiesIterator} object. */ - private TreePropertiesIterator iterator(String prefix) { + private TreePropertiesIterator iterator(final String prefix) { return new TreePropertiesIterator(prefix); } @@ -384,7 +395,7 @@ public class TreeProperties implements Iterable { private TreePropertiesIterator child; private PropertyElement next; - private TreePropertiesIterator(String prefix) { + private TreePropertiesIterator(final String prefix) { entries = properties.entrySet().iterator(); this.prefix = prefix; } @@ -392,9 +403,11 @@ public class TreeProperties implements Iterable { //After this call, the next element is determined, or the child iterator has next public boolean hasNext() { - if (next != null) return true; - else if (child != null && child.hasNext()) return true; - else if (entries.hasNext()) { + if (next != null) { + return true; + } else if (child != null && child.hasNext()) { + return true; + } else if (entries.hasNext()) { Entry entry = entries.next(); final String[] parts = entry.getKey().split("--"); final Class cls; @@ -402,11 +415,11 @@ public class TreeProperties implements Iterable { if (parts.length == 1) { cls = String.class; - } else if (parts[1].equals(transparent)) { + } else if (parts[1].equals(TRANSPARENT)) { child = ((TreeProperties) entry.getValue()).iterator(prefix); //recursive, for the case that the child iterator is empty return hasNext(); - } else if (parts[1].equals(TreeProperties.child)) { + } else if (parts[1].equals(TreeProperties.CHILD)) { child = ((TreeProperties) entry.getValue()).iterator(prefix + parts[0] + "/"); //recursive, for the case that the child iterator is empty return hasNext(); @@ -432,21 +445,26 @@ public class TreeProperties implements Iterable { } - public void setValue(String value) { + public void setValue(final String value) { } }; return true; - } else return false; + } else { + return false; + } } public PropertyElement next() { - if (!hasNext()) throw new NoSuchElementException(); - else if (next != null) { + if (!hasNext()) { + throw new NoSuchElementException(); + } else if (next != null) { PropertyElement next = this.next; this.next = null; return next; - } else return child.next(); + } else { + return child.next(); + } }