summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/data/util
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2011-03-02 08:51:59 +0000
committerHenri Sara <henri.sara@itmill.com>2011-03-02 08:51:59 +0000
commitdf82d111b0f41daafc215124bde1fceb595d0b3b (patch)
tree7de8a7278c3e6f0008a21a932f06e170593bde5b /src/com/vaadin/data/util
parent59d0a558ee01c72244b2d95af1678c9d17a972a0 (diff)
downloadvaadin-framework-df82d111b0f41daafc215124bde1fceb595d0b3b.tar.gz
vaadin-framework-df82d111b0f41daafc215124bde1fceb595d0b3b.zip
Minor refactoring in AbstractBeanContainer: eliminate duplicated code for bean id resolving
svn changeset:17538/svn branch:6.6
Diffstat (limited to 'src/com/vaadin/data/util')
-rw-r--r--src/com/vaadin/data/util/AbstractBeanContainer.java41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java
index 45b7df6535..c71bf565a5 100644
--- a/src/com/vaadin/data/util/AbstractBeanContainer.java
+++ b/src/com/vaadin/data/util/AbstractBeanContainer.java
@@ -753,14 +753,10 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
*/
protected BeanItem<BEANTYPE> addBean(BEANTYPE bean)
throws IllegalStateException, IllegalArgumentException {
- if (beanIdResolver == null) {
- throw new IllegalStateException(
- "Bean item identifier resolver is required.");
- }
if (bean == null) {
return null;
}
- IDTYPE itemId = beanIdResolver.getIdForBean(bean);
+ IDTYPE itemId = resolveBeanId(bean);
if (itemId == null) {
throw new IllegalArgumentException(
"Resolved identifier for a bean must not be null");
@@ -790,14 +786,10 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
protected BeanItem<BEANTYPE> addBeanAfter(IDTYPE previousItemId,
BEANTYPE bean) throws IllegalStateException,
IllegalArgumentException {
- if (beanIdResolver == null) {
- throw new IllegalStateException(
- "Bean item identifier resolver is required.");
- }
if (bean == null) {
return null;
}
- IDTYPE itemId = beanIdResolver.getIdForBean(bean);
+ IDTYPE itemId = resolveBeanId(bean);
if (itemId == null) {
throw new IllegalArgumentException(
"Resolved identifier for a bean must not be null");
@@ -825,14 +817,10 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
*/
protected BeanItem<BEANTYPE> addBeanAt(int index, BEANTYPE bean)
throws IllegalStateException, IllegalArgumentException {
- if (beanIdResolver == null) {
- throw new IllegalStateException(
- "Bean item identifier resolver is required.");
- }
if (bean == null) {
return null;
}
- IDTYPE itemId = beanIdResolver.getIdForBean(bean);
+ IDTYPE itemId = resolveBeanId(bean);
if (itemId == null) {
throw new IllegalArgumentException(
"Resolved identifier for a bean must not be null");
@@ -854,14 +842,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
*/
protected void addAll(Collection<? extends BEANTYPE> collection)
throws IllegalStateException {
- if (beanIdResolver == null) {
- throw new IllegalStateException(
- "Bean item identifier resolver is required.");
- }
-
int idx = internalIndexOf(lastItemId()) + 1;
for (BEANTYPE bean : collection) {
- IDTYPE itemId = beanIdResolver.getIdForBean(bean);
+ IDTYPE itemId = resolveBeanId(bean);
if (internalAddAt(idx, itemId, bean) != null) {
idx++;
}
@@ -872,6 +855,22 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
}
/**
+ * Use the bean resolver to get the identifier for a bean.
+ *
+ * @param bean
+ * @return resolved bean identifier, null if could not be resolved
+ * @throws IllegalStateException
+ * if no bean resolver is set
+ */
+ protected IDTYPE resolveBeanId(BEANTYPE bean) {
+ if (beanIdResolver == null) {
+ throw new IllegalStateException(
+ "Bean item identifier resolver is required.");
+ }
+ return beanIdResolver.getIdForBean(bean);
+ }
+
+ /**
* Sets the resolver that finds the item id for a bean, or null not to use
* automatic resolving.
*