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-01 17:27:48 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-07-01 17:27:48 -0400
commit02bc52037e9ccccca672d6156d9c325c74fe28b3 (patch)
treedb022b83c90562f461f4a27412caa9936a8dfd04 /projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal
parentc75d7dbd613a47b217499f7a856c469a8bc59e2a (diff)
Update a whole bunch of things
Yeah... not a great commit message. t.b.h, I could maybe've split the commit into more parts; but that would be quite a lot off effort and would have a pretty decent chance of at least one of the commits leaving the repository in a non-working state. For the future, will want to try and commit more often so there aren't these mega-commits where it's just "a whole bunch of stuff changed"
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/Duplicator.java32
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/IntrospectorException.java1
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/MissingPropertyException.java1
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NullPrimitiveException.java1
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyComparator.java12
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/QueueMap.java127
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java59
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/WotonomyException.java7
8 files changed, 137 insertions, 103 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Duplicator.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Duplicator.java
index 16ef393..8ecb7a3 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Duplicator.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Duplicator.java
@@ -19,8 +19,6 @@ License along with this library; if not, see http://www.gnu.org
package net.wotonomy.foundation.internal;
import net.wotonomy.foundation.*;
-import net.wotonomy.foundation.internal.Introspector;
-import net.wotonomy.foundation.internal.WotonomyException;
import java.io.*;
import java.util.*; //collections
@@ -49,14 +47,14 @@ public class Duplicator {
* Returns a list of properties for the specified class that are both readable
* and writable.
*/
- static public List editablePropertiesForObject(Object anObject) {
- List readProperties = new ArrayList();
+ static public List<String> editablePropertiesForObject(Object anObject) {
+ List<String> readProperties = new ArrayList<>();
String[] read = Introspector.getReadPropertiesForObject(anObject);
for (int i = 0; i < read.length; i++) {
readProperties.add(read[i]);
}
- List properties = new ArrayList();
+ List<String> properties = new ArrayList<>();
String[] write = Introspector.getWritePropertiesForObject(anObject);
for (int i = 0; i < write.length; i++) {
properties.add(write[i]);
@@ -73,12 +71,12 @@ public class Duplicator {
* and their values. Any null values for properties will be represented with the
* NULL object.
*/
- static public Map readPropertiesForObject(Object anObject) {
- NSMutableDictionary result = new NSMutableDictionary();
+ static public Map<String, Object> readPropertiesForObject(Object anObject) {
+ NSMutableDictionary<String, Object> result = new NSMutableDictionary<>();
String key;
Object value;
- Iterator it = editablePropertiesForObject(anObject).iterator();
+ Iterator<String> it = editablePropertiesForObject(anObject).iterator();
while (it.hasNext()) {
key = it.next().toString();
value = Introspector.get(anObject, key);
@@ -93,10 +91,12 @@ public class Duplicator {
* Returns a Map containing only the mutable properties for the specified object
* and deep clones of their values. Nulls are represented by the NULL object.
*/
- static public Map clonePropertiesForObject(Object anObject) {
- Object key, value;
- Map result = readPropertiesForObject(anObject);
- Iterator it = result.keySet().iterator();
+ static public Map<String, Object> clonePropertiesForObject(Object anObject) {
+ String key;
+ Object value;
+
+ Map<String, Object> result = readPropertiesForObject(anObject);
+ Iterator<String> it = result.keySet().iterator();
while (it.hasNext()) {
key = it.next();
value = result.get(key);
@@ -110,10 +110,10 @@ public class Duplicator {
* Applies the map of properties and values to the specified object. Null values
* for properties must be represented by the NULL object.
*/
- static public void writePropertiesForObject(Map aMap, Object anObject) {
+ static public void writePropertiesForObject(Map<String, Object> aMap, Object anObject) {
String key;
Object value;
- Iterator it = aMap.keySet().iterator();
+ Iterator<String> it = aMap.keySet().iterator();
while (it.hasNext()) {
key = it.next().toString();
value = aMap.get(key);
@@ -141,9 +141,9 @@ public class Duplicator {
}
}
- Class c = aSource.getClass();
+ Class<?> c = aSource.getClass();
try {
- result = c.newInstance();
+ result = c.getDeclaredConstructor().newInstance();
} catch (Exception exc) {
throw new WotonomyException(exc);
}
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/IntrospectorException.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/IntrospectorException.java
index 45080a2..a5887ab 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/IntrospectorException.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/IntrospectorException.java
@@ -28,4 +28,5 @@ package net.wotonomy.foundation.internal;
*/
public class IntrospectorException extends WotonomyException {
+ private static final long serialVersionUID = -997809394704941577L;
}
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/MissingPropertyException.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/MissingPropertyException.java
index c89742f..c53595c 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/MissingPropertyException.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/MissingPropertyException.java
@@ -28,4 +28,5 @@ package net.wotonomy.foundation.internal;
*/
public class MissingPropertyException extends IntrospectorException {
+ private static final long serialVersionUID = -6130027204690491083L;
}
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NullPrimitiveException.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NullPrimitiveException.java
index bf1dffd..aa52e69 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NullPrimitiveException.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NullPrimitiveException.java
@@ -28,4 +28,5 @@ package net.wotonomy.foundation.internal;
*/
public class NullPrimitiveException extends IntrospectorException {
+ private static final long serialVersionUID = -572058252131498585L;
}
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyComparator.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyComparator.java
index c804893..f8b1cca 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyComparator.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyComparator.java
@@ -29,7 +29,8 @@ import java.util.Comparator;
* @author $Author: cgruber $
* @version $Revision: 893 $
*/
-public class PropertyComparator implements Comparator, Serializable {
+public class PropertyComparator<T> implements Comparator<T>, Serializable {
+ private static final long serialVersionUID = -3028294144521868334L;
private String property;
/**
@@ -43,13 +44,15 @@ public class PropertyComparator implements Comparator, Serializable {
// interface Comparator
+ @SuppressWarnings("unchecked")
+ @Override
public int compare(Object o1, Object o2) {
Object v1 = Introspector.get(o1, property);
Object v2 = Introspector.get(o2, property);
- if (v1 instanceof Comparable) {
- return ((Comparable) v1).compareTo(v2);
+ if (v1 instanceof Comparable<?>) {
+ return ((Comparable<Object>) v1).compareTo(v2);
} else if (v2 instanceof Comparable) {
- return ((Comparable) v2).compareTo(v1);
+ return ((Comparable<Object>) v2).compareTo(v1);
} else {
if (v1 == null) {
if (v2 == null) {
@@ -64,6 +67,7 @@ public class PropertyComparator implements Comparator, Serializable {
return v1.toString().compareTo(v2.toString());
}
+ @Override
public boolean equals(Object obj) {
return (obj instanceof PropertyComparator);
}
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/QueueMap.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/QueueMap.java
index 59104e5..2f6accf 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/QueueMap.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/QueueMap.java
@@ -22,9 +22,9 @@ import java.util.*; //collections
/**
* A queue based implementation of the Map interface. This class provides for
- * all the opertions of a map, but keeps the entries in the same sequence as
+ * all the operations of a map, but keeps the entries in the same sequence as
* originally added. The first entry placed in the map will be the first entry
- * retreived during iteration: first-in, first-out (FIFO). <BR>
+ * retrieved during iteration: first-in, first-out (FIFO). <BR>
* <BR>
*
* Keys cannot be duplicated. If an entry is made using a key that already
@@ -33,9 +33,9 @@ import java.util.*; //collections
* <BR>
*
* Some convenience methods are provided for the queue type operations. The
- * first key can be retreived as well as the last key. A key can be used to
- * retreive its corresponding value from the map. A value can also be used to
- * retreive its key from the map, however, since there may be multiple values of
+ * first key can be retrieved as well as the last key. A key can be used to
+ * retrieve its corresponding value from the map. A value can also be used to
+ * retrieve its key from the map, however, since there may be multiple values of
* the same equality, the first key found will be returned. <BR>
* <BR>
*
@@ -44,31 +44,31 @@ import java.util.*; //collections
* @date $Date: 2006-02-18 17:41:36 -0500 (Sat, 18 Feb 2006) $
* @revision $Revision: 899 $
*/
-public class QueueMap implements Map {
- List values;
- List keys;
- Map keyToValue;
+public class QueueMap<K, V> implements Map<K, V> {
+ List<V> values;
+ List<K> keys;
+ Map<K, V> keyToValue;
/**
* Creates an empty QueueMap.
*/
public QueueMap() {
- values = new LinkedList();
- keys = new LinkedList();
- keyToValue = new HashMap();
+ values = new LinkedList<>();
+ keys = new LinkedList<>();
+ keyToValue = new HashMap<>();
}
/**
* Creates a QueueMap and places the entries from the passed in map into this
- * map. The order of the entries is based on however the iterator iteratated
+ * map. The order of the entries is based on however the iterator iterated
* through the map entries.
*
* @param t A map object.
*/
- public QueueMap(Map t) {
- values = new ArrayList();
- keys = new ArrayList();
- keyToValue = new HashMap();
+ public QueueMap(Map<K, V> t) {
+ values = new ArrayList<>();
+ keys = new ArrayList<>();
+ keyToValue = new HashMap<>();
putAll(t);
}
@@ -76,6 +76,7 @@ public class QueueMap implements Map {
/**
* Removes all the entries from this map.
*/
+ @Override
public void clear() {
values.clear();
keys.clear();
@@ -89,6 +90,7 @@ public class QueueMap implements Map {
*
* @return True if the map contains the given key, false otherwise.
*/
+ @Override
public boolean containsKey(Object key) {
return keyToValue.containsKey(key);
}
@@ -102,6 +104,7 @@ public class QueueMap implements Map {
*
* @return True if the map contains the given value, false otherwise.
*/
+ @Override
public boolean containsValue(Object value) {
return keyToValue.containsValue(value);
}
@@ -114,11 +117,12 @@ public class QueueMap implements Map {
*
* @return a set view of the mappings contained in this map.
*/
- public Set entrySet() {
- Set result = new HashSet(keys.size(), 1F);
+ @Override
+ public Set<Map.Entry<K, V>> entrySet() {
+ Set<Map.Entry<K, V>> result = new HashSet<>(keys.size(), 1F);
for (int i = 0; i < keys.size(); i++) {
- result.add(new KeyValuePair(keys.get(i), values.get(i)));
+ result.add(new KeyValuePair<>(keys.get(i), values.get(i)));
}
return result;
@@ -135,6 +139,7 @@ public class QueueMap implements Map {
* @param o object to be compared for equality with this map.
* @return <tt>true</tt> if the specified object is equal to this map.
*/
+ @Override
public boolean equals(Object o) {
return keyToValue.equals(o);
}
@@ -149,7 +154,8 @@ public class QueueMap implements Map {
* @return The value corresponding to the key (can be null), or null if the key
* is not contained in the map.
*/
- public Object get(Object key) {
+ @Override
+ public V get(Object key) {
return keyToValue.get(key);
}
@@ -162,6 +168,7 @@ public class QueueMap implements Map {
*
* @return the hash code value for this map.
*/
+ @Override
public int hashCode() {
return keyToValue.hashCode();
}
@@ -171,6 +178,7 @@ public class QueueMap implements Map {
*
* @return True is this map contains no entries, false otherwise.
*/
+ @Override
public boolean isEmpty() {
return keyToValue.isEmpty();
}
@@ -181,8 +189,9 @@ public class QueueMap implements Map {
*
* @return A Set containing all the keys used in the map.
*/
- public Set keySet() {
- Set result = new HashSet(keys.size(), 1F);
+ @Override
+ public Set<K> keySet() {
+ Set<K> result = new HashSet<>(keys.size(), 1F);
for (int i = 0; i < keys.size(); i++) {
result.add(keys.get(i));
@@ -202,7 +211,8 @@ public class QueueMap implements Map {
* @return Null if the key is new, the replaced value if the key already
* existed. (Note: If the key was null, then null is returned.)
*/
- public Object put(Object key, Object value) {
+ @Override
+ public V put(K key, V value) {
if (key == null)
return null;
@@ -223,15 +233,16 @@ public class QueueMap implements Map {
*
* @param t A map of key/value entries.
*/
- public void putAll(Map t) {
+ @Override
+ public void putAll(Map<? extends K, ? extends V> t) {
if (t == null) {
// Nothing to do!
return;
}
// Place the entries from the passed in map into this map.
- for (Iterator it = t.keySet().iterator(); it.hasNext();) {
- Object aKey = it.next();
+ for (Iterator<? extends K> it = t.keySet().iterator(); it.hasNext();) {
+ K aKey = it.next();
put(aKey, t.get(aKey));
}
}
@@ -245,11 +256,12 @@ public class QueueMap implements Map {
* Null could also be returned if the associated value of the key was
* null.
*/
- public Object remove(Object key) {
+ @Override
+ public V remove(Object key) {
if (key == null)
return null;
- Object value = null;
+ V value = null;
if (containsKey(key)) {
value = keyToValue.remove(key);
@@ -268,6 +280,7 @@ public class QueueMap implements Map {
*
* @return The number of pairs.
*/
+ @Override
public int size() {
return values.size();
}
@@ -280,7 +293,7 @@ public class QueueMap implements Map {
*
* @return An ordered list of keys.
*/
- public List keys() {
+ public List<K> keys() {
return keys;
}
@@ -292,7 +305,8 @@ public class QueueMap implements Map {
*
* @return An ordered list of values.
*/
- public Collection values() {
+ @Override
+ public Collection<V> values() {
return values;
}
@@ -306,7 +320,7 @@ public class QueueMap implements Map {
* @return The value corresponding to the key (can be null), or null if the key
* is not contained in the map.
*/
- public Object getValueForKey(Object key) {
+ public V getValueForKey(K key) {
return keyToValue.get(key);
}
@@ -318,7 +332,7 @@ public class QueueMap implements Map {
* @param value A value that is contained in this map.
* @return A first key that corresponds to this value.
*/
- public Object getKeyForValue(Object value) {
+ public K getKeyForValue(V value) {
int i = values.indexOf(value);
if (i != -1) {
return keys.get(i);
@@ -331,7 +345,7 @@ public class QueueMap implements Map {
*
* @return The first key in the map, null if there are no mappings.
*/
- public Object getFirstKey() {
+ public K getFirstKey() {
if (keys.size() < 1) {
return null;
}
@@ -343,7 +357,7 @@ public class QueueMap implements Map {
*
* @return The last key in the map, null if there are no mappings.
*/
- public Object getLastKey() {
+ public K getLastKey() {
if (keys.size() < 1) {
return null;
}
@@ -354,9 +368,9 @@ public class QueueMap implements Map {
* This class contains a key/value pair. The key must be a valid object, it
* cannot be null. The value can be a valid object or null.
*/
- static public class KeyValuePair implements Map.Entry {
- Object key;
- Object value;
+ static public class KeyValuePair<K, V> implements Map.Entry<K, V> {
+ K key;
+ V value;
/**
* Default constructor. The constructor takes the key and value as parameters.
@@ -366,7 +380,7 @@ public class QueueMap implements Map {
* @param key The key object of this pair. The key cannot be null.
* @param value The value object of this pair. The value can be null.
*/
- public KeyValuePair(Object aKey, Object aValue) {
+ public KeyValuePair(K aKey, V aValue) {
key = aKey;
value = aValue;
}
@@ -376,7 +390,8 @@ public class QueueMap implements Map {
*
* @return The key object.
*/
- public Object getKey() {
+ @Override
+ public K getKey() {
return key;
}
@@ -385,7 +400,8 @@ public class QueueMap implements Map {
*
* @return The value object.
*/
- public Object getValue() {
+ @Override
+ public V getValue() {
return value;
}
@@ -394,15 +410,18 @@ public class QueueMap implements Map {
*
* @param aValue The value object to place into this pair.
*/
- public Object setValue(Object aValue) {
- Object result = value;
+ @Override
+ public V setValue(V aValue) {
+ V result = value;
value = aValue;
return result;
}
+ @Override
public boolean equals(Object o) {
if (o instanceof KeyValuePair) {
- KeyValuePair p = (KeyValuePair) o;
+ @SuppressWarnings("unchecked")
+ KeyValuePair<K, V> p = (KeyValuePair<K, V>) o;
if ((key.equals(p.getKey())) && (value.equals(p.getValue()))) {
return true;
}
@@ -412,9 +431,10 @@ public class QueueMap implements Map {
}
/**
- * Returns a string reprsentation of this class. The contents of the map are
+ * Returns a string representation of this class. The contents of the map are
* placed in the string in its proper order.
*/
+ @Override
public String toString() {
int max = size() - 1;
StringBuffer buf = new StringBuffer();
@@ -432,10 +452,11 @@ public class QueueMap implements Map {
}
// unit test
+ // TODO convert to JUnit test
public static void main(String[] argv) {
- QueueMap qMap;
+ QueueMap<String, String> qMap;
- qMap = new QueueMap();
+ qMap = new QueueMap<>();
for (int i = 0; i < 5; i++) {
qMap.put(Integer.toString(i), Integer.toString(i));
}
@@ -443,7 +464,7 @@ public class QueueMap implements Map {
System.out.println("Keys = " + qMap.keys());
System.out.println("Values = " + qMap.values());
- qMap = new QueueMap();
+ qMap = new QueueMap<>();
for (int i = 0; i < 5; i++) {
qMap.put(Integer.toString(i), "A");
}
@@ -451,7 +472,7 @@ public class QueueMap implements Map {
System.out.println("Keys = " + qMap.keys());
System.out.println("Values = " + qMap.values());
- qMap = new QueueMap();
+ qMap = new QueueMap<>();
for (int i = 0; i < 5; i++) {
qMap.put(Integer.toString(i), null);
}
@@ -459,17 +480,17 @@ public class QueueMap implements Map {
System.out.println("Keys = " + qMap.keys());
System.out.println("Values = " + qMap.values());
- Map aMap = new HashMap();
+ Map<String, String> aMap = new HashMap<>();
for (int i = 0; i < 5; i++) {
aMap.put(Integer.toString(i), Integer.toString(i));
}
- qMap = new QueueMap(aMap);
+ qMap = new QueueMap<>(aMap);
System.out.println("\nHashMap = " + aMap);
System.out.println("Map = " + qMap);
System.out.println("Keys = " + qMap.keys());
System.out.println("Values = " + qMap.values());
- qMap = new QueueMap();
+ qMap = new QueueMap<>();
qMap.put("Test1", "String1");
qMap.put("Test2", "String2");
qMap.put("Test3", "String3");
@@ -498,7 +519,7 @@ public class QueueMap implements Map {
qMap.put("Test12", "String12");
System.out.println("Clear Test, Map = " + qMap);
- aMap = new HashMap();
+ aMap = new HashMap<>();
aMap.put("Test10", "String10");
aMap.put("Test11", "String11");
aMap.put("Test12", "String12");
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 7f28e06..3d995e5 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
@@ -37,69 +37,70 @@ public class ValueConverter {
* Returns the specified object as converted to an instance of the specified
* class, or null if the conversion could not be performed.
*/
- static public Object convertObjectToClass(Object anObject, Class aClass) {
+ @SuppressWarnings("unchecked")
+ static public <C> C convertObjectToClass(Object anObject, Class<C> aClass) {
if (aClass == String.class) {
- return getString(anObject);
+ return (C) getString(anObject);
}
if (aClass == Short.class) {
- return getShort(anObject);
+ return (C) getShort(anObject);
}
if (aClass == short.class) {
- return getShort(anObject);
+ return (C) getShort(anObject);
}
if (aClass == Integer.class) {
- return getInteger(anObject);
+ return (C) getInteger(anObject);
}
if (aClass == int.class) {
- return getInteger(anObject);
+ return (C) getInteger(anObject);
}
if (aClass == Long.class) {
- return getLong(anObject);
+ return (C) getLong(anObject);
}
if (aClass == long.class) {
- return getLong(anObject);
+ return (C) getLong(anObject);
}
if (aClass == Float.class) {
- return getFloat(anObject);
+ return (C) getFloat(anObject);
}
if (aClass == float.class) {
- return getFloat(anObject);
+ return (C) getFloat(anObject);
}
if (aClass == Double.class) {
- return getDouble(anObject);
+ return (C) getDouble(anObject);
}
if (aClass == double.class) {
- return getDouble(anObject);
+ return (C) getDouble(anObject);
}
if (aClass == java.util.Date.class) {
- return getDate(anObject);
+ return (C) getDate(anObject);
}
if (aClass == Boolean.class) {
- return getBoolean(anObject);
+ return (C) getBoolean(anObject);
}
if (aClass == boolean.class) {
- return getBoolean(anObject);
+ return (C) getBoolean(anObject);
}
if (aClass == Character.class) {
- return getCharacter(anObject);
+ return (C) getCharacter(anObject);
}
if (aClass == char.class) {
- return getCharacter(anObject);
+ return (C) getCharacter(anObject);
}
if (aClass == Byte.class) {
- return getByte(anObject);
+ return (C) getByte(anObject);
}
if (aClass == byte.class) {
- return getByte(anObject);
+ return (C) getByte(anObject);
}
if (Collection.class.isAssignableFrom(aClass)) {
- return getCollection(anObject, aClass);
+ return (C) getCollection(anObject, aClass);
}
if (aClass.isArray()) {
- return getArray(anObject, aClass);
+ return (C) getArray(anObject, aClass);
}
- return convert(anObject, aClass);
+ return (C) convert(anObject, aClass);
}
/**
@@ -108,10 +109,10 @@ public class ValueConverter {
* the best fit to the object. and returns a new instance with that constructor.
* Subclasses can override to directly support specific types.
*/
- static protected Object convert(Object anObject, Class aClass) {
- Constructor[] ctors = aClass.getConstructors();
+ static protected Object convert(Object anObject, Class<?> aClass) {
+ Constructor<?>[] ctors = aClass.getConstructors();
- Class[] types;
+ Class<?>[] types;
for (int i = 0; i < ctors.length; i++) {
types = ctors[i].getParameterTypes();
if (types.length == 1) {
@@ -148,9 +149,9 @@ public class ValueConverter {
static protected Object preprocess(Object anObject) {
if (anObject instanceof Boolean) {
if (((Boolean) anObject).booleanValue()) {
- return new Double(1.0);
+ return Double.valueOf(1.0);
}
- return new Double(0.0);
+ return Double.valueOf(0.0);
}
if (anObject instanceof Character) {
@@ -167,9 +168,9 @@ public class ValueConverter {
static public Short getShort(Object anObject) {
if (anObject == null)
- return new Short((short) 0);
+ return Short.valueOf((short) 0);
if ("".equals(anObject))
- return new Short((short) 0);
+ return Short.valueOf((short) 0);
if (anObject instanceof Short)
return (Short) anObject;
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/WotonomyException.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/WotonomyException.java
index 21b47b3..041a216 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/WotonomyException.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/WotonomyException.java
@@ -26,7 +26,7 @@ import java.io.PrintWriter;
* Behaves as a normal RuntimeException except that it prints a stack trace of
* the wrapped throwable if one is specified.
*
- * Intended to be used anytime you'd report an exception with
+ * Intended to be used any time you'd report an exception with
* System.out.println: that is, for debugging and non-user-visible exceptions.
*
* @author michael@mpowers.net
@@ -35,6 +35,8 @@ import java.io.PrintWriter;
*/
public class WotonomyException extends RuntimeException {
+ private static final long serialVersionUID = -7267633105344041941L;
+
protected String message;
protected Throwable wrappedThrowable;
@@ -81,6 +83,7 @@ public class WotonomyException extends RuntimeException {
return wrappedThrowable;
}
+ @Override
public void printStackTrace(PrintWriter s) {
if (message != null) {
s.println("Exception: " + message);
@@ -92,6 +95,7 @@ public class WotonomyException extends RuntimeException {
super.printStackTrace(s);
}
+ @Override
public void printStackTrace(PrintStream s) {
if (message != null) {
s.println("Exception: " + message);
@@ -103,6 +107,7 @@ public class WotonomyException extends RuntimeException {
super.printStackTrace(s);
}
+ @Override
public void printStackTrace() {
if (message != null) {
System.err.println("Exception: " + message);