Map.equals method.
*
* @param o the object to be compared to this list
* @return true if the two maps are equal
*/
public boolean equals(Object o) {
// Simple tests that require no synchronization
if (o == this) {
return (true);
} else if (!(o instanceof Map)) {
return (false);
}
Map mo = (Map) o;
// Compare the two maps for equality
if (fast) {
if (mo.size() != map.size()) {
return (false);
}
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry e = (Map.Entry) i.next();
Object key = e.getKey();
Object value = e.getValue();
if (value == null) {
if (!(mo.get(key) == null && mo.containsKey(key))) {
return (false);
}
} else {
if (!value.equals(mo.get(key))) {
return (false);
}
}
}
return (true);
} else {
synchronized (map) {
if (mo.size() != map.size()) {
return (false);
}
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry e = (Map.Entry) i.next();
Object key = e.getKey();
Object value = e.getValue();
if (value == null) {
if (!(mo.get(key) == null && mo.containsKey(key))) {
return (false);
}
} else {
if (!value.equals(mo.get(key))) {
return (false);
}
}
}
return (true);
}
}
}
/**
* Return the hash code value for this map. This implementation uses
* exactly the code that is used to define the list hash function in the
* documentation for the Map.hashCode
method.
*
* @return suitable integer hash code
*/
public int hashCode() {
if (fast) {
int h = 0;
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
h += i.next().hashCode();
}
return (h);
} else {
synchronized (map) {
int h = 0;
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
h += i.next().hashCode();
}
return (h);
}
}
}
/**
* Return a shallow copy of this FastHashMap
instance.
* The keys and values themselves are not copied.
*
* @return a clone of this map
*/
public Object clone() {
]]>
");
} else if (value instanceof String) {
sb.append((String) value);
} else if (value instanceof String[]) {
String[] values = (String[]) value;
sb.append('[');
for (int i = 0; i < values.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(values[i]);
}
sb.append(']');
} else {
sb.append(value.toString());
}
sb.append(')');
log.trace(sb.toString());
}
// Resolve any nested expression to get the actual target bean
Object target = bean;
Resolver resolver = getPropertyUtils().getResolver();
while (resolver.hasNested(name)) {
try {
target = getPropertyUtils().getProperty(target, resolver.next(name));
name = resolver.remove(name);
} catch (NoSuchMethodException e) {
return; // Skip this property setter
}
}
if (log.isTraceEnabled()) {
log.trace(" Target bean = " + target);
log.trace(" Target name = " + name);
}
// Declare local variables we will require
String propName = resolver.getProperty(name); // Simple name of target property
Class type = null; // Java type of target property
int index = resolver.getIndex(name); // Indexed subscript value (if any)
String key = resolver.getKey(name); // Mapped key value (if any)
// Calculate the property type
if (target instanceof DynaBean) {
DynaClass dynaClass = ((DynaBean) target).getDynaClass();
DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
if (dynaProperty == null) {
return; // Skip this property setter
}
type = dynaProperty.getType();
} else if (target instanceof Map) {
]]>
");
}
else if (value instanceof String) {
sb.append((String) value);
}
else if (value instanceof String[]) {
String[] values = (String[]) value;
sb.append('[');
for (int i = 0; i < values.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(values[i]);
}
sb.append(']');
}
else {
sb.append(value.toString());
}
sb.append(')');
log.trace(sb.toString());
}
// Resolve any nested expression to get the actual target bean
Object target = bean;
Resolver resolver = getPropertyUtils().getResolver();
while (resolver.hasNested(name)) {
try {
target = getPropertyUtils().getProperty(target, resolver.next(name));
name = resolver.remove(name);
} catch (NoSuchMethodException e) {
return; // Skip this property setter
}
}
if (log.isTraceEnabled()) {
log.trace(" Target bean = " + target);
log.trace(" Target name = " + name);
}
// Declare local variables we will require
String propName = resolver.getProperty(name); // Simple name of target property
]]>
");
}
else if (value instanceof String) {
sb.append((String) value);
}
else if (value instanceof String[]) {
String[] values = (String[]) value;
sb.append('[');
for (int i = 0; i < values.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(values[i]);
}
sb.append(']');
}
else {
sb.append(value.toString());
}
sb.append(')');
log.trace(sb.toString());
}
// Resolve any nested expression to get the actual target bean
Object target = bean;
Resolver resolver = getPropertyUtils().getResolver();
while (resolver.hasNested(name)) {
try {
target = getPropertyUtils().getProperty(target, resolver.next(name));
name = resolver.remove(name);
} catch (NoSuchMethodException e) {
return; // Skip this property setter
}
}
if (log.isTraceEnabled()) {
log.trace(" Target bean = " + target);
log.trace(" Target name = " + name);
}
// Declare local variables we will require
String propName = resolver.getProperty(name); // Simple name of target property
]]>
null if the map contains no mapping for this key, or if
* there is a mapping with a value of null
. Use the
* containsKey()
method to disambiguate these cases.
*
* @param key the key whose value is to be returned
* @return the value mapped to that key, or null
*/
public Object get(Object key) {
if (fast) {
return (map.get(key));
} else {
synchronized (map) {
return (map.get(key));
}
}
}
/**
* Return the number of key-value mappings in this map.
*
* @return the current size of the map
*/
public int size() {
if (fast) {
return (map.size());
} else {
synchronized (map) {
return (map.size());
}
}
}
/**
* Return true
if this map contains no mappings.
*
* @return is the map currently empty
*/
public boolean isEmpty() {
if (fast) {
return (map.isEmpty());
} else {
synchronized (map) {
return (map.isEmpty());
}
}
}
/**
* Return true
if this map contains a mapping for the
* specified key.
*
* @param key the key to be searched for
* @return true if the map contains the key
*/
public boolean containsKey(Object key) {
if (fast) {
return (map.containsKey(key));
} else {
synchronized (map) {
return (map.containsKey(key));
}
}
}
/**
* Return true
if this map contains one or more keys mapping
* to the specified value.
*
* @param value the value to be searched for
* @return true if the map contains the value
*/
public boolean containsValue(Object value) {
if (fast) {
return (map.containsValue(value));
} else {
synchronized (map) {
return (map.containsValue(value));
}
}
}
// Map modification
// ----------------------------------------------------------------------
// These methods perform special behaviour in 'fast' mode.
// The map is cloned, updated and then assigned back.
// See the comments at the top as to why this won't always work.
/**
* Associate the specified value with the specified key in this map.
* If the map previously contained a mapping for this key, the old
* value is replaced and returned.
*
* @param key the key with which the value is to be associated
* @param value the value to be associated with this key
* @return the value previously mapped to the key, or null
*/
public Object put(Object key, Object value) {
if (fast) {
synchronized (this) {
]]>
0) {
valueString += ", " ;
}
if (values[i] == null) {
valueString += "";
} else {
valueString += (values[i]).getClass().getName();
}
}
}
String expectedString = "";
Class[] parTypes = method.getParameterTypes();
if (parTypes != null) {
for (int i = 0; i < parTypes.length; i++) {
if (i > 0) {
expectedString += ", ";
}
expectedString += parTypes[i].getName();
}
}
IllegalArgumentException e = new IllegalArgumentException(
"Cannot invoke " + method.getDeclaringClass().getName() + "."
+ method.getName() + " on bean class '" + bean.getClass() +
"' - " + cause.getMessage()
// as per https://issues.apache.org/jira/browse/BEANUTILS-224
+ " - had objects of type \"" + valueString
+ "\" but expected signature \""
+ expectedString + "\""
);
if (!BeanUtils.initCause(e, cause)) {
log.error("Method invocation failed", cause);
}
throw e;
}
]]>
true if the source class is assignable to the
* destination class, otherwise false
*/
protected boolean isAssignable(Class dest, Class source) {
if (dest.isAssignableFrom(source) ||
((dest == Boolean.TYPE) && (source == Boolean.class)) ||
((dest == Byte.TYPE) && (source == Byte.class)) ||
((dest == Character.TYPE) && (source == Character.class)) ||
((dest == Double.TYPE) && (source == Double.class)) ||
((dest == Float.TYPE) && (source == Float.class)) ||
((dest == Integer.TYPE) && (source == Integer.class)) ||
((dest == Long.TYPE) && (source == Long.class)) ||
((dest == Short.TYPE) && (source == Short.class))) {
return (true);
} else {
return (false);
}
}
]]>