summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-22 20:09:36 +0300
committerSauli Tähkäpää <sauli@vaadin.com>2014-11-28 12:18:26 +0200
commitac3ed7465c1f7c6620034c131142365a993ae537 (patch)
treed5cdb6398650e842e45bff4c30d9786494c94b1a /server/src
parent6728b47e364c89795aaf16a1d99f8a3be405334f (diff)
downloadvaadin-framework-ac3ed7465c1f7c6620034c131142365a993ae537.tar.gz
vaadin-framework-ac3ed7465c1f7c6620034c131142365a993ae537.zip
Optimizing and avoiding NPE in RowId and ReadOnlyRowId toString(#10410).
Change-Id: I6f16b9c55f661f5f75628ff627a01f8ec35e714e
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/ReadOnlyRowId.java11
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/RowId.java46
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/TemporaryRowId.java2
3 files changed, 24 insertions, 35 deletions
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/ReadOnlyRowId.java b/server/src/com/vaadin/data/util/sqlcontainer/ReadOnlyRowId.java
index dcad8f7c5d..c845cadc7a 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/ReadOnlyRowId.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/ReadOnlyRowId.java
@@ -26,18 +26,23 @@ public class ReadOnlyRowId extends RowId {
@Override
public int hashCode() {
- return rowNum.hashCode();
+ return getRowNum();
}
@Override
public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof ReadOnlyRowId)) {
+ if (obj == null || !(ReadOnlyRowId.class.equals(obj.getClass()))) {
return false;
}
- return rowNum.equals(((ReadOnlyRowId) obj).rowNum);
+ return getRowNum() == (((ReadOnlyRowId) obj).getRowNum());
}
public int getRowNum() {
return rowNum;
}
+
+ @Override
+ public String toString() {
+ return String.valueOf(getRowNum());
+ }
}
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/RowId.java b/server/src/com/vaadin/data/util/sqlcontainer/RowId.java
index 8674b9dca0..79c16b0f60 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/RowId.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/RowId.java
@@ -16,6 +16,7 @@
package com.vaadin.data.util.sqlcontainer;
import java.io.Serializable;
+import java.util.Arrays;
/**
* RowId represents identifiers of a single database result set row.
@@ -47,47 +48,30 @@ public class RowId implements Serializable {
@Override
public int hashCode() {
- int result = 31;
- if (id != null) {
- for (Object o : id) {
- if (o != null) {
- result += o.hashCode();
- }
- }
- }
- return result;
+ return Arrays.hashCode(getId());
}
@Override
public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof RowId)) {
- return false;
- }
- Object[] compId = ((RowId) obj).getId();
- if (id == null && compId == null) {
- return true;
- }
- if (id.length != compId.length) {
+ if (obj == null || !(RowId.class.equals(obj.getClass()))) {
return false;
}
- for (int i = 0; i < id.length; i++) {
- if ((id[i] == null && compId[i] != null)
- || (id[i] != null && !id[i].equals(compId[i]))) {
- return false;
- }
- }
- return true;
+ return Arrays.equals(getId(), ((RowId) obj).getId());
}
@Override
public String toString() {
- StringBuffer s = new StringBuffer();
- for (int i = 0; i < id.length; i++) {
- s.append(id[i]);
- if (i < id.length - 1) {
- s.append("/");
- }
+ if (getId() == null) {
+ return "";
+ }
+ StringBuilder builder = new StringBuilder();
+ for (Object id : getId()) {
+ builder.append(id);
+ builder.append('/');
+ }
+ if (builder.length() > 0) {
+ return builder.substring(0, builder.length() - 1);
}
- return s.toString();
+ return builder.toString();
}
}
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/TemporaryRowId.java b/server/src/com/vaadin/data/util/sqlcontainer/TemporaryRowId.java
index 6c1e07756f..ca2f25963e 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/TemporaryRowId.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/TemporaryRowId.java
@@ -29,7 +29,7 @@ public class TemporaryRowId extends RowId {
@Override
public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof TemporaryRowId)) {
+ if (obj == null || !(TemporaryRowId.class.equals(obj.getClass()))) {
return false;
}
Object[] compId = ((TemporaryRowId) obj).getId();