summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-02-05 11:56:57 +0200
committerLeif Åstrand <leif@vaadin.com>2013-02-06 13:55:33 +0200
commitf15030a65a787684c046985f8b9369e82be9c4b2 (patch)
treee6bf7ae7081957dd5b627d7a526a222f95929178 /client/src
parent28b7703d29d93f0fefc7e020d9f7cf14c0349aa7 (diff)
downloadvaadin-framework-f15030a65a787684c046985f8b9369e82be9c4b2.tar.gz
vaadin-framework-f15030a65a787684c046985f8b9369e82be9c4b2.zip
Use native collections in TypeDataStore and related classes (#10937)
Change-Id: I6762c9411119ea3a363d2a605f71d20871d73209
Diffstat (limited to 'client/src')
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java13
-rw-r--r--client/src/com/vaadin/client/communication/JsonDecoder.java8
-rw-r--r--client/src/com/vaadin/client/communication/JsonEncoder.java9
-rw-r--r--client/src/com/vaadin/client/metadata/Method.java13
-rw-r--r--client/src/com/vaadin/client/metadata/Property.java13
-rw-r--r--client/src/com/vaadin/client/metadata/Type.java34
-rw-r--r--client/src/com/vaadin/client/metadata/TypeDataStore.java132
7 files changed, 163 insertions, 59 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index bc260a2bbc..b2a9541d80 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -1911,8 +1911,11 @@ public class ApplicationConnection {
private void addAllStateFields(Type type,
Set<String> foundProperties, String context) {
try {
- Collection<Property> properties = type.getProperties();
- for (Property property : properties) {
+ JsArrayObject<Property> properties = type
+ .getPropertiesAsArray();
+ int size = properties.size();
+ for (int i = 0; i < size; i++) {
+ Property property = properties.get(i);
String propertyName = context + property.getName();
foundProperties.add(propertyName);
@@ -2113,7 +2116,11 @@ public class ApplicationConnection {
SharedState state = connector.getState();
- for (Property property : stateType.getProperties()) {
+ JsArrayObject<Property> properties = stateType
+ .getPropertiesAsArray();
+ int size = properties.size();
+ for (int i = 0; i < size; i++) {
+ Property property = properties.get(i);
property.setValue(state,
property.getValue(defaultState));
}
diff --git a/client/src/com/vaadin/client/communication/JsonDecoder.java b/client/src/com/vaadin/client/communication/JsonDecoder.java
index d32cdd92aa..d4d71b3bc4 100644
--- a/client/src/com/vaadin/client/communication/JsonDecoder.java
+++ b/client/src/com/vaadin/client/communication/JsonDecoder.java
@@ -31,6 +31,7 @@ import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.FastStringSet;
+import com.vaadin.client.JsArrayObject;
import com.vaadin.client.metadata.NoDataException;
import com.vaadin.client.metadata.Property;
import com.vaadin.client.metadata.Type;
@@ -141,13 +142,16 @@ public class JsonDecoder {
}
} else {
try {
- Collection<Property> properties = type.getProperties();
+ JsArrayObject<Property> properties = type
+ .getPropertiesAsArray();
if (target == null) {
target = type.createInstance();
}
JSONObject jsonObject = jsonValue.isObject();
- for (Property property : properties) {
+ int size = properties.size();
+ for (int i = 0; i < size; i++) {
+ Property property = properties.get(i);
JSONValue encodedPropertyValue = jsonObject.get(property
.getName());
if (encodedPropertyValue == null) {
diff --git a/client/src/com/vaadin/client/communication/JsonEncoder.java b/client/src/com/vaadin/client/communication/JsonEncoder.java
index 17d11bb946..49cd613a2c 100644
--- a/client/src/com/vaadin/client/communication/JsonEncoder.java
+++ b/client/src/com/vaadin/client/communication/JsonEncoder.java
@@ -30,6 +30,7 @@ import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.JsArrayObject;
import com.vaadin.client.metadata.NoDataException;
import com.vaadin.client.metadata.Property;
import com.vaadin.client.metadata.Type;
@@ -111,10 +112,14 @@ public class JsonEncoder {
} else if (type != null) {
// And finally try using bean serialization logic
try {
- Collection<Property> properties = type.getProperties();
+ JsArrayObject<Property> properties = type
+ .getPropertiesAsArray();
JSONObject jsonObject = new JSONObject();
- for (Property property : properties) {
+
+ int size = properties.size();
+ for (int i = 0; i < size; i++) {
+ Property property = properties.get(i);
Object propertyValue = property.getValue(value);
Type propertyType = property.getType();
JSONValue encodedPropertyValue = encode(propertyValue,
diff --git a/client/src/com/vaadin/client/metadata/Method.java b/client/src/com/vaadin/client/metadata/Method.java
index da7fcd4d8c..aea2fd7f85 100644
--- a/client/src/com/vaadin/client/metadata/Method.java
+++ b/client/src/com/vaadin/client/metadata/Method.java
@@ -19,10 +19,13 @@ public class Method {
private final Type type;
private final String name;
+ private String signature;
public Method(Type type, String name) {
this.type = type;
this.name = name;
+ // Cache derived signature value
+ signature = type.getSignature() + "." + name;
}
public Type getType() {
@@ -41,8 +44,16 @@ public class Method {
TypeDataStore.getInvoker(this).invoke(target, params);
}
+ /**
+ * The unique signature used to identify this method. The structure of the
+ * returned string may change without notice and should not be used for any
+ * other purpose than identification. The signature is currently based on
+ * the declaring type's signature and the method's name.
+ *
+ * @return the unique signature of this method
+ */
public String getSignature() {
- return type.toString() + "." + name;
+ return signature;
}
@Override
diff --git a/client/src/com/vaadin/client/metadata/Property.java b/client/src/com/vaadin/client/metadata/Property.java
index 539f27961d..c0c375c14c 100644
--- a/client/src/com/vaadin/client/metadata/Property.java
+++ b/client/src/com/vaadin/client/metadata/Property.java
@@ -20,10 +20,13 @@ import com.vaadin.shared.annotations.DelegateToWidget;
public class Property {
private final Type bean;
private final String name;
+ private final String signature;
public Property(Type bean, String name) {
this.bean = bean;
this.name = name;
+ // Cache derived signature value
+ signature = bean.getSignature() + "." + name;
}
public Object getValue(Object bean) throws NoDataException {
@@ -47,8 +50,16 @@ public class Property {
return TypeDataStore.getType(this);
}
+ /**
+ * The unique signature used to identify this property. The structure of the
+ * returned string may change without notice and should not be used for any
+ * other purpose than identification. The signature is currently based on
+ * the declaring type's signature and the property's name.
+ *
+ * @return the unique signature of this property
+ */
public String getSignature() {
- return bean.toString() + "." + name;
+ return signature;
}
@Override
diff --git a/client/src/com/vaadin/client/metadata/Type.java b/client/src/com/vaadin/client/metadata/Type.java
index a904a3d624..9c8a52d8e5 100644
--- a/client/src/com/vaadin/client/metadata/Type.java
+++ b/client/src/com/vaadin/client/metadata/Type.java
@@ -17,20 +17,23 @@ package com.vaadin.client.metadata;
import java.util.Collection;
+import com.vaadin.client.JsArrayObject;
import com.vaadin.client.communication.JSONSerializer;
public class Type {
private final String name;
private final Type[] parameterTypes;
+ private final String signature;
public Type(Class<?> clazz) {
- name = clazz.getName();
- parameterTypes = null;
+ this(clazz.getName(), null);
}
public Type(String baseTypeName, Type[] parameterTypes) {
name = baseTypeName;
this.parameterTypes = parameterTypes;
+ // Cache derived signature value
+ signature = calculateSignature(name, parameterTypes);
}
public String getBaseTypeName() {
@@ -50,15 +53,28 @@ public class Type {
return new Method(this, name);
}
+ /**
+ * @return
+ * @throws NoDataException
+ *
+ * @deprecated As of 7.0.1, use {@link #getPropertiesAsArray()} instead for
+ * improved performance
+ */
+ @Deprecated
public Collection<Property> getProperties() throws NoDataException {
return TypeDataStore.getProperties(this);
}
+ public JsArrayObject<Property> getPropertiesAsArray()
+ throws NoDataException {
+ return TypeDataStore.getPropertiesAsArray(this);
+ }
+
public Property getProperty(String propertyName) {
return new Property(this, propertyName);
}
- public String getSignature() {
+ private static String calculateSignature(String name, Type[] parameterTypes) {
String string = name;
if (parameterTypes != null && parameterTypes.length != 0) {
string += '<';
@@ -74,6 +90,18 @@ public class Type {
return string;
}
+ /**
+ * The unique signature used to identify this type. The structure of the
+ * returned string may change without notice and should not be used for any
+ * other purpose than identification. The signature is currently based on
+ * the fully qualified name of the type.
+ *
+ * @return the unique signature of this type
+ */
+ public String getSignature() {
+ return signature;
+ }
+
@Override
public String toString() {
return getSignature();
diff --git a/client/src/com/vaadin/client/metadata/TypeDataStore.java b/client/src/com/vaadin/client/metadata/TypeDataStore.java
index 2f56d6eb52..5b466146a3 100644
--- a/client/src/com/vaadin/client/metadata/TypeDataStore.java
+++ b/client/src/com/vaadin/client/metadata/TypeDataStore.java
@@ -15,35 +15,39 @@
*/
package com.vaadin.client.metadata;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import com.google.gwt.core.client.JavaScriptObject;
+import com.vaadin.client.FastStringMap;
+import com.vaadin.client.FastStringSet;
+import com.vaadin.client.JsArrayObject;
import com.vaadin.client.communication.JSONSerializer;
public class TypeDataStore {
private static final String CONSTRUCTOR_NAME = "!new";
- private final Map<String, Class<?>> identifiers = new HashMap<String, Class<?>>();
+ private final FastStringMap<Class<?>> identifiers = FastStringMap.create();
- private final Map<Type, Invoker> serializerFactories = new HashMap<Type, Invoker>();
- private final Map<Type, ProxyHandler> proxyHandlers = new HashMap<Type, ProxyHandler>();
- private final Map<Type, Collection<Property>> properties = new HashMap<Type, Collection<Property>>();
+ private final FastStringMap<Invoker> serializerFactories = FastStringMap
+ .create();
+ private final FastStringMap<ProxyHandler> proxyHandlers = FastStringMap
+ .create();
+ private final FastStringMap<JsArrayObject<Property>> properties = FastStringMap
+ .create();
- private final Set<Method> delayedMethods = new HashSet<Method>();
- private final Set<Method> lastOnlyMethods = new HashSet<Method>();
+ private final FastStringSet delayedMethods = FastStringSet.create();
+ private final FastStringSet lastOnlyMethods = FastStringSet.create();
- private final Map<Method, Type> returnTypes = new HashMap<Method, Type>();
- private final Map<Method, Invoker> invokers = new HashMap<Method, Invoker>();
- private final Map<Method, Type[]> paramTypes = new HashMap<Method, Type[]>();
+ private final FastStringMap<Type> returnTypes = FastStringMap.create();
+ private final FastStringMap<Invoker> invokers = FastStringMap.create();
+ private final FastStringMap<Type[]> paramTypes = FastStringMap.create();
- private final Map<Property, Type> propertyTypes = new HashMap<Property, Type>();
- private final Map<Property, Invoker> setters = new HashMap<Property, Invoker>();
- private final Map<Property, Invoker> getters = new HashMap<Property, Invoker>();
- private final Map<Property, String> delegateToWidget = new HashMap<Property, String>();
+ private final FastStringMap<Type> propertyTypes = FastStringMap.create();
+ private final FastStringMap<Invoker> setters = FastStringMap.create();
+ private final FastStringMap<Invoker> getters = FastStringMap.create();
+ private final FastStringMap<String> delegateToWidget = FastStringMap
+ .create();
public static TypeDataStore get() {
return ConnectorBundleLoader.get().getTypeDataStore();
@@ -67,7 +71,7 @@ public class TypeDataStore {
}
public static Type getReturnType(Method method) throws NoDataException {
- Type type = get().returnTypes.get(method);
+ Type type = get().returnTypes.get(method.getSignature());
if (type == null) {
throw new NoDataException("There is no return type for "
+ method.getSignature());
@@ -76,7 +80,7 @@ public class TypeDataStore {
}
public static Invoker getInvoker(Method method) throws NoDataException {
- Invoker invoker = get().invokers.get(method);
+ Invoker invoker = get().invokers.get(method.getSignature());
if (invoker == null) {
throw new NoDataException("There is no invoker for "
+ method.getSignature());
@@ -85,8 +89,8 @@ public class TypeDataStore {
}
public static Invoker getConstructor(Type type) throws NoDataException {
- Invoker invoker = get().invokers
- .get(new Method(type, CONSTRUCTOR_NAME));
+ Invoker invoker = get().invokers.get(new Method(type, CONSTRUCTOR_NAME)
+ .getSignature());
if (invoker == null) {
throw new NoDataException("There is no constructor for "
+ type.getSignature());
@@ -95,7 +99,7 @@ public class TypeDataStore {
}
public static Invoker getGetter(Property property) throws NoDataException {
- Invoker getter = get().getters.get(property);
+ Invoker getter = get().getters.get(property.getSignature());
if (getter == null) {
throw new NoDataException("There is no getter for "
+ property.getSignature());
@@ -105,21 +109,24 @@ public class TypeDataStore {
}
public void setGetter(Class<?> clazz, String propertyName, Invoker invoker) {
- getters.put(new Property(getType(clazz), propertyName), invoker);
+ getters.put(new Property(getType(clazz), propertyName).getSignature(),
+ invoker);
}
public static String getDelegateToWidget(Property property) {
- return get().delegateToWidget.get(property);
+ return get().delegateToWidget.get(property.getSignature());
}
public void setDelegateToWidget(Class<?> clazz, String propertyName,
String delegateValue) {
- delegateToWidget.put(new Property(getType(clazz), propertyName),
+ delegateToWidget.put(
+ new Property(getType(clazz), propertyName).getSignature(),
delegateValue);
}
public void setReturnType(Class<?> type, String methodName, Type returnType) {
- returnTypes.put(new Method(getType(type), methodName), returnType);
+ returnTypes.put(new Method(getType(type), methodName).getSignature(),
+ returnType);
}
public void setConstructor(Class<?> type, Invoker constructor) {
@@ -127,11 +134,12 @@ public class TypeDataStore {
}
public void setInvoker(Class<?> type, String methodName, Invoker invoker) {
- invokers.put(new Method(getType(type), methodName), invoker);
+ invokers.put(new Method(getType(type), methodName).getSignature(),
+ invoker);
}
public static Type[] getParamTypes(Method method) throws NoDataException {
- Type[] types = get().paramTypes.get(method);
+ Type[] types = get().paramTypes.get(method.getSignature());
if (types == null) {
throw new NoDataException("There are no parameter type data for "
+ method.getSignature());
@@ -141,7 +149,9 @@ public class TypeDataStore {
public void setParamTypes(Class<?> type, String methodName,
Type[] paramTypes) {
- this.paramTypes.put(new Method(getType(type), methodName), paramTypes);
+ this.paramTypes.put(
+ new Method(getType(type), methodName).getSignature(),
+ paramTypes);
}
public static boolean hasIdentifier(String identifier) {
@@ -150,7 +160,8 @@ public class TypeDataStore {
public static ProxyHandler getProxyHandler(Type type)
throws NoDataException {
- ProxyHandler proxyHandler = get().proxyHandlers.get(type);
+ ProxyHandler proxyHandler = get().proxyHandlers
+ .get(type.getSignature());
if (proxyHandler == null) {
throw new NoDataException("No proxy handler for "
+ type.getSignature());
@@ -159,28 +170,51 @@ public class TypeDataStore {
}
public void setProxyHandler(Class<?> type, ProxyHandler proxyHandler) {
- proxyHandlers.put(getType(type), proxyHandler);
+ proxyHandlers.put(getType(type).getSignature(), proxyHandler);
}
public static boolean isDelayed(Method method) {
- return get().delayedMethods.contains(method);
+ return get().delayedMethods.contains(method.getSignature());
}
public void setDelayed(Class<?> type, String methodName) {
- delayedMethods.add(getType(type).getMethod(methodName));
+ delayedMethods.add(getType(type).getMethod(methodName).getSignature());
}
public static boolean isLastOnly(Method method) {
- return get().lastOnlyMethods.contains(method);
+ return get().lastOnlyMethods.contains(method.getSignature());
}
public void setLastOnly(Class<?> clazz, String methodName) {
- lastOnlyMethods.add(getType(clazz).getMethod(methodName));
+ lastOnlyMethods
+ .add(getType(clazz).getMethod(methodName).getSignature());
+ }
+
+ /**
+ * @param type
+ * @return
+ * @throws NoDataException
+ *
+ * @deprecated As of 7.0.1, use {@link #getPropertiesAsArray(Type)} instead
+ * for improved performance
+ */
+ @Deprecated
+ public static Collection<Property> getProperties(Type type)
+ throws NoDataException {
+ JsArrayObject<Property> propertiesArray = getPropertiesAsArray(type);
+ int size = propertiesArray.size();
+ ArrayList<Property> properties = new ArrayList<Property>(size);
+ for (int i = 0; i < size; i++) {
+ properties.add(propertiesArray.get(i));
+ }
+
+ return properties;
}
- public static Collection<Property> getProperties(Type type)
+ public static JsArrayObject<Property> getPropertiesAsArray(Type type)
throws NoDataException {
- Collection<Property> properties = get().properties.get(type);
+ JsArrayObject<Property> properties = get().properties.get(type
+ .getSignature());
if (properties == null) {
throw new NoDataException("No property list for "
+ type.getSignature());
@@ -189,16 +223,17 @@ public class TypeDataStore {
}
public void setProperties(Class<?> clazz, String[] propertyNames) {
- Set<Property> properties = new HashSet<Property>();
+ JsArrayObject<Property> properties = JavaScriptObject.createArray()
+ .cast();
Type type = getType(clazz);
for (String name : propertyNames) {
properties.add(new Property(type, name));
}
- this.properties.put(type, Collections.unmodifiableSet(properties));
+ this.properties.put(type.getSignature(), properties);
}
public static Type getType(Property property) throws NoDataException {
- Type type = get().propertyTypes.get(property);
+ Type type = get().propertyTypes.get(property.getSignature());
if (type == null) {
throw new NoDataException("No return type for "
+ property.getSignature());
@@ -207,11 +242,12 @@ public class TypeDataStore {
}
public void setPropertyType(Class<?> clazz, String propertName, Type type) {
- propertyTypes.put(new Property(getType(clazz), propertName), type);
+ propertyTypes.put(
+ new Property(getType(clazz), propertName).getSignature(), type);
}
public static Invoker getSetter(Property property) throws NoDataException {
- Invoker setter = get().setters.get(property);
+ Invoker setter = get().setters.get(property.getSignature());
if (setter == null) {
throw new NoDataException("No setter for "
+ property.getSignature());
@@ -220,15 +256,17 @@ public class TypeDataStore {
}
public void setSetter(Class<?> clazz, String propertyName, Invoker setter) {
- setters.put(new Property(getType(clazz), propertyName), setter);
+ setters.put(new Property(getType(clazz), propertyName).getSignature(),
+ setter);
}
public void setSerializerFactory(Class<?> clazz, Invoker factory) {
- serializerFactories.put(getType(clazz), factory);
+ serializerFactories.put(getType(clazz).getSignature(), factory);
}
public static JSONSerializer<?> findSerializer(Type type) {
- Invoker factoryCreator = get().serializerFactories.get(type);
+ Invoker factoryCreator = get().serializerFactories.get(type
+ .getSignature());
if (factoryCreator == null) {
return null;
}
@@ -236,6 +274,6 @@ public class TypeDataStore {
}
public static boolean hasProperties(Type type) {
- return get().properties.containsKey(type);
+ return get().properties.containsKey(type.getSignature());
}
}