Update of
/var/cvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/util/bundles
In directory
james.mmbase.org:/tmp/cvs-serv19747/cmsc/utilities/src/java/com/finalist/cmsc/util/bundles
Modified Files:
RelationshipLoader.java InheritedPropertyResourceBundle.java
Log Message:
CMSC-907 Code Quality with PMD
PMD error fixes
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/util/bundles
See also: http://www.mmbase.org/jira/browse/CMSC-907
Index: RelationshipLoader.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/util/bundles/RelationshipLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- RelationshipLoader.java 26 Nov 2007 11:43:41 -0000 1.3
+++ RelationshipLoader.java 9 Jun 2008 21:23:23 -0000 1.4
@@ -1,13 +1,7 @@
package com.finalist.cmsc.util.bundles;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.BufferedReader;
-
-import java.util.Locale;
-import java.util.Vector;
-import java.util.Enumeration;
+import java.io.*;
+import java.util.*;
/**
* This class is used to load the relationships file.
@@ -37,7 +31,7 @@
/**
* The parent bundles loaded from the relationships file.
*/
- private Vector<InheritedPropertyResourceBundle> relationships = null;
+ private List<InheritedPropertyResourceBundle> relationships = null;
/**
* The file extensions which is searched on to obtain the relationships
file.
@@ -83,10 +77,10 @@
* Subsequent to this method call, the createRelationships() method can be
* called to set up the parents in the resource bundle.
*/
- protected void initRelationships() {
+ protected final void initRelationships() {
// all parent bundles defined in the relationships file.
- relationships = new Vector<InheritedPropertyResourceBundle>();
+ relationships = new ArrayList<InheritedPropertyResourceBundle>();
// gets all parent bundle names from the file.
Enumeration<String> e = getRelationshipNames();
@@ -129,7 +123,7 @@
*/
private Enumeration<String> getRelationshipNames() {
- Vector<String> retVal = new Vector<String>();
+ List<String> retVal = new ArrayList<String>();
InputStream is = null;
InputStreamReader isr = null;
@@ -138,8 +132,7 @@
try {
// convert the resource base name to the file system
// equivalent.
- String rName = baseName.replace('.', RESOURCE_SEPARATOR);
- rName += FILE_EXTENSION;
+ String rName = baseName.replace('.', RESOURCE_SEPARATOR) +
FILE_EXTENSION;
// retrieve the resource from the class loader. If no class
// loader is defined, the system class loader is used.
@@ -151,8 +144,9 @@
}
// no relationships file was found, return.
- if (is == null)
- return retVal.elements();
+ if (is == null) {
+ return Collections.enumeration(retVal);
+ }
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
@@ -162,13 +156,13 @@
while ((line = br.readLine()) != null) {
if (!line.startsWith(COMMENT_ID)) {
line = line.trim();
- if (!line.equals("")) {
+ if (!"".equals(line)) {
retVal.add(line);
}
}
}
- return retVal.elements();
+ return Collections.enumeration(retVal);
}
catch (IOException ioe) {
@@ -177,13 +171,16 @@
}
finally {
try {
- if (br != null)
+ if (br != null) {
br.close();
- if (isr != null)
+ }
+ if (isr != null) {
isr.close();
- if (is != null)
+ }
+ if (is != null) {
is.close();
}
+ }
catch (IOException ioe2) {
// this is very bad. System resources could not be cleaned up.
// In production level code, this should probably either throw
Index: InheritedPropertyResourceBundle.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/util/bundles/InheritedPropertyResourceBundle.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- InheritedPropertyResourceBundle.java 26 Nov 2007 11:43:41 -0000
1.4
+++ InheritedPropertyResourceBundle.java 9 Jun 2008 21:23:23 -0000
1.5
@@ -1,10 +1,6 @@
package com.finalist.cmsc.util.bundles;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Locale;
-import java.util.Enumeration;
-import java.util.Vector;
+import java.util.*;
/**
* The class for representing an inherited PropertyResourceBundle. This class
@@ -45,7 +41,7 @@
* InheritedPropertyResourceBundles. These parent bundles will be checked if
* any key cannot be found in this bundle.
*/
- private Vector<InheritedPropertyResourceBundle> relationships = null;
+ private List<InheritedPropertyResourceBundle> relationships = null;
/**
* The java.util.ResourceBundle that backs this instance. This bundle will
@@ -86,7 +82,7 @@
* relationships files.
*/
protected InheritedPropertyResourceBundle(String baseName, Locale locale,
ClassLoader loader) {
-
+ super();
// cache all creation information.
this.baseName = baseName;
this.locale = locale;
@@ -115,12 +111,12 @@
*
* @see RelationshipLoader
*/
- protected void initRelationships() {
+ protected final void initRelationships() {
// create a RelationshipLoader with the appropriate context.
RelationshipLoader rl = new RelationshipLoader(baseName, locale, loader);
- relationships = new Vector<InheritedPropertyResourceBundle>();
+ relationships = new ArrayList<InheritedPropertyResourceBundle>();
// add the parent relationships to this instance.
rl.createRelations(this);
@@ -133,7 +129,7 @@
*/
@Override
public Enumeration<String> getKeys() {
- Vector<String> temp = new Vector<String>();
+ List<String> temp = new ArrayList<String>();
// get all keys for the backed PropertyResourceBundle
for (Enumeration<String> e = instance.getKeys(); e.hasMoreElements();) {
@@ -152,14 +148,14 @@
String k = g.nextElement();
// only add the key if it does not already exist.
- if (!temp.contains(k))
+ if (!temp.contains(k)) {
temp.add(k);
}
}
}
+ }
- return temp.elements();
-
+ return Collections.enumeration(temp);
}
@@ -186,17 +182,15 @@
// of this inherited bundle.
}
- if (retVal == null) {
+ if (retVal == null && relationships != null) {
// resource not found in PropertyResourceBundle, check all parents.
- if (relationships != null) {
for (Object element : relationships) {
// attempt to get the resource from the current parent bundle.
retVal = ((InheritedPropertyResourceBundle)
element).handleGetObject(key);
- if (retVal != null)
+ if (retVal != null) {
return retVal;
-
}
}
}
@@ -251,8 +245,9 @@
* @return an Enumeration of the parent resource bundles.
*/
public Enumeration<InheritedPropertyResourceBundle> getRelationships() {
- if (relationships == null)
- return (new Vector<InheritedPropertyResourceBundle>().elements());
- return relationships.elements();
+ if (relationships == null) {
+ return Collections.enumeration(new
ArrayList<InheritedPropertyResourceBundle>());
+ }
+ return Collections.enumeration(relationships);
}
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs