summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-07-05 12:43:13 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-07-05 12:43:13 -0400
commit6d46c473d41c6c47e6b8bd8c676d925e544bd378 (patch)
tree796d51bfff52f8f3fa383b2d26847b7c8160677b /projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal
parent02bc52037e9ccccca672d6156d9c325c74fe28b3 (diff)
More cleanup
Diffstat (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal')
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java8
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java25
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java12
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java5
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java78
5 files changed, 68 insertions, 60 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java
index 09687e2..870ff83 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java
@@ -35,7 +35,7 @@ import java.util.Set;
* <br>
*
* Of particular note are the get() and set() methods, which will attempt to get
- * and set artibrary values on arbitrary objects to the best of its ability,
+ * and set arbitrary values on arbitrary objects to the best of its ability,
* converting values as appropriate. Properties of the form
* "property.nestedproperty.anotherproperty" are supported to get and set values
* on property values directly.<br>
@@ -72,10 +72,10 @@ public class Introspector {
// wildcard value - using this class to represent a "wildcard" generic class.
// we have to do this when matching methods by parameter types and a
// null value is passed in - can't tell what class the null should be.
- public static Class WILD = Introspector.class;
+ public static Class<?> WILD = Introspector.class;
// empty class array - prevents having to create one every time
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
+ private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
// use OGNL for property access
private static boolean useOGNL;
@@ -99,7 +99,7 @@ public class Introspector {
* parameters.
* @return The appropriate method for the class, or null if not found.
*/
- static public Method getPropertyReadMethod(Class objectClass, String aProperty, Class[] paramTypes) {
+ static public Method getPropertyReadMethod(Class<?> objectClass, String aProperty, Class<?>[] paramTypes) {
Method result = null;
result = getMethodFromClass(objectClass, aProperty, paramTypes, true);
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java
index 7761876..a36c616 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java
@@ -79,8 +79,8 @@ import java.util.Hashtable;
*/
public class NetworkClassLoader extends ClassLoader {
private ClassLoader parent = null; // parent classloader
- private Hashtable classCache = new Hashtable();
- private Hashtable urlset = new Hashtable();
+ private Hashtable<String, Class<?>> classCache = new Hashtable<>();
+ private Hashtable<URL, URLResourceReader> urlset = new Hashtable<>();
/**
* Creates a new instance of the class loader.
@@ -132,14 +132,15 @@ public class NetworkClassLoader extends ClassLoader {
/**
* @return An enumeration of URLs where this class loader looks for classes.
*/
- public Enumeration getURLs() {
+ public Enumeration<URL> getURLs() {
return urlset.keys();
}
/**
* Call this to bypass the implementation of loadClass.
*/
- public Class findClass(String name) {
+ @Override
+ public Class<?> findClass(String name) {
byte[] b = loadClassData(name);
if (b == null)
return null;
@@ -158,7 +159,7 @@ public class NetworkClassLoader extends ClassLoader {
protected byte[] loadResource(String resource) {
byte[] barray = null;
- for (Enumeration e = urlset.keys(); e.hasMoreElements();) {
+ for (Enumeration<URL> e = urlset.keys(); e.hasMoreElements();) {
URL url = (URL) e.nextElement();
try {
@@ -182,11 +183,12 @@ public class NetworkClassLoader extends ClassLoader {
* Overridden to search for a resource and return a "jar"-style URL or normal
* "file" URL as necessary.
*/
+ @Override
protected URL findResource(String name) { // System.out.println( "findResource: " + name );
URL url;
byte[] barray = null;
- for (Enumeration e = urlset.keys(); e.hasMoreElements();) {
+ for (Enumeration<URL> e = urlset.keys(); e.hasMoreElements();) {
url = (URL) e.nextElement();
try {
barray = loadResource(url, name); // loads fully: wasteful
@@ -216,6 +218,7 @@ public class NetworkClassLoader extends ClassLoader {
* @return The resource as the input stream if such a resource exists, otherwise
* returns null.
*/
+ @Override
public InputStream getResourceAsStream(String name) {
// System.out.println( "getResourceAsStream: " + name );
InputStream istream = null;
@@ -257,12 +260,13 @@ public class NetworkClassLoader extends ClassLoader {
* @param The class data bytes.
* @return The class object.
*/
- protected Class defineClass(String classname, byte[] classdata) {
+ protected Class<?> defineClass(String classname, byte[] classdata) {
return defineClass(classname, classdata, 0, classdata.length);
}
- public synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
- Class c = null;
+ @Override
+ public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ Class<?> c = null;
// Algorithm: (Please do not change the order; unless you
// have a good reason to do so).
@@ -293,7 +297,7 @@ public class NetworkClassLoader extends ClassLoader {
}
// Lets see if the class is in the cache..
- c = (Class) classCache.get(name);
+ c = (Class<?>) classCache.get(name);
if (c != null)
return c;
@@ -328,6 +332,7 @@ public class NetworkClassLoader extends ClassLoader {
* This method resets this ClassLoader's state and resets the references for
* garbage collection.
*/
+ @Override
protected void finalize() throws Throwable {
// Cleanup real well. Otherwise, this can be
// a major source of memory leaks...
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java
index 3698325..c44a892 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java
@@ -26,7 +26,7 @@ import java.io.*;
* return the top-level object represented by the plist.
* <p>
*
- * A property list is a heirarchical data structure containing only Maps, Lists,
+ * A property list is a hierarchical data structure containing only Maps, Lists,
* and Strings -- nothing else. In other words, a property list is either a Map,
* List, or String instance, with the restrictions that the collections may only
* contain Map, List, or String instances.
@@ -79,7 +79,7 @@ import java.io.*;
* are thrown with the line number and column of the problem.
* <p>
*
- * Currenty, HashMaps and ArrayLists are the actual Map and List classes used
+ * Currently, HashMaps and ArrayLists are the actual Map and List classes used
* when creating the property list.
* <p>
*
@@ -456,8 +456,8 @@ public class PropertyListParser {
return stringBuffer.toString();
}
- private List readList() {
- List newList = new ArrayList();
+ private List<Object> readList() {
+ List<Object> newList = new ArrayList<>();
currIndex++; // skip over '('
skipCommentWhitespace();
@@ -488,8 +488,8 @@ public class PropertyListParser {
return newList;
}
- private Map readMap() {
- HashMap newMap = new HashMap();
+ private Map<Object, Object> readMap() {
+ HashMap<Object, Object> newMap = new HashMap<>();
currIndex++; // skip over open brace
skipCommentWhitespace();
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java
index 8694564..92862f6 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java
@@ -72,7 +72,7 @@ import java.util.zip.ZipInputStream;
* @author Harish Prabandham
*/
public class URLResourceReader {
- private Hashtable resourceCache = new Hashtable();
+ private Hashtable<String, Object> resourceCache = new Hashtable<>();
private boolean iszip = true;
private URL url = null;
private boolean cache = true;
@@ -147,7 +147,7 @@ public class URLResourceReader {
/**
* Returns an Enumeration of all "known" resource names.
*/
- public Enumeration getResourceNames() {
+ public Enumeration<String> getResourceNames() {
return resourceCache.keys();
}
@@ -188,6 +188,7 @@ public class URLResourceReader {
resourceCache = null;
}
+ @Override
public String toString() {
return url.toString();
}
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java
index 3d995e5..551e4ce 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java
@@ -177,7 +177,7 @@ public class ValueConverter {
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Short(((Number) anObject).shortValue());
+ return Short.valueOf(((Number) anObject).shortValue());
}
try {
@@ -194,16 +194,16 @@ public class ValueConverter {
static public Integer getInteger(Object anObject) {
if (anObject == null)
- return new Integer(0);
+ return Integer.valueOf(0);
if ("".equals(anObject))
- return new Integer(0);
+ return Integer.valueOf(0);
if (anObject instanceof Integer)
return (Integer) anObject;
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Integer(((Number) anObject).intValue());
+ return Integer.valueOf(((Number) anObject).intValue());
}
try {
@@ -220,16 +220,16 @@ public class ValueConverter {
static public Long getLong(Object anObject) {
if (anObject == null)
- return new Long(0);
+ return Long.valueOf(0);
if ("".equals(anObject))
- return new Long(0);
+ return Long.valueOf(0);
if (anObject instanceof Long)
return (Long) anObject;
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Long(((Number) anObject).longValue());
+ return Long.valueOf(((Number) anObject).longValue());
}
try {
@@ -246,16 +246,16 @@ public class ValueConverter {
static public Double getDouble(Object anObject) {
if (anObject == null)
- return new Double(0.0);
+ return Double.valueOf(0.0);
if ("".equals(anObject))
- return new Double(0);
+ return Double.valueOf(0);
if (anObject instanceof Double)
return (Double) anObject;
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Double(((Number) anObject).doubleValue());
+ return Double.valueOf(((Number) anObject).doubleValue());
}
try {
@@ -272,16 +272,16 @@ public class ValueConverter {
static public Float getFloat(Object anObject) {
if (anObject == null)
- return new Float(0.0);
+ return Float.valueOf(0.0f);
if ("".equals(anObject))
- return new Float(0.0);
+ return Float.valueOf(0.0f);
if (anObject instanceof Float)
return (Float) anObject;
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Float(((Number) anObject).floatValue());
+ return Float.valueOf(((Number) anObject).floatValue());
}
try {
@@ -298,18 +298,18 @@ public class ValueConverter {
static public Character getCharacter(Object anObject) {
if (anObject == null)
- return new Character((char) 0);
+ return Character.valueOf((char) 0);
if (anObject instanceof Character)
return (Character) anObject;
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Character((char) ((Number) anObject).byteValue());
+ return Character.valueOf((char) ((Number) anObject).byteValue());
}
try {
- return new Character(anObject.toString().charAt(0));
+ return Character.valueOf(anObject.toString().charAt(0));
} catch (Exception exc) {
return null;
}
@@ -322,16 +322,16 @@ public class ValueConverter {
static public Byte getByte(Object anObject) {
if (anObject == null)
- return new Byte(Byte.MIN_VALUE);
+ return Byte.valueOf(Byte.MIN_VALUE);
if ("".equals(anObject))
- return new Byte(Byte.MIN_VALUE);
+ return Byte.valueOf(Byte.MIN_VALUE);
if (anObject instanceof Byte)
return (Byte) anObject;
anObject = preprocess(anObject);
if (anObject instanceof Number) {
- return new Byte(((Number) anObject).byteValue());
+ return Byte.valueOf(((Number) anObject).byteValue());
}
try {
@@ -364,14 +364,14 @@ public class ValueConverter {
return (Boolean) anObject;
}
if (anObject instanceof Number) {
- return new Boolean(((Number) anObject).doubleValue() == 0.0);
+ return Boolean.valueOf(((Number) anObject).doubleValue() == 0.0);
}
if (anObject instanceof String) {
if (anObject.toString().toLowerCase().equals("yes")) {
return Boolean.TRUE;
}
- return new Boolean((String) anObject);
+ return Boolean.valueOf((String) anObject);
}
return null;
@@ -396,24 +396,25 @@ public class ValueConverter {
* in any other way, resorts to creating a new collection of the specified type
* containing the specified object.
*/
- static public Collection getCollection(Object anObject, Class aCollectionClass) {
+ @SuppressWarnings("unchecked")
+ static public Collection<?> getCollection(Object anObject, Class<?> aCollectionClass) {
if (anObject == null)
return null;
if (aCollectionClass.isAssignableFrom(anObject.getClass())) {
- return (Collection) anObject;
+ return (Collection<?>) anObject;
}
- Collection converted = null;
+ Collection<Object> converted = null;
// convert to collection class
if (anObject instanceof Collection) {
- converted = (Collection) anObject;
+ converted = (Collection<Object>) anObject;
} else
// try to convert an array
if (anObject.getClass().isArray()) {
try {
int length = Array.getLength(anObject);
- converted = new LinkedList();
+ converted = new LinkedList<>();
for (int i = 0; i < length; i++) {
converted.add(Array.get(anObject, i));
}
@@ -423,25 +424,25 @@ public class ValueConverter {
} else
// convert map values to collection and pass through
if (anObject instanceof Map) {
- converted = ((Map) anObject).values();
+ converted = ((Map<?, Object>) anObject).values();
}
// fall back on list containing the object
if (converted == null) {
- converted = new LinkedList();
+ converted = new LinkedList<>();
converted.add(anObject);
}
- Collection result = null;
+ Collection<Object> result = null;
if (converted != null) {
try {
// collections required to have the copy constructor.
- Constructor ctor = aCollectionClass.getConstructor(new Class[] { Collection.class });
- result = (Collection) ctor.newInstance(new Object[] { converted });
+ Constructor<?> ctor = aCollectionClass.getConstructor(new Class[] { Collection.class });
+ result = (Collection<Object>) ctor.newInstance(new Object[] { converted });
} catch (Exception exc) {
try {
- result = new LinkedList();
+ result = new LinkedList<>();
result.addAll(converted);
} catch (Exception exc2) {
// all attempts failed
@@ -456,7 +457,8 @@ public class ValueConverter {
/**
* Convert the object to the specified array type.
*/
- static public Object getArray(Object anObject, Class anArrayClass) {
+ @SuppressWarnings("unchecked")
+ static public Object getArray(Object anObject, Class<?> anArrayClass) {
if (anObject == null)
return null;
@@ -475,14 +477,14 @@ public class ValueConverter {
}
// convert map values to collection and pass through
if (anObject instanceof Map) {
- anObject = ((Map) anObject).values();
+ anObject = ((Map<?, Object>) anObject).values();
}
// try to convert a collection
if (anObject instanceof Collection) {
try {
- int length = ((Collection) anObject).size();
+ int length = ((Collection<?>) anObject).size();
Object result = Array.newInstance(anArrayClass.getComponentType(), length);
- Iterator it = ((Collection) anObject).iterator();
+ Iterator<?> it = ((Collection<?>) anObject).iterator();
for (int i = 0; i < length; i++) {
Array.set(result, i, it.next());
}
@@ -545,12 +547,12 @@ public class ValueConverter {
public static Object invert(Object anObject) {
if (anObject == null)
return null;
- Class aClass = anObject.getClass();
+ Class<?> aClass = anObject.getClass();
if (((anObject instanceof Number) && !(anObject instanceof Byte) && !(anObject instanceof Character))
|| (aClass == short.class) || (aClass == int.class) || (aClass == long.class) || (aClass == float.class)
|| (aClass == double.class)) {
- return convertObjectToClass(new Double(getDoubleValue(anObject) * -1), aClass);
+ return convertObjectToClass(Double.valueOf(getDoubleValue(anObject) * -1), aClass);
}
Boolean converted = getBoolean(anObject);