summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-04-05 18:32:50 +0300
committerLeif Åstrand <leif@vaadin.com>2013-04-10 14:47:18 +0300
commit2700cd2fe6c48b29478f1b8e14fde1d405a6ab7d (patch)
treefdef2375cc28a6c9db4501cd4535152434c97d10
parentfd4f1d280e8eb6a453868db01b8accc1e7b8d0b1 (diff)
downloadvaadin-framework-2700cd2fe6c48b29478f1b8e14fde1d405a6ab7d.tar.gz
vaadin-framework-2700cd2fe6c48b29478f1b8e14fde1d405a6ab7d.zip
Added SharedUtil for helpers shared by client and server
Change-Id: Ie289e8eefd962631a43f35dbb47fa192fcf60abf
-rw-r--r--client/src/com/vaadin/client/Util.java20
-rw-r--r--server/src/com/vaadin/ui/AbstractField.java24
-rw-r--r--server/src/com/vaadin/ui/Label.java3
-rw-r--r--shared/src/com/vaadin/shared/util/SharedUtil.java45
4 files changed, 74 insertions, 18 deletions
diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java
index 9810156bcc..8972670232 100644
--- a/client/src/com/vaadin/client/Util.java
+++ b/client/src/com/vaadin/client/Util.java
@@ -48,6 +48,7 @@ import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.communication.MethodInvocation;
import com.vaadin.shared.ui.ComponentStateUtil;
+import com.vaadin.shared.util.SharedUtil;
public class Util {
@@ -550,12 +551,21 @@ public class Util {
}
}
+ /**
+ * Checks if a and b are equals using {@link #equals(Object)}. Handles null
+ * values as well. Does not ensure that objects are of the same type.
+ * Assumes that the first object's equals method handle equals properly.
+ *
+ * @param a
+ * The first value to compare
+ * @param b
+ * The second value to compare
+ * @return
+ * @deprecated As of 7.1 use {@link SharedUtil#equals(Object)} instead
+ */
+ @Deprecated
public static boolean equals(Object a, Object b) {
- if (a == null) {
- return b == null;
- }
-
- return a.equals(b);
+ return SharedUtil.equals(a, b);
}
public static void updateRelativeChildrenAndSendSizeUpdateEvent(
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index 4ec6d7bac2..eb8fc30a45 100644
--- a/server/src/com/vaadin/ui/AbstractField.java
+++ b/server/src/com/vaadin/ui/AbstractField.java
@@ -42,6 +42,7 @@ import com.vaadin.server.AbstractErrorMessage;
import com.vaadin.server.CompositeErrorMessage;
import com.vaadin.server.ErrorMessage;
import com.vaadin.shared.AbstractFieldState;
+import com.vaadin.shared.util.SharedUtil;
/**
* <p>
@@ -427,7 +428,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
throws Property.ReadOnlyException, Converter.ConversionException,
InvalidValueException {
- if (!equals(newFieldValue, getInternalValue())) {
+ if (!SharedUtil.equals(newFieldValue, getInternalValue())) {
// Read only fields can not be changed
if (isReadOnly()) {
@@ -435,7 +436,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
}
try {
T doubleConvertedFieldValue = convertFromModel(convertToModel(newFieldValue));
- if (!equals(newFieldValue, doubleConvertedFieldValue)) {
+ if (!SharedUtil
+ .equals(newFieldValue, doubleConvertedFieldValue)) {
newFieldValue = doubleConvertedFieldValue;
repaintIsNotNeeded = false;
}
@@ -512,11 +514,9 @@ public abstract class AbstractField<T> extends AbstractComponent implements
}
}
+ @Deprecated
static boolean equals(Object value1, Object value2) {
- if (value1 == null) {
- return value2 == null;
- }
- return value1.equals(value2);
+ return SharedUtil.equals(value1, value2);
}
/* External data source */
@@ -1204,8 +1204,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
public void valueChange(Property.ValueChangeEvent event) {
if (!isBuffered()) {
if (committingValueToDataSource) {
- boolean propertyNotifiesOfTheBufferedValue = equals(event
- .getProperty().getValue(), getInternalValue());
+ boolean propertyNotifiesOfTheBufferedValue = SharedUtil.equals(
+ event.getProperty().getValue(), getInternalValue());
if (!propertyNotifiesOfTheBufferedValue) {
/*
* Property (or chained property like PropertyFormatter) now
@@ -1321,7 +1321,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
}
private void localeMightHaveChanged() {
- if (!equals(valueLocale, getLocale())) {
+ if (!SharedUtil.equals(valueLocale, getLocale())) {
// The locale HAS actually changed
if (dataSource != null && !isModified()) {
@@ -1329,7 +1329,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
// read from that we want to update the value
T newInternalValue = convertFromModel(getPropertyDataSource()
.getValue());
- if (!equals(newInternalValue, getInternalValue())) {
+ if (!SharedUtil.equals(newInternalValue, getInternalValue())) {
setInternalValue(newInternalValue);
fireValueChange(false);
}
@@ -1345,7 +1345,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
Object convertedValue = convertToModel(getInternalValue(),
valueLocale);
T newinternalValue = convertFromModel(convertedValue);
- if (!equals(getInternalValue(), newinternalValue)) {
+ if (!SharedUtil.equals(getInternalValue(), newinternalValue)) {
setConvertedValue(convertedValue);
}
}
@@ -1594,7 +1594,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
setModified(false);
// If the new value differs from the previous one
- if (!equals(newFieldValue, getInternalValue())) {
+ if (!SharedUtil.equals(newFieldValue, getInternalValue())) {
setInternalValue(newFieldValue);
fireValueChange(false);
} else if (wasModified) {
diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java
index f413ea47f2..72f556ee5b 100644
--- a/server/src/com/vaadin/ui/Label.java
+++ b/server/src/com/vaadin/ui/Label.java
@@ -25,6 +25,7 @@ import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.ConverterUtil;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.shared.ui.label.LabelState;
+import com.vaadin.shared.util.SharedUtil;
/**
* Label component for showing non-editable short texts.
@@ -402,7 +403,7 @@ public class Label extends AbstractComponent implements Property<String>,
private void updateValueFromDataSource() {
// Update the internal value from the data source
String newConvertedValue = getDataSourceValue();
- if (!AbstractField.equals(newConvertedValue, getState().text)) {
+ if (!SharedUtil.equals(newConvertedValue, getState().text)) {
getState().text = newConvertedValue;
fireValueChange();
}
diff --git a/shared/src/com/vaadin/shared/util/SharedUtil.java b/shared/src/com/vaadin/shared/util/SharedUtil.java
new file mode 100644
index 0000000000..2242fa4363
--- /dev/null
+++ b/shared/src/com/vaadin/shared/util/SharedUtil.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * 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.
+ */
+package com.vaadin.shared.util;
+
+/**
+ * Misc internal utility methods used by both the server and the client package.
+ *
+ * @author Vaadin Ltd
+ * @since 7.1
+ *
+ */
+public class SharedUtil {
+ /**
+ * Checks if a and b are equals using {@link #equals(Object)}. Handles null
+ * values as well. Does not ensure that objects are of the same type.
+ * Assumes that the first object's equals method handle equals properly.
+ *
+ * @param o1
+ * The first value to compare
+ * @param o2
+ * The second value to compare
+ * @return true if the objects are equal, false otherwise
+ */
+ public static boolean equals(Object o1, Object o2) {
+ if (o1 == null) {
+ return o2 == null;
+ }
+
+ return o1.equals(o2);
+ }
+
+}