diff --git a/querydsl-core/src/main/java/com/mysema/util/BeanMap.java b/querydsl-core/src/main/java/com/mysema/util/BeanMap.java index 9aae8b2ff..86da08b4b 100644 --- a/querydsl-core/src/main/java/com/mysema/util/BeanMap.java +++ b/querydsl-core/src/main/java/com/mysema/util/BeanMap.java @@ -1,18 +1,18 @@ +// GenericsNote: Converted to . /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2001-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.mysema.util; @@ -27,34 +27,35 @@ import java.util.AbstractMap; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; import com.google.common.base.Function; - -/** +/** * An implementation of Map for JavaBeans which uses introspection to * get and put properties in the bean. - *

+ *

* If an exception occurs during attempts to get or set a property then the * property is considered non existent in the Map + *

* - * @version $Revision: 812176 $ $Date: 2009-09-07 15:59:25 +0100 (Mon, 07 Sep 2009) $ - * * @author James Strachan - * @author Stephen Colebourne + * @author Matt Hall, John Watkinson, Stephen Colebourne + * @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:19 $ + * @since Commons Collections 1.0 */ +@SuppressWarnings("rawtypes") public class BeanMap extends AbstractMap implements Cloneable { private transient Object bean; - private transient HashMap readMethods = new HashMap(); - private transient HashMap writeMethods = new HashMap(); - private transient HashMap types = new HashMap(); + private transient HashMap readMethods = new HashMap(); + private transient HashMap writeMethods = new HashMap(); + private transient HashMap> types = new HashMap>(); /** * An empty array. Used to invoke accessors via reflection. @@ -62,129 +63,55 @@ public class BeanMap extends AbstractMap implements Cloneable { public static final Object[] NULL_ARGUMENTS = {}; /** - * Maps primitive Class types to applyers. The applyer - * apply strings into the appropriate primitive wrapper. - * - * N.B. private & unmodifiable replacement for the (public & static) defaultFunctions instance. + * Maps primitive Class types to transformers. The transformer + * transform strings into the appropriate primitive wrapper. */ - private static final Map typeFunctions = Collections.unmodifiableMap(createTypeFunctions()); + public static HashMap, Function> defaultFunctions = new HashMap, Function>(); - /** - * This HashMap has been made unmodifiable to prevent issues when - * loaded in a shared ClassLoader enviroment. - * - * @see "http://issues.apache.org/jira/browse/BEANUTILS-112" - * @deprecated Use {@link BeanMap#getTypeFunction(Class)} method - */ - public static HashMap defaultFunctions = new HashMap() { - public void clear() { - throw new UnsupportedOperationException(); - } - public boolean containsKey(Object key) { - return typeFunctions.containsKey(key); - } - public boolean containsValue(Object value) { - return typeFunctions.containsValue(value); - } - public Set entrySet() { - return typeFunctions.entrySet(); - } - public Object get(Object key) { - return typeFunctions.get(key); - } - public boolean isEmpty() { - return false; - } - public Set keySet() { - return typeFunctions.keySet(); - } - public Object put(Object key, Object value) { - throw new UnsupportedOperationException(); - } - public void putAll(Map m) { - throw new UnsupportedOperationException(); - } - public Object remove(Object key) { - throw new UnsupportedOperationException(); - } - public int size() { - return typeFunctions.size(); - } - public Collection values() { - return typeFunctions.values(); - } - }; - - private static Map createTypeFunctions() { - Map defaultFunctions = new HashMap(); - defaultFunctions.put( - Boolean.TYPE, - new Function() { - public Object apply( Object input ) { - return Boolean.valueOf( input.toString() ); - } + static { + defaultFunctions.put(Boolean.TYPE, new Function() { + public Object apply(Object input) { + return Boolean.valueOf(input.toString()); } - ); - defaultFunctions.put( - Character.TYPE, - new Function() { - public Object apply( Object input ) { - return new Character( input.toString().charAt( 0 ) ); - } + }); + defaultFunctions.put(Character.TYPE, new Function() { + public Object apply(Object input) { + return new Character(input.toString().charAt(0)); } - ); - defaultFunctions.put( - Byte.TYPE, - new Function() { - public Object apply( Object input ) { - return Byte.valueOf( input.toString() ); - } + }); + defaultFunctions.put(Byte.TYPE, new Function() { + public Object apply(Object input) { + return Byte.valueOf(input.toString()); } - ); - defaultFunctions.put( - Short.TYPE, - new Function() { - public Object apply( Object input ) { - return Short.valueOf( input.toString() ); - } + }); + defaultFunctions.put(Short.TYPE, new Function() { + public Object apply(Object input) { + return Short.valueOf(input.toString()); } - ); - defaultFunctions.put( - Integer.TYPE, - new Function() { - public Object apply( Object input ) { - return Integer.valueOf( input.toString() ); - } + }); + defaultFunctions.put(Integer.TYPE, new Function() { + public Object apply(Object input) { + return Integer.valueOf(input.toString()); } - ); - defaultFunctions.put( - Long.TYPE, - new Function() { - public Object apply( Object input ) { - return Long.valueOf( input.toString() ); - } + }); + defaultFunctions.put(Long.TYPE, new Function() { + public Object apply(Object input) { + return Long.valueOf(input.toString()); } - ); - defaultFunctions.put( - Float.TYPE, - new Function() { - public Object apply( Object input ) { - return Float.valueOf( input.toString() ); - } + }); + defaultFunctions.put(Float.TYPE, new Function() { + public Object apply(Object input) { + return Float.valueOf(input.toString()); } - ); - defaultFunctions.put( - Double.TYPE, - new Function() { - public Object apply( Object input ) { - return Double.valueOf( input.toString() ); - } + }); + defaultFunctions.put(Double.TYPE, new Function() { + public Object apply(Object input) { + return Double.valueOf(input.toString()); } - ); - return defaultFunctions; + }); } - - + + // Constructors //------------------------------------------------------------------------- @@ -195,11 +122,11 @@ public class BeanMap extends AbstractMap implements Cloneable { } /** - * Constructs a new BeanMap that operates on the + * Constructs a new BeanMap that operates on the * specified bean. If the given bean is null, then * this map will be empty. * - * @param bean the bean for this map to operate on + * @param bean the bean for this map to operate on */ public BeanMap(Object bean) { this.bean = bean; @@ -209,84 +136,71 @@ public class BeanMap extends AbstractMap implements Cloneable { // Map interface //------------------------------------------------------------------------- - /** - * Renders a string representation of this object. - * @return a String representation of this object - */ public String toString() { return "BeanMap<" + String.valueOf(bean) + ">"; } - + /** - * Clone this bean map using the following process: - * + * Clone this bean map using the following process: + *

*