Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2008-02-03 16:40:54 +0000
committertle2008-02-03 16:40:54 +0000
commit7f7b20a5d66bf69e88734ead5036e4d6664aa381 (patch)
tree97dacecfda81e183389ab1c0adb3a83b953823ad /jpa/tests/org.eclipse.jpt.utility.tests
parent145c144380950bd4b49fd4597a1a0695cf7c8b7b (diff)
downloadwebtools.dali-7f7b20a5d66bf69e88734ead5036e4d6664aa381.tar.gz
webtools.dali-7f7b20a5d66bf69e88734ead5036e4d6664aa381.tar.xz
webtools.dali-7f7b20a5d66bf69e88734ead5036e4d6664aa381.zip
Merged jpt_2_0_exp branch into Head.v20080202_Merged
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.utility.tests')
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java101
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java38
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IndentingPrintWriterTests.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JavaTypeTests.java30
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java164
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeIteratorTests.java18
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeListIteratorTests.java95
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java49
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/ReadOnlyCompositeListIteratorTests.java205
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/AbstractModelTests.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java410
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java90
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java68
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java72
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java112
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java149
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java256
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java63
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java108
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java46
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java123
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java126
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java135
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java120
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java16
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java137
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java81
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java67
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java16
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java88
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java44
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java43
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java45
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java14
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java51
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java63
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java66
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java19
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java80
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java46
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java28
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java158
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java169
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java144
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java144
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java86
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java52
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java8
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java53
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java28
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java20
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java26
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java84
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java85
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java18
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java20
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java14
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java36
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java24
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java22
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java53
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java135
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java143
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java210
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java36
77 files changed, 3694 insertions, 1718 deletions
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.utility.tests/.settings/org.eclipse.core.resources.prefs
index c74f41d1cd..f68f9c2597 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/.settings/org.eclipse.core.resources.prefs
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,3 @@
-#Sun May 27 15:11:44 EDT 2007
+#Tue Jan 15 11:12:26 EST 2008
eclipse.preferences.version=1
encoding/<project>=ISO-8859-1
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java
index 504b621daa..f2e4eae173 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClassToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -93,7 +93,7 @@ public class ClassToolsTests extends TestCase {
Vector<?> v = ClassTools.newInstance(java.util.Vector.class, int.class, new Integer(initialCapacity));
assertNotNull(v);
assertEquals(0, v.size());
- Object[] elementData = (Object[]) ClassTools.getFieldValue(v, "elementData");
+ Object[] elementData = (Object[]) ClassTools.fieldValue(v, "elementData");
assertEquals(initialCapacity, elementData.length);
}
@@ -106,7 +106,7 @@ public class ClassToolsTests extends TestCase {
Vector<?> v = ClassTools.newInstance(java.util.Vector.class, parmTypes, parms);
assertNotNull(v);
assertEquals(0, v.size());
- Object[] elementData = (Object[]) ClassTools.getFieldValue(v, "elementData");
+ Object[] elementData = (Object[]) ClassTools.fieldValue(v, "elementData");
assertEquals(initialCapacity, elementData.length);
parms[0] = new Integer(-1);
@@ -129,14 +129,14 @@ public class ClassToolsTests extends TestCase {
assertTrue("NoSuchMethodException not thrown", exCaught);
}
- public void testGetFieldValue() {
+ public void testFieldValue() {
int initialCapacity = 200;
Vector<?> v = new Vector<Object>(initialCapacity);
- Object[] elementData = (Object[]) ClassTools.getFieldValue(v, "elementData");
+ Object[] elementData = (Object[]) ClassTools.fieldValue(v, "elementData");
assertEquals(initialCapacity, elementData.length);
// test inherited field
- Integer modCountInteger = (Integer) ClassTools.getFieldValue(v, "modCount");
+ Integer modCountInteger = (Integer) ClassTools.fieldValue(v, "modCount");
int modCount = modCountInteger.intValue();
assertEquals(0, modCount);
@@ -493,7 +493,68 @@ public class ClassToolsTests extends TestCase {
assertEquals('B', ClassTools.codeForClassNamed("byte"));
}
- public void testClassForTypeDeclaration() throws Exception {
+ public void testClassIsPrimitiveWrapperClass() {
+ assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Void.class));
+ assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Boolean.class));
+ assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Integer.class));
+ assertTrue(ClassTools.classIsPrimitiveWrapperClass(java.lang.Float.class));
+
+ assertFalse(ClassTools.classIsPrimitiveWrapperClass(java.lang.String.class));
+ assertFalse(ClassTools.classIsPrimitiveWrapperClass(void.class));
+ assertFalse(ClassTools.classIsPrimitiveWrapperClass(int.class));
+ }
+
+ public void testClassIsVariablePrimitiveWrapperClass() {
+ assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Void.class));
+
+ assertTrue(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Boolean.class));
+ assertTrue(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Integer.class));
+ assertTrue(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.Float.class));
+
+ assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(java.lang.String.class));
+ assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(void.class));
+ assertFalse(ClassTools.classIsVariablePrimitiveWrapperClass(int.class));
+ }
+
+ public void testClassNamedIsPrimitive() {
+ assertTrue(void.class.isPrimitive());
+
+ assertTrue(ClassTools.classNamedIsPrimitive(void.class.getName()));
+ assertTrue(ClassTools.classNamedIsPrimitive(int.class.getName()));
+ assertTrue(ClassTools.classNamedIsPrimitive(float.class.getName()));
+ assertTrue(ClassTools.classNamedIsPrimitive(boolean.class.getName()));
+
+ assertFalse(ClassTools.classNamedIsPrimitive(java.lang.Number.class.getName()));
+ assertFalse(ClassTools.classNamedIsPrimitive(java.lang.String.class.getName()));
+ assertFalse(ClassTools.classNamedIsPrimitive(java.lang.Boolean.class.getName()));
+ assertFalse(ClassTools.classNamedIsPrimitive(java.lang.Integer.class.getName()));
+ }
+
+ public void testClassNamedIsVariablePrimitive() {
+ assertFalse(ClassTools.classNamedIsVariablePrimitive(void.class.getName()));
+
+ assertTrue(ClassTools.classNamedIsVariablePrimitive(int.class.getName()));
+ assertTrue(ClassTools.classNamedIsVariablePrimitive(float.class.getName()));
+ assertTrue(ClassTools.classNamedIsVariablePrimitive(boolean.class.getName()));
+
+ assertFalse(ClassTools.classNamedIsVariablePrimitive(java.lang.Number.class.getName()));
+ assertFalse(ClassTools.classNamedIsVariablePrimitive(java.lang.String.class.getName()));
+ assertFalse(ClassTools.classNamedIsVariablePrimitive(java.lang.Boolean.class.getName()));
+ }
+
+ public void testClassNamedIsVariablePrimitiveWrapperClass() {
+ assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Void.class.getName()));
+
+ assertTrue(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Integer.class.getName()));
+ assertTrue(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Float.class.getName()));
+ assertTrue(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Boolean.class.getName()));
+
+ assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Number.class.getName()));
+ assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.String.class.getName()));
+ assertFalse(ClassTools.classNamedIsVariablePrimitiveWrapperClass(java.lang.Object.class.getName()));
+ }
+
+ public void testClassForTypeDeclarationStringInt() throws Exception {
assertEquals(int.class, ClassTools.classForTypeDeclaration("int", 0));
assertEquals(int[].class, ClassTools.classForTypeDeclaration("int", 1));
assertEquals(int[][][].class, ClassTools.classForTypeDeclaration("int", 3));
@@ -510,7 +571,31 @@ public class ClassToolsTests extends TestCase {
}
}
- public void testClassNameForTypeDeclaration() throws Exception {
+ public void testClassNameForTypeDeclarationString() throws Exception {
+ assertEquals("int", ClassTools.classNameForTypeDeclaration("int"));
+ assertEquals("[I", ClassTools.classNameForTypeDeclaration("int[]"));
+ assertEquals("[[I", ClassTools.classNameForTypeDeclaration("int [ ] [ ]"));
+
+ assertEquals("java.lang.Object", ClassTools.classNameForTypeDeclaration("java.lang.Object"));
+ assertEquals("[Ljava.lang.Object;", ClassTools.classNameForTypeDeclaration("java.lang.Object\t[]"));
+ assertEquals("[[Ljava.lang.Object;", ClassTools.classNameForTypeDeclaration("java.lang.Object\t[]\t[]"));
+ }
+
+ public void testArrayDepthForTypeDeclarationString() throws Exception {
+ assertEquals(0, ClassTools.arrayDepthForTypeDeclaration("java.lang.Object"));
+ assertEquals(1, ClassTools.arrayDepthForTypeDeclaration("java.lang.Object[]"));
+ assertEquals(3, ClassTools.arrayDepthForTypeDeclaration("java.lang.Object[][][]"));
+
+ assertEquals(0, ClassTools.arrayDepthForTypeDeclaration("int"));
+ assertEquals(1, ClassTools.arrayDepthForTypeDeclaration("int[]"));
+ assertEquals(3, ClassTools.arrayDepthForTypeDeclaration("int[][][]"));
+
+ assertEquals(0, ClassTools.arrayDepthForTypeDeclaration("float"));
+ assertEquals(1, ClassTools.arrayDepthForTypeDeclaration("float [ ]"));
+ assertEquals(3, ClassTools.arrayDepthForTypeDeclaration("float[] [] []"));
+ }
+
+ public void testClassNameForTypeDeclarationStringInt() throws Exception {
assertEquals(int.class.getName(), ClassTools.classNameForTypeDeclaration("int", 0));
assertEquals(int[].class.getName(), ClassTools.classNameForTypeDeclaration("int", 1));
assertEquals(int[][][].class.getName(), ClassTools.classNameForTypeDeclaration("int", 3));
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java
index 54beea0c81..4e19dac30c 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/ClasspathTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -106,7 +106,7 @@ public class ClasspathTests extends TestCase {
public void testEntries() {
Classpath cp = new Classpath(this.morph("C:\\jdk\\rt.jar;;.;C:\\jdk\\i18n.jar;;;C:\\jdk\\jaws.jar;;C:\\foo\\classes;C:\\bar\\bar.jar;C:\\bar\\bar.jar;"));
- Classpath.Entry[] entries = cp.getEntries();
+ Classpath.Entry[] entries = cp.entries();
int i = 0;
assertEquals(this.morph("C:\\jdk\\rt.jar"), entries[i++].fileName());
assertEquals(this.morph("."), entries[i++].fileName());
@@ -118,7 +118,7 @@ public class ClasspathTests extends TestCase {
assertEquals(i, entries.length);
cp = cp.compressed();
- entries = cp.getEntries();
+ entries = cp.entries();
i = 0;
assertEquals(this.morph("C:\\jdk\\rt.jar"), entries[i++].fileName());
assertEquals(this.morph("."), entries[i++].fileName());
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java
index 654fc83d80..e02ee44d6f 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/CollectionToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -279,6 +279,14 @@ public class CollectionToolsTests extends TestCase {
assertTrue(Arrays.equals(new Object[] { "a", "b", "X", "X", "X", "c", "d" }, a));
}
+ public void testAddAllObjectArrayIntObjectArray4() {
+ Object[] a = new Object[] { "a", "b", "c", "d" };
+ a = CollectionTools.addAll(a, 4, new String[] { "X", "X", "X" });
+ assertEquals(7, a.length);
+ assertTrue(CollectionTools.contains(a, "X"));
+ assertTrue(Arrays.equals(new Object[] { "a", "b", "c", "d", "X", "X", "X" }, a));
+ }
+
public void testAddAllCharArrayCharArray() {
char[] a = CollectionTools.addAll(this.buildCharArray(), new char[] { 'd', 'e' });
assertEquals(5, a.length);
@@ -1259,9 +1267,9 @@ public class CollectionToolsTests extends TestCase {
boolean exceptionThrown = false;
try {
- emptyIterable.iterator();
- }
- catch (IllegalStateException ise) {
+ emptyIterator = emptyIterable.iterator();
+ fail("invalid iterator: " + emptyIterator);
+ } catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue("IllegalStateException not thrown.", exceptionThrown);
@@ -1933,16 +1941,34 @@ public class CollectionToolsTests extends TestCase {
assertTrue(Arrays.equals(new String[] { "A", "B", "A", "D" }, a));
}
+ public void testRemoveElementsAtIndexObjectArrayIntIntEmpty() {
+ String[] a = new String[] { "A", "B", "A", "C", "A", "D" };
+ a = CollectionTools.removeElementsAtIndex(a, 0, 6);
+ assertEquals(0, a.length);
+ }
+
public void testRemoveElementsAtIndexCharArrayIntInt() {
char[] a = new char[] { 'A', 'B', 'A', 'C', 'A', 'D' };
a = CollectionTools.removeElementsAtIndex(a, 0, 5);
assertTrue(Arrays.equals(new char[] { 'D' }, a));
}
+ public void testRemoveElementsAtIndexCharArrayIntIntEmpty() {
+ char[] a = new char[] { 'A', 'B', 'A', 'C', 'A', 'D' };
+ a = CollectionTools.removeElementsAtIndex(a, 0, 6);
+ assertEquals(0, a.length);
+ }
+
public void testRemoveElementsAtIndexIntArrayIntInt() {
int[] a = new int[] { 8, 6, 7, 33, 2, 11 };
- a = CollectionTools.removeElementAtIndex(a, 3);
- assertTrue(Arrays.equals(new int[] { 8, 6, 7, 2, 11 }, a));
+ a = CollectionTools.removeElementsAtIndex(a, 3, 3);
+ assertTrue(Arrays.equals(new int[] { 8, 6, 7 }, a));
+ }
+
+ public void testRemoveElementsAtIndexIntArrayIntIntEmpty() {
+ int[] a = new int[] { 8, 6, 7, 33, 2, 11 };
+ a = CollectionTools.removeElementsAtIndex(a, 0, 6);
+ assertEquals(0, a.length);
}
public void testReplaceAllObjectArray1() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IndentingPrintWriterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IndentingPrintWriterTests.java
index c96213249b..b971895bc1 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IndentingPrintWriterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/IndentingPrintWriterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -41,31 +41,31 @@ public class IndentingPrintWriterTests extends TestCase {
}
public void testIndent() {
- assertEquals("wrong indent level", 0, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 0, this.ipw1.indentLevel());
this.ipw1.indent();
- assertEquals("wrong indent level", 1, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 1, this.ipw1.indentLevel());
}
public void testUndent() {
- assertEquals("wrong indent level", 0, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 0, this.ipw1.indentLevel());
this.ipw1.indent();
- assertEquals("wrong indent level", 1, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 1, this.ipw1.indentLevel());
this.ipw1.undent();
- assertEquals("wrong indent level", 0, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 0, this.ipw1.indentLevel());
}
public void testIncrementIndentLevel() {
- assertEquals("wrong indent level", 0, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 0, this.ipw1.indentLevel());
this.ipw1.incrementIndentLevel();
- assertEquals("wrong indent level", 1, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 1, this.ipw1.indentLevel());
}
public void testDecrementIndentLevel() {
- assertEquals("wrong indent level", 0, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 0, this.ipw1.indentLevel());
this.ipw1.incrementIndentLevel();
- assertEquals("wrong indent level", 1, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 1, this.ipw1.indentLevel());
this.ipw1.decrementIndentLevel();
- assertEquals("wrong indent level", 0, this.ipw1.getIndentLevel());
+ assertEquals("wrong indent level", 0, this.ipw1.indentLevel());
}
public void testPrintTab() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java
index 40f152dfa9..07dad198b5 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JDBCTypeTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -26,19 +26,19 @@ public class JDBCTypeTests extends TestCase {
public void testName() {
JDBCType jdbcType;
jdbcType = JDBCType.type(Types.VARCHAR);
- assertEquals("VARCHAR", jdbcType.getName());
+ assertEquals("VARCHAR", jdbcType.name());
jdbcType = JDBCType.type(Types.INTEGER);
- assertEquals("INTEGER", jdbcType.getName());
+ assertEquals("INTEGER", jdbcType.name());
}
public void testCode() {
JDBCType jdbcType;
jdbcType = JDBCType.type(Types.VARCHAR);
- assertEquals(Types.VARCHAR, jdbcType.getCode());
+ assertEquals(Types.VARCHAR, jdbcType.code());
jdbcType = JDBCType.type(Types.INTEGER);
- assertEquals(Types.INTEGER, jdbcType.getCode());
+ assertEquals(Types.INTEGER, jdbcType.code());
}
public void testInvalidTypeCode() throws Exception {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JavaTypeTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JavaTypeTests.java
index 1a0c0b826f..57a10be26a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JavaTypeTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/JavaTypeTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -76,49 +76,49 @@ public class JavaTypeTests extends TestCase {
public void testElementTypeName() throws Exception {
JavaType javaType;
javaType = new JavaType(java.lang.Object.class);
- assertEquals("java.lang.Object", javaType.getElementTypeName());
+ assertEquals("java.lang.Object", javaType.elementTypeName());
javaType = new JavaType(java.lang.Object[].class);
- assertEquals("java.lang.Object", javaType.getElementTypeName());
+ assertEquals("java.lang.Object", javaType.elementTypeName());
javaType = new JavaType(int.class);
- assertEquals("int", javaType.getElementTypeName());
+ assertEquals("int", javaType.elementTypeName());
javaType = new JavaType(int[].class);
- assertEquals("int", javaType.getElementTypeName());
+ assertEquals("int", javaType.elementTypeName());
javaType = new JavaType(void.class);
- assertEquals("void", javaType.getElementTypeName());
+ assertEquals("void", javaType.elementTypeName());
javaType = new JavaType(java.util.Map.Entry.class);
- assertEquals("java.util.Map$Entry", javaType.getElementTypeName());
+ assertEquals("java.util.Map$Entry", javaType.elementTypeName());
javaType = new JavaType(java.util.Map.Entry[][].class);
- assertEquals("java.util.Map$Entry", javaType.getElementTypeName());
+ assertEquals("java.util.Map$Entry", javaType.elementTypeName());
}
public void testArrayDepth() throws Exception {
JavaType javaType;
javaType = new JavaType(java.lang.Object.class);
- assertEquals(0, javaType.getArrayDepth());
+ assertEquals(0, javaType.arrayDepth());
javaType = new JavaType(java.lang.Object[].class);
- assertEquals(1, javaType.getArrayDepth());
+ assertEquals(1, javaType.arrayDepth());
javaType = new JavaType(int.class);
- assertEquals(0, javaType.getArrayDepth());
+ assertEquals(0, javaType.arrayDepth());
javaType = new JavaType(int[].class);
- assertEquals(1, javaType.getArrayDepth());
+ assertEquals(1, javaType.arrayDepth());
javaType = new JavaType(void.class);
- assertEquals(0, javaType.getArrayDepth());
+ assertEquals(0, javaType.arrayDepth());
javaType = new JavaType(java.util.Map.Entry.class);
- assertEquals(0, javaType.getArrayDepth());
+ assertEquals(0, javaType.arrayDepth());
javaType = new JavaType(java.util.Map.Entry[][].class);
- assertEquals(2, javaType.getArrayDepth());
+ assertEquals(2, javaType.arrayDepth());
}
public void testIsArray() throws Exception {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
index 68161e88fc..42f6936eb1 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -515,6 +515,67 @@ public class StringToolsTests extends TestCase {
assertEquals(expectedString, sb.toString());
}
+ public void testRemoveAllWhitespace() {
+ this.verifyRemoveAllWhitespace("Employee Fred\t", ' ', "EmployeeFred");
+ this.verifyRemoveAllWhitespace("\tEmployee\n", ' ', "Employee");
+ this.verifyRemoveAllWhitespace("Employee \t Foo", ' ', "EmployeeFoo");
+ this.verifyRemoveAllWhitespace(" Emp\tloyee \n Foo", ' ', "EmployeeFoo");
+ }
+
+ private void verifyRemoveAllWhitespace(String string, char charToRemove, String expectedString) {
+ assertEquals(expectedString, StringTools.removeAllWhitespace(string));
+ }
+
+ public void testRemoveAllWhitespaceCharArray() {
+ this.verifyRemoveAllWhitespaceCharArray("Employee Fred\t", ' ', "EmployeeFred");
+ this.verifyRemoveAllWhitespaceCharArray("\tEmployee\n", ' ', "Employee");
+ this.verifyRemoveAllWhitespaceCharArray("Employee \t Foo", ' ', "EmployeeFoo");
+ this.verifyRemoveAllWhitespaceCharArray(" Emp\tloyee \n Foo", ' ', "EmployeeFoo");
+ }
+
+ private void verifyRemoveAllWhitespaceCharArray(String string, char charToRemove, String expectedString) {
+ assertEquals(expectedString, new String(StringTools.removeAllWhitespace(string.toCharArray())));
+ }
+
+ public void testRemoveAllWhitespaceOnWriter() {
+ this.verifyRemoveAllWhitespaceOnWriter("Employee Fred\t", ' ', "EmployeeFred");
+ this.verifyRemoveAllWhitespaceOnWriter("\tEmployee\n", ' ', "Employee");
+ this.verifyRemoveAllWhitespaceOnWriter("Employee \t Foo", ' ', "EmployeeFoo");
+ this.verifyRemoveAllWhitespaceOnWriter(" Emp\tloyee \n Foo", ' ', "EmployeeFoo");
+ }
+
+ private void verifyRemoveAllWhitespaceOnWriter(String string, char charToRemove, String expectedString) {
+ Writer writer = new StringWriter();
+ StringTools.removeAllWhitespaceOn(string, writer);
+ assertEquals(expectedString, writer.toString());
+ }
+
+ public void testRemoveAllWhitespaceOnStringBuffer() {
+ this.verifyRemoveAllWhitespaceOnStringBuffer("Employee Fred\t", ' ', "EmployeeFred");
+ this.verifyRemoveAllWhitespaceOnStringBuffer("\tEmployee\n", ' ', "Employee");
+ this.verifyRemoveAllWhitespaceOnStringBuffer("Employee \t Foo", ' ', "EmployeeFoo");
+ this.verifyRemoveAllWhitespaceOnStringBuffer(" Emp\tloyee \n Foo", ' ', "EmployeeFoo");
+ }
+
+ private void verifyRemoveAllWhitespaceOnStringBuffer(String string, char charToRemove, String expectedString) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.removeAllWhitespaceOn(string, sb);
+ assertEquals(expectedString, sb.toString());
+ }
+
+ public void testRemoveAllWhitespaceOnStringBuilder() {
+ this.verifyRemoveAllWhitespaceOnStringBuilder("Employee Fred\t", ' ', "EmployeeFred");
+ this.verifyRemoveAllWhitespaceOnStringBuilder("\tEmployee\n", ' ', "Employee");
+ this.verifyRemoveAllWhitespaceOnStringBuilder("Employee \t Foo", ' ', "EmployeeFoo");
+ this.verifyRemoveAllWhitespaceOnStringBuilder(" Emp\tloyee \n Foo", ' ', "EmployeeFoo");
+ }
+
+ private void verifyRemoveAllWhitespaceOnStringBuilder(String string, char charToRemove, String expectedString) {
+ StringBuilder sb = new StringBuilder();
+ StringTools.removeAllWhitespaceOn(string, sb);
+ assertEquals(expectedString, sb.toString());
+ }
+
// ********** common prefix **********
public void testCommonPrefixLength() {
@@ -885,6 +946,38 @@ public class StringToolsTests extends TestCase {
assertEquals(expected, writer.toString());
}
+ public void testConvertCamelCaseToAllCapsOnStringBuffer() {
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST", "test");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST", "TEST");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST_TEST", "testTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST_TEST", "TestTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST_TEST_TEST", "testTESTTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST_TEST_TEST", "TestTESTTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuffer("TEST_TEST_TEST_T", "TestTESTTestT");
+ }
+
+ private void verifyConvertCamelCaseToAllCapsOnStringBuffer(String expected, String string) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.convertCamelCaseToAllCapsOn(string, sb);
+ assertEquals(expected, sb.toString());
+ }
+
+ public void testConvertCamelCaseToAllCapsOnStringBuilder() {
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST", "test");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST", "TEST");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST_TEST", "testTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST_TEST", "TestTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST_TEST_TEST", "testTESTTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST_TEST_TEST", "TestTESTTest");
+ this.verifyConvertCamelCaseToAllCapsOnStringBuilder("TEST_TEST_TEST_T", "TestTESTTestT");
+ }
+
+ private void verifyConvertCamelCaseToAllCapsOnStringBuilder(String expected, String string) {
+ StringBuilder sb = new StringBuilder();
+ StringTools.convertCamelCaseToAllCapsOn(string, sb);
+ assertEquals(expected, sb.toString());
+ }
+
public void testConvertCamelCaseToAllCapsMaxLength() {
assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("test", 44));
assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("test", 4));
@@ -929,6 +1022,31 @@ public class StringToolsTests extends TestCase {
assertEquals(expected, writer.toString());
}
+ public void testConvertCamelCaseToAllCapsMaxLengthOnStringBuffer() {
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST", "test", 44);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST", "test", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TES", "test", 3);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST", "TEST", 5);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TE", "TEST", 2);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST", "testTest", 9);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TES", "testTest", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_T", "testTest", 6);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_", "testTest", 5);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST", "testTest", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST", "TestTest", 9);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST", "TestTest", 1100);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST_", "testTESTTest", 10);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST_TEST", "TestTESTTest", 14);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST_TEST_T", "TestTESTTestT", 16);
+ this.verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer("TEST_TEST_TEST_", "TestTESTTestT", 15);
+ }
+
+ private void verifyConvertCamelCaseToAllCapsMaxLengthOnStringBuffer(String expected, String string, int max) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.convertCamelCaseToAllCapsOn(string, max, sb);
+ assertEquals(expected, sb.toString());
+ }
+
public void testConvertUnderscoresToCamelCase() {
assertEquals("test", StringTools.convertUnderscoresToCamelCase("TEST", false));
assertEquals("test", StringTools.convertUnderscoresToCamelCase("TEST_", false));
@@ -1011,4 +1129,48 @@ public class StringToolsTests extends TestCase {
assertEquals(expected, writer.toString());
}
+ public void testConvertUnderscoresToCamelCaseOnStringBuffer() {
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "TEST", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "TEST_", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "TEST____", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("Test", "TEST", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "TeST", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTest", "TEST_TEST", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTest", "TEST___TEST", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTest", "TEST_TEST", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTest", "TEST_TEST_TEST", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTest", "TEST_TEST_TEST", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTestT", "TEST_TEST_TEST_T", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTestT", "_TEST_TEST_TEST_T", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTestT", "__TEST_TEST_TEST_T", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTestT", "TEST_TEST_TEST_T", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTestT", "_TEST_TEST_TEST_T", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTestT", "__TEST_TEST_TEST_T", true);
+ }
+
+ public void testConvertUnderscoresToCamelCaseOnStringBufferLowercase() {
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "test", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "test_", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "test____", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("Test", "test", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("test", "test", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTest", "test_test", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTest", "test___test", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTest", "test_test", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTest", "test_test_test", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTest", "test_test_test", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTestT", "test_test_test_t", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTestT", "_test_test_test_t", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("testTestTestT", "__test_test_test_t", false);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTestT", "test_test_test_t", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTestT", "_test_test_test_t", true);
+ this.verifyConvertUnderscoresToCamelCaseOnStringBuffer("TestTestTestT", "__test_test_test_t", true);
+ }
+
+ private void verifyConvertUnderscoresToCamelCaseOnStringBuffer(String expected, String string, boolean capitalizeFirstLetter) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.convertUnderscoresToCamelCaseOn(string, capitalizeFirstLetter, sb);
+ assertEquals(expected, sb.toString());
+ }
+
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeIteratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeIteratorTests.java
index d7173cefa8..58c3976076 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeIteratorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeIteratorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -73,6 +73,10 @@ public class CompositeIteratorTests extends TestCase {
}
public void testRemove() {
+ this.verifyRemove();
+ }
+
+ protected void verifyRemove() {
List<String> list1 = this.buildList1();
Object lastElement1 = list1.get(list1.size() - 1);
List<String> list2 = this.buildList2();
@@ -153,6 +157,10 @@ public class CompositeIteratorTests extends TestCase {
}
public void testIllegalStateException() {
+ this.verifyIllegalStateException();
+ }
+
+ void verifyIllegalStateException() {
this.verifyIllegalStateException(this.buildCompositeIterator());
}
@@ -184,6 +192,10 @@ public class CompositeIteratorTests extends TestCase {
}
public void testEmptyIllegalStateException1() {
+ this.verifyEmptyIllegalStateException1();
+ }
+
+ void verifyEmptyIllegalStateException1() {
this.verifyIllegalStateException(this.buildEmptyCompositeIterator1());
}
@@ -196,6 +208,10 @@ public class CompositeIteratorTests extends TestCase {
}
public void testEmptyIllegalStateException2() {
+ this.verifyEmptyIllegalStateException2();
+ }
+
+ void verifyEmptyIllegalStateException2() {
this.verifyIllegalStateException(this.buildEmptyCompositeIterator2());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeListIteratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeListIteratorTests.java
index f2de1d1426..2d2bdbec7a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeListIteratorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/CompositeListIteratorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,38 +13,16 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-import java.util.NoSuchElementException;
+
import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator;
-public class CompositeListIteratorTests extends CompositeIteratorTests {
+public class CompositeListIteratorTests extends ReadOnlyCompositeListIteratorTests {
public CompositeListIteratorTests(String name) {
super(name);
}
@Override
- void verifyHasAnother(Iterator<String> stream) {
- super.verifyHasAnother(stream);
- ListIterator<String> stream2 = (ListIterator<String>) stream;
- int i = 0;
- while (stream2.hasPrevious()) {
- stream2.previous();
- i++;
- }
- assertEquals(8, i);
- }
-
- @Override
- void verifyAnother(Iterator<String> stream) {
- super.verifyAnother(stream);
- int i = 8;
- ListIterator<String> stream2 = (ListIterator<String>) stream;
- while (stream2.hasPrevious()) {
- assertEquals("bogus element", String.valueOf(i--), stream2.previous().substring(0, 1));
- }
- }
-
- @Override
public void testRemove() {
super.testRemove();
List<String> list1 = this.buildList1();
@@ -270,6 +248,7 @@ public class CompositeListIteratorTests extends CompositeIteratorTests {
assertFalse("element not set in collection 3", list3.contains(firstElement3));
}
+ @Override
public void testNextIndexPreviousIndex() {
int i = 0;
ListIterator<String> stream = (ListIterator<String>) this.buildCompositeIterator();
@@ -310,68 +289,19 @@ public class CompositeListIteratorTests extends CompositeIteratorTests {
assertEquals("index is corrupt", 0, i);
}
- public void testPreviousIndex() {
- // TODO
- }
-
@Override
- void verifyNoSuchElementException(Iterator<String> stream) {
- super.verifyNoSuchElementException(stream);
- ListIterator<String> stream2 = (ListIterator<String>) stream;
- boolean exCaught = false;
- String string = null;
- while (stream2.hasPrevious()) {
- string = stream2.previous();
- }
- try {
- string = stream2.previous();
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue("NoSuchElementException not thrown: " + string, exCaught);
- }
-
- @Override
- void verifyUnsupportedOperationException(Iterator<String> stream) {
- super.verifyUnsupportedOperationException(stream);
- boolean exCaught = false;
- ListIterator<String> stream2 = (ListIterator<String>) stream;
- while (stream2.hasPrevious()) {
- Object string = stream2.previous();
- if (string.equals("333")) {
- try {
- stream2.remove();
- } catch (UnsupportedOperationException ex) {
- exCaught = true;
- }
- }
- }
- assertTrue("UnsupportedOperationException not thrown", exCaught);
+ public void testIllegalStateException() {
+ this.verifyIllegalStateException();
}
@Override
- void verifyIllegalStateException(Iterator<String> stream) {
- super.verifyIllegalStateException(stream);
- ListIterator<String> stream2 = (ListIterator<String>) stream;
- boolean exCaught = false;
- try {
- stream2.set("junk");
- } catch (IllegalStateException ex) {
- exCaught = true;
- }
- assertTrue("IllegalStateException not thrown", exCaught);
+ public void testEmptyIllegalStateException1() {
+ this.verifyEmptyIllegalStateException1();
}
@Override
- void verifyEmptyHasAnother(Iterator<String> stream) {
- super.verifyEmptyHasAnother(stream);
- ListIterator<String> stream2 = (ListIterator<String>) stream;
- int i = 0;
- while (stream2.hasPrevious()) {
- stream2.previous();
- i++;
- }
- assertEquals(0, i);
+ public void testEmptyIllegalStateException2() {
+ this.verifyEmptyIllegalStateException2();
}
// unchecked so we can override the unchecked method in superclass
@@ -393,10 +323,7 @@ public class CompositeListIteratorTests extends CompositeIteratorTests {
return new CompositeListIterator<String>(new ListIterator[] { this.buildIterator1(), this.buildIterator2(), this.buildIterator3() });
}
- Iterator<String> buildCompositeIterator(String string, ListIterator<String> iterator) {
- return this.buildCompositeListIterator(string, iterator);
- }
-
+ @Override
ListIterator<String> buildCompositeListIterator(String string, ListIterator<String> iterator) {
return new CompositeListIterator<String>(string, iterator);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java
index 44b9c8c0c3..c23fcfa94b 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/FilteringIteratorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -129,10 +129,10 @@ public class FilteringIteratorTests extends TestCase {
integers.add(new Integer(1));
integers.add(new Integer(2));
integers.add(new Integer(3));
- Iterator<Number> stream = new FilteringIterator<Number>(integers.iterator()) {
+ Iterator<Number> stream = new FilteringIterator<Integer, Number>(integers.iterator()) {
@Override
- protected boolean accept(Object o) {
- return ((Number) o).intValue() > 1;
+ protected boolean accept(Integer o) {
+ return o.intValue() > 1;
}
};
assertEquals(2, CollectionTools.size(stream));
@@ -141,14 +141,14 @@ public class FilteringIteratorTests extends TestCase {
// test a filtered iterator with a nested iterator of a super-type (Integer vs. Number)
// i.e. trust that Filter will only return the appropriate sub-type objects
public void testGenerics2() {
- List<Number> integers = new ArrayList<Number>();
- integers.add(new Integer(0));
- integers.add(new Long(1));
- integers.add(new Integer(2));
- integers.add(new Float(3));
- Iterator<Integer> stream = new FilteringIterator<Integer>(integers.iterator()) {
+ List<Number> numbers = new ArrayList<Number>();
+ numbers.add(new Integer(0));
+ numbers.add(new Long(1));
+ numbers.add(new Integer(2));
+ numbers.add(new Float(3));
+ Iterator<Integer> stream = new FilteringIterator<Number, Integer>(numbers.iterator()) {
@Override
- protected boolean accept(Object o) {
+ protected boolean accept(Number o) {
return o instanceof Integer;
}
};
@@ -171,14 +171,14 @@ public class FilteringIteratorTests extends TestCase {
}
private Iterator<String> buildFilteredIterator(Iterator<String> nestedIterator, Filter<String> filter) {
- return new FilteringIterator<String>(nestedIterator, filter);
+ return new FilteringIterator<String, String>(nestedIterator, filter);
}
private Iterator<String> buildInnerFilteredIterator(Iterator<String> nestedIterator) {
- return new FilteringIterator<String>(nestedIterator) {
+ return new FilteringIterator<String, String>(nestedIterator) {
@Override
- protected boolean accept(Object o) {
- return ((String) o).startsWith(PREFIX);
+ protected boolean accept(String s) {
+ return s.startsWith(PREFIX);
}
};
}
@@ -189,10 +189,10 @@ public class FilteringIteratorTests extends TestCase {
// this inner iterator will call the "outer" object
private Iterator<String> buildInnerFilteredIterator2(Iterator<String> nestedIterator) {
- return new FilteringIterator<String>(nestedIterator) {
+ return new FilteringIterator<String, String>(nestedIterator) {
@Override
- protected boolean accept(Object o) {
- return ((String) o).startsWith(FilteringIteratorTests.this.getPrefix());
+ protected boolean accept(String s) {
+ return s.startsWith(FilteringIteratorTests.this.getPrefix());
}
};
}
@@ -286,6 +286,19 @@ public class FilteringIteratorTests extends TestCase {
boolean exCaught = false;
try {
// missing method override
+ Iterator<String> iterator = new FilteringIterator<String, String>(this.buildNestedIterator());
+ String s = iterator.next();
+ fail("invalid string: " + s);
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue("NoSuchElementException not thrown", exCaught);
+ }
+
+ public void testInvalidFilteringIterator() {
+ boolean exCaught = false;
+ try {
+ // missing method override
Iterator<String> iterator = new FilteringIterator<String>(this.buildNestedIterator());
String s = iterator.next();
fail("invalid string: " + s);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java
index 297876647b..8d9d3f7270 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/JptUtilityIteratorsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -35,6 +35,7 @@ public class JptUtilityIteratorsTests {
suite.addTestSuite(GraphIteratorTests.class);
suite.addTestSuite(IteratorEnumerationTests.class);
suite.addTestSuite(PeekableIteratorTests.class);
+ suite.addTestSuite(ReadOnlyCompositeListIteratorTests.class);
suite.addTestSuite(ReadOnlyIteratorTests.class);
suite.addTestSuite(ReadOnlyListIteratorTests.class);
suite.addTestSuite(SingleElementIteratorTests.class);
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/ReadOnlyCompositeListIteratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/ReadOnlyCompositeListIteratorTests.java
new file mode 100644
index 0000000000..a031166f12
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/iterators/ReadOnlyCompositeListIteratorTests.java
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.iterators;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+import org.eclipse.jpt.utility.internal.iterators.ReadOnlyCompositeListIterator;
+
+public class ReadOnlyCompositeListIteratorTests extends CompositeIteratorTests {
+
+ public ReadOnlyCompositeListIteratorTests(String name) {
+ super(name);
+ }
+
+ @Override
+ void verifyHasAnother(Iterator<String> stream) {
+ super.verifyHasAnother(stream);
+ ListIterator<String> stream2 = (ListIterator<String>) stream;
+ int i = 0;
+ while (stream2.hasPrevious()) {
+ stream2.previous();
+ i++;
+ }
+ assertEquals(8, i);
+ }
+
+ @Override
+ void verifyAnother(Iterator<String> stream) {
+ super.verifyAnother(stream);
+ int i = 8;
+ ListIterator<String> stream2 = (ListIterator<String>) stream;
+ while (stream2.hasPrevious()) {
+ assertEquals("bogus element", String.valueOf(i--), stream2.previous().substring(0, 1));
+ }
+ }
+
+ public void testNextIndexPreviousIndex() {
+ int i = 0;
+ ListIterator<String> stream = (ListIterator<String>) this.buildCompositeIterator();
+ assertEquals(i, stream.nextIndex());
+ assertEquals(i - 1, stream.previousIndex());
+ while (stream.hasNext()) {
+ stream.next();
+ i++;
+ assertEquals(i, stream.nextIndex());
+ assertEquals(i - 1, stream.previousIndex());
+ }
+ assertEquals("index is corrupt", 8, i);
+
+ assertEquals(i, stream.nextIndex());
+ assertEquals(i - 1, stream.previousIndex());
+ while (stream.hasPrevious()) {
+ stream.previous();
+ i--;
+ assertEquals(i, stream.nextIndex());
+ assertEquals(i - 1, stream.previousIndex());
+ }
+ assertEquals("index is corrupt", 0, i);
+ }
+
+ public void testPreviousIndex() {
+ // TODO
+ }
+
+ @Override
+ public void testRemove() {
+ // #remove() is not supported
+ }
+
+ @Override
+ public void testIllegalStateException() {
+ // #remove() is not supported
+ }
+
+ @Override
+ public void testEmptyIllegalStateException1() {
+ // #remove() is not supported
+ }
+
+ @Override
+ public void testEmptyIllegalStateException2() {
+ // #remove() is not supported
+ }
+
+ @Override
+ void verifyNoSuchElementException(Iterator<String> stream) {
+ super.verifyNoSuchElementException(stream);
+ ListIterator<String> stream2 = (ListIterator<String>) stream;
+ boolean exCaught = false;
+ String string = null;
+ while (stream2.hasPrevious()) {
+ string = stream2.previous();
+ }
+ try {
+ string = stream2.previous();
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue("NoSuchElementException not thrown: " + string, exCaught);
+ }
+
+ @Override
+ void verifyUnsupportedOperationException(Iterator<String> stream) {
+ super.verifyUnsupportedOperationException(stream);
+ boolean exCaught = false;
+ ListIterator<String> stream2 = (ListIterator<String>) stream;
+ while (stream2.hasPrevious()) {
+ Object string = stream2.previous();
+ if (string.equals("333")) {
+ try {
+ stream2.remove();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue("UnsupportedOperationException not thrown", exCaught);
+ }
+
+ @Override
+ void verifyIllegalStateException(Iterator<String> stream) {
+ super.verifyIllegalStateException(stream);
+ ListIterator<String> stream2 = (ListIterator<String>) stream;
+ boolean exCaught = false;
+ try {
+ stream2.set("junk");
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue("IllegalStateException not thrown", exCaught);
+ }
+
+ @Override
+ void verifyEmptyHasAnother(Iterator<String> stream) {
+ super.verifyEmptyHasAnother(stream);
+ ListIterator<String> stream2 = (ListIterator<String>) stream;
+ int i = 0;
+ while (stream2.hasPrevious()) {
+ stream2.previous();
+ i++;
+ }
+ assertEquals(0, i);
+ }
+
+ // unchecked so we can override the unchecked method in superclass
+ @Override
+ @SuppressWarnings("unchecked")
+ Iterator<String> buildCompositeIterator(Iterator iterators) {
+ return new ReadOnlyCompositeListIterator<String>((ListIterator<ListIterator<String>>) iterators);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ Iterator<String> buildCompositeIterator2() {
+ return new ReadOnlyCompositeListIterator<String>(this.buildIterator1(), this.buildIterator2(), this.buildIterator3());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ Iterator<String> buildCompositeIterator3() {
+ return new ReadOnlyCompositeListIterator<String>(new ListIterator[] { this.buildIterator1(), this.buildIterator2(), this.buildIterator3() });
+ }
+
+ Iterator<String> buildCompositeIterator(String string, ListIterator<String> iterator) {
+ return this.buildCompositeListIterator(string, iterator);
+ }
+
+ ListIterator<String> buildCompositeListIterator(String string, ListIterator<String> iterator) {
+ return new ReadOnlyCompositeListIterator<String>(string, iterator);
+ }
+
+ public void testVariedNestedIterators() {
+ List<Integer> integerList = new ArrayList<Integer>();
+ integerList.add(42);
+ integerList.add(22);
+ integerList.add(111);
+ integerList.add(77);
+
+ List<Float> floatList = new ArrayList<Float>();
+ floatList.add(42.42f);
+ floatList.add(22.22f);
+ floatList.add(111.111f);
+ floatList.add(77.77f);
+
+ List<ListIterator<? extends Number>> list = new ArrayList<ListIterator<? extends Number>>();
+ list.add(integerList.listIterator());
+ list.add(floatList.listIterator());
+ ListIterator<Number> li = new ReadOnlyCompositeListIterator<Number>(list);
+ while (li.hasNext()) {
+ assertTrue(li.next().intValue() > 0);
+ }
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/AbstractModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/AbstractModelTests.java
index 93dc75a361..75a9d62fd9 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/AbstractModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/AbstractModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -1346,8 +1346,9 @@ public class AbstractModelTests
// assertEquals(Joo.class, listeners2[0].getClass());
// }
+// >>>>>>>>>>>>>>>>> these methods are called by #testSerialization(), commented out above...
private ChangeListener[] listeners(LocalModel model, Class<? extends ChangeListener> listenerClass) {
- ChangeSupport changeSupport = (ChangeSupport) ClassTools.getFieldValue(model, "changeSupport");
+ ChangeSupport changeSupport = (ChangeSupport) ClassTools.fieldValue(model, "changeSupport");
return (ChangeListener[]) ClassTools.executeMethod(changeSupport, "listeners", Class.class, listenerClass);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java
new file mode 100644
index 0000000000..6f31dac827
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java
@@ -0,0 +1,410 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.Date;
+
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.BufferedWritablePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class BufferedWritablePropertyValueModelTests extends TestCase {
+ private Employee employee;
+ private WritablePropertyValueModel<Employee> employeeHolder;
+ PropertyChangeEvent employeeEvent;
+
+ private WritablePropertyValueModel<Integer> idAdapter;
+ private WritablePropertyValueModel<String> nameAdapter;
+ private WritablePropertyValueModel<Date> hireDateAdapter;
+ PropertyChangeEvent adapterEvent;
+
+ private BufferedWritablePropertyValueModel.Trigger trigger;
+ private WritablePropertyValueModel<Integer> bufferedIDHolder;
+ private WritablePropertyValueModel<String> bufferedNameHolder;
+ private WritablePropertyValueModel<Date> bufferedHireDateHolder;
+ PropertyChangeEvent bufferedEvent;
+
+ public BufferedWritablePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.employee = new Employee(17, "Freddy", new Date());
+ this.employeeHolder = new SimplePropertyValueModel<Employee>(this.employee);
+
+ this.trigger = new BufferedWritablePropertyValueModel.Trigger();
+
+ this.idAdapter = this.buildIDAdapter(this.employeeHolder);
+ this.bufferedIDHolder = new BufferedWritablePropertyValueModel<Integer>(this.idAdapter, this.trigger);
+
+ this.nameAdapter = this.buildNameAdapter(this.employeeHolder);
+ this.bufferedNameHolder = new BufferedWritablePropertyValueModel<String>(this.nameAdapter, this.trigger);
+
+ this.hireDateAdapter = this.buildHireDateAdapter(this.employeeHolder);
+ this.bufferedHireDateHolder = new BufferedWritablePropertyValueModel<Date>(this.hireDateAdapter, this.trigger);
+ }
+
+ private WritablePropertyValueModel<Integer> buildIDAdapter(PropertyValueModel<Employee> eHolder) {
+ return new PropertyAspectAdapter<Employee, Integer>(eHolder, Employee.ID_PROPERTY) {
+ @Override
+ protected Integer buildValue_() {
+ return new Integer(this.subject.getID());
+ }
+ @Override
+ protected void setValue_(Integer value) {
+ this.subject.setID(value.intValue());
+ }
+ };
+ }
+
+ private WritablePropertyValueModel<String> buildNameAdapter(PropertyValueModel<Employee> eHolder) {
+ return new PropertyAspectAdapter<Employee, String>(eHolder, Employee.NAME_PROPERTY) {
+ @Override
+ protected String buildValue_() {
+ return this.subject.getName();
+ }
+ @Override
+ protected void setValue_(String value) {
+ this.subject.setName(value);
+ }
+ };
+ }
+
+ private WritablePropertyValueModel<Date> buildHireDateAdapter(PropertyValueModel<Employee> eHolder) {
+ return new PropertyAspectAdapter<Employee, Date>(eHolder, Employee.HIRE_DATE_PROPERTY) {
+ @Override
+ protected Date buildValue_() {
+ return this.subject.getHireDate();
+ }
+ @Override
+ protected void setValue_(Date value) {
+ this.subject.setHireDate(value);
+ }
+ };
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testValue() {
+ PropertyChangeListener bufferedListener = this.buildBufferedListener();
+ this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+
+ assertEquals(new Integer(17), this.idAdapter.value());
+ assertEquals(new Integer(17), this.bufferedIDHolder.value());
+
+ assertEquals("Freddy", this.employee.getName());
+ assertEquals("Freddy", this.nameAdapter.value());
+ assertEquals("Freddy", this.bufferedNameHolder.value());
+
+ Date temp = this.employee.getHireDate();
+ assertEquals(temp, this.employee.getHireDate());
+ assertEquals(temp, this.hireDateAdapter.value());
+ assertEquals(temp, this.bufferedHireDateHolder.value());
+
+ this.bufferedIDHolder.setValue(new Integer(323));
+ assertEquals(17, this.employee.getID());
+ assertEquals(new Integer(17), this.idAdapter.value());
+ assertEquals(new Integer(323), this.bufferedIDHolder.value());
+
+ this.bufferedNameHolder.setValue("Ripley");
+ assertEquals("Freddy", this.employee.getName());
+ assertEquals("Freddy", this.nameAdapter.value());
+ assertEquals("Ripley", this.bufferedNameHolder.value());
+
+ this.bufferedHireDateHolder.setValue(null);
+ assertEquals(temp, this.employee.getHireDate());
+ assertEquals(temp, this.hireDateAdapter.value());
+ assertEquals(null, this.bufferedHireDateHolder.value());
+ }
+
+ public void testAccept() {
+ PropertyChangeListener bufferedListener = this.buildBufferedListener();
+ this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+
+ this.bufferedIDHolder.setValue(new Integer(323));
+ assertEquals(17, this.employee.getID());
+ assertEquals(new Integer(17), this.idAdapter.value());
+ assertEquals(new Integer(323), this.bufferedIDHolder.value());
+
+ this.bufferedNameHolder.setValue("Ripley");
+ assertEquals("Freddy", this.employee.getName());
+ assertEquals("Freddy", this.nameAdapter.value());
+ assertEquals("Ripley", this.bufferedNameHolder.value());
+
+ Date temp = this.employee.getHireDate();
+ this.bufferedHireDateHolder.setValue(null);
+ assertEquals(temp, this.employee.getHireDate());
+ assertEquals(temp, this.hireDateAdapter.value());
+ assertEquals(null, this.bufferedHireDateHolder.value());
+
+ this.trigger.accept();
+
+ assertEquals(323, this.employee.getID());
+ assertEquals(new Integer(323), this.idAdapter.value());
+ assertEquals(new Integer(323), this.bufferedIDHolder.value());
+
+ assertEquals("Ripley", this.employee.getName());
+ assertEquals("Ripley", this.nameAdapter.value());
+ assertEquals("Ripley", this.bufferedNameHolder.value());
+
+ assertEquals(null, this.employee.getHireDate());
+ assertEquals(null, this.hireDateAdapter.value());
+ assertEquals(null, this.bufferedHireDateHolder.value());
+ }
+
+ public void testReset() {
+ PropertyChangeListener bufferedListener = this.buildBufferedListener();
+ this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+
+ this.bufferedIDHolder.setValue(new Integer(323));
+ assertEquals(17, this.employee.getID());
+ assertEquals(new Integer(17), this.idAdapter.value());
+ assertEquals(new Integer(323), this.bufferedIDHolder.value());
+
+ this.bufferedNameHolder.setValue("Ripley");
+ assertEquals("Freddy", this.employee.getName());
+ assertEquals("Freddy", this.nameAdapter.value());
+ assertEquals("Ripley", this.bufferedNameHolder.value());
+
+ Date temp = this.employee.getHireDate();
+ this.bufferedHireDateHolder.setValue(null);
+ assertEquals(temp, this.employee.getHireDate());
+ assertEquals(temp, this.hireDateAdapter.value());
+ assertEquals(null, this.bufferedHireDateHolder.value());
+
+ this.trigger.reset();
+
+ assertEquals(17, this.employee.getID());
+ assertEquals(new Integer(17), this.idAdapter.value());
+ assertEquals(new Integer(17), this.bufferedIDHolder.value());
+
+ assertEquals("Freddy", this.employee.getName());
+ assertEquals("Freddy", this.nameAdapter.value());
+ assertEquals("Freddy", this.bufferedNameHolder.value());
+
+ assertEquals(temp, this.employee.getHireDate());
+ assertEquals(temp, this.hireDateAdapter.value());
+ assertEquals(temp, this.bufferedHireDateHolder.value());
+ }
+
+ public void testLazyListening() {
+ assertTrue(((AbstractModel) this.bufferedIDHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.bufferedNameHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.bufferedHireDateHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ assertTrue(((AbstractModel) this.idAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.nameAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.hireDateAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.ID_PROPERTY));
+ assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.NAME_PROPERTY));
+ assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.HIRE_DATE_PROPERTY));
+
+ PropertyChangeListener bufferedListener = this.buildBufferedListener();
+ this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+
+ assertTrue(((AbstractModel) this.bufferedIDHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.bufferedNameHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.bufferedHireDateHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ assertTrue(((AbstractModel) this.idAdapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.nameAdapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.hireDateAdapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ assertTrue(this.employee.hasAnyPropertyChangeListeners(Employee.ID_PROPERTY));
+ assertTrue(this.employee.hasAnyPropertyChangeListeners(Employee.NAME_PROPERTY));
+ assertTrue(this.employee.hasAnyPropertyChangeListeners(Employee.HIRE_DATE_PROPERTY));
+
+ this.bufferedIDHolder.removePropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedNameHolder.removePropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+ this.bufferedHireDateHolder.removePropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+
+ assertTrue(((AbstractModel) this.bufferedIDHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.bufferedNameHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.bufferedHireDateHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ assertTrue(((AbstractModel) this.idAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.nameAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.hireDateAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.ID_PROPERTY));
+ assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.NAME_PROPERTY));
+ assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.HIRE_DATE_PROPERTY));
+ }
+
+ public void testPropertyChange1() {
+ PropertyChangeListener bufferedListener = this.buildBufferedListener();
+ this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener);
+
+ PropertyChangeListener adapterListener = this.buildAdapterListener();
+ this.nameAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, adapterListener);
+
+ PropertyChangeListener employeeListener = this.buildEmployeeListener();
+ this.employee.addPropertyChangeListener(Employee.NAME_PROPERTY, employeeListener);
+
+ this.verifyPropertyChanges();
+ }
+
+ public void testPropertyChange2() {
+ PropertyChangeListener bufferedListener = this.buildBufferedListener();
+ this.bufferedNameHolder.addPropertyChangeListener(bufferedListener);
+
+ PropertyChangeListener adapterListener = this.buildAdapterListener();
+ this.nameAdapter.addPropertyChangeListener(adapterListener);
+
+ PropertyChangeListener employeeListener = this.buildEmployeeListener();
+ this.employee.addPropertyChangeListener(employeeListener);
+
+ this.verifyPropertyChanges();
+ }
+
+ private void verifyPropertyChanges() {
+ this.bufferedEvent = null;
+ this.adapterEvent = null;
+ this.employeeEvent = null;
+ this.bufferedNameHolder.setValue("Ripley");
+ this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Freddy", "Ripley");
+ assertNull(this.adapterEvent);
+ assertNull(this.employeeEvent);
+
+ this.bufferedEvent = null;
+ this.adapterEvent = null;
+ this.employeeEvent = null;
+ this.bufferedNameHolder.setValue("Charlie");
+ this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Ripley", "Charlie");
+ assertNull(this.adapterEvent);
+ assertNull(this.employeeEvent);
+
+ this.bufferedEvent = null;
+ this.adapterEvent = null;
+ this.employeeEvent = null;
+ this.trigger.accept();
+ assertNull(this.bufferedEvent);
+ this.verifyEvent(this.adapterEvent, this.nameAdapter, PropertyValueModel.VALUE, "Freddy", "Charlie");
+ this.verifyEvent(this.employeeEvent, this.employee, Employee.NAME_PROPERTY, "Freddy", "Charlie");
+
+ this.bufferedEvent = null;
+ this.adapterEvent = null;
+ this.employeeEvent = null;
+ this.bufferedNameHolder.setValue("Jason");
+ this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Charlie", "Jason");
+ assertNull(this.adapterEvent);
+ assertNull(this.employeeEvent);
+
+ this.bufferedEvent = null;
+ this.adapterEvent = null;
+ this.employeeEvent = null;
+ this.trigger.reset();
+ this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Jason", "Charlie");
+ assertNull(this.adapterEvent);
+ assertNull(this.employeeEvent);
+ }
+
+ private PropertyChangeListener buildBufferedListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ BufferedWritablePropertyValueModelTests.this.bufferedEvent = e;
+ }
+ };
+ }
+
+ private PropertyChangeListener buildAdapterListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ BufferedWritablePropertyValueModelTests.this.adapterEvent = e;
+ }
+ };
+ }
+
+ private PropertyChangeListener buildEmployeeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ BufferedWritablePropertyValueModelTests.this.employeeEvent = e;
+ }
+ };
+ }
+
+ private void verifyEvent(PropertyChangeEvent event, Object source, String propertyName, Object oldValue, Object newValue) {
+ assertEquals(source, event.getSource());
+ assertEquals(propertyName, event.propertyName());
+ assertEquals(oldValue, event.oldValue());
+ assertEquals(newValue, event.newValue());
+ }
+
+
+ // ********** inner class **********
+
+ private class Employee extends AbstractModel {
+ private int id;
+ public static final String ID_PROPERTY = "id";
+ private String name;
+ public static final String NAME_PROPERTY = "name";
+ private Date hireDate;
+ public static final String HIRE_DATE_PROPERTY = "hireDate";
+
+ Employee(int id, String name, Date hireDate) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.hireDate = hireDate;
+ }
+ int getID() {
+ return this.id;
+ }
+ void setID(int id) {
+ int old = this.id;
+ this.id = id;
+ this.firePropertyChanged(ID_PROPERTY, old, id);
+ }
+ String getName() {
+ return this.name;
+ }
+ void setName(String name) {
+ Object old = this.name;
+ this.name = name;
+ this.firePropertyChanged(NAME_PROPERTY, old, name);
+ }
+ Date getHireDate() {
+ return this.hireDate;
+ }
+ void setHireDate(Date hireDate) {
+ Object old = this.hireDate;
+ this.hireDate = hireDate;
+ this.firePropertyChanged(HIRE_DATE_PROPERTY, old, hireDate);
+ }
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.name);
+ }
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
index 78ccff0688..4d9e8bf51b 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,16 +21,16 @@ import org.eclipse.jpt.utility.internal.model.event.CollectionChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.CollectionChangeListener;
import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class CollectionAspectAdapterTests extends TestCase {
private TestSubject subject1;
- private PropertyValueModel subjectHolder1;
+ private WritablePropertyValueModel<TestSubject> subjectHolder1;
private LocalCollectionAspectAdapter aa1;
private CollectionChangeEvent event1;
private CollectionChangeListener listener1;
@@ -53,7 +53,7 @@ public class CollectionAspectAdapterTests extends TestCase {
this.subject1 = new TestSubject();
this.subject1.addNames(this.subject1Names());
this.subject1.addDescriptions(this.subject1Descriptions());
- this.subjectHolder1 = new SimplePropertyValueModel(this.subject1);
+ this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1);
this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
this.listener1 = this.buildValueChangeListener1();
this.aa1.addCollectionChangeListener(CollectionValueModel.VALUES, this.listener1);
@@ -93,7 +93,7 @@ public class CollectionAspectAdapterTests extends TestCase {
return result;
}
- private LocalCollectionAspectAdapter buildAspectAdapter(ValueModel subjectHolder) {
+ private LocalCollectionAspectAdapter buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
return new LocalCollectionAspectAdapter(subjectHolder);
}
@@ -126,7 +126,7 @@ public class CollectionAspectAdapterTests extends TestCase {
}
public void testSubjectHolder() {
- assertEquals(this.subject1Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator()));
assertNull(this.event1);
this.subjectHolder1.setValue(this.subject2);
@@ -135,7 +135,7 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(this.aa1, this.event1.getSource());
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertFalse(this.event1.items().hasNext());
- assertEquals(this.subject2Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject2Names(), CollectionTools.bag(this.aa1.iterator()));
this.event1 = null;
this.event1Type = null;
@@ -145,7 +145,7 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(this.aa1, this.event1.getSource());
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertFalse(this.event1.items().hasNext());
- assertFalse(((Iterator) this.aa1.iterator()).hasNext());
+ assertFalse((this.aa1.iterator()).hasNext());
this.event1 = null;
this.event1Type = null;
@@ -155,11 +155,11 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(this.aa1, this.event1.getSource());
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertFalse(this.event1.items().hasNext());
- assertEquals(this.subject1Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator()));
}
public void testAdd() {
- assertEquals(this.subject1Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator()));
assertNull(this.event1);
this.subject1.addName("jam");
@@ -168,9 +168,9 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(this.aa1, this.event1.getSource());
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertEquals("jam", this.event1.items().next());
- Collection namesPlus = this.subject1Names();
+ Collection<String> namesPlus = this.subject1Names();
namesPlus.add("jam");
- assertEquals(namesPlus, CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(namesPlus, CollectionTools.bag(this.aa1.iterator()));
this.event1 = null;
this.event1Type = null;
@@ -181,11 +181,11 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertEquals("jaz", this.event1.items().next());
namesPlus.add("jaz");
- assertEquals(namesPlus, CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(namesPlus, CollectionTools.bag(this.aa1.iterator()));
}
public void testRemove() {
- assertEquals(this.subject1Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator()));
assertNull(this.event1);
this.subject1.removeName("foo");
@@ -194,9 +194,9 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(this.aa1, this.event1.getSource());
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertEquals("foo", this.event1.items().next());
- Collection namesMinus = this.subject1Names();
+ Collection<String> namesMinus = this.subject1Names();
namesMinus.remove("foo");
- assertEquals(namesMinus, CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(namesMinus, CollectionTools.bag(this.aa1.iterator()));
this.event1 = null;
this.event1Type = null;
@@ -207,11 +207,11 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertEquals("bar", this.event1.items().next());
namesMinus.remove("bar");
- assertEquals(namesMinus, CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(namesMinus, CollectionTools.bag(this.aa1.iterator()));
}
public void testCollectionChange() {
- assertEquals(this.subject1Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator()));
assertNull(this.event1);
this.subject1.addTwoNames("jam", "jaz");
@@ -220,20 +220,20 @@ public class CollectionAspectAdapterTests extends TestCase {
assertEquals(this.aa1, this.event1.getSource());
assertEquals(CollectionValueModel.VALUES, this.event1.collectionName());
assertFalse(this.event1.items().hasNext());
- Collection namesPlus2 = this.subject1Names();
+ Collection<String> namesPlus2 = this.subject1Names();
namesPlus2.add("jam");
namesPlus2.add("jaz");
- assertEquals(namesPlus2, CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(namesPlus2, CollectionTools.bag(this.aa1.iterator()));
}
public void testIterator() {
assertEquals(this.subject1Names(), CollectionTools.bag(this.subject1.names()));
- assertEquals(this.subject1Names(), CollectionTools.bag((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator()));
}
public void testSize() {
assertEquals(this.subject1Names().size(), CollectionTools.size(this.subject1.names()));
- assertEquals(this.subject1Names().size(), CollectionTools.size((Iterator) this.aa1.iterator()));
+ assertEquals(this.subject1Names().size(), CollectionTools.size(this.aa1.iterator()));
}
public void testHasListeners() {
@@ -315,51 +315,51 @@ public class CollectionAspectAdapterTests extends TestCase {
}
// this is not a typical aspect adapter - the value is determined by the aspect name
- private class LocalCollectionAspectAdapter extends CollectionAspectAdapter {
+ private class LocalCollectionAspectAdapter extends CollectionAspectAdapter<TestSubject, String> {
- LocalCollectionAspectAdapter(ValueModel subjectHolder) {
+ LocalCollectionAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
super(subjectHolder, TestSubject.NAMES_COLLECTION);
}
@Override
protected Iterator<String> iterator_() {
- if (this.collectionName == TestSubject.NAMES_COLLECTION) {
- return ((TestSubject) this.subject).names();
+ if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ return this.subject.names();
}
- if (this.collectionName == TestSubject.DESCRIPTIONS_COLLECTION) {
- return ((TestSubject) this.subject).descriptions();
+ if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ return this.subject.descriptions();
}
- throw new IllegalStateException("invalid aspect name: " + this.collectionName);
+ throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
}
- public void add(Object item) {
- if (this.collectionName == TestSubject.NAMES_COLLECTION) {
- ((TestSubject) this.subject).addName((String) item);
- } else if (this.collectionName == TestSubject.DESCRIPTIONS_COLLECTION) {
- ((TestSubject) this.subject).addDescription((String) item);
+ public void add(String item) {
+ if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ this.subject.addName(item);
+ } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ this.subject.addDescription(item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.collectionName);
+ throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
}
}
- public void addAll(Collection items) {
- for (Iterator stream = items.iterator(); stream.hasNext(); ) {
+ public void addAll(Collection<String> items) {
+ for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) {
this.add(stream.next());
}
}
public void remove(Object item) {
- if (this.collectionName == TestSubject.NAMES_COLLECTION) {
- ((TestSubject) this.subject).removeName((String) item);
- } else if (this.collectionName == TestSubject.DESCRIPTIONS_COLLECTION) {
- ((TestSubject) this.subject).removeDescription((String) item);
+ if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ this.subject.removeName((String) item);
+ } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ this.subject.removeDescription((String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.collectionName);
+ throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
}
}
- public void removeAll(Collection items) {
- for (Iterator stream = items.iterator(); stream.hasNext(); ) {
+ public void removeAll(Collection<String> items) {
+ for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) {
this.remove(stream.next());
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java
index 8e6e684988..eefaaed685 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.utility.tests.internal.model.value;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import javax.swing.JList;
@@ -22,7 +21,6 @@ import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.ListChangeListener;
import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter;
-import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter;
@@ -31,9 +29,9 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class CollectionListValueModelAdapterTests extends TestCase {
- private ListValueModel adapter;
- private SimpleCollectionValueModel wrappedCollectionHolder;
- private Collection wrappedCollection;
+ private ListValueModel<String> adapter;
+ private SimpleCollectionValueModel<String> wrappedCollectionHolder;
+ private Collection<String> wrappedCollection;
public CollectionListValueModelAdapterTests(String name) {
super(name);
@@ -42,9 +40,9 @@ public class CollectionListValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.wrappedCollection = new HashBag();
- this.wrappedCollectionHolder = new SimpleCollectionValueModel(this.wrappedCollection);
- this.adapter = new CollectionListValueModelAdapter(this.wrappedCollectionHolder);
+ this.wrappedCollection = new HashBag<String>();
+ this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>(this.wrappedCollection);
+ this.adapter = new CollectionListValueModelAdapter<String>(this.wrappedCollectionHolder);
}
@Override
@@ -55,42 +53,48 @@ public class CollectionListValueModelAdapterTests extends TestCase {
public void testIterator() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
});
this.wrappedCollectionHolder.add("foo");
this.wrappedCollectionHolder.add("bar");
this.wrappedCollectionHolder.add("baz");
- Collection adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ Collection<String> adapterCollection = this.adapterCollection();
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection, adapterCollection);
}
+ private Collection<String> adapterCollection() {
+ return CollectionTools.collection(this.adapter.iterator());
+ }
+
public void testStaleValue() {
ListChangeListener listener = new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
};
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, listener);
this.wrappedCollectionHolder.add("foo");
this.wrappedCollectionHolder.add("bar");
this.wrappedCollectionHolder.add("baz");
- Collection adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ Collection<String> adapterCollection = this.adapterCollection();
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection, adapterCollection);
this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, listener);
- adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ adapterCollection = this.adapterCollection();
assertEquals(0, adapterCollection.size());
- assertEquals(new HashBag(), adapterCollection);
+ assertEquals(new HashBag<String>(), adapterCollection);
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, listener);
- adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ adapterCollection = this.adapterCollection();
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection, adapterCollection);
}
public void testAdd() {
- List synchList = new SynchronizedList(this.adapter);
- Bag synchCollection = new SynchronizedBag(this.wrappedCollectionHolder);
+ List<String> synchList = new CoordinatedList<String>(this.adapter);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder);
this.wrappedCollectionHolder.add("foo");
assertTrue(this.wrappedCollection.contains("foo"));
this.wrappedCollectionHolder.add("bar");
@@ -100,15 +104,15 @@ public class CollectionListValueModelAdapterTests extends TestCase {
this.wrappedCollectionHolder.add("jaz");
assertEquals(6, this.wrappedCollection.size());
- Collection adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ Collection<String> adapterCollection = this.adapterCollection();
assertEquals(this.wrappedCollection, adapterCollection);
assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator()));
assertEquals(this.wrappedCollection, synchCollection);
}
public void testRemove() {
- List synchList = new SynchronizedList(this.adapter);
- Bag synchCollection = new SynchronizedBag(this.wrappedCollectionHolder);
+ List<String> synchList = new CoordinatedList<String>(this.adapter);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder);
this.wrappedCollectionHolder.add("foo");
this.wrappedCollectionHolder.add("bar");
this.wrappedCollectionHolder.add("baz");
@@ -122,7 +126,7 @@ public class CollectionListValueModelAdapterTests extends TestCase {
assertFalse(this.wrappedCollection.contains("foo"));
assertEquals(4, this.wrappedCollection.size());
- Collection adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ Collection<String> adapterCollection = this.adapterCollection();
assertEquals(this.wrappedCollection, adapterCollection);
assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator()));
assertEquals(this.wrappedCollection, synchCollection);
@@ -130,7 +134,9 @@ public class CollectionListValueModelAdapterTests extends TestCase {
public void testListSynch() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(ListChangeEvent e) {/* OK */}
});
this.wrappedCollectionHolder.add("foo");
@@ -145,13 +151,13 @@ public class CollectionListValueModelAdapterTests extends TestCase {
assertFalse(this.wrappedCollection.contains("foo"));
assertEquals(4, this.wrappedCollection.size());
- Collection adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ Collection<String> adapterCollection = this.adapterCollection();
assertEquals(this.wrappedCollection, adapterCollection);
}
public void testHasListeners() {
assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- SynchronizedList synchList = new SynchronizedList(this.adapter);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(this.adapter);
assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, synchList);
assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
@@ -163,45 +169,51 @@ public class CollectionListValueModelAdapterTests extends TestCase {
public void testCollectionChangedToEmpty() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(ListChangeEvent e) {/* OK */}
});
this.wrappedCollectionHolder.add("foo");
this.wrappedCollectionHolder.add("bar");
this.wrappedCollectionHolder.add("baz");
JList jList = new JList(new ListModelAdapter(this.adapter));
- ((SimpleCollectionValueModel) this.wrappedCollectionHolder).setCollection(new HashBag());
+ this.wrappedCollectionHolder.setCollection(new HashBag<String>());
assertEquals(0, jList.getModel().getSize());
}
public void testCollectionChangedFromEmpty() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(ListChangeEvent e) {/* OK */}
});
JList jList = new JList(new ListModelAdapter(this.adapter));
- HashBag bag = new HashBag();
+ HashBag<String> bag = new HashBag<String>();
bag.add("foo");
bag.add("bar");
- ((SimpleCollectionValueModel) this.wrappedCollectionHolder).setCollection(bag);
+ this.wrappedCollectionHolder.setCollection(bag);
assertEquals(2, jList.getModel().getSize());
}
public void testCollectionChangedFromEmptyToEmpty() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(ListChangeEvent e) {/* OK */}
});
JList jList = new JList(new ListModelAdapter(this.adapter));
- HashBag bag = new HashBag();
- ((SimpleCollectionValueModel) this.wrappedCollectionHolder).setCollection(bag);
+ HashBag<String> bag = new HashBag<String>();
+ this.wrappedCollectionHolder.setCollection(bag);
assertEquals(0, jList.getModel().getSize());
}
- private class TestListChangeListener implements ListChangeListener {
+ class TestListChangeListener implements ListChangeListener {
public void itemsAdded(ListChangeEvent e) {
fail("unexpected event");
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
index 5965cf214b..ff8ea31327 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.utility.tests.internal.model.value;
import java.util.Collection;
-import java.util.Iterator;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
@@ -20,14 +19,14 @@ import org.eclipse.jpt.utility.internal.model.value.CollectionPropertyValueModel
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class CollectionPropertyValueModelAdapterTests extends TestCase {
- private PropertyValueModel adapter;
- private SimpleCollectionValueModel wrappedCollectionHolder;
+ private WritablePropertyValueModel<Boolean> adapter;
+ private SimpleCollectionValueModel<String> wrappedCollectionHolder;
PropertyChangeEvent event;
public CollectionPropertyValueModelAdapterTests(String name) {
@@ -37,7 +36,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.wrappedCollectionHolder = new SimpleCollectionValueModel();
+ this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>();
this.adapter = new LocalAdapter(this.wrappedCollectionHolder, "666");
this.event = null;
}
@@ -49,15 +48,15 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
}
private boolean booleanValue() {
- return ((Boolean) this.adapter.value()).booleanValue();
+ return this.adapter.value().booleanValue();
}
- private Collection wrappedCollection() {
- return CollectionTools.collection((Iterator) this.wrappedCollectionHolder.iterator());
+ private Collection<String> wrappedCollection() {
+ return CollectionTools.collection(this.wrappedCollectionHolder.iterator());
}
public void testValue() {
- this.adapter.addPropertyChangeListener(ValueModel.VALUE, new PropertyChangeListener() {
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {/* OK */}
});
assertFalse(this.booleanValue());
@@ -81,13 +80,13 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
assertTrue(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
- ((SimpleCollectionValueModel) this.wrappedCollectionHolder).clear();
+ this.wrappedCollectionHolder.clear();
assertFalse(this.booleanValue());
assertFalse(this.wrappedCollection().contains("666"));
}
public void testSetValue() {
- this.adapter.addPropertyChangeListener(ValueModel.VALUE, new PropertyChangeListener() {
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {/* OK */}
});
assertFalse(this.booleanValue());
@@ -103,7 +102,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
}
public void testEventFiring() {
- this.adapter.addPropertyChangeListener(ValueModel.VALUE, new PropertyChangeListener() {
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {
CollectionPropertyValueModelAdapterTests.this.event = e;
}
@@ -125,7 +124,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
this.wrappedCollectionHolder.add("666");
this.verifyEvent(false, true);
- ((SimpleCollectionValueModel) this.wrappedCollectionHolder).clear();
+ this.wrappedCollectionHolder.clear();
this.verifyEvent(true, false);
}
@@ -140,41 +139,41 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {/* OK */}
};
- this.adapter.addPropertyChangeListener(ValueModel.VALUE, listener);
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
this.wrappedCollectionHolder.add("666");
assertTrue(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
- this.adapter.removePropertyChangeListener(ValueModel.VALUE, listener);
+ this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
assertFalse(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
- this.adapter.addPropertyChangeListener(ValueModel.VALUE, listener);
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
assertTrue(this.booleanValue());
assertTrue(this.wrappedCollection().contains("666"));
}
public void testHasListeners() {
- assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {/* OK */}
};
- this.adapter.addPropertyChangeListener(ValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertTrue(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
- this.adapter.removePropertyChangeListener(ValueModel.VALUE, listener);
- assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.addPropertyChangeListener(listener);
- assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertTrue(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.removePropertyChangeListener(listener);
- assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
}
@@ -185,10 +184,13 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
* the value is true if the wrapped collection contains the specified item,
* otherwise the value is false
*/
- private static class LocalAdapter extends CollectionPropertyValueModelAdapter {
- private Object item;
+ private static class LocalAdapter
+ extends CollectionPropertyValueModelAdapter<Boolean>
+ implements WritablePropertyValueModel<Boolean>
+ {
+ private String item;
- LocalAdapter(CollectionValueModel collectionHolder, Object item) {
+ LocalAdapter(CollectionValueModel<String> collectionHolder, String item) {
super(collectionHolder);
this.item = item;
}
@@ -198,27 +200,27 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
* always return a Boolean
*/
@Override
- public Object value() {
- Object result = super.value();
+ public Boolean value() {
+ Boolean result = super.value();
return (result == null) ? Boolean.FALSE : result;
}
- @Override
- public void setValue(Object value) {
+ @SuppressWarnings("unchecked")
+ public void setValue(Boolean value) {
if (this.booleanValue()) {
if ( ! this.booleanValueOf(value)) {
// the value is changing from true to false
- ((SimpleCollectionValueModel) this.collectionHolder).remove(this.item);
+ ((SimpleCollectionValueModel<String>) this.collectionHolder).remove(this.item);
}
} else {
if (this.booleanValueOf(value)) {
// the value is changing from false to true
- ((SimpleCollectionValueModel) this.collectionHolder).add(this.item);
+ ((SimpleCollectionValueModel<String>) this.collectionHolder).add(this.item);
}
}
}
@Override
- protected Object buildValue() {
- return Boolean.valueOf(CollectionTools.contains((Iterator) this.collectionHolder.iterator(), this.item));
+ protected Boolean buildValue() {
+ return Boolean.valueOf(CollectionTools.contains(this.collectionHolder.iterator(), this.item));
}
// ********** internal methods **********
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java
index 9ed70bc967..ccad1df6ab 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,16 +22,16 @@ import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.CompositeCollectionValueModel;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class CompositeCollectionValueModelTests extends TestCase {
private Neighborhood neighborhood;
- private PropertyValueModel neighborhoodHolder;
+ private WritablePropertyValueModel<Neighborhood> neighborhoodHolder;
public CompositeCollectionValueModelTests(String name) {
super(name);
@@ -41,7 +41,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.neighborhood = new Neighborhood("Hanna-Barbera");
- this.neighborhoodHolder = new SimplePropertyValueModel(this.neighborhood);
+ this.neighborhoodHolder = new SimplePropertyValueModel<Neighborhood>(this.neighborhood);
}
@Override
@@ -58,10 +58,10 @@ public class CompositeCollectionValueModelTests extends TestCase {
this.verifySynch(this.buildAllMembersComposite2(this.neighborhoodHolder));
}
- private void verifySynch(CollectionValueModel compositeCVM) {
- assertEquals(0, CollectionTools.size((Iterator) compositeCVM.iterator()));
- Bag familiesSynch = new SynchronizedBag(this.buildFamiliesAspectAdapter(this.neighborhoodHolder));
- Bag membersSynch = new SynchronizedBag(compositeCVM);
+ private void verifySynch(CollectionValueModel<Member> compositeCVM) {
+ assertEquals(0, CollectionTools.size(compositeCVM.iterator()));
+ Bag<Family> familiesSynch = new CoordinatedBag<Family>(this.buildFamiliesAspectAdapter(this.neighborhoodHolder));
+ Bag<Member> membersSynch = new CoordinatedBag<Member>(compositeCVM);
this.populateNeighborhood(this.neighborhood);
Family jetsons = this.neighborhood.familyNamed("Jetson");
@@ -70,35 +70,35 @@ public class CompositeCollectionValueModelTests extends TestCase {
assertEquals(12, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(12, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
jetsons.removeMember(jetsons.memberNamed("Astro"));
assertEquals(3, familiesSynch.size());
assertEquals(11, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(11, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
jetsons.removeMember(jetsons.memberNamed("Judy"));
assertEquals(3, familiesSynch.size());
assertEquals(10, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(10, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
jetsons.addMember("Fido");
assertEquals(3, familiesSynch.size());
assertEquals(11, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(11, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
this.neighborhood.removeFamily(jetsons);
assertEquals(2, familiesSynch.size());
assertEquals(7, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(7, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
Family bears = this.neighborhood.addFamily("Bear");
bears.addMember("Yogi");
@@ -106,14 +106,14 @@ public class CompositeCollectionValueModelTests extends TestCase {
assertEquals(8, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(8, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
bears.addMember("Boo-Boo");
assertEquals(3, familiesSynch.size());
assertEquals(9, CollectionTools.size(this.neighborhood.allMembers()));
assertEquals(9, membersSynch.size());
assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
Neighborhood n2 = new Neighborhood("Hanna-Barbera 2");
this.neighborhoodHolder.setValue(n2);
@@ -122,11 +122,11 @@ public class CompositeCollectionValueModelTests extends TestCase {
assertEquals(12, CollectionTools.size(n2.allMembers()));
assertEquals(12, membersSynch.size());
assertEquals(CollectionTools.bag(n2.allMembers()), membersSynch);
- assertEquals(membersSynch, CollectionTools.bag((Iterator) compositeCVM.iterator()));
+ assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator()));
}
public void testNoTransformer() {
- Bag synchBag = new SynchronizedBag(this.buildBogusAllMembersComposite(this.neighborhoodHolder));
+ Bag<Member> synchBag = new CoordinatedBag<Member>(this.buildBogusAllMembersComposite(this.neighborhoodHolder));
boolean exCaught = false;
try {
this.populateNeighborhood(this.neighborhood);
@@ -143,7 +143,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
}
public void testDuplicateItem() {
- Bag synchBag = new SynchronizedBag(this.buildAllMembersComposite(this.neighborhoodHolder));
+ Bag<Member> synchBag = new CoordinatedBag<Member>(this.buildAllMembersComposite(this.neighborhoodHolder));
this.populateNeighborhood(this.neighborhood);
boolean exCaught = false;
try {
@@ -158,8 +158,8 @@ public class CompositeCollectionValueModelTests extends TestCase {
}
public void testHasListeners() {
- CompositeCollectionValueModel compositeCVM = this.buildAllMembersComposite(this.neighborhoodHolder);
- SynchronizedBag synchBag = new SynchronizedBag(compositeCVM);
+ CompositeCollectionValueModel<Family, Member> compositeCVM = this.buildAllMembersComposite(this.neighborhoodHolder);
+ CoordinatedBag<Member> synchBag = new CoordinatedBag<Member>(compositeCVM);
this.populateNeighborhood(this.neighborhood);
Family jetsons = this.neighborhood.familyNamed("Jetson");
@@ -193,45 +193,48 @@ public class CompositeCollectionValueModelTests extends TestCase {
family3.addMember("Astro");
}
- private CollectionValueModel buildFamiliesAspectAdapter(ValueModel communeHolder) {
- return new CollectionAspectAdapter(communeHolder, Neighborhood.FAMILIES_COLLECTION) {
- protected Iterator iterator_() {
- return ((Neighborhood) this.subject).families();
+ private CollectionValueModel<Family> buildFamiliesAspectAdapter(PropertyValueModel<Neighborhood> communeHolder) {
+ return new CollectionAspectAdapter<Neighborhood, Family>(communeHolder, Neighborhood.FAMILIES_COLLECTION) {
+ @Override
+ protected Iterator<Family> iterator_() {
+ return this.subject.families();
}
};
}
- CollectionValueModel buildMembersAdapter(Family family) {
- return new CollectionAspectAdapter(Family.MEMBERS_COLLECTION, family) {
- protected Iterator iterator_() {
- return ((Family) this.subject).members();
+ CollectionValueModel<Member> buildMembersAdapter(Family family) {
+ return new CollectionAspectAdapter<Family, Member>(Family.MEMBERS_COLLECTION, family) {
+ @Override
+ protected Iterator<Member> iterator_() {
+ return this.subject.members();
}
};
}
- private CompositeCollectionValueModel buildAllMembersComposite(ValueModel communeHolder) {
+ private CompositeCollectionValueModel<Family, Member> buildAllMembersComposite(PropertyValueModel<Neighborhood> communeHolder) {
// override #transform(Object)
- return new CompositeCollectionValueModel(this.buildFamiliesAspectAdapter(communeHolder)) {
- protected CollectionValueModel transform(Object value) {
- return CompositeCollectionValueModelTests.this.buildMembersAdapter((Family) value);
+ return new CompositeCollectionValueModel<Family, Member>(this.buildFamiliesAspectAdapter(communeHolder)) {
+ @Override
+ protected CollectionValueModel<Member> transform(Family family) {
+ return CompositeCollectionValueModelTests.this.buildMembersAdapter(family);
}
};
}
- private CollectionValueModel buildAllMembersComposite2(ValueModel communeHolder) {
+ private CollectionValueModel<Member> buildAllMembersComposite2(PropertyValueModel<Neighborhood> communeHolder) {
// build a custom Transformer
- return new CompositeCollectionValueModel(this.buildFamiliesAspectAdapter(communeHolder), this.buildTransformer());
+ return new CompositeCollectionValueModel<Family, Member>(this.buildFamiliesAspectAdapter(communeHolder), this.buildTransformer());
}
- private CollectionValueModel buildBogusAllMembersComposite(ValueModel communeHolder) {
+ private CollectionValueModel<Member> buildBogusAllMembersComposite(PropertyValueModel<Neighborhood> communeHolder) {
// DISABLED Transformer
- return new CompositeCollectionValueModel(this.buildFamiliesAspectAdapter(communeHolder));
+ return new CompositeCollectionValueModel<Family, Member>(this.buildFamiliesAspectAdapter(communeHolder));
}
- private Transformer buildTransformer() {
- return new Transformer() {
- public Object transform(Object value) {
- return CompositeCollectionValueModelTests.this.buildMembersAdapter((Family) value);
+ private Transformer<Family, CollectionValueModel<Member>> buildTransformer() {
+ return new Transformer<Family, CollectionValueModel<Member>>() {
+ public CollectionValueModel<Member> transform(Family family) {
+ return CompositeCollectionValueModelTests.this.buildMembersAdapter(family);
}
@Override
public String toString() {
@@ -249,7 +252,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
private class Neighborhood extends AbstractModel {
private String name;
public static final String NAME_PROPERTY = "name";
- private Collection families = new ArrayList();
+ private Collection<Family> families = new ArrayList<Family>();
public static final String FAMILIES_COLLECTION = "families";
public Neighborhood(String name) {
@@ -267,7 +270,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
this.firePropertyChanged(NAME_PROPERTY, old, name);
}
- public Iterator families() {
+ public Iterator<Family> families() {
return this.families.iterator();
}
@@ -286,8 +289,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
}
public Family familyNamed(String familyName) {
- for (Iterator stream = this.families.iterator(); stream.hasNext(); ) {
- Family family = (Family) stream.next();
+ for (Family family : this.families) {
if (family.getName().equals(familyName)) {
return family;
}
@@ -295,14 +297,15 @@ public class CompositeCollectionValueModelTests extends TestCase {
throw new IllegalArgumentException(familyName);
}
- public Iterator allMembers() {
- return new CompositeIterator(this.membersIterators());
+ public Iterator<Member> allMembers() {
+ return new CompositeIterator<Member>(this.membersIterators());
}
- private Iterator membersIterators() {
- return new TransformationIterator(this.families()) {
- protected Object transform(Object next) {
- return ((Family) next).members();
+ private Iterator<Iterator<Member>> membersIterators() {
+ return new TransformationIterator<Family, Iterator<Member>>(this.families()) {
+ @Override
+ protected Iterator<Member> transform(Family family) {
+ return family.members();
}
};
}
@@ -325,7 +328,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
private class Family extends AbstractModel {
private String name;
public static final String NAME_PROPERTY = "name";
- private Collection members = new ArrayList();
+ private Collection<Member> members = new ArrayList<Member>();
public static final String MEMBERS_COLLECTION = "members";
public Family(String name) {
@@ -343,7 +346,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
this.firePropertyChanged(NAME_PROPERTY, old, name);
}
- public Iterator members() {
+ public Iterator<Member> members() {
return this.members.iterator();
}
@@ -358,8 +361,7 @@ public class CompositeCollectionValueModelTests extends TestCase {
}
public Member memberNamed(String memberName) {
- for (Iterator stream = this.members.iterator(); stream.hasNext(); ) {
- Member member = (Member) stream.next();
+ for (Member member : this.members) {
if (member.getName().equals(memberName)) {
return member;
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java
new file mode 100644
index 0000000000..3b12bdb852
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.Collection;
+import java.util.Iterator;
+import org.eclipse.jpt.utility.internal.Bag;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.HashBag;
+import org.eclipse.jpt.utility.internal.model.event.CollectionChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.CollectionChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
+
+/**
+ * Helper class that keeps an internal collection in synch with the
+ * collection held by a collection value model.
+ */
+class CoordinatedBag<E> implements Bag<E>, CollectionChangeListener {
+
+ private Bag<E> synchBag = new HashBag<E>();
+
+ CoordinatedBag(CollectionValueModel<E> cvm) {
+ cvm.addCollectionChangeListener(CollectionValueModel.VALUES, this);
+ }
+
+
+ // ********** Collection implementation **********
+
+ public boolean add(E o) {
+ return this.synchBag.add(o);
+ }
+
+ public boolean addAll(Collection<? extends E> c) {
+ return this.synchBag.addAll(c);
+ }
+
+ public void clear() {
+ this.synchBag.clear();
+ }
+
+ public boolean contains(Object o) {
+ return this.synchBag.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return this.synchBag.containsAll(c);
+ }
+
+ public boolean isEmpty() {
+ return this.synchBag.isEmpty();
+ }
+
+ public Iterator<E> iterator() {
+ return this.synchBag.iterator();
+ }
+
+ public boolean remove(Object o) {
+ return this.synchBag.remove(o);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return this.synchBag.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return this.synchBag.retainAll(c);
+ }
+
+ public int size() {
+ return this.synchBag.size();
+ }
+
+ public Object[] toArray() {
+ return this.synchBag.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return this.synchBag.toArray(a);
+ }
+
+
+ // ********** Bag implementation **********
+
+ public int count(Object o) {
+ return this.synchBag.count(o);
+ }
+
+ public boolean add(E o, int count) {
+ return this.synchBag.add(o, count);
+ }
+
+ public boolean remove(Object o, int count) {
+ return this.synchBag.remove(o, count);
+ }
+
+ public Iterator<E> uniqueIterator() {
+ return this.synchBag.uniqueIterator();
+ }
+
+ // ********** CollectionChangeListener implementation **********
+
+ public void itemsAdded(CollectionChangeEvent e) {
+ for (@SuppressWarnings("unchecked") Iterator<E> stream = (Iterator<E>) e.items(); stream.hasNext(); ) {
+ this.synchBag.add(stream.next());
+ }
+ }
+
+ public void itemsRemoved(CollectionChangeEvent e) {
+ for (@SuppressWarnings("unchecked") Iterator<E> stream = (Iterator<E>) e.items(); stream.hasNext(); ) {
+ this.synchBag.remove(stream.next());
+ }
+ }
+
+ public void collectionCleared(CollectionChangeEvent e) {
+ this.synchBag.clear();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void collectionChanged(CollectionChangeEvent e) {
+ this.synchBag.clear();
+ CollectionTools.addAll(this.synchBag, ((CollectionValueModel<E>) e.getSource()).iterator());
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public boolean equals(Object o) {
+ return this.synchBag.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.synchBag.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return this.synchBag.toString();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java
new file mode 100644
index 0000000000..b74c0a87e5
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java
@@ -0,0 +1,256 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.swing.ListModel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.ListChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
+
+/**
+ * Helper class that keeps an internal list in synch with the
+ * list held by a list value model.
+ */
+public class CoordinatedList<E> implements List<E>, ListChangeListener, ListDataListener {
+ private List<E> synchList = new ArrayList<E>();
+
+ public CoordinatedList(ListValueModel<E> listValueModel) {
+ listValueModel.addListChangeListener(ListValueModel.LIST_VALUES, this);
+ for (Iterator<E> stream = listValueModel.iterator(); stream.hasNext(); ) {
+ this.add(stream.next());
+ }
+ }
+
+ public CoordinatedList(ListModel listModel) {
+ listModel.addListDataListener(this);
+ for (int i = 0; i < listModel.getSize(); i++) {
+ this.add(i, this.getElementAt(listModel, i));
+ }
+ }
+
+
+ // ********** List implementation **********
+
+ public void add(int index, E element) {
+ this.synchList.add(index, element);
+ }
+
+ public boolean add(E o) {
+ return this.synchList.add(o);
+ }
+
+ public boolean addAll(Collection<? extends E> c) {
+ return this.synchList.addAll(c);
+ }
+
+ public boolean addAll(int index, Collection<? extends E> c) {
+ return this.synchList.addAll(index, c);
+ }
+
+ public void clear() {
+ this.synchList.clear();
+ }
+
+ public boolean contains(Object o) {
+ return this.synchList.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return this.synchList.containsAll(c);
+ }
+
+ public E get(int index) {
+ return this.synchList.get(index);
+ }
+
+ public int indexOf(Object o) {
+ return this.synchList.indexOf(o);
+ }
+
+ public boolean isEmpty() {
+ return this.synchList.isEmpty();
+ }
+
+ public Iterator<E> iterator() {
+ return this.synchList.iterator();
+ }
+
+ public int lastIndexOf(Object o) {
+ return this.synchList.lastIndexOf(o);
+ }
+
+ public ListIterator<E> listIterator() {
+ return this.synchList.listIterator();
+ }
+
+ public ListIterator<E> listIterator(int index) {
+ return this.synchList.listIterator(index);
+ }
+
+ public E remove(int index) {
+ return this.synchList.remove(index);
+ }
+
+ public boolean remove(Object o) {
+ return this.synchList.remove(o);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return this.synchList.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return this.synchList.retainAll(c);
+ }
+
+ public E set(int index, E element) {
+ return this.synchList.set(index, element);
+ }
+
+ public int size() {
+ return this.synchList.size();
+ }
+
+ public List<E> subList(int fromIndex, int toIndex) {
+ return this.synchList.subList(fromIndex, toIndex);
+ }
+
+ public Object[] toArray() {
+ return this.synchList.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return this.synchList.toArray(a);
+ }
+
+
+ // ********** ListChangeListener implementation **********
+
+ public void itemsAdded(ListChangeEvent e) {
+ int i = e.index();
+ for (Iterator<E> stream = this.items(e); stream.hasNext(); ) {
+ this.synchList.add(i++, stream.next());
+ }
+ }
+
+ public void itemsRemoved(ListChangeEvent e) {
+ int i = e.index();
+ for (Iterator<E> stream = this.items(e); stream.hasNext(); ) {
+ stream.next();
+ this.synchList.remove(i);
+ }
+ }
+
+ public void itemsReplaced(ListChangeEvent e) {
+ int i = e.index();
+ for (Iterator<E> stream = this.items(e); stream.hasNext(); ) {
+ this.synchList.set(i++, stream.next());
+ }
+ }
+
+ public void itemsMoved(ListChangeEvent e) {
+ CollectionTools.move(this.synchList, e.targetIndex(), e.sourceIndex(), e.itemsSize());
+ }
+
+ public void listCleared(ListChangeEvent e) {
+ this.synchList.clear();
+ }
+
+ public void listChanged(ListChangeEvent e) {
+ this.synchList.clear();
+ CollectionTools.addAll(this.synchList, this.getSource(e).iterator());
+ }
+
+
+ // ********** ListDataListener implementation **********
+
+ public void contentsChanged(ListDataEvent e) {
+ this.synchList.clear();
+ ListModel lm = (ListModel) e.getSource();
+ int size = lm.getSize();
+ for (int i = 0; i < size; i++) {
+ this.synchList.add(i, this.getElementAt(lm, i));
+ }
+ }
+
+ public void intervalAdded(ListDataEvent e) {
+ ListModel lm = (ListModel) e.getSource();
+ int start = Math.min(e.getIndex0(), e.getIndex1());
+ int end = Math.max(e.getIndex0(), e.getIndex1());
+ for (int i = start; i <= end; i++) {
+ this.synchList.add(i, this.getElementAt(lm, i));
+ }
+ }
+
+ public void intervalRemoved(ListDataEvent e) {
+ int start = Math.min(e.getIndex0(), e.getIndex1());
+ int end = Math.max(e.getIndex0(), e.getIndex1());
+ int length = end - start + 1;
+ for (int i = 1; i <= length; i++) {
+ this.synchList.remove(start);
+ }
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public boolean equals(Object o) {
+ return this.synchList.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.synchList.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return this.synchList.toString();
+ }
+
+
+ // ********** internal methods **********
+
+ /**
+ * minimize the scope of the suppressed warnings.=
+ */
+ @SuppressWarnings("unchecked")
+ private E getElementAt(ListModel listModel, int index) {
+ return (E) listModel.getElementAt(index);
+ }
+
+ /**
+ * minimize the scope of the suppressed warnings.=
+ */
+ @SuppressWarnings("unchecked")
+ private Iterator<E> items(ListChangeEvent event) {
+ return (Iterator<E>) event.items();
+ }
+
+ /**
+ * minimize the scope of the suppressed warnings.=
+ */
+ @SuppressWarnings("unchecked")
+ private ListValueModel<E> getSource(ListChangeEvent event) {
+ return (ListValueModel<E>) event.getSource();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java
index d728f58cd7..ecda537173 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
@@ -27,8 +26,8 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class ExtendedListValueModelWrapperTests extends TestCase {
- private SimpleListValueModel listHolder;
- private ListValueModel extendedListHolder;
+ private SimpleListValueModel<String> listHolder;
+ private ListValueModel<String> extendedListHolder;
ListChangeEvent event;
String eventType;
@@ -46,12 +45,12 @@ public class ExtendedListValueModelWrapperTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.listHolder = new SimpleListValueModel(this.buildList());
+ this.listHolder = new SimpleListValueModel<String>(this.buildList());
this.extendedListHolder = this.buildExtendedListHolder(this.listHolder);
}
- private List buildList() {
- List result = new ArrayList();
+ private List<String> buildList() {
+ List<String> result = new ArrayList<String>();
result.add("A");
result.add("B");
result.add("C");
@@ -59,31 +58,31 @@ public class ExtendedListValueModelWrapperTests extends TestCase {
return result;
}
- private List buildExtendedList() {
- List extendedList = new ArrayList();
+ private List<String> buildExtendedList() {
+ List<String> extendedList = new ArrayList<String>();
extendedList.addAll(this.buildPrefix());
extendedList.addAll(this.buildList());
extendedList.addAll(this.buildSuffix());
return extendedList;
}
- private List buildPrefix() {
- List prefix = new ArrayList();
+ private List<String> buildPrefix() {
+ List<String> prefix = new ArrayList<String>();
prefix.add("x");
prefix.add("y");
prefix.add("z");
return prefix;
}
- private List buildSuffix() {
- List suffix = new ArrayList();
+ private List<String> buildSuffix() {
+ List<String> suffix = new ArrayList<String>();
suffix.add("i");
suffix.add("j");
return suffix;
}
- private ListValueModel buildExtendedListHolder(ListValueModel lvm) {
- return new ExtendedListValueModelWrapper(this.buildPrefix(), lvm, this.buildSuffix());
+ private ListValueModel<String> buildExtendedListHolder(ListValueModel<String> lvm) {
+ return new ExtendedListValueModelWrapper<String>(this.buildPrefix(), lvm, this.buildSuffix());
}
@Override
@@ -107,13 +106,13 @@ public class ExtendedListValueModelWrapperTests extends TestCase {
return CollectionTools.contains(this.extendedListHolder.iterator(), item);
}
- private boolean extendedListContainsAll(Collection items) {
+ private boolean extendedListContainsAll(Collection<String> items) {
return CollectionTools.containsAll(this.extendedListHolder.iterator(), items);
}
- private boolean extendedListContainsAny(Collection items) {
- List extendedList = CollectionTools.list(this.extendedListHolder.iterator());
- for (Iterator stream = items.iterator(); stream.hasNext(); ) {
+ private boolean extendedListContainsAny(Collection<String> items) {
+ List<String> extendedList = CollectionTools.list(this.extendedListHolder.iterator());
+ for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) {
if (extendedList.contains(stream.next())) {
return true;
}
@@ -125,20 +124,20 @@ public class ExtendedListValueModelWrapperTests extends TestCase {
return CollectionTools.contains(this.listHolder.iterator(), item);
}
- private boolean listContainsAll(Collection items) {
+ private boolean listContainsAll(Collection<String> items) {
return CollectionTools.containsAll(this.listHolder.iterator(), items);
}
- private boolean listContainsAny(Collection items) {
- List extendedList = CollectionTools.list(this.listHolder.iterator());
- for (Iterator stream = items.iterator(); stream.hasNext(); ) {
- if (extendedList.contains(stream.next())) {
- return true;
- }
- }
- return false;
- }
-
+// private boolean listContainsAny(Collection<String> items) {
+// List<String> extendedList = CollectionTools.list(this.listHolder.iterator());
+// for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) {
+// if (extendedList.contains(stream.next())) {
+// return true;
+// }
+// }
+// return false;
+// }
+//
public void testAdd1() {
this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener());
@@ -157,8 +156,8 @@ public class ExtendedListValueModelWrapperTests extends TestCase {
assertTrue(this.listContains(null));
}
- private List buildAddList() {
- List addList = new ArrayList();
+ private List<String> buildAddList() {
+ List<String> addList = new ArrayList<String>();
addList.add("E");
addList.add("F");
return addList;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java
index c7a0e361f3..9742dd34f8 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -24,13 +24,13 @@ import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
public class FilteringCollectionValueModelTests extends TestCase {
- private SimpleCollectionValueModel collectionHolder;
+ private SimpleCollectionValueModel<String> collectionHolder;
CollectionChangeEvent addEvent;
CollectionChangeEvent removeEvent;
CollectionChangeEvent collectionClearedEvent;
CollectionChangeEvent collectionChangedEvent;
- private CollectionValueModel filteredCollectionHolder;
+ private CollectionValueModel<String> filteredCollectionHolder;
CollectionChangeEvent filteredAddEvent;
CollectionChangeEvent filteredRemoveEvent;
CollectionChangeEvent filteredCollectionClearedEvent;
@@ -43,20 +43,20 @@ public class FilteringCollectionValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.collectionHolder = new SimpleCollectionValueModel(buildCollection());
- this.filteredCollectionHolder = new FilteringCollectionValueModel(this.collectionHolder, this.buildFilter());
+ this.collectionHolder = new SimpleCollectionValueModel<String>(buildCollection());
+ this.filteredCollectionHolder = new FilteringCollectionValueModel<String>(this.collectionHolder, this.buildFilter());
}
- private Collection buildCollection() {
- Collection collection = new Vector();
+ private Collection<String> buildCollection() {
+ Collection<String> collection = new Vector<String>();
collection.add("foo");
return collection;
}
- private Filter buildFilter() {
- return new Filter() {
- public boolean accept(Object o) {
- return ((String) o).startsWith("b");
+ private Filter<String> buildFilter() {
+ return new Filter<String>() {
+ public boolean accept(String s) {
+ return s.startsWith("b");
}
};
}
@@ -71,43 +71,43 @@ public class FilteringCollectionValueModelTests extends TestCase {
// add a listener to "activate" the wrapper
this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
- assertEquals("foo", ((Iterator) this.collectionHolder.iterator()).next());
- assertFalse(((Iterator) this.filteredCollectionHolder.iterator()).hasNext());
+ assertEquals("foo", this.collectionHolder.iterator().next());
+ assertFalse(this.filteredCollectionHolder.iterator().hasNext());
this.collectionHolder.add("bar");
- Iterator collectionHolderValue = (Iterator) this.collectionHolder.iterator();
+ Iterator<String> collectionHolderValue = this.collectionHolder.iterator();
assertEquals("foo", collectionHolderValue.next());
assertEquals("bar", collectionHolderValue.next());
- assertTrue(((Iterator) this.filteredCollectionHolder.iterator()).hasNext());
- assertEquals("bar", ((Iterator) this.filteredCollectionHolder.iterator()).next());
+ assertTrue(this.filteredCollectionHolder.iterator().hasNext());
+ assertEquals("bar", this.filteredCollectionHolder.iterator().next());
this.collectionHolder.remove("bar");
- assertEquals("foo", ((Iterator) this.collectionHolder.iterator()).next());
- assertFalse(((Iterator) this.filteredCollectionHolder.iterator()).hasNext());
+ assertEquals("foo", this.collectionHolder.iterator().next());
+ assertFalse(this.filteredCollectionHolder.iterator().hasNext());
this.collectionHolder.remove("foo");
- assertFalse(((Iterator) this.collectionHolder.iterator()).hasNext());
- assertFalse(((Iterator) this.filteredCollectionHolder.iterator()).hasNext());
+ assertFalse(this.collectionHolder.iterator().hasNext());
+ assertFalse(this.filteredCollectionHolder.iterator().hasNext());
this.collectionHolder.add("foo");
- assertEquals("foo", ((Iterator) this.collectionHolder.iterator()).next());
- assertFalse(((Iterator) this.filteredCollectionHolder.iterator()).hasNext());
+ assertEquals("foo", this.collectionHolder.iterator().next());
+ assertFalse(this.filteredCollectionHolder.iterator().hasNext());
}
public void testSetValue() {
// add a listener to "activate" the wrapper
this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
- Collection newCollection = new Vector();
+ Collection<String> newCollection = new Vector<String>();
newCollection.add("fox");
newCollection.add("baz");
- ((SimpleCollectionValueModel) this.collectionHolder).setCollection(newCollection);
+ this.collectionHolder.setCollection(newCollection);
- Iterator collectionValues = (Iterator) this.collectionHolder.iterator();
+ Iterator<String> collectionValues = this.collectionHolder.iterator();
assertEquals("fox", collectionValues.next());
assertEquals("baz", collectionValues.next());
- Iterator filteredCollectionValues = (Iterator) this.filteredCollectionHolder.iterator();
+ Iterator<String> filteredCollectionValues = this.filteredCollectionHolder.iterator();
assertEquals("baz", filteredCollectionValues.next());
assertFalse(filteredCollectionValues.hasNext());
}
@@ -152,7 +152,7 @@ public class FilteringCollectionValueModelTests extends TestCase {
private void verifyCollectionChanges() {
clearEvents();
this.collectionHolder.add("bar");
- Collection tempCollection = new Vector();
+ Collection<String> tempCollection = new Vector<String>();
tempCollection.add("bar");
this.verifyEvent(this.addEvent, this.collectionHolder, tempCollection);
this.verifyEvent(this.filteredAddEvent, this.filteredCollectionHolder, tempCollection);
@@ -182,17 +182,17 @@ public class FilteringCollectionValueModelTests extends TestCase {
clearEvents();
- Collection newCollection = new Vector();
+ Collection<String> newCollection = new Vector<String>();
newCollection.add("fox");
newCollection.add("baz");
- ((SimpleCollectionValueModel) this.collectionHolder).setCollection(newCollection);
+ this.collectionHolder.setCollection(newCollection);
- this.verifyEvent(this.collectionChangedEvent, this.collectionHolder, new Vector());
+ this.verifyEvent(this.collectionChangedEvent, this.collectionHolder, new Vector<String>());
tempCollection.remove("foo");
tempCollection.add("baz");
- this.verifyEvent(this.filteredCollectionChangedEvent, this.filteredCollectionHolder, new Vector());
+ this.verifyEvent(this.filteredCollectionChangedEvent, this.filteredCollectionHolder, new Vector<String>());
}
@@ -238,48 +238,50 @@ public class FilteringCollectionValueModelTests extends TestCase {
public void testRemoveFilteredItem() {
// build collection with TestItems
- this.collectionHolder = new SimpleCollectionValueModel(this.buildCollection2());
- this.filteredCollectionHolder = new FilteringCollectionValueModel(this.collectionHolder, this.buildFilter2());
+ SimpleCollectionValueModel<TestItem> tiHolder = new SimpleCollectionValueModel<TestItem>(this.buildCollection2());
+ CollectionValueModel<TestItem> filteredTIHolder = new FilteringCollectionValueModel<TestItem>(tiHolder, this.buildFilter2());
// add a listener to "activate" the wrapper
- this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
+ filteredTIHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener());
- assertEquals(0, this.filteredCollectionHolder.size());
+ assertEquals(0, filteredTIHolder.size());
- this.collectionHolder.add(new TestItem("bar"));
- assertEquals(1, this.filteredCollectionHolder.size());
+ tiHolder.add(new TestItem("bar"));
+ assertEquals(1, filteredTIHolder.size());
TestItem baz = new TestItem("baz");
- this.collectionHolder.add(baz);
- assertEquals(2, this.filteredCollectionHolder.size());
+ tiHolder.add(baz);
+ assertEquals(2, filteredTIHolder.size());
// before removing it, change the item so that it is filtered
baz.name = "jaz";
- this.collectionHolder.remove(baz);
+ tiHolder.remove(baz);
// this would fail because the item was not removed from
// the filtered collection cache... but we've fixed it now
- assertEquals(1, this.filteredCollectionHolder.size());
+ assertEquals(1, filteredTIHolder.size());
}
- private Collection buildCollection2() {
- Collection collection = new Vector();
+ private Collection<TestItem> buildCollection2() {
+ Collection<TestItem> collection = new Vector<TestItem>();
collection.add(new TestItem("foo"));
return collection;
}
- private Filter buildFilter2() {
- return new Filter() {
- public boolean accept(Object o) {
- return ((TestItem) o).name.startsWith("b");
+ private Filter<TestItem> buildFilter2() {
+ return new Filter<TestItem>() {
+ public boolean accept(TestItem ti) {
+ return ti.name.startsWith("b");
}
};
}
-private class TestItem {
- String name;
- TestItem(String name) {
- super();
- this.name = name;
+ // ********** TestItem inner class **********
+
+ private class TestItem {
+ String name;
+ TestItem(String name) {
+ super();
+ this.name = name;
+ }
}
-}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
index ad22856e42..823ae2f391 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,19 +13,19 @@ import org.eclipse.jpt.utility.internal.BidiFilter;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.FilteringPropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.FilteringWritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class FilteringPropertyValueModelTests extends TestCase {
- private PropertyValueModel objectHolder;
+ private WritablePropertyValueModel<String> objectHolder;
PropertyChangeEvent event;
- private PropertyValueModel filteredObjectHolder;
+ private WritablePropertyValueModel<String> filteredObjectHolder;
PropertyChangeEvent filteredEvent;
public FilteringPropertyValueModelTests(String name) {
@@ -35,17 +35,17 @@ public class FilteringPropertyValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.objectHolder = new SimplePropertyValueModel("foo");
- this.filteredObjectHolder = new FilteringPropertyValueModel(this.objectHolder, this.buildFilter());
+ this.objectHolder = new SimplePropertyValueModel<String>("foo");
+ this.filteredObjectHolder = new FilteringWritablePropertyValueModel<String>(this.objectHolder, this.buildFilter());
}
- private BidiFilter buildFilter() {
- return new BidiFilter() {
- public boolean accept(Object o) {
- return (o != null) && ((String) o).startsWith("b");
+ private BidiFilter<String> buildFilter() {
+ return new BidiFilter<String>() {
+ public boolean accept(String s) {
+ return (s != null) && s.startsWith("b");
}
- public boolean reverseAccept(Object o) {
- return (o != null) && ((String) o).startsWith("b");
+ public boolean reverseAccept(String s) {
+ return (s != null) && s.startsWith("b");
}
};
}
@@ -98,17 +98,17 @@ public class FilteringPropertyValueModelTests extends TestCase {
}
public void testLazyListening() {
- assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
PropertyChangeListener listener = this.buildFilteredListener();
this.filteredObjectHolder.addPropertyChangeListener(listener);
- assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.filteredObjectHolder.removePropertyChangeListener(listener);
- assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
- this.filteredObjectHolder.addPropertyChangeListener(ValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(ValueModel.VALUE));
- this.filteredObjectHolder.removePropertyChangeListener(ValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(ValueModel.VALUE));
+ this.filteredObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.filteredObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
}
public void testPropertyChange1() {
@@ -118,8 +118,8 @@ public class FilteringPropertyValueModelTests extends TestCase {
}
public void testPropertyChange2() {
- this.objectHolder.addPropertyChangeListener(ValueModel.VALUE, this.buildListener());
- this.filteredObjectHolder.addPropertyChangeListener(ValueModel.VALUE, this.buildFilteredListener());
+ this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.filteredObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildFilteredListener());
this.verifyPropertyChanges();
}
@@ -179,7 +179,7 @@ public class FilteringPropertyValueModelTests extends TestCase {
private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) {
assertEquals(source, e.getSource());
- assertEquals(ValueModel.VALUE, e.propertyName());
+ assertEquals(PropertyValueModel.VALUE, e.propertyName());
assertEquals(oldValue, e.oldValue());
assertEquals(newValue, e.newValue());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java
index 3ac27dbad6..92ba0b2831 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,7 +18,6 @@ import javax.swing.Icon;
import org.eclipse.jpt.utility.internal.Bag;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ItemCollectionListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
@@ -67,9 +66,9 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
}
public void testCollectionSynchronization() {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListValueModel listValueModel = new ItemCollectionListValueModelAdapter(collectionHolder, Junk.STUFF_COLLECTION);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder();
+ ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(collectionHolder, Junk.STUFF_COLLECTION);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -87,9 +86,9 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
}
public void testListSynchronization() {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemCollectionListValueModelAdapter(listHolder, Junk.STUFF_COLLECTION);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -106,7 +105,7 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
this.compare(listValueModel, synchList);
}
- private void compare(ListValueModel listValueModel, List list) {
+ private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) {
assertEquals(listValueModel.size(), list.size());
for (int i = 0; i < listValueModel.size(); i++) {
assertEquals(listValueModel.get(i), list.get(i));
@@ -115,18 +114,18 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
public void testHasListeners() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_COLLECTION));
assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_COLLECTION));
- ListValueModel listValueModel = new ItemCollectionListValueModelAdapter(listHolder, Junk.STUFF_COLLECTION);
+ ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION);
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
assertFalse(this.jaz.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
this.verifyHasNoListeners(listValueModel);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertTrue(this.foo.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
assertTrue(this.jaz.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
@@ -140,18 +139,18 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
}
public void testGetSize() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemCollectionListValueModelAdapter(listHolder, Junk.STUFF_COLLECTION);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(6, listValueModel.size());
assertEquals(6, synchList.size());
}
public void testGet() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new SortedListValueModelAdapter(new ItemCollectionListValueModelAdapter(listHolder, Junk.STUFF_COLLECTION));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new SortedListValueModelAdapter<Junk>(new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(this.bar, listValueModel.get(0));
assertEquals(this.bar, synchList.get(0));
@@ -163,35 +162,35 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
this.bar.removeStuff("zzz");
}
- private void verifyHasNoListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES));
}
- private void verifyHasListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
}
- private SimpleCollectionValueModel buildCollectionHolder() {
- return new SimpleCollectionValueModel(this.buildCollection());
+ private SimpleCollectionValueModel<Junk> buildCollectionHolder() {
+ return new SimpleCollectionValueModel<Junk>(this.buildCollection());
}
- private Collection buildCollection() {
- Bag bag = new HashBag();
+ private Collection<Junk> buildCollection() {
+ Bag<Junk> bag = new HashBag<Junk>();
this.populateCollection(bag);
return bag;
}
- private SimpleListValueModel buildListHolder() {
- return new SimpleListValueModel(this.buildList());
+ private SimpleListValueModel<Junk> buildListHolder() {
+ return new SimpleListValueModel<Junk>(this.buildList());
}
- private List buildList() {
- List list = new ArrayList();
+ private List<Junk> buildList() {
+ List<Junk> list = new ArrayList<Junk>();
this.populateCollection(list);
return list;
}
- private void populateCollection(Collection c) {
+ private void populateCollection(Collection<Junk> c) {
c.add(this.foo);
c.add(this.bar);
c.add(this.baz);
@@ -201,41 +200,43 @@ public class ItemCollectionListValueModelAdapterTests extends TestCase {
}
-private class Junk extends AbstractModel implements Displayable {
- private Collection stuff;
- public static final String STUFF_COLLECTION = "stuff";
-
-
- public Junk(String stuffItem) {
- this.stuff = new ArrayList();
- this.stuff.add(stuffItem);
- }
+ // ********** Junk class **********
- public void addStuff(String stuffItem) {
- this.addItemToCollection(stuffItem, this.stuff, STUFF_COLLECTION);
- }
+ private class Junk extends AbstractModel implements Displayable {
+ private Collection<String> stuff;
+ public static final String STUFF_COLLECTION = "stuff";
+
- public void removeStuff(String stuffItem) {
- this.removeItemFromCollection(stuffItem, this.stuff, STUFF_COLLECTION);
- }
-
- public String displayString() {
- return toString();
- }
-
- public Icon icon() {
- return null;
- }
+ public Junk(String stuffItem) {
+ this.stuff = new ArrayList<String>();
+ this.stuff.add(stuffItem);
+ }
+
+ public void addStuff(String stuffItem) {
+ this.addItemToCollection(stuffItem, this.stuff, STUFF_COLLECTION);
+ }
+
+ public void removeStuff(String stuffItem) {
+ this.removeItemFromCollection(stuffItem, this.stuff, STUFF_COLLECTION);
+ }
+
+ public String displayString() {
+ return toString();
+ }
+
+ public Icon icon() {
+ return null;
+ }
+
+ public int compareTo(Displayable o) {
+ return DEFAULT_COMPARATOR.compare(this, o);
+ }
+
+ @Override
+ public String toString() {
+ return "Junk(" + this.stuff + ")";
+ }
- public int compareTo(Displayable o) {
- return DEFAULT_COMPARATOR.compare(this, o);
- }
-
- @Override
- public String toString() {
- return "Junk(" + this.stuff + ")";
}
}
-
-}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java
index 739f1abdf1..d414f5c9f7 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,7 +18,6 @@ import javax.swing.Icon;
import org.eclipse.jpt.utility.internal.Bag;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ItemListListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
@@ -67,9 +66,9 @@ public class ItemListListValueModelAdapterTests extends TestCase {
}
public void testCollectionSynchronization() {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListValueModel listValueModel = new ItemListListValueModelAdapter(collectionHolder, Junk.STUFF_LIST);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder();
+ ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(collectionHolder, Junk.STUFF_LIST);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -87,9 +86,9 @@ public class ItemListListValueModelAdapterTests extends TestCase {
}
public void testListSynchronization() {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemListListValueModelAdapter(listHolder, Junk.STUFF_LIST);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -106,7 +105,7 @@ public class ItemListListValueModelAdapterTests extends TestCase {
this.compare(listValueModel, synchList);
}
- private void compare(ListValueModel listValueModel, List list) {
+ private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) {
assertEquals(listValueModel.size(), list.size());
for (int i = 0; i < listValueModel.size(); i++) {
assertEquals(listValueModel.get(i), list.get(i));
@@ -115,18 +114,18 @@ public class ItemListListValueModelAdapterTests extends TestCase {
public void testHasListeners() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST));
assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST));
- ListValueModel listValueModel = new ItemListListValueModelAdapter(listHolder, Junk.STUFF_LIST);
+ ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST);
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST));
assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST));
this.verifyHasNoListeners(listValueModel);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertTrue(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST));
assertTrue(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST));
@@ -140,18 +139,18 @@ public class ItemListListValueModelAdapterTests extends TestCase {
}
public void testGetSize() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemListListValueModelAdapter(listHolder, Junk.STUFF_LIST);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(6, listValueModel.size());
assertEquals(6, synchList.size());
}
public void testGet() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new SortedListValueModelAdapter(new ItemListListValueModelAdapter(listHolder, Junk.STUFF_LIST));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new SortedListValueModelAdapter<Junk>(new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(this.bar, listValueModel.get(0));
assertEquals(this.bar, synchList.get(0));
@@ -163,35 +162,35 @@ public class ItemListListValueModelAdapterTests extends TestCase {
this.bar.removeStuff("zzz");
}
- private void verifyHasNoListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES));
}
- private void verifyHasListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
}
- private SimpleCollectionValueModel buildCollectionHolder() {
- return new SimpleCollectionValueModel(this.buildCollection());
+ private SimpleCollectionValueModel<Junk> buildCollectionHolder() {
+ return new SimpleCollectionValueModel<Junk>(this.buildCollection());
}
- private Collection buildCollection() {
- Bag bag = new HashBag();
+ private Collection<Junk> buildCollection() {
+ Bag<Junk> bag = new HashBag<Junk>();
this.populateCollection(bag);
return bag;
}
- private SimpleListValueModel buildListHolder() {
- return new SimpleListValueModel(this.buildList());
+ private SimpleListValueModel<Junk> buildListHolder() {
+ return new SimpleListValueModel<Junk>(this.buildList());
}
- private List buildList() {
- List list = new ArrayList();
+ private List<Junk> buildList() {
+ List<Junk> list = new ArrayList<Junk>();
this.populateCollection(list);
return list;
}
- private void populateCollection(Collection c) {
+ private void populateCollection(Collection<Junk> c) {
c.add(this.foo);
c.add(this.bar);
c.add(this.baz);
@@ -200,42 +199,45 @@ public class ItemListListValueModelAdapterTests extends TestCase {
c.add(this.jaz);
}
-private class Junk extends AbstractModel implements Displayable {
- private List stuff;
- public static final String STUFF_LIST = "stuff";
-
-
- public Junk(String stuffItem) {
- this.stuff = new ArrayList();
- this.stuff.add(stuffItem);
- }
- public void addStuff(String stuffItem) {
- this.stuff.add(stuffItem);
- fireItemAdded(STUFF_LIST, this.stuff.indexOf(stuffItem), stuffItem);
- }
-
- public void removeStuff(String stuffItem) {
- int index = this.stuff.indexOf(stuffItem);
- this.stuff.remove(stuffItem);
- fireItemRemoved(STUFF_LIST, index, stuffItem);
- }
- public String displayString() {
- return toString();
- }
+ // ********** Junk class **********
- public Icon icon() {
- return null;
- }
+ private class Junk extends AbstractModel implements Displayable {
+ private List<String> stuff;
+ public static final String STUFF_LIST = "stuff";
+
- public int compareTo(Displayable o) {
- return DEFAULT_COMPARATOR.compare(this, o);
- }
-
- @Override
- public String toString() {
- return "Junk(" + this.stuff + ")";
+ public Junk(String stuffItem) {
+ this.stuff = new ArrayList<String>();
+ this.stuff.add(stuffItem);
+ }
+ public void addStuff(String stuffItem) {
+ this.stuff.add(stuffItem);
+ fireItemAdded(STUFF_LIST, this.stuff.indexOf(stuffItem), stuffItem);
+ }
+
+ public void removeStuff(String stuffItem) {
+ int index = this.stuff.indexOf(stuffItem);
+ this.stuff.remove(stuffItem);
+ fireItemRemoved(STUFF_LIST, index, stuffItem);
+ }
+
+ public String displayString() {
+ return toString();
+ }
+
+ public Icon icon() {
+ return null;
+ }
+
+ public int compareTo(Displayable o) {
+ return DEFAULT_COMPARATOR.compare(this, o);
+ }
+
+ @Override
+ public String toString() {
+ return "Junk(" + this.stuff + ")";
+ }
}
-}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java
index d0b0149fd2..5d9bdda881 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -70,9 +70,9 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
}
public void testCollectionSynchronization() {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListValueModel listValueModel = new ItemPropertyListValueModelAdapter(collectionHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder();
+ ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(collectionHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -94,9 +94,9 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
}
public void testListSynchronization() {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemPropertyListValueModelAdapter(listHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(listHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -118,7 +118,7 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
this.compare(listValueModel, synchList);
}
- private void compare(ListValueModel listValueModel, List list) {
+ private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) {
assertEquals(listValueModel.size(), list.size());
for (int i = 0; i < listValueModel.size(); i++) {
assertEquals(listValueModel.get(i), list.get(i));
@@ -141,19 +141,19 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
this.verifyListSort(this.buildCustomComparator());
}
- private Comparator buildCustomComparator() {
+ private Comparator<Junk> buildCustomComparator() {
// sort with reverse order
- return new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) o2).compareTo(o1);
+ return new Comparator<Junk>() {
+ public int compare(Junk o1, Junk o2) {
+ return o2.compareTo(o1);
}
};
}
- private void verifyCollectionSort(Comparator comparator) {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListValueModel listValueModel = new ItemPropertyListValueModelAdapter(new SortedListValueModelAdapter(collectionHolder, comparator), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ private void verifyCollectionSort(Comparator<Junk> comparator) {
+ SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder();
+ ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(collectionHolder, comparator), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compareSort(listValueModel, synchList, comparator);
@@ -174,10 +174,10 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
this.compareSort(listValueModel, synchList, comparator);
}
- private void verifyListSort(Comparator comparator) {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemPropertyListValueModelAdapter(new SortedListValueModelAdapter(listHolder, comparator), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ private void verifyListSort(Comparator<Junk> comparator) {
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(listHolder, comparator), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compareSort(listValueModel, synchList, comparator);
@@ -199,26 +199,26 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
this.compareSort(listValueModel, synchList, comparator);
}
- private void compareSort(ListValueModel listValueModel, List list, Comparator comparator) {
- SortedSet ss = new TreeSet(comparator);
+ private void compareSort(ListValueModel<Junk> listValueModel, List<Junk> list, Comparator<Junk> comparator) {
+ SortedSet<Junk> ss = new TreeSet<Junk>(comparator);
for (int i = 0; i < listValueModel.size(); i++) {
ss.add(listValueModel.get(i));
}
assertEquals(ss.size(), list.size());
- for (Iterator stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) {
+ for (Iterator<Junk> stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) {
assertEquals(stream1.next(), stream2.next());
}
}
public void testHasListeners() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY));
assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY));
assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY));
assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY));
- ListValueModel listValueModel = new ItemPropertyListValueModelAdapter(new SortedListValueModelAdapter(listHolder), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
+ ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(listHolder), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY));
assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY));
@@ -226,7 +226,7 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY));
this.verifyHasNoListeners(listValueModel);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertTrue(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY));
assertTrue(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY));
@@ -244,18 +244,18 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
}
public void testGetSize() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemPropertyListValueModelAdapter(new SortedListValueModelAdapter(listHolder), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(listHolder), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(6, listValueModel.size());
assertEquals(6, synchList.size());
}
public void testGet() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new SortedListValueModelAdapter(new ItemPropertyListValueModelAdapter(listHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new SortedListValueModelAdapter<Junk>(new ItemPropertyListValueModelAdapter<Junk>(listHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(this.bar, listValueModel.get(0));
assertEquals(this.bar, synchList.get(0));
@@ -265,35 +265,35 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
this.bar.setName("this.bar");
}
- private void verifyHasNoListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES));
}
- private void verifyHasListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
}
- private SimpleCollectionValueModel buildCollectionHolder() {
- return new SimpleCollectionValueModel(this.buildCollection());
+ private SimpleCollectionValueModel<Junk> buildCollectionHolder() {
+ return new SimpleCollectionValueModel<Junk>(this.buildCollection());
}
- private Collection buildCollection() {
- Bag bag = new HashBag();
+ private Collection<Junk> buildCollection() {
+ Bag<Junk> bag = new HashBag<Junk>();
this.populateCollection(bag);
return bag;
}
- private SimpleListValueModel buildListHolder() {
- return new SimpleListValueModel(this.buildList());
+ private SimpleListValueModel<Junk> buildListHolder() {
+ return new SimpleListValueModel<Junk>(this.buildList());
}
- private List buildList() {
- List list = new ArrayList();
+ private List<Junk> buildList() {
+ List<Junk> list = new ArrayList<Junk>();
this.populateCollection(list);
return list;
}
- private void populateCollection(Collection c) {
+ private void populateCollection(Collection<Junk> c) {
c.add(this.foo);
c.add(this.bar);
c.add(this.baz);
@@ -302,29 +302,32 @@ public class ItemPropertyListValueModelAdapterTests extends TestCase {
c.add(this.jaz);
}
-private class Junk extends AbstractModel implements Displayable {
- private String name;
- public Junk(String name) {
- this.name = name;
- }
- public String displayString() {
- return this.name;
- }
- public Icon icon() {
- return null;
- }
- public int compareTo(Displayable o) {
- return DEFAULT_COMPARATOR.compare(this, o);
- }
- public void setName(String name) {
- Object old = this.name;
- this.name = name;
- this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name);
- }
- @Override
- public String toString() {
- return "Junk(" + this.name + ")";
+
+ // ********** Junk class **********
+
+ private class Junk extends AbstractModel implements Displayable {
+ private String name;
+ public Junk(String name) {
+ this.name = name;
+ }
+ public String displayString() {
+ return this.name;
+ }
+ public Icon icon() {
+ return null;
+ }
+ public int compareTo(Displayable o) {
+ return DEFAULT_COMPARATOR.compare(this, o);
+ }
+ public void setName(String name) {
+ Object old = this.name;
+ this.name = name;
+ this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name);
+ }
+ @Override
+ public String toString() {
+ return "Junk(" + this.name + ")";
+ }
}
-}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java
index 365a5716d1..5030a0ee22 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,7 +20,6 @@ import java.util.TreeSet;
import org.eclipse.jpt.utility.internal.Bag;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ItemStateListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
@@ -68,9 +67,9 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
}
public void testCollectionSynchronization() {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListValueModel listValueModel = new ItemStateListValueModelAdapter(collectionHolder);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder();
+ ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(collectionHolder);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -88,9 +87,9 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
}
public void testListSynchronization() {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemStateListValueModelAdapter(listHolder);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(listHolder);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compare(listValueModel, synchList);
@@ -107,7 +106,7 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
this.compare(listValueModel, synchList);
}
- private void compare(ListValueModel listValueModel, List list) {
+ private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) {
assertEquals(listValueModel.size(), list.size());
for (int i = 0; i < listValueModel.size(); i++) {
assertEquals(listValueModel.get(i), list.get(i));
@@ -130,19 +129,19 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
this.verifyListSort(this.buildCustomComparator());
}
- private Comparator buildCustomComparator() {
+ private Comparator<Junk> buildCustomComparator() {
// sort with reverse order
- return new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) o2).compareTo(o1);
+ return new Comparator<Junk>() {
+ public int compare(Junk o1, Junk o2) {
+ return o2.compareTo(o1);
}
};
}
- private void verifyCollectionSort(Comparator comparator) {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListValueModel listValueModel = new ItemStateListValueModelAdapter(new SortedListValueModelAdapter(collectionHolder, comparator));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ private void verifyCollectionSort(Comparator<Junk> comparator) {
+ SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder();
+ ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(collectionHolder, comparator));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compareSort(listValueModel, synchList, comparator);
@@ -159,10 +158,10 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
this.compareSort(listValueModel, synchList, comparator);
}
- private void verifyListSort(Comparator comparator) {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemStateListValueModelAdapter(new SortedListValueModelAdapter(listHolder, comparator));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ private void verifyListSort(Comparator<Junk> comparator) {
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(listHolder, comparator));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertEquals(6, synchList.size());
this.compareSort(listValueModel, synchList, comparator);
@@ -180,26 +179,26 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
this.compareSort(listValueModel, synchList, comparator);
}
- private void compareSort(ListValueModel listValueModel, List list, Comparator comparator) {
- SortedSet ss = new TreeSet(comparator);
+ private void compareSort(ListValueModel<Junk> listValueModel, List<Junk> list, Comparator<Junk> comparator) {
+ SortedSet<Junk> ss = new TreeSet<Junk>(comparator);
for (int i = 0; i < listValueModel.size(); i++) {
ss.add(listValueModel.get(i));
}
assertEquals(ss.size(), list.size());
- for (Iterator stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) {
+ for (Iterator<Junk> stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) {
assertEquals(stream1.next(), stream2.next());
}
}
public void testHasListeners() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyStateChangeListeners());
assertFalse(this.foo.hasAnyStateChangeListeners());
assertFalse(this.jaz.hasAnyStateChangeListeners());
assertFalse(this.jaz.hasAnyStateChangeListeners());
- ListValueModel listValueModel = new ItemStateListValueModelAdapter(new SortedListValueModelAdapter(listHolder));
+ ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(listHolder));
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertFalse(this.foo.hasAnyStateChangeListeners());
assertFalse(this.foo.hasAnyStateChangeListeners());
@@ -207,7 +206,7 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
assertFalse(this.jaz.hasAnyStateChangeListeners());
this.verifyHasNoListeners(listValueModel);
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertTrue(this.foo.hasAnyStateChangeListeners());
assertTrue(this.foo.hasAnyStateChangeListeners());
@@ -225,18 +224,18 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
}
public void testGetSize() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new ItemStateListValueModelAdapter(new SortedListValueModelAdapter(listHolder));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(listHolder));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(6, listValueModel.size());
assertEquals(6, synchList.size());
}
public void testGet() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListValueModel listValueModel = new SortedListValueModelAdapter(new ItemStateListValueModelAdapter(listHolder));
- SynchronizedList synchList = new SynchronizedList(listValueModel);
+ SimpleListValueModel<Junk> listHolder = this.buildListHolder();
+ ListValueModel<Junk> listValueModel = new SortedListValueModelAdapter<Junk>(new ItemStateListValueModelAdapter<Junk>(listHolder));
+ CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel);
this.verifyHasListeners(listValueModel);
assertEquals(this.bar, listValueModel.get(0));
assertEquals(this.bar, synchList.get(0));
@@ -246,35 +245,35 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
this.bar.setName("this.bar");
}
- private void verifyHasNoListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES));
}
- private void verifyHasListeners(ListValueModel listValueModel) throws Exception {
+ private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception {
assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
}
- private SimpleCollectionValueModel buildCollectionHolder() {
- return new SimpleCollectionValueModel(this.buildCollection());
+ private SimpleCollectionValueModel<Junk> buildCollectionHolder() {
+ return new SimpleCollectionValueModel<Junk>(this.buildCollection());
}
- private Collection buildCollection() {
- Bag bag = new HashBag();
+ private Collection<Junk> buildCollection() {
+ Bag<Junk> bag = new HashBag<Junk>();
this.populateCollection(bag);
return bag;
}
- private SimpleListValueModel buildListHolder() {
- return new SimpleListValueModel(this.buildList());
+ private SimpleListValueModel<Junk> buildListHolder() {
+ return new SimpleListValueModel<Junk>(this.buildList());
}
- private List buildList() {
- List list = new ArrayList();
+ private List<Junk> buildList() {
+ List<Junk> list = new ArrayList<Junk>();
this.populateCollection(list);
return list;
}
- private void populateCollection(Collection c) {
+ private void populateCollection(Collection<Junk> c) {
c.add(this.foo);
c.add(this.bar);
c.add(this.baz);
@@ -283,22 +282,23 @@ public class ItemStateListValueModelAdapterTests extends TestCase {
c.add(this.jaz);
}
-private class Junk extends AbstractModel implements Comparable<Junk> {
- private String name;
- public Junk(String name) {
- this.name = name;
- }
- public void setName(String name) {
- this.name = name;
- this.fireStateChanged();
- }
- public int compareTo(Junk j) {
- return this.name.compareTo(j.name);
- }
- @Override
- public String toString() {
- return "Junk(" + this.name + ")";
+ // ********** Junk class **********
+ private class Junk extends AbstractModel implements Comparable<Junk> {
+ private String name;
+ public Junk(String name) {
+ this.name = name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ this.fireStateChanged();
+ }
+ public int compareTo(Junk j) {
+ return this.name.compareTo(j.name);
+ }
+ @Override
+ public String toString() {
+ return "Junk(" + this.name + ")";
+ }
}
-}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java
index eae9934d9f..bbaa8e5d91 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,7 +23,7 @@ public class JptUtilityModelValueTests {
suite.addTest(JptUtilityModelValuePrefsTests.suite());
suite.addTest(JptUtilityModelValueSwingTests.suite());
- suite.addTestSuite(BufferedPropertyValueModelTests.class);
+ suite.addTestSuite(BufferedWritablePropertyValueModelTests.class);
suite.addTestSuite(CollectionAspectAdapterTests.class);
suite.addTestSuite(CollectionListValueModelAdapterTests.class);
suite.addTestSuite(CollectionPropertyValueModelAdapterTests.class);
@@ -43,8 +43,8 @@ public class JptUtilityModelValueTests {
suite.addTestSuite(NullPropertyValueModelTests.class);
suite.addTestSuite(PropertyAspectAdapterTests.class);
suite.addTestSuite(PropertyCollectionValueModelAdapterTests.class);
- suite.addTestSuite(ReadOnlyCollectionValueModelTests.class);
- suite.addTestSuite(ReadOnlyListValueModelTests.class);
+ suite.addTestSuite(StaticCollectionValueModelTests.class);
+ suite.addTestSuite(StaticListValueModelTests.class);
suite.addTestSuite(SimpleCollectionValueModelTests.class);
suite.addTestSuite(SimpleListValueModelTests.class);
suite.addTestSuite(SimplePropertyValueModelTests.class);
@@ -54,10 +54,10 @@ public class JptUtilityModelValueTests {
suite.addTestSuite(TransformationListValueModelAdapterTests.TransformerTests.class);
suite.addTestSuite(TransformationPropertyValueModelTests.class);
suite.addTestSuite(TreeAspectAdapterTests.class);
- suite.addTestSuite(ValueCollectionPropertyValueModelAdapterTests.class);
- suite.addTestSuite(ValueListPropertyValueModelAdapterTests.class);
- suite.addTestSuite(ValuePropertyPropertyValueModelAdapterTests.class);
- suite.addTestSuite(ValueStatePropertyValueModelAdapterTests.class);
+ suite.addTestSuite(ValueCollectionAdapterTests.class);
+ suite.addTestSuite(ValueListAdapterTests.class);
+ suite.addTestSuite(ValuePropertyAdapterTests.class);
+ suite.addTestSuite(ValueStateAdapterTests.class);
return suite;
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java
index 0486ebf4df..a2741adf44 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.utility.tests.internal.model.value;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -23,14 +22,14 @@ import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class ListAspectAdapterTests extends TestCase {
private TestSubject subject1;
- private PropertyValueModel subjectHolder1;
+ private WritablePropertyValueModel<TestSubject> subjectHolder1;
private LocalListAspectAdapter aa1;
private ListChangeEvent event1;
private ListChangeListener listener1;
@@ -47,7 +46,7 @@ public class ListAspectAdapterTests extends TestCase {
this.subject1 = new TestSubject();
this.subject1.addNames(this.subject1Names());
this.subject1.addDescriptions(this.subject1Descriptions());
- this.subjectHolder1 = new SimplePropertyValueModel(this.subject1);
+ this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1);
this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
this.listener1 = this.buildValueChangeListener1();
this.aa1.addListChangeListener(ListValueModel.LIST_VALUES, this.listener1);
@@ -58,8 +57,8 @@ public class ListAspectAdapterTests extends TestCase {
this.subject2.addDescriptions(this.subject2Descriptions());
}
- private List subject1Names() {
- List result = new ArrayList();
+ private List<String> subject1Names() {
+ List<String> result = new ArrayList<String>();
result.add("foo");
result.add("bar");
result.add("baz");
@@ -67,15 +66,15 @@ public class ListAspectAdapterTests extends TestCase {
return result;
}
- private List subject1Descriptions() {
- List result = new ArrayList();
+ private List<String> subject1Descriptions() {
+ List<String> result = new ArrayList<String>();
result.add("this.subject1 description1");
result.add("this.subject1 description2");
return result;
}
- private List subject2Names() {
- List result = new ArrayList();
+ private List<String> subject2Names() {
+ List<String> result = new ArrayList<String>();
result.add("joo");
result.add("jar");
result.add("jaz");
@@ -83,14 +82,14 @@ public class ListAspectAdapterTests extends TestCase {
return result;
}
- private List subject2Descriptions() {
- List result = new ArrayList();
+ private List<String> subject2Descriptions() {
+ List<String> result = new ArrayList<String>();
result.add("this.subject2 description1");
result.add("this.subject2 description2");
return result;
}
- private LocalListAspectAdapter buildAspectAdapter(ValueModel subjectHolder) {
+ private LocalListAspectAdapter buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
return new LocalListAspectAdapter(subjectHolder);
}
@@ -168,7 +167,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(this.subject1Names().size(), this.event1.index());
assertEquals("jam", this.event1.items().next());
- List namesPlus = this.subject1Names();
+ List<String> namesPlus = this.subject1Names();
namesPlus.add("jam");
assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator()));
@@ -187,7 +186,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator()));
assertNull(this.event1);
- List items = new ArrayList();
+ List<String> items = new ArrayList<String>();
items.add("joo");
items.add("jar");
items.add("jaz");
@@ -200,7 +199,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(5, this.event1.index()); // only the last "add" event will still be there
assertEquals("jam", this.event1.items().next());
- List namesPlus = this.subject1Names();
+ List<String> namesPlus = this.subject1Names();
namesPlus.addAll(2, items);
assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator()));
}
@@ -215,7 +214,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(0, this.event1.index());
assertEquals(removedName, this.event1.items().next());
- List namesMinus = this.subject1Names();
+ List<String> namesMinus = this.subject1Names();
namesMinus.remove(0);
assertEquals(namesMinus, CollectionTools.list(this.aa1.listIterator()));
@@ -234,7 +233,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator()));
assertNull(this.event1);
- List items = new ArrayList();
+ List<String> items = new ArrayList<String>();
items.add("bar");
items.add("baz");
@@ -245,7 +244,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(1, this.event1.index()); // only the last "remove" event will still be there
assertEquals("baz", this.event1.items().next());
- List namesPlus = this.subject1Names();
+ List<String> namesPlus = this.subject1Names();
namesPlus.remove(1);
namesPlus.remove(1);
assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator()));
@@ -262,7 +261,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(0, this.event1.index());
assertEquals("jelly", this.event1.items().next());
assertEquals(replacedName, this.event1.replacedItems().next());
- List namesChanged = this.subject1Names();
+ List<String> namesChanged = this.subject1Names();
namesChanged.set(0, "jelly");
assertEquals(namesChanged, CollectionTools.list(this.aa1.listIterator()));
@@ -290,7 +289,7 @@ public class ListAspectAdapterTests extends TestCase {
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(-1, this.event1.index());
assertFalse(this.event1.items().hasNext());
- List namesPlus2 = this.subject1Names();
+ List<String> namesPlus2 = this.subject1Names();
namesPlus2.add(0, "jaz");
namesPlus2.add(0, "jam");
assertEquals(namesPlus2, CollectionTools.list(this.aa1.listIterator()));
@@ -331,20 +330,20 @@ public class ListAspectAdapterTests extends TestCase {
// ********** inner class **********
private class TestSubject extends AbstractModel {
- private List names;
+ private List<String> names;
public static final String NAMES_LIST = "names";
- private List descriptions;
+ private List<String> descriptions;
public static final String DESCRIPTIONS_LIST = "descriptions";
public TestSubject() {
- this.names = new ArrayList();
- this.descriptions = new ArrayList();
+ this.names = new ArrayList<String>();
+ this.descriptions = new ArrayList<String>();
}
- public ListIterator names() {
- return new ReadOnlyListIterator(this.names);
+ public ListIterator<String> names() {
+ return new ReadOnlyListIterator<String>(this.names);
}
public String getName(int index) {
- return (String) this.names.get(index);
+ return this.names.get(index);
}
public void addName(int index, String name) {
this.names.add(index, name);
@@ -353,12 +352,12 @@ public class ListAspectAdapterTests extends TestCase {
public void addName(String name) {
this.addName(this.names.size(), name);
}
- public void addNames(ListIterator newNames) {
+ public void addNames(ListIterator<String> newNames) {
while (newNames.hasNext()) {
- this.addName((String) newNames.next());
+ this.addName(newNames.next());
}
}
- public void addNames(List newNames) {
+ public void addNames(List<String> newNames) {
this.addNames(newNames.listIterator());
}
public void addTwoNames(String name1, String name2) {
@@ -367,20 +366,20 @@ public class ListAspectAdapterTests extends TestCase {
this.fireListChanged(NAMES_LIST);
}
public String removeName(int index) {
- String removedName = (String) this.names.remove(index);
+ String removedName = this.names.remove(index);
this.fireItemRemoved(NAMES_LIST, index, removedName);
return removedName;
}
public String setName(int index, String name) {
- String replacedName = (String) this.names.set(index, name);
+ String replacedName = this.names.set(index, name);
this.fireItemReplaced(NAMES_LIST, index, name, replacedName);
return replacedName;
}
- public ListIterator descriptions() {
- return new ReadOnlyListIterator(this.descriptions);
+ public ListIterator<String> descriptions() {
+ return new ReadOnlyListIterator<String>(this.descriptions);
}
public String getDescription(int index) {
- return (String) this.descriptions.get(index);
+ return this.descriptions.get(index);
}
public void addDescription(int index, String description) {
this.descriptions.add(index, description);
@@ -389,21 +388,21 @@ public class ListAspectAdapterTests extends TestCase {
public void addDescription(String description) {
this.addDescription(this.descriptions.size(), description);
}
- public void addDescriptions(ListIterator newDescriptions) {
+ public void addDescriptions(ListIterator<String> newDescriptions) {
while (newDescriptions.hasNext()) {
- this.addDescription((String) newDescriptions.next());
+ this.addDescription(newDescriptions.next());
}
}
- public void addDescriptions(List newDescriptions) {
+ public void addDescriptions(List<String> newDescriptions) {
this.addDescriptions(newDescriptions.listIterator());
}
public String removeDescription(int index) {
- String removedDescription = (String) this.descriptions.remove(index);
+ String removedDescription = this.descriptions.remove(index);
this.fireItemRemoved(DESCRIPTIONS_LIST, index, removedDescription);
return removedDescription;
}
public String setDescription(int index, String description) {
- String replacedDescription = (String) this.descriptions.set(index, description);
+ String replacedDescription = this.descriptions.set(index, description);
this.fireItemReplaced(DESCRIPTIONS_LIST, index, description, replacedDescription);
return replacedDescription;
}
@@ -411,51 +410,51 @@ public class ListAspectAdapterTests extends TestCase {
// this is not a typical aspect adapter - the value is determined by the aspect name
- private class LocalListAspectAdapter extends ListAspectAdapter {
+ private class LocalListAspectAdapter extends ListAspectAdapter<TestSubject, String> {
- LocalListAspectAdapter(ValueModel subjectHolder) {
+ LocalListAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
super(subjectHolder, TestSubject.NAMES_LIST);
}
@Override
- protected ListIterator listIterator_() {
- if (this.listName == TestSubject.NAMES_LIST) {
- return ((TestSubject) this.subject).names();
- } else if (this.listName == TestSubject.DESCRIPTIONS_LIST) {
- return ((TestSubject) this.subject).descriptions();
+ protected ListIterator<String> listIterator_() {
+ if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ return this.subject.names();
+ } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ return this.subject.descriptions();
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listName);
+ throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
}
}
public void add(int index, Object item) {
- if (this.listName == TestSubject.NAMES_LIST) {
- ((TestSubject) this.subject).addName(index, (String) item);
- } else if (this.listName == TestSubject.DESCRIPTIONS_LIST) {
- ((TestSubject) this.subject).addDescription(index, (String) item);
+ if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ this.subject.addName(index, (String) item);
+ } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ this.subject.addDescription(index, (String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listName);
+ throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
}
}
- public void addAll(int index, List items) {
+ public void addAll(int index, List<String> items) {
for (int i = 0; i < items.size(); i++) {
this.add(index + i, items.get(i));
}
}
- public Object remove(int index) {
- if (this.listName == TestSubject.NAMES_LIST) {
- return ((TestSubject) this.subject).removeName(index);
- } else if (this.listName == TestSubject.DESCRIPTIONS_LIST) {
- return ((TestSubject) this.subject).removeDescription(index);
+ public String remove(int index) {
+ if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ return this.subject.removeName(index);
+ } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ return this.subject.removeDescription(index);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listName);
+ throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
}
}
- public List remove(int index, int length) {
- List removedItems = new ArrayList(length);
+ public List<String> remove(int index, int length) {
+ List<String> removedItems = new ArrayList<String>(length);
for (int i = 0; i < length; i++) {
removedItems.add(this.remove(index));
}
@@ -463,12 +462,12 @@ public class ListAspectAdapterTests extends TestCase {
}
public Object replace(int index, Object item) {
- if (this.listName == TestSubject.NAMES_LIST) {
- return ((TestSubject) this.subject).setName(index, (String) item);
- } else if (this.listName == TestSubject.DESCRIPTIONS_LIST) {
- return ((TestSubject) this.subject).setDescription(index, (String) item);
+ if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ return this.subject.setName(index, (String) item);
+ } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ return this.subject.setDescription(index, (String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listName);
+ throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
}
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java
index 03d54cf9a5..338adf3d76 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,10 +11,10 @@ package org.eclipse.jpt.utility.tests.internal.model.value;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
+
import javax.swing.JList;
-import junit.framework.TestCase;
+
import org.eclipse.jpt.utility.internal.Bag;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.HashBag;
@@ -23,15 +23,16 @@ import org.eclipse.jpt.utility.internal.model.event.CollectionChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.CollectionChangeListener;
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ListCollectionValueModelAdapter;
-import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
+
public class ListCollectionValueModelAdapterTests extends TestCase {
- CollectionValueModel adapter;
- private SimpleListValueModel wrappedListHolder;
- private List wrappedList;
+ CollectionValueModel<String> adapter;
+ private SimpleListValueModel<String> wrappedListHolder;
+ private List<String> wrappedList;
public ListCollectionValueModelAdapterTests(String name) {
super(name);
@@ -40,12 +41,12 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.wrappedList = new ArrayList();
- this.wrappedListHolder = new SimpleListValueModel(this.wrappedList);
- this.adapter = new ListCollectionValueModelAdapter(this.wrappedListHolder);
+ this.wrappedList = new ArrayList<String>();
+ this.wrappedListHolder = new SimpleListValueModel<String>(this.wrappedList);
+ this.adapter = new ListCollectionValueModelAdapter<String>(this.wrappedListHolder);
}
- private Collection wrappedCollection() {
+ private Collection<String> wrappedCollection() {
return CollectionTools.collection(this.wrappedList.iterator());
}
@@ -57,6 +58,7 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
public void testIterator() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {
// override failure
}
@@ -64,37 +66,38 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
this.wrappedListHolder.add(0, "foo");
this.wrappedListHolder.add(1, "bar");
this.wrappedListHolder.add(2, "baz");
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
}
public void testStaleValues() {
CollectionChangeListener listener = new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
};
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener);
this.wrappedListHolder.add(0, "foo");
this.wrappedListHolder.add(1, "bar");
this.wrappedListHolder.add(2, "baz");
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, listener);
- adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(0, adapterCollection.size());
- assertEquals(new HashBag(), adapterCollection);
+ assertEquals(new HashBag<String>(), adapterCollection);
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener);
- adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
}
public void testAdd() {
- Bag synchCollection = new SynchronizedBag(this.adapter);
- List synchList = new SynchronizedList(this.wrappedListHolder);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.adapter);
+ List<String> synchList = new CoordinatedList<String>(this.wrappedListHolder);
this.wrappedListHolder.add(0, "foo");
assertTrue(this.wrappedList.contains("foo"));
this.wrappedListHolder.add(1, "bar");
@@ -104,15 +107,15 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
this.wrappedListHolder.add(5, "jaz");
assertEquals(6, this.wrappedList.size());
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(this.wrappedCollection(), adapterCollection);
assertEquals(this.wrappedCollection(), CollectionTools.collection(synchList.iterator()));
assertEquals(this.wrappedCollection(), synchCollection);
}
public void testRemove() {
- Bag synchCollection = new SynchronizedBag(this.adapter);
- List synchList = new SynchronizedList(this.wrappedListHolder);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.adapter);
+ List<String> synchList = new CoordinatedList<String>(this.wrappedListHolder);
this.wrappedListHolder.add(0, "foo");
this.wrappedListHolder.add(1, "bar");
this.wrappedListHolder.add(2, "baz");
@@ -125,7 +128,7 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
assertFalse(this.wrappedList.contains("foo"));
assertEquals(4, this.wrappedList.size());
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(this.wrappedCollection(), adapterCollection);
assertEquals(this.wrappedCollection(), CollectionTools.collection(synchList.iterator()));
assertEquals(this.wrappedCollection(), synchCollection);
@@ -133,9 +136,11 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
public void testListSynch() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {
// override failure
}
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {
// override failure
}
@@ -152,15 +157,17 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
assertFalse(this.wrappedList.contains("foo"));
assertEquals(4, this.wrappedList.size());
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(this.wrappedCollection(), adapterCollection);
}
public void testReplace() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {
// override failure
}
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {
// override failure
}
@@ -168,28 +175,30 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
this.wrappedListHolder.add(0, "foo");
this.wrappedListHolder.add(1, "bar");
this.wrappedListHolder.add(2, "baz");
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(3, adapterCollection.size());
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {
assertEquals("foo", e.items().next());
- assertFalse(CollectionTools.contains((Iterator) ListCollectionValueModelAdapterTests.this.adapter.iterator(), "joo"));
+ assertFalse(CollectionTools.contains(ListCollectionValueModelAdapterTests.this.adapter.iterator(), "joo"));
assertEquals(2, ListCollectionValueModelAdapterTests.this.adapter.size());
}
+ @Override
public void itemsAdded(CollectionChangeEvent e) {
assertEquals("joo", e.items().next());
assertEquals(3, ListCollectionValueModelAdapterTests.this.adapter.size());
}
});
this.wrappedListHolder.set(0, "joo");
- adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(3, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
}
public void testHasListeners() {
assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
- SynchronizedBag synchCollection = new SynchronizedBag(this.adapter);
+ CoordinatedBag<String> synchCollection = new CoordinatedBag<String>(this.adapter);
assertTrue(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, synchCollection);
assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
@@ -201,47 +210,53 @@ public class ListCollectionValueModelAdapterTests extends TestCase {
public void testListChangedToEmpty() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {/* OK */}
});
this.wrappedListHolder.add(0, "foo");
this.wrappedListHolder.add(1, "bar");
this.wrappedListHolder.add(2, "baz");
JList jList = new JList(new ListModelAdapter(this.adapter));
- ((SimpleListValueModel) this.wrappedListHolder).setList(new ArrayList());
+ this.wrappedListHolder.setList(new ArrayList<String>());
assertEquals(0, jList.getModel().getSize());
}
public void testCollectionChangedFromEmpty() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {/* OK */}
});
JList jList = new JList(new ListModelAdapter(this.adapter));
- ArrayList list = new ArrayList();
+ ArrayList<String> list = new ArrayList<String>();
list.add("foo");
list.add("bar");
- ((SimpleListValueModel) this.wrappedListHolder).setList(list);
+ this.wrappedListHolder.setList(list);
assertEquals(2, jList.getModel().getSize());
}
public void testCollectionChangedFromEmptyToEmpty() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {/* OK */}
});
JList jList = new JList(new ListModelAdapter(this.adapter));
- ArrayList list = new ArrayList();
- ((SimpleListValueModel) this.wrappedListHolder).setList(list);
+ ArrayList<String> list = new ArrayList<String>();
+ this.wrappedListHolder.setList(list);
assertEquals(0, jList.getModel().getSize());
}
// ********** inner class **********
- private class TestListener implements CollectionChangeListener {
+ class TestListener implements CollectionChangeListener {
public void itemsAdded(CollectionChangeEvent e) {
fail("unexpected event");
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java
index 184a449d7e..97cc528a11 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,9 +21,9 @@ import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.ListChangeListener;
import org.eclipse.jpt.utility.internal.model.value.ListCurator;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
@@ -32,9 +32,9 @@ public final class ListCuratorTests
extends TestCase
{
private TestSubject subject1;
- private PropertyValueModel subjectHolder1;
+ private WritablePropertyValueModel<TestSubject> subjectHolder1;
- private ListCurator curator;
+ private ListCurator<TestSubject, String> curator;
private ListChangeListener listener1;
private ListChangeEvent event1;
@@ -48,7 +48,7 @@ public final class ListCuratorTests
protected void setUp() throws Exception {
super.setUp();
this.subject1 = new TestSubject(this.subject1Names());
- this.subjectHolder1 = new SimplePropertyValueModel(this.subject1);
+ this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1);
this.curator = this.buildListCurator(this.subjectHolder1);
this.listener1 = this.buildListChangeListener1();
this.curator.addListChangeListener(ListValueModel.LIST_VALUES, this.listener1);
@@ -57,8 +57,8 @@ public final class ListCuratorTests
this.subject2 = new TestSubject(this.subject2Names());
}
- private List subject1Names() {
- ArrayList list = new ArrayList();
+ private List<String> subject1Names() {
+ ArrayList<String> list = new ArrayList<String>();
list.add("alpha");
list.add("bravo");
list.add("charlie");
@@ -66,8 +66,8 @@ public final class ListCuratorTests
return list;
}
- private List subject2Names() {
- ArrayList list = new ArrayList();
+ private List<String> subject2Names() {
+ ArrayList<String> list = new ArrayList<String>();
list.add("echo");
list.add("foxtrot");
list.add("glove");
@@ -75,10 +75,11 @@ public final class ListCuratorTests
return list;
}
- private ListCurator buildListCurator(ValueModel subjectHolder) {
- return new ListCurator(subjectHolder) {
- public Iterator iteratorForRecord() {
- return ((TestSubject) this.subject).strings();
+ private ListCurator<TestSubject, String> buildListCurator(PropertyValueModel<TestSubject> subjectHolder) {
+ return new ListCurator<TestSubject, String>(subjectHolder) {
+ @Override
+ public Iterator<String> iteratorForRecord() {
+ return this.subject.strings();
}
};
}
@@ -157,7 +158,7 @@ public final class ListCuratorTests
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(this.subject1Names().size(), this.event1.index());
assertEquals("echo", this.event1.items().next());
- List stringsPlus = this.subject1Names();
+ List<String> stringsPlus = this.subject1Names();
stringsPlus.add("echo");
assertEquals(stringsPlus, CollectionTools.list(this.curator.listIterator()));
@@ -182,7 +183,7 @@ public final class ListCuratorTests
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
assertEquals(0, this.event1.index());
assertEquals(removedString, this.event1.items().next());
- List stringsMinus = this.subject1Names();
+ List<String> stringsMinus = this.subject1Names();
stringsMinus.remove(0);
assertEquals(stringsMinus, CollectionTools.list(this.curator.listIterator()));
@@ -204,21 +205,21 @@ public final class ListCuratorTests
assertNotNull(this.event1);
assertEquals(this.curator, this.event1.getSource());
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
- List newStrings = this.subject2Names();
+ List<String> newStrings = this.subject2Names();
assertEquals(newStrings, CollectionTools.list(this.curator.listIterator()));
}
public void testPartialListChange() {
- List startingList = CollectionTools.list(this.curator.listIterator());
+ List<String> startingList = CollectionTools.list(this.curator.listIterator());
assertEquals(this.subject1Names(), startingList);
assertNull(this.event1);
- String identicalString = (String) startingList.get(1); // should be "bravo"
- String nonidenticalString = (String) startingList.get(0); // should be "alpha"
- List newStrings = CollectionTools.list(new String[] {new String("bravo"), new String("alpha"), "echo", "delta", "foxtrot"});
+ String identicalString = startingList.get(1); // should be "bravo"
+ String nonidenticalString = startingList.get(0); // should be "alpha"
+ List<String> newStrings = CollectionTools.list(new String[] {new String("bravo"), new String("alpha"), "echo", "delta", "foxtrot"});
this.subject1.setStrings(newStrings);
- List finalList = CollectionTools.list(this.curator.listIterator());
+ List<String> finalList = CollectionTools.list(this.curator.listIterator());
assertNotNull(this.event1);
assertEquals(this.curator, this.event1.getSource());
assertEquals(ListValueModel.LIST_VALUES, this.event1.listName());
@@ -262,26 +263,24 @@ public final class ListCuratorTests
// **************** Inner Class *******************************************
- private class TestSubject
- extends AbstractModel
- {
- private List strings;
+ class TestSubject extends AbstractModel {
+ private List<String> strings;
public TestSubject() {
- this.strings = new ArrayList();
+ this.strings = new ArrayList<String>();
}
- public TestSubject(List strings) {
+ public TestSubject(List<String> strings) {
this();
this.setStrings(strings);
}
public String getString(int index) {
- return (String) this.strings.get(index);
+ return this.strings.get(index);
}
- public ListIterator strings() {
- return new ReadOnlyListIterator(this.strings);
+ public ListIterator<String> strings() {
+ return new ReadOnlyListIterator<String>(this.strings);
}
public void addString(int index, String string) {
@@ -294,7 +293,7 @@ public final class ListCuratorTests
}
public String removeString(int index) {
- String string = (String) this.strings.get(index);
+ String string = this.strings.get(index);
this.removeString(string);
return string;
}
@@ -304,8 +303,8 @@ public final class ListCuratorTests
this.fireStateChanged();
}
- public void setStrings(List strings) {
- this.strings = new ArrayList(strings);
+ public void setStrings(List<String> strings) {
+ this.strings = new ArrayList<String>(strings);
this.fireStateChanged();
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java
index 7113451e42..4e69a71c8c 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,7 +16,7 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class NullCollectionValueModelTests extends TestCase {
- private CollectionValueModel collectionHolder;
+ private CollectionValueModel<Object> collectionHolder;
public NullCollectionValueModelTests(String name) {
super(name);
@@ -25,7 +25,7 @@ public class NullCollectionValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.collectionHolder = NullCollectionValueModel.instance();
+ this.collectionHolder = new NullCollectionValueModel<Object>();
}
@Override
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java
index 94ae069293..1bf206c6ee 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,10 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal.model.value;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.NullListValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
@@ -20,7 +16,7 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class NullListValueModelTests extends TestCase {
- private ListValueModel listHolder;
+ private ListValueModel<Object> listHolder;
public NullListValueModelTests(String name) {
super(name);
@@ -29,7 +25,7 @@ public class NullListValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.listHolder = NullListValueModel.instance();
+ this.listHolder = new NullListValueModel<Object>();
}
@Override
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java
index 00a03bc2d0..4968dbccfd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,7 +16,7 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class NullPropertyValueModelTests extends TestCase {
- private PropertyValueModel valueHolder;
+ private PropertyValueModel<Object> valueHolder;
public NullPropertyValueModelTests(String name) {
super(name);
@@ -25,7 +25,7 @@ public class NullPropertyValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.valueHolder = NullPropertyValueModel.instance();
+ this.valueHolder = new NullPropertyValueModel<Object>();
}
@Override
@@ -34,16 +34,6 @@ public class NullPropertyValueModelTests extends TestCase {
super.tearDown();
}
- public void testSetValue() {
- boolean exCaught = false;
- try {
- this.valueHolder.setValue("foo");
- } catch (UnsupportedOperationException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
public void testValue() {
assertNull(this.valueHolder.value());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
index 8d574a033c..536ba7a45a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
@@ -13,17 +13,17 @@ import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class PropertyAspectAdapterTests extends TestCase {
private TestSubject subject1;
- private PropertyValueModel subjectHolder1;
- private PropertyAspectAdapter aa1;
+ private WritablePropertyValueModel<TestSubject> subjectHolder1;
+ private PropertyAspectAdapter<TestSubject, String> aa1;
private PropertyChangeEvent event1;
private PropertyChangeListener listener1;
@@ -42,34 +42,34 @@ public class PropertyAspectAdapterTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.subject1 = new TestSubject("foo", "test subject 1");
- this.subjectHolder1 = new SimplePropertyValueModel(this.subject1);
+ this.subjectHolder1 = new SimplePropertyValueModel<TestSubject> (this.subject1);
this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
this.listener1 = this.buildValueChangeListener1();
- this.aa1.addPropertyChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1);
this.event1 = null;
this.subject2 = new TestSubject("bar", "test subject 2");
}
- private PropertyAspectAdapter buildAspectAdapter(ValueModel subjectHolder) {
- return new PropertyAspectAdapter(subjectHolder, TestSubject.NAME_PROPERTY) {
+ private PropertyAspectAdapter<TestSubject, String> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
+ return new PropertyAspectAdapter<TestSubject, String>(subjectHolder, TestSubject.NAME_PROPERTY) {
// this is not a aspect adapter - the value is determined by the aspect name
@Override
- protected Object buildValue_() {
+ protected String buildValue_() {
if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) {
- return ((TestSubject) this.subject).getName();
+ return this.subject.getName();
} else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
- return ((TestSubject) this.subject).getDescription();
+ return this.subject.getDescription();
} else {
throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]);
}
}
@Override
- protected void setValue_(Object value) {
+ protected void setValue_(String value) {
if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) {
- ((TestSubject) this.subject).setName((String) value);
+ this.subject.setName(value);
} else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
- ((TestSubject) this.subject).setDescription((String) value);
+ this.subject.setDescription(value);
} else {
throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]);
}
@@ -102,7 +102,7 @@ public class PropertyAspectAdapterTests extends TestCase {
this.subjectHolder1.setValue(this.subject2);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event1.propertyName());
assertEquals("foo", this.event1.oldValue());
assertEquals("bar", this.event1.newValue());
assertEquals("bar", this.aa1.value());
@@ -111,7 +111,7 @@ public class PropertyAspectAdapterTests extends TestCase {
this.subjectHolder1.setValue(null);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event1.propertyName());
assertEquals("bar", this.event1.oldValue());
assertNull(this.event1.newValue());
assertNull(this.aa1.value());
@@ -120,7 +120,7 @@ public class PropertyAspectAdapterTests extends TestCase {
this.subjectHolder1.setValue(this.subject1);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event1.propertyName());
assertEquals(null, this.event1.oldValue());
assertEquals("foo", this.event1.newValue());
assertEquals("foo", this.aa1.value());
@@ -133,7 +133,7 @@ public class PropertyAspectAdapterTests extends TestCase {
this.subject1.setName("baz");
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event1.propertyName());
assertEquals("foo", this.event1.oldValue());
assertEquals("baz", this.event1.newValue());
assertEquals("baz", this.aa1.value());
@@ -142,7 +142,7 @@ public class PropertyAspectAdapterTests extends TestCase {
this.subject1.setName(null);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event1.propertyName());
assertEquals("baz", this.event1.oldValue());
assertEquals(null, this.event1.newValue());
assertEquals(null, this.aa1.value());
@@ -151,7 +151,7 @@ public class PropertyAspectAdapterTests extends TestCase {
this.subject1.setName("foo");
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event1.propertyName());
assertEquals(null, this.event1.oldValue());
assertEquals("foo", this.event1.newValue());
assertEquals("foo", this.aa1.value());
@@ -166,17 +166,17 @@ public class PropertyAspectAdapterTests extends TestCase {
assertEquals("foo", this.subject1.getName());
assertEquals("foo", this.aa1.value());
- this.aa1.removePropertyChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1);
assertEquals(null, this.aa1.value());
- this.aa1.addPropertyChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1);
assertEquals("foo", this.aa1.value());
- this.aa1.removePropertyChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1);
this.subjectHolder1.setValue(this.subject2);
assertEquals(null, this.aa1.value());
- this.aa1.addPropertyChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1);
assertEquals("bar", this.aa1.value());
}
@@ -187,27 +187,27 @@ public class PropertyAspectAdapterTests extends TestCase {
}
public void testHasListeners() {
- assertTrue(this.aa1.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertTrue(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY));
- this.aa1.removePropertyChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1);
assertFalse(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY));
- assertFalse(this.aa1.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
PropertyChangeListener listener2 = this.buildValueChangeListener1();
this.aa1.addPropertyChangeListener(listener2);
- assertTrue(this.aa1.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertTrue(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY));
this.aa1.removePropertyChangeListener(listener2);
assertFalse(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY));
- assertFalse(this.aa1.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
}
public void testMultipleAspectAdapter() {
TestSubject testSubject = new TestSubject("fred", "husband");
- PropertyValueModel testSubjectHolder = new SimplePropertyValueModel(testSubject);
- PropertyValueModel testAA = this.buildMultipleAspectAdapter(testSubjectHolder);
+ WritablePropertyValueModel<TestSubject> testSubjectHolder = new SimplePropertyValueModel<TestSubject>(testSubject);
+ WritablePropertyValueModel<String> testAA = this.buildMultipleAspectAdapter(testSubjectHolder);
PropertyChangeListener testListener = this.buildMultipleValueChangeListener();
- testAA.addPropertyChangeListener(ValueModel.VALUE, testListener);
+ testAA.addPropertyChangeListener(PropertyValueModel.VALUE, testListener);
assertEquals("fred:husband", testAA.value());
this.multipleValueEvent = null;
@@ -223,12 +223,11 @@ public class PropertyAspectAdapterTests extends TestCase {
assertEquals("wilma:wife", this.multipleValueEvent.newValue());
}
- private PropertyValueModel buildMultipleAspectAdapter(ValueModel subjectHolder) {
- return new PropertyAspectAdapter(subjectHolder, TestSubject.NAME_PROPERTY, TestSubject.DESCRIPTION_PROPERTY) {
+ private WritablePropertyValueModel<String> buildMultipleAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
+ return new PropertyAspectAdapter<TestSubject, String>(subjectHolder, TestSubject.NAME_PROPERTY, TestSubject.DESCRIPTION_PROPERTY) {
@Override
- protected Object buildValue_() {
- TestSubject ts = (TestSubject) this.subject;
- return ts.getName() + ":" + ts.getDescription();
+ protected String buildValue_() {
+ return this.subject.getName() + ":" + this.subject.getDescription();
}
};
}
@@ -253,10 +252,10 @@ public class PropertyAspectAdapterTests extends TestCase {
*/
public void testCustomBuildValueWithNullSubject() {
TestSubject customSubject = new TestSubject("fred", "laborer");
- PropertyValueModel customSubjectHolder = new SimplePropertyValueModel(customSubject);
- PropertyValueModel customAA = this.buildCustomAspectAdapter(customSubjectHolder);
+ WritablePropertyValueModel<TestSubject> customSubjectHolder = new SimplePropertyValueModel<TestSubject>(customSubject);
+ WritablePropertyValueModel<String> customAA = this.buildCustomAspectAdapter(customSubjectHolder);
PropertyChangeListener customListener = this.buildCustomValueChangeListener();
- customAA.addPropertyChangeListener(ValueModel.VALUE, customListener);
+ customAA.addPropertyChangeListener(PropertyValueModel.VALUE, customListener);
assertEquals("fred", customAA.value());
this.customValueEvent = null;
@@ -273,12 +272,11 @@ public class PropertyAspectAdapterTests extends TestCase {
assertEquals("<unnamed>", this.customValueEvent.newValue());
}
- private PropertyValueModel buildCustomAspectAdapter(ValueModel subjectHolder) {
- return new PropertyAspectAdapter(subjectHolder, TestSubject.NAME_PROPERTY) {
+ private WritablePropertyValueModel<String> buildCustomAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
+ return new PropertyAspectAdapter<TestSubject, String>(subjectHolder, TestSubject.NAME_PROPERTY) {
@Override
- protected Object buildValue() {
- TestSubject ts = (TestSubject) this.subject;
- return (ts == null) ? "<unnamed>" : ts.getName();
+ protected String buildValue() {
+ return (this.subject == null) ? "<unnamed>" : this.subject.getName();
}
};
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java
index dc837b5d67..254a8b7708 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,9 +10,9 @@
package org.eclipse.jpt.utility.tests.internal.model.value;
import java.util.Collection;
-import java.util.Iterator;
+
import javax.swing.JList;
-import junit.framework.TestCase;
+
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator;
@@ -21,14 +21,16 @@ import org.eclipse.jpt.utility.internal.model.event.CollectionChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.CollectionChangeListener;
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyCollectionValueModelAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
+
public class PropertyCollectionValueModelAdapterTests extends TestCase {
- private CollectionValueModel adapter;
- private PropertyValueModel wrappedValueHolder;
+ private CollectionValueModel<String> adapter;
+ private WritablePropertyValueModel<String> wrappedValueHolder;
public PropertyCollectionValueModelAdapterTests(String name) {
super(name);
@@ -37,12 +39,12 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.wrappedValueHolder = new SimplePropertyValueModel();
- this.adapter = new PropertyCollectionValueModelAdapter(this.wrappedValueHolder);
+ this.wrappedValueHolder = new SimplePropertyValueModel<String>();
+ this.adapter = new PropertyCollectionValueModelAdapter<String>(this.wrappedValueHolder);
}
- private Collection wrappedCollection() {
- return CollectionTools.collection(new SingleElementIterator(this.wrappedValueHolder.value()));
+ private Collection<String> wrappedCollection() {
+ return CollectionTools.collection(new SingleElementIterator<String>(this.wrappedValueHolder.value()));
}
@Override
@@ -53,10 +55,11 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
public void testIterator() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
});
this.wrappedValueHolder.setValue("foo");
- Collection adapterCollection = CollectionTools.collection(this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(1, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
assertEquals("foo", adapterCollection.iterator().next());
@@ -64,22 +67,23 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
public void testStaleValue() {
CollectionChangeListener listener = new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
};
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener);
this.wrappedValueHolder.setValue("foo");
- Collection adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(1, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
assertEquals("foo", adapterCollection.iterator().next());
this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, listener);
- adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(0, adapterCollection.size());
- assertEquals(new HashBag(), adapterCollection);
+ assertEquals(new HashBag<String>(), adapterCollection);
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener);
- adapterCollection = CollectionTools.collection((Iterator) this.adapter.iterator());
+ adapterCollection = CollectionTools.collection(this.adapter.iterator());
assertEquals(1, adapterCollection.size());
assertEquals(this.wrappedCollection(), adapterCollection);
assertEquals("foo", adapterCollection.iterator().next());
@@ -87,7 +91,7 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
public void testHasListeners() {
assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
- SynchronizedBag synchCollection = new SynchronizedBag(this.adapter);
+ CoordinatedBag<String> synchCollection = new CoordinatedBag<String>(this.adapter);
assertTrue(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, synchCollection);
assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
@@ -99,7 +103,9 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
public void testListChangedToEmpty() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(CollectionChangeEvent e) {/* OK */}
});
this.wrappedValueHolder.setValue("foo");
@@ -110,6 +116,7 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
public void testCollectionChangedFromEmpty() {
this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() {
+ @Override
public void itemsAdded(CollectionChangeEvent e) {/* OK */}
});
JList jList = new JList(new ListModelAdapter(this.adapter));
@@ -129,10 +136,7 @@ public class PropertyCollectionValueModelAdapterTests extends TestCase {
// ********** member class **********
- private static class TestListener implements CollectionChangeListener {
- TestListener() {
- super();
- }
+ static class TestListener implements CollectionChangeListener {
public void collectionChanged(CollectionChangeEvent e) {
fail("unexpected event");
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java
index d1a994fb71..66b77bd700 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,9 +11,8 @@ package org.eclipse.jpt.utility.tests.internal.model.value;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
-import junit.framework.TestCase;
+
import org.eclipse.jpt.utility.internal.Bag;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.HashBag;
@@ -23,12 +22,14 @@ import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
+
public class SimpleCollectionValueModelTests extends TestCase {
- private SimpleCollectionValueModel bagHolder;
+ private SimpleCollectionValueModel<String> bagHolder;
CollectionChangeEvent bagEvent;
String bagEventType;
- private SimpleCollectionValueModel setHolder;
+ private SimpleCollectionValueModel<String> setHolder;
CollectionChangeEvent setEvent;
String setEventType;
@@ -45,8 +46,8 @@ public class SimpleCollectionValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.bagHolder = new SimpleCollectionValueModel(this.buildBag());
- this.setHolder = new SimpleCollectionValueModel(this.buildSet());
+ this.bagHolder = new SimpleCollectionValueModel<String>(this.buildBag());
+ this.setHolder = new SimpleCollectionValueModel<String>(this.buildSet());
}
private Bag<String> buildBag() {
@@ -94,28 +95,28 @@ public class SimpleCollectionValueModelTests extends TestCase {
}
public void testSize() {
- assertEquals(this.buildBag().size(), CollectionTools.size((Iterator) this.bagHolder.iterator()));
- assertEquals(this.buildSet().size(), CollectionTools.size((Iterator) this.setHolder.iterator()));
+ assertEquals(this.buildBag().size(), CollectionTools.size(this.bagHolder.iterator()));
+ assertEquals(this.buildSet().size(), CollectionTools.size(this.setHolder.iterator()));
}
private boolean bagHolderContains(Object item) {
- return CollectionTools.contains((Iterator) this.bagHolder.iterator(), item);
+ return CollectionTools.contains(this.bagHolder.iterator(), item);
}
private boolean setHolderContains(Object item) {
- return CollectionTools.contains((Iterator) this.setHolder.iterator(), item);
+ return CollectionTools.contains(this.setHolder.iterator(), item);
}
private boolean bagHolderContainsAll(Collection<String> items) {
- return CollectionTools.containsAll((Iterator) this.bagHolder.iterator(), items);
+ return CollectionTools.containsAll(this.bagHolder.iterator(), items);
}
private boolean setHolderContainsAll(Collection<String> items) {
- return CollectionTools.containsAll((Iterator) this.setHolder.iterator(), items);
+ return CollectionTools.containsAll(this.setHolder.iterator(), items);
}
private boolean bagHolderContainsAny(Collection<String> items) {
- Bag bag = CollectionTools.bag((Iterator) this.bagHolder.iterator());
+ Bag<String> bag = CollectionTools.bag(this.bagHolder.iterator());
for (String string : items) {
if (bag.contains(string)) {
return true;
@@ -125,7 +126,7 @@ public class SimpleCollectionValueModelTests extends TestCase {
}
private boolean setHolderContainsAny(Collection<String> items) {
- Set set = CollectionTools.set((Iterator) this.setHolder.iterator());
+ Set<String> set = CollectionTools.set(this.setHolder.iterator());
for (String string : items) {
if (set.contains(string)) {
return true;
@@ -195,7 +196,7 @@ public class SimpleCollectionValueModelTests extends TestCase {
public void testSetCollection() {
assertTrue(this.bagHolderContains("bar"));
assertFalse(this.bagHolderContains("jar"));
- ((SimpleCollectionValueModel) this.bagHolder).setCollection(this.buildAddItems());
+ this.bagHolder.setCollection(this.buildAddItems());
assertFalse(this.bagHolderContains("bar"));
assertTrue(this.bagHolderContains("jar"));
@@ -204,12 +205,12 @@ public class SimpleCollectionValueModelTests extends TestCase {
this.bagHolder.remove(null);
assertFalse(this.bagHolderContains(null));
- ((SimpleCollectionValueModel) this.bagHolder).setCollection(new HashBag());
+ this.bagHolder.setCollection(new HashBag<String>());
assertFalse(this.bagHolderContains("jar"));
assertTrue(this.setHolderContains("bar"));
assertFalse(this.setHolderContains("jar"));
- ((SimpleCollectionValueModel) this.setHolder).setCollection(this.buildAddItems());
+ this.setHolder.setCollection(this.buildAddItems());
assertFalse(this.setHolderContains("bar"));
assertTrue(this.setHolderContains("jar"));
@@ -218,7 +219,7 @@ public class SimpleCollectionValueModelTests extends TestCase {
this.setHolder.remove(null);
assertFalse(this.setHolderContains(null));
- ((SimpleCollectionValueModel) this.setHolder).setCollection(new HashBag());
+ this.setHolder.setCollection(new HashBag<String>());
assertFalse(this.setHolderContains("jar"));
}
@@ -276,7 +277,7 @@ public class SimpleCollectionValueModelTests extends TestCase {
this.bagEvent = null;
this.bagEventType = null;
- ((SimpleCollectionValueModel) this.bagHolder).setCollection(this.buildBag());
+ this.bagHolder.setCollection(this.buildBag());
this.verifyBagEvent(CHANGE);
this.bagEvent = null;
@@ -333,7 +334,7 @@ public class SimpleCollectionValueModelTests extends TestCase {
this.setEvent = null;
this.setEventType = null;
- ((SimpleCollectionValueModel) this.setHolder).setCollection(this.buildSet());
+ this.setHolder.setCollection(this.buildSet());
this.verifySetEvent(CHANGE);
this.setEvent = null;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java
index 01f8480440..d4636ea74c 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent;
@@ -25,7 +24,7 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class SimpleListValueModelTests extends TestCase {
- private SimpleListValueModel listHolder;
+ private SimpleListValueModel<String> listHolder;
ListChangeEvent event;
String eventType;
@@ -44,32 +43,32 @@ public class SimpleListValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.listHolder = new SimpleListValueModel(this.buildList());
+ this.listHolder = new SimpleListValueModel<String>(this.buildList());
}
- private List buildList() {
- List result = new ArrayList();
+ private List<String> buildList() {
+ List<String> result = new ArrayList<String>();
result.add("foo");
result.add("bar");
result.add("baz");
return result;
}
- private List buildAddList() {
- List result = new ArrayList();
+ private List<String> buildAddList() {
+ List<String> result = new ArrayList<String>();
result.add("joo");
result.add("jar");
result.add("jaz");
return result;
}
- private List buildRemoveList() {
- List result = new ArrayList();
- result.add("foo");
- result.add("bar");
- return result;
- }
-
+// private List<String> buildRemoveList() {
+// List<String> result = new ArrayList<String>();
+// result.add("foo");
+// result.add("bar");
+// return result;
+// }
+//
@Override
protected void tearDown() throws Exception {
TestTools.clear(this);
@@ -88,13 +87,13 @@ public class SimpleListValueModelTests extends TestCase {
return CollectionTools.contains(this.listHolder.listIterator(), item);
}
- private boolean listContainsAll(Collection items) {
+ private boolean listContainsAll(Collection<String> items) {
return CollectionTools.containsAll(this.listHolder.listIterator(), items);
}
- private boolean listContainsAny(Collection items) {
- List list = CollectionTools.list(this.listHolder.iterator());
- for (Iterator stream = items.iterator(); stream.hasNext(); ) {
+ private boolean listContainsAny(Collection<String> items) {
+ List<String> list = CollectionTools.list(this.listHolder.iterator());
+ for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) {
if (list.contains(stream.next())) {
return true;
}
@@ -130,14 +129,14 @@ public class SimpleListValueModelTests extends TestCase {
}
public void testSetValues() {
- List newList = new ArrayList();
+ List<String> newList = new ArrayList<String>();
newList.add("joo");
newList.add("jar");
newList.add("jaz");
assertTrue(this.listContains("bar"));
assertFalse(this.listContains("jar"));
- ((SimpleListValueModel) this.listHolder).setList(newList);
+ this.listHolder.setList(newList);
assertFalse(this.listContains("bar"));
assertTrue(this.listContains("jar"));
@@ -146,7 +145,7 @@ public class SimpleListValueModelTests extends TestCase {
this.listHolder.remove(1);
assertFalse(this.listContains(null));
- ((SimpleListValueModel) this.listHolder).setList(new ArrayList());
+ this.listHolder.setList(new ArrayList<String>());
assertFalse(this.listContains("jar"));
}
@@ -183,7 +182,7 @@ public class SimpleListValueModelTests extends TestCase {
this.event = null;
this.eventType = null;
- ((SimpleListValueModel) this.listHolder).setList(this.buildList());
+ this.listHolder.setList(this.buildList());
this.verifyEvent(CHANGE);
this.event = null;
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java
index b4c0707f38..bcbd9a6410 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,15 +11,15 @@ package org.eclipse.jpt.utility.tests.internal.model.value;
import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class SimplePropertyValueModelTests extends TestCase {
- private PropertyValueModel objectHolder;
+ private WritablePropertyValueModel<String> objectHolder;
PropertyChangeEvent event;
@@ -30,7 +30,7 @@ public class SimplePropertyValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.objectHolder = new SimplePropertyValueModel("foo");
+ this.objectHolder = new SimplePropertyValueModel<String>("foo");
}
@Override
@@ -58,7 +58,7 @@ public class SimplePropertyValueModelTests extends TestCase {
}
public void testPropertyChange2() {
- this.objectHolder.addPropertyChangeListener(ValueModel.VALUE, this.buildListener());
+ this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
this.verifyPropertyChange();
}
@@ -86,7 +86,7 @@ public class SimplePropertyValueModelTests extends TestCase {
private void verifyEvent(Object oldValue, Object newValue) {
assertEquals(this.objectHolder, this.event.getSource());
- assertEquals(ValueModel.VALUE, this.event.propertyName());
+ assertEquals(PropertyValueModel.VALUE, this.event.propertyName());
assertEquals(oldValue, this.event.oldValue());
assertEquals(newValue, this.event.newValue());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java
index cd77e2fef1..3e7c761037 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
-import java.util.ListIterator;
import java.util.TreeSet;
import org.eclipse.jpt.utility.internal.Bag;
@@ -23,7 +22,6 @@ import org.eclipse.jpt.utility.internal.ReverseComparator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.ListChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter;
@@ -32,9 +30,9 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class SortedListValueModelAdapterTests extends TestCase {
- private SortedListValueModelAdapter adapter;
- private SimpleCollectionValueModel wrappedCollectionHolder;
- private Collection wrappedCollection;
+ private SortedListValueModelAdapter<String> adapter;
+ private SimpleCollectionValueModel<String> wrappedCollectionHolder;
+ private Collection<String> wrappedCollection;
public SortedListValueModelAdapterTests(String name) {
@@ -44,9 +42,9 @@ public class SortedListValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.wrappedCollection = new HashBag();
- this.wrappedCollectionHolder = new SimpleCollectionValueModel(this.wrappedCollection);
- this.adapter = new SortedListValueModelAdapter(this.wrappedCollectionHolder);
+ this.wrappedCollection = new HashBag<String>();
+ this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>(this.wrappedCollection);
+ this.adapter = new SortedListValueModelAdapter<String>(this.wrappedCollectionHolder);
}
@Override
@@ -55,21 +53,23 @@ public class SortedListValueModelAdapterTests extends TestCase {
super.tearDown();
}
- private void verifyList(Collection expected, ListValueModel actual) {
+ private void verifyList(Collection<String> expected, ListValueModel<String> actual) {
this.verifyList(expected, actual, null);
}
- private void verifyList(Collection expected, ListValueModel actual, Comparator comparator) {
- Collection sortedSet = new TreeSet(comparator);
+ private void verifyList(Collection<String> expected, ListValueModel<String> actual, Comparator<String> comparator) {
+ Collection<String> sortedSet = new TreeSet<String>(comparator);
sortedSet.addAll(expected);
- List expectedList = new ArrayList(sortedSet);
- List actualList = CollectionTools.list(actual.iterator());
+ List<String> expectedList = new ArrayList<String>(sortedSet);
+ List<String> actualList = CollectionTools.list(actual.iterator());
assertEquals(expectedList, actualList);
}
public void testAdd() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsReplaced(ListChangeEvent e) {/* OK */}
});
this.wrappedCollectionHolder.add("foo");
@@ -80,8 +80,8 @@ public class SortedListValueModelAdapterTests extends TestCase {
}
public void testAddItem() {
- List synchList = new SynchronizedList(this.adapter);
- Bag synchCollection = new SynchronizedBag(this.wrappedCollectionHolder);
+ List<String> synchList = new CoordinatedList<String>(this.adapter);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder);
this.wrappedCollectionHolder.add("foo");
assertTrue(this.wrappedCollection.contains("foo"));
this.wrappedCollectionHolder.add("bar");
@@ -97,8 +97,8 @@ public class SortedListValueModelAdapterTests extends TestCase {
}
public void testRemoveItem() {
- List synchList = new SynchronizedList(this.adapter);
- Bag synchCollection = new SynchronizedBag(this.wrappedCollectionHolder);
+ List<String> synchList = new CoordinatedList<String>(this.adapter);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder);
this.wrappedCollectionHolder.add("foo");
this.wrappedCollectionHolder.add("bar");
this.wrappedCollectionHolder.add("baz");
@@ -118,8 +118,11 @@ public class SortedListValueModelAdapterTests extends TestCase {
public void testListSynch() {
this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() {
+ @Override
public void itemsAdded(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsRemoved(ListChangeEvent e) {/* OK */}
+ @Override
public void itemsReplaced(ListChangeEvent e) {/* OK */}
});
this.wrappedCollectionHolder.add("foo");
@@ -138,8 +141,8 @@ public class SortedListValueModelAdapterTests extends TestCase {
}
public void testSetComparator() {
- List synchList = new SynchronizedList(this.adapter);
- Bag synchCollection = new SynchronizedBag(this.wrappedCollectionHolder);
+ List<String> synchList = new CoordinatedList<String>(this.adapter);
+ Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder);
this.wrappedCollectionHolder.add("foo");
assertTrue(this.wrappedCollection.contains("foo"));
this.wrappedCollectionHolder.add("bar");
@@ -153,15 +156,15 @@ public class SortedListValueModelAdapterTests extends TestCase {
assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator()));
assertEquals(this.wrappedCollection, synchCollection);
- this.adapter.setComparator(new ReverseComparator());
- this.verifyList(this.wrappedCollection, this.adapter, new ReverseComparator());
+ this.adapter.setComparator(new ReverseComparator<String>());
+ this.verifyList(this.wrappedCollection, this.adapter, new ReverseComparator<String>());
assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator()));
assertEquals(this.wrappedCollection, synchCollection);
}
public void testHasListeners() {
assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- SynchronizedList synchList = new SynchronizedList(this.adapter);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(this.adapter);
assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, synchList);
assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
@@ -171,7 +174,7 @@ public class SortedListValueModelAdapterTests extends TestCase {
assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
}
- private class TestListChangeListener implements ListChangeListener {
+ class TestListChangeListener implements ListChangeListener {
public void itemsAdded(ListChangeEvent e) {
fail("unexpected event");
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java
new file mode 100644
index 0000000000..e5c7a1e449
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.Collection;
+
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.HashBag;
+import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
+import org.eclipse.jpt.utility.internal.model.value.StaticCollectionValueModel;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class StaticCollectionValueModelTests extends TestCase {
+
+ private static final Collection<String> COLLECTION = buildCollection();
+ private static Collection<String> buildCollection() {
+ Collection<String> result = new HashBag<String>();
+ result.add("foo");
+ result.add("bar");
+ return result;
+ }
+
+ private CollectionValueModel<String> collectionHolder;
+
+
+ public StaticCollectionValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.collectionHolder = this.buildCollectionHolder();
+ }
+
+ private CollectionValueModel<String> buildCollectionHolder() {
+ return new StaticCollectionValueModel<String>(COLLECTION);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testIterator() {
+ assertEquals(buildCollection(), CollectionTools.bag(this.collectionHolder.iterator()));
+ }
+
+ public void testSize() {
+ assertEquals(buildCollection().size(), this.collectionHolder.size());
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java
new file mode 100644
index 0000000000..f2a666de05
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
+import org.eclipse.jpt.utility.internal.model.value.StaticListValueModel;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class StaticListValueModelTests extends TestCase {
+
+ private static final List<String> LIST = buildList();
+ private static List<String> buildList() {
+ List<String> result = new ArrayList<String>();
+ result.add("foo");
+ result.add("bar");
+ return result;
+ }
+
+ private ListValueModel<String> listHolder;
+
+
+ public StaticListValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.listHolder = new StaticListValueModel<String>(LIST);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testGet() {
+ List<String> expected = buildList();
+ for (int i = 0; i < this.listHolder.size(); i++) {
+ assertEquals(expected.get(i), this.listHolder.get(i));
+ }
+ }
+
+ public void testIterator() {
+ assertEquals(buildList(), CollectionTools.list(this.listHolder.listIterator()));
+ }
+
+ public void testSize() {
+ assertEquals(buildList().size(), this.listHolder.size());
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java
index c9b65bd21b..505eff6434 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,14 +9,15 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal.model.value;
-import org.eclipse.jpt.utility.internal.model.value.AbstractReadOnlyPropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class StaticValueModelTests extends TestCase {
- private ValueModel objectHolder;
+ private PropertyValueModel<String> objectHolder;
+ private static final PropertyValueModel<String> OBJECT_HOLDER = new StaticPropertyValueModel<String>("foo");
public StaticValueModelTests(String name) {
@@ -26,15 +27,7 @@ public class StaticValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.objectHolder = this.buildObjectHolder();
- }
-
- private ValueModel buildObjectHolder() {
- return new AbstractReadOnlyPropertyValueModel() {
- public Object value() {
- return "foo";
- }
- };
+ this.objectHolder = OBJECT_HOLDER;
}
@Override
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java
index bc213b23b1..bdfd9cd728 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,7 +14,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.Transformer;
@@ -29,8 +28,8 @@ import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class TransformationListValueModelAdapterTests extends TestCase {
- private SimpleListValueModel listHolder;
- private ListValueModel transformedListHolder;
+ private SimpleListValueModel<String> listHolder;
+ private ListValueModel<String> transformedListHolder;
ListChangeEvent event;
String eventType;
@@ -49,26 +48,25 @@ public class TransformationListValueModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.listHolder = new SimpleListValueModel(this.buildList());
+ this.listHolder = new SimpleListValueModel<String>(this.buildList());
this.transformedListHolder = this.buildTransformedListHolder(this.listHolder);
}
- private List buildList() {
- List result = new ArrayList();
+ private List<String> buildList() {
+ List<String> result = new ArrayList<String>();
result.add("foo");
result.add("bar");
result.add("baz");
return result;
}
- private List buildTransformedList() {
+ private List<String> buildTransformedList() {
return this.transform(this.buildList());
}
- private List transform(List list) {
- List result = new ArrayList(list.size());
- for (Iterator stream = list.iterator(); stream.hasNext(); ) {
- String string = (String) stream.next();
+ private List<String> transform(List<String> list) {
+ List<String> result = new ArrayList<String>(list.size());
+ for (String string : list) {
if (string == null) {
result.add(null);
} else {
@@ -78,33 +76,34 @@ public class TransformationListValueModelAdapterTests extends TestCase {
return result;
}
- private List buildAddList() {
- List result = new ArrayList();
+ private List<String> buildAddList() {
+ List<String> result = new ArrayList<String>();
result.add("joo");
result.add("jar");
result.add("jaz");
return result;
}
- private List buildTransformedAddList() {
+ private List<String> buildTransformedAddList() {
return this.transform(this.buildAddList());
}
- private List buildRemoveList() {
- List result = new ArrayList();
- result.add("foo");
- result.add("bar");
- return result;
- }
-
- private List buildTransformedRemoveList() {
- return this.transform(this.buildRemoveList());
- }
-
- ListValueModel buildTransformedListHolder(ListValueModel lvm) {
- return new TransformationListValueModelAdapter(lvm) {
- protected Object transformItem(Object item) {
- return (item == null) ? null : ((String) item).toUpperCase();
+// private List<String> buildRemoveList() {
+// List<String> result = new ArrayList<String>();
+// result.add("foo");
+// result.add("bar");
+// return result;
+// }
+//
+// private List<String> buildTransformedRemoveList() {
+// return this.transform(this.buildRemoveList());
+// }
+//
+ ListValueModel<String> buildTransformedListHolder(ListValueModel<String> lvm) {
+ return new TransformationListValueModelAdapter<String, String>(lvm) {
+ @Override
+ protected String transformItem(String s) {
+ return (s == null) ? null : s.toUpperCase();
}
};
}
@@ -138,13 +137,13 @@ public class TransformationListValueModelAdapterTests extends TestCase {
return CollectionTools.contains(this.transformedListHolder.iterator(), item);
}
- private boolean transformedListContainsAll(Collection items) {
+ private boolean transformedListContainsAll(Collection<String> items) {
return CollectionTools.containsAll(this.transformedListHolder.iterator(), items);
}
- private boolean transformedListContainsAny(Collection items) {
- List transformedList = CollectionTools.list(this.transformedListHolder.iterator());
- for (Iterator stream = items.iterator(); stream.hasNext(); ) {
+ private boolean transformedListContainsAny(Collection<String> items) {
+ List<String> transformedList = CollectionTools.list(this.transformedListHolder.iterator());
+ for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) {
if (transformedList.contains(stream.next())) {
return true;
}
@@ -304,13 +303,14 @@ public class TransformationListValueModelAdapterTests extends TestCase {
public TransformerTests(String name) {
super(name);
}
- ListValueModel buildTransformedListHolder(ListValueModel lvm) {
- return new TransformationListValueModelAdapter(lvm, this.buildTransformer());
+ @Override
+ ListValueModel<String> buildTransformedListHolder(ListValueModel<String> lvm) {
+ return new TransformationListValueModelAdapter<String, String>(lvm, this.buildTransformer());
}
- private Transformer buildTransformer() {
- return new Transformer() {
- public Object transform(Object o) {
- return (o == null) ? null : ((String) o).toUpperCase();
+ private Transformer<String, String> buildTransformer() {
+ return new Transformer<String, String>() {
+ public String transform(String s) {
+ return (s == null) ? null : s.toUpperCase();
}
};
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
index 536f6b2dd6..6c293edf9a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,17 +15,17 @@ import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.TransformationWritablePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class TransformationPropertyValueModelTests extends TestCase {
- private PropertyValueModel objectHolder;
+ private WritablePropertyValueModel<String> objectHolder;
PropertyChangeEvent event;
- private PropertyValueModel transformationObjectHolder;
+ private WritablePropertyValueModel<String> transformationObjectHolder;
PropertyChangeEvent transformationEvent;
public TransformationPropertyValueModelTests(String name) {
@@ -35,17 +35,17 @@ public class TransformationPropertyValueModelTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.objectHolder = new SimplePropertyValueModel("foo");
- this.transformationObjectHolder = new TransformationPropertyValueModel(this.objectHolder, this.buildTransformer());
+ this.objectHolder = new SimplePropertyValueModel<String>("foo");
+ this.transformationObjectHolder = new TransformationWritablePropertyValueModel<String, String>(this.objectHolder, this.buildTransformer());
}
- private BidiTransformer buildTransformer() {
- return new BidiTransformer() {
- public Object transform(Object o) {
- return (o == null) ? null : ((String) o).toUpperCase();
+ private BidiTransformer<String, String> buildTransformer() {
+ return new BidiTransformer<String, String>() {
+ public String transform(String s) {
+ return (s == null) ? null : s.toUpperCase();
}
- public Object reverseTransform(Object o) {
- return (o == null) ? null : ((String) o).toLowerCase();
+ public String reverseTransform(String s) {
+ return (s == null) ? null : s.toLowerCase();
}
};
}
@@ -96,17 +96,17 @@ public class TransformationPropertyValueModelTests extends TestCase {
}
public void testLazyListening() {
- assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
PropertyChangeListener listener = this.buildTransformationListener();
this.transformationObjectHolder.addPropertyChangeListener(listener);
- assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.transformationObjectHolder.removePropertyChangeListener(listener);
- assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
- this.transformationObjectHolder.addPropertyChangeListener(ValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(ValueModel.VALUE));
- this.transformationObjectHolder.removePropertyChangeListener(ValueModel.VALUE, listener);
- assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(ValueModel.VALUE));
+ this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
}
public void testPropertyChange1() {
@@ -116,8 +116,8 @@ public class TransformationPropertyValueModelTests extends TestCase {
}
public void testPropertyChange2() {
- this.objectHolder.addPropertyChangeListener(ValueModel.VALUE, this.buildListener());
- this.transformationObjectHolder.addPropertyChangeListener(ValueModel.VALUE, this.buildTransformationListener());
+ this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener());
this.verifyPropertyChanges();
}
@@ -177,7 +177,7 @@ public class TransformationPropertyValueModelTests extends TestCase {
private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) {
assertEquals(source, e.getSource());
- assertEquals(ValueModel.VALUE, e.propertyName());
+ assertEquals(PropertyValueModel.VALUE, e.propertyName());
assertEquals(oldValue, e.oldValue());
assertEquals(newValue, e.newValue());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java
index 8b14d7aa58..80555e8770 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,19 +21,19 @@ import org.eclipse.jpt.utility.internal.iterators.TreeIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.event.TreeChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.TreeChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.TreeAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.TreeValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class TreeAspectAdapterTests extends TestCase {
private TestSubject subject1;
- private PropertyValueModel subjectHolder1;
- private TreeAspectAdapter aa1;
+ private WritablePropertyValueModel<TestSubject> subjectHolder1;
+ private TreeAspectAdapter<TestSubject, TestNode[]> aa1;
private TreeChangeEvent event1;
private TreeChangeListener listener1;
@@ -66,7 +66,7 @@ public class TreeAspectAdapterTests extends TestCase {
this.subject1.addDescription(node, "description 1.2.1");
node = this.subject1.addDescription(root, "description 1.3");
- this.subjectHolder1 = new SimplePropertyValueModel(this.subject1);
+ this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1);
this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
this.listener1 = this.buildValueChangeListener1();
this.aa1.addTreeChangeListener(TreeValueModel.NODES, this.listener1);
@@ -91,18 +91,18 @@ public class TreeAspectAdapterTests extends TestCase {
node = this.subject2.addDescription(root, "description 2.3");
}
- private TreeAspectAdapter buildAspectAdapter(ValueModel subjectHolder) {
- return new TreeAspectAdapter(subjectHolder, TestSubject.NAMES_TREE) {
+ private TreeAspectAdapter<TestSubject, TestNode[]> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
+ return new TreeAspectAdapter<TestSubject, TestNode[]>(subjectHolder, TestSubject.NAMES_TREE) {
// this is not a typical aspect adapter - the value is determined by the aspect name
@Override
- protected Iterator nodes_() {
- if (this.treeName == TestSubject.NAMES_TREE) {
- return ((TestSubject) this.subject).namePaths();
+ protected Iterator<TestNode[]> nodes_() {
+ if (this.treeNames[0] == TestSubject.NAMES_TREE) {
+ return this.subject.namePaths();
}
- if (this.treeName == TestSubject.DESCRIPTIONS_TREE) {
- return ((TestSubject) this.subject).descriptionPaths();
+ if (this.treeNames[0] == TestSubject.DESCRIPTIONS_TREE) {
+ return this.subject.descriptionPaths();
}
- throw new IllegalStateException("invalid aspect name: " + this.treeName);
+ throw new IllegalStateException("invalid aspect name: " + this.treeNames[0]);
}
};
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java
new file mode 100644
index 0000000000..6bd028a273
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.internal.model.event.StateChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.internal.model.listener.StateChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.ValueCollectionAdapter;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class ValueCollectionAdapterTests extends TestCase {
+ private Junk junk;
+ private SimplePropertyValueModel<Junk> junkHolder;
+ private ValueCollectionAdapter<Junk> junkHolder2;
+
+
+ public ValueCollectionAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.junk = new Junk("foo");
+ this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk);
+ this.junkHolder2 = new ValueCollectionAdapter<Junk>(this.junkHolder, Junk.STUFF_COLLECTION);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testWrappedPVM() {
+ Junk junk2 = new Junk("bar");
+ LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2);
+ this.junkHolder2.addPropertyChangeListener(l);
+ this.junkHolder.setValue(junk2);
+ assertTrue(l.eventReceived());
+ }
+
+ public void testHasPropertyChangeListeners() throws Exception {
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addPropertyChangeListener(l);
+ assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.junkHolder2.removePropertyChangeListener(l);
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testHasStateChangeListeners() throws Exception {
+ assertFalse(this.junk.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ assertTrue(this.junk.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
+ assertTrue(this.junkHolder2.hasAnyStateChangeListeners());
+
+ this.junkHolder2.removeStateChangeListener(l);
+ assertFalse(this.junk.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION));
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+ }
+
+ public void testCollectionAdd() {
+ LocalListener l = new LocalListener(this.junkHolder2);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.addStuff("bar");
+ assertTrue(l.eventReceived());
+ }
+
+ public void testCollectionRemove() {
+ LocalListener l = new LocalListener(this.junkHolder2);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.removeStuff("foo");
+ assertTrue(l.eventReceived());
+ }
+
+
+ private class LocalListener implements PropertyChangeListener, StateChangeListener {
+ private boolean eventReceived = false;
+ private final Object source;
+ private final Object oldValue;
+ private final Object newValue;
+ LocalListener(Object source) {
+ this(source, null, null);
+ }
+ LocalListener(Object source, Object oldValue, Object newValue) {
+ super();
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertEquals(this.oldValue, e.oldValue());
+ assertEquals(this.newValue, e.newValue());
+ assertEquals(PropertyValueModel.VALUE, e.propertyName());
+ }
+ public void stateChanged(StateChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertNull(e.aspectName());
+ }
+ boolean eventReceived() {
+ return this.eventReceived;
+ }
+ }
+
+
+ private class Junk extends AbstractModel {
+ private Collection<String> stuff;
+ public static final String STUFF_COLLECTION = "stuff";
+
+ public Junk(String stuffItem) {
+ this.stuff = new ArrayList<String>();
+ this.stuff.add(stuffItem);
+ }
+
+ public void addStuff(String stuffItem) {
+ this.addItemToCollection(stuffItem, this.stuff, STUFF_COLLECTION);
+ }
+
+ public void removeStuff(String stuffItem) {
+ this.removeItemFromCollection(stuffItem, this.stuff, STUFF_COLLECTION);
+ }
+
+ @Override
+ public String toString() {
+ return "Junk(" + this.stuff + ")";
+ }
+
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java
new file mode 100644
index 0000000000..432f56ac0c
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.internal.model.event.StateChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.internal.model.listener.StateChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.ValueListAdapter;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class ValueListAdapterTests extends TestCase {
+ private Junk junk;
+ private SimplePropertyValueModel<Junk> junkHolder;
+ private ValueListAdapter<Junk> junkHolder2;
+
+
+
+ public ValueListAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.junk = new Junk("foo");
+ this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk);
+ this.junkHolder2 = new ValueListAdapter<Junk>(this.junkHolder, Junk.STUFF_LIST);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testWrappedPVM() {
+ Junk junk2 = new Junk("bar");
+ LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2);
+ this.junkHolder2.addPropertyChangeListener(l);
+ this.junkHolder.setValue(junk2);
+ assertTrue(l.eventReceived());
+ }
+
+ public void testHasPropertyChangeListeners() throws Exception {
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addPropertyChangeListener(l);
+ assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.junkHolder2.removePropertyChangeListener(l);
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testHasStateChangeListeners() throws Exception {
+ assertFalse(this.junk.hasAnyListChangeListeners(Junk.STUFF_LIST));
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ assertTrue(this.junk.hasAnyListChangeListeners(Junk.STUFF_LIST));
+ assertTrue(this.junkHolder2.hasAnyStateChangeListeners());
+
+ this.junkHolder2.removeStateChangeListener(l);
+ assertFalse(this.junk.hasAnyListChangeListeners(Junk.STUFF_LIST));
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+ }
+
+ public void testListAdd() {
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.addStuff("bar");
+ assertTrue(l.eventReceived());
+ }
+
+ public void testListRemove() {
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.removeStuff("foo");
+ assertTrue(l.eventReceived());
+ }
+
+ public void testListReplace() {
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.replaceStuff("foo", "bar");
+ assertTrue(l.eventReceived());
+ }
+
+
+ private class LocalListener implements PropertyChangeListener, StateChangeListener {
+ private boolean eventReceived = false;
+ private final Object source;
+ private final Object oldValue;
+ private final Object newValue;
+ LocalListener(Object source) {
+ this(source, null, null);
+ }
+ LocalListener(Object source, Object oldValue, Object newValue) {
+ super();
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertEquals(this.oldValue, e.oldValue());
+ assertEquals(this.newValue, e.newValue());
+ assertEquals(PropertyValueModel.VALUE, e.propertyName());
+ }
+ public void stateChanged(StateChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertNull(e.aspectName());
+ }
+ boolean eventReceived() {
+ return this.eventReceived;
+ }
+ }
+
+ private class Junk extends AbstractModel {
+ private List<String> stuff;
+ public static final String STUFF_LIST = "stuff";
+
+ public Junk(String stuffItem) {
+ this.stuff = new ArrayList<String>();
+ this.stuff.add(stuffItem);
+ }
+
+ public void addStuff(String stuffItem) {
+ this.addItemToList(stuffItem, this.stuff, STUFF_LIST);
+ }
+
+ public void removeStuff(String stuffItem) {
+ this.removeItemFromList(stuffItem, this.stuff, STUFF_LIST);
+ }
+
+ public void replaceStuff(String oldStuffItem, String newStuffItem) {
+ this.replaceItemInList(oldStuffItem, newStuffItem, this.stuff, STUFF_LIST);
+ }
+
+ @Override
+ public String toString() {
+ return "Junk(" + this.stuff + ")";
+ }
+
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java
new file mode 100644
index 0000000000..7fba30fa1e
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.internal.model.event.StateChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.internal.model.listener.StateChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.ValuePropertyAdapter;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class ValuePropertyAdapterTests extends TestCase {
+ private Junk junk;
+ private SimplePropertyValueModel<Junk> junkHolder;
+ private ValuePropertyAdapter<Junk> junkHolder2;
+
+
+ public ValuePropertyAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.junk = new Junk("foo");
+ this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk);
+ this.junkHolder2 = new ValuePropertyAdapter<Junk>(this.junkHolder, Junk.NAME_PROPERTY);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testWrappedPVM() {
+ Junk junk2 = new Junk("bar");
+ LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2);
+ this.junkHolder2.addPropertyChangeListener(l);
+ this.junkHolder.setValue(junk2);
+ assertTrue(l.eventReceived());
+ }
+
+ public void testHasPropertyChangeListeners() throws Exception {
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addPropertyChangeListener(l);
+ assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.junkHolder2.removePropertyChangeListener(l);
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testHasStateChangeListeners() throws Exception {
+ assertFalse(this.junk.hasAnyPropertyChangeListeners(Junk.NAME_PROPERTY));
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ assertTrue(this.junk.hasAnyPropertyChangeListeners(Junk.NAME_PROPERTY));
+ assertTrue(this.junkHolder2.hasAnyStateChangeListeners());
+
+ this.junkHolder2.removeStateChangeListener(l);
+ assertFalse(this.junk.hasAnyPropertyChangeListeners(Junk.NAME_PROPERTY));
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+ }
+
+ public void testChangeProperty() {
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.setName("bar");
+ assertTrue(l.eventReceived());
+ }
+
+
+ private class LocalListener implements PropertyChangeListener, StateChangeListener {
+ private boolean eventReceived = false;
+ private final Object source;
+ private final Object oldValue;
+ private final Object newValue;
+ LocalListener(Object source) {
+ this(source, null, null);
+ }
+ LocalListener(Object source, Object oldValue, Object newValue) {
+ super();
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertEquals(this.oldValue, e.oldValue());
+ assertEquals(this.newValue, e.newValue());
+ assertEquals(PropertyValueModel.VALUE, e.propertyName());
+ }
+ public void stateChanged(StateChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertNull(e.aspectName());
+ }
+ boolean eventReceived() {
+ return this.eventReceived;
+ }
+ }
+
+ private class Junk extends AbstractModel {
+ private String name;
+ public static final String NAME_PROPERTY = "name";
+
+ public Junk(String name) {
+ this.name = name;
+ }
+
+ public void setName(String name) {
+ String old = this.name;
+ this.name = name;
+ this.firePropertyChanged(NAME_PROPERTY, old, name);
+ }
+
+ @Override
+ public String toString() {
+ return "Junk(" + this.name + ")";
+ }
+
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java
new file mode 100644
index 0000000000..95ddb96b89
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.internal.model.event.StateChangeEvent;
+import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.internal.model.listener.StateChangeListener;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.ValueStateAdapter;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class ValueStateAdapterTests extends TestCase {
+ private Junk junk;
+ private SimplePropertyValueModel<Junk> junkHolder;
+ private ValueStateAdapter<Junk> junkHolder2;
+
+
+ public ValueStateAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.junk = new Junk("foo");
+ this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk);
+ this.junkHolder2 = new ValueStateAdapter<Junk>(this.junkHolder);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testWrappedPVM() {
+ Junk junk2 = new Junk("bar");
+ LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2);
+ this.junkHolder2.addPropertyChangeListener(l);
+ this.junkHolder.setValue(junk2);
+ assertTrue(l.eventReceived());
+ }
+
+ public void testHasPropertyChangeListeners() throws Exception {
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addPropertyChangeListener(l);
+ assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.junkHolder2.removePropertyChangeListener(l);
+ assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testHasStateChangeListeners() throws Exception {
+ assertFalse(this.junk.hasAnyStateChangeListeners());
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addStateChangeListener(l);
+ assertTrue(this.junk.hasAnyStateChangeListeners());
+ assertTrue(this.junkHolder2.hasAnyStateChangeListeners());
+
+ this.junkHolder2.removeStateChangeListener(l);
+ assertFalse(this.junk.hasAnyStateChangeListeners());
+ assertFalse(this.junkHolder2.hasAnyStateChangeListeners());
+ }
+
+ public void testChangeState() {
+ LocalListener l = new LocalListener(this.junkHolder2, null, this.junk);
+ this.junkHolder2.addPropertyChangeListener(l);
+ this.junkHolder2.addStateChangeListener(l);
+ this.junk.setName("bar");
+ assertTrue(l.eventReceived());
+ }
+
+
+ private class LocalListener implements PropertyChangeListener, StateChangeListener {
+ private boolean eventReceived = false;
+ private final Object source;
+ private final Object oldValue;
+ private final Object newValue;
+ LocalListener(Object source) {
+ this(source, null, null);
+ }
+ LocalListener(Object source, Object oldValue, Object newValue) {
+ super();
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+ public void propertyChanged(PropertyChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertEquals(this.oldValue, e.oldValue());
+ assertEquals(this.newValue, e.newValue());
+ assertEquals(PropertyValueModel.VALUE, e.propertyName());
+ }
+ public void stateChanged(StateChangeEvent e) {
+ this.eventReceived = true;
+ assertEquals(this.source, e.getSource());
+ assertNull(e.aspectName());
+ }
+ boolean eventReceived() {
+ return this.eventReceived;
+ }
+ }
+
+ private class Junk extends AbstractModel {
+ private String name;
+ public static final String NAME_PROPERTY = "name";
+
+ public Junk(String name) {
+ this.name = name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ this.fireStateChanged();
+ }
+
+ @Override
+ public String toString() {
+ return "Junk(" + this.name + ")";
+ }
+
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java
index cf033eae36..b9e256ccf3 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,18 +15,18 @@ import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
-import org.eclipse.jpt.utility.internal.BidiStringConverter;
import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.model.Model;
import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencePropertyValueModel;
public class PreferencePropertyValueModelTests extends PreferencesTestCase {
- private PropertyValueModel nodeHolder;
- PreferencePropertyValueModel preferenceAdapter;
+ private WritablePropertyValueModel<Preferences> nodeHolder;
+ PreferencePropertyValueModel<String> preferenceAdapter;
PropertyChangeEvent event;
PropertyChangeListener listener;
boolean listenerRemoved = false;
@@ -43,10 +43,10 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
super.setUp();
this.testNode.put(KEY_NAME, STRING_VALUE);
- this.nodeHolder = new SimplePropertyValueModel(this.testNode);
- this.preferenceAdapter = new PreferencePropertyValueModel(this.nodeHolder, KEY_NAME);
+ this.nodeHolder = new SimplePropertyValueModel<Preferences>(this.testNode);
+ this.preferenceAdapter = new PreferencePropertyValueModel<String>(this.nodeHolder, KEY_NAME);
this.listener = this.buildValueChangeListener();
- this.preferenceAdapter.addPropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener);
this.event = null;
}
@@ -124,19 +124,19 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
}
public void testHasListeners() throws Exception {
- assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertTrue(this.nodeHasAnyPrefListeners(this.testNode));
- this.preferenceAdapter.removePropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
assertFalse(this.nodeHasAnyPrefListeners(this.testNode));
- assertFalse(this.preferenceAdapter.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
PropertyChangeListener listener2 = this.buildValueChangeListener();
this.preferenceAdapter.addPropertyChangeListener(listener2);
- assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
assertTrue(this.nodeHasAnyPrefListeners(this.testNode));
this.preferenceAdapter.removePropertyChangeListener(listener2);
assertFalse(this.nodeHasAnyPrefListeners(this.testNode));
- assertFalse(this.preferenceAdapter.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
}
public void testRemoveAndReAddPreference() throws Exception {
@@ -163,9 +163,9 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
public void testDefaultValue() throws Exception {
// rebuild the adapter with a default value
String DEFAULT_VALUE = "default value";
- this.preferenceAdapter.removePropertyChangeListener(ValueModel.VALUE, this.listener);
- this.preferenceAdapter = new PreferencePropertyValueModel(this.nodeHolder, KEY_NAME, DEFAULT_VALUE);
- this.preferenceAdapter.addPropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+ this.preferenceAdapter = new PreferencePropertyValueModel<String>(this.nodeHolder, KEY_NAME, DEFAULT_VALUE);
+ this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener);
assertEquals(STRING_VALUE, this.testNode.get(KEY_NAME, null));
assertEquals(STRING_VALUE, this.preferenceAdapter.value());
@@ -192,7 +192,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
assertNull(this.event);
// remove the this.listener so the adapter no longer listens to the preference
- this.preferenceAdapter.removePropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
this.testNode.put(KEY_NAME, STRING_VALUE + STRING_VALUE);
this.waitForEventQueueToClear();
@@ -212,35 +212,37 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
assertNull(this.preferenceAdapter.value());
// add the this.listener so the adapter synchs
- this.preferenceAdapter.addPropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener);
assertEquals(STRING_VALUE, this.preferenceAdapter.value());
}
public void testIntegerPreference() throws Exception {
// stop listening to the node and convert it to an integer
- this.preferenceAdapter.removePropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+
+ PreferencePropertyValueModel<Integer> integerPreferenceAdapter = new PreferencePropertyValueModel<Integer>(this.nodeHolder, KEY_NAME);
this.testNode.putInt(KEY_NAME, 123);
- this.preferenceAdapter = PreferencePropertyValueModel.forInteger(this.testNode, KEY_NAME, 0);
- this.preferenceAdapter.addPropertyChangeListener(ValueModel.VALUE, this.listener);
- assertEquals(new Integer(123), this.preferenceAdapter.value());
+ integerPreferenceAdapter = PreferencePropertyValueModel.forInteger(this.testNode, KEY_NAME, 0);
+ integerPreferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+ assertEquals(new Integer(123), integerPreferenceAdapter.value());
assertNull(this.event);
this.testNode.putInt(KEY_NAME, 246);
this.waitForEventQueueToClear();
- this.verifyEvent(new Integer(123), new Integer(246));
- assertEquals(new Integer(246), this.preferenceAdapter.value());
+ this.verifyEvent(integerPreferenceAdapter, new Integer(123), new Integer(246));
+ assertEquals(new Integer(246), integerPreferenceAdapter.value());
this.event = null;
this.testNode.remove(KEY_NAME);
this.waitForEventQueueToClear();
- this.verifyEvent(new Integer(246), new Integer(0));
- assertEquals(new Integer(0), this.preferenceAdapter.value());
+ this.verifyEvent(integerPreferenceAdapter, new Integer(246), new Integer(0));
+ assertEquals(new Integer(0), integerPreferenceAdapter.value());
this.event = null;
this.testNode.putInt(KEY_NAME, 123);
this.waitForEventQueueToClear();
- this.verifyEvent(new Integer(0), new Integer(123));
- assertEquals(new Integer(123), this.preferenceAdapter.value());
+ this.verifyEvent(integerPreferenceAdapter, new Integer(0), new Integer(123));
+ assertEquals(new Integer(123), integerPreferenceAdapter.value());
}
/**
@@ -251,7 +253,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
* - the node will throw an IllegalStateException - the adapter should handle it OK...
*/
public void testRemoveNode() throws Exception {
- assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
Preferences parent = this.testNode.parent();
parent.addNodeChangeListener(this.buildParentNodeChangeListener());
@@ -260,7 +262,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
this.waitForEventQueueToClear();
assertTrue(this.listenerRemoved);
- assertTrue(this.preferenceAdapter.hasNoPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(this.preferenceAdapter.hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
}
private NodeChangeListener buildParentNodeChangeListener() {
@@ -270,7 +272,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
}
public void childRemoved(NodeChangeEvent e) {
if (e.getChild() == PreferencePropertyValueModelTests.this.testNode) {
- PreferencePropertyValueModelTests.this.preferenceAdapter.removePropertyChangeListener(ValueModel.VALUE, PreferencePropertyValueModelTests.this.listener);
+ PreferencePropertyValueModelTests.this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, PreferencePropertyValueModelTests.this.listener);
// this line of code will not execute if the line above triggers an exception
PreferencePropertyValueModelTests.this.listenerRemoved = true;
}
@@ -303,9 +305,9 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
assertNull(this.event);
assertNull(this.preferenceEvent);
- this.preferenceAdapter.removePropertyChangeListener(ValueModel.VALUE, this.listener);
- this.preferenceAdapter = new AlwaysUpdatePreferencePropertyValueModel(this.nodeHolder, KEY_NAME);
- this.preferenceAdapter.addPropertyChangeListener(ValueModel.VALUE, this.listener);
+ this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+ this.preferenceAdapter = new AlwaysUpdatePreferencePropertyValueModel<String>(this.nodeHolder, KEY_NAME);
+ this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener);
this.testNode.addPreferenceChangeListener(this.buildPreferenceChangeListener());
@@ -335,14 +337,18 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
};
}
- private void verifyEvent(Object oldValue, Object newValue) {
+ private void verifyEvent(Model source, Object oldValue, Object newValue) {
assertNotNull(this.event);
- assertEquals(this.preferenceAdapter, this.event.getSource());
- assertEquals(ValueModel.VALUE, this.event.propertyName());
+ assertEquals(source, this.event.getSource());
+ assertEquals(PropertyValueModel.VALUE, this.event.propertyName());
assertEquals(oldValue, this.event.oldValue());
assertEquals(newValue, this.event.newValue());
}
+ private void verifyEvent(Object oldValue, Object newValue) {
+ this.verifyEvent(this.preferenceAdapter, oldValue, newValue);
+ }
+
private void verifyPreferenceEvent(Object newValue) {
assertNotNull(this.preferenceEvent);
assertEquals(this.testNode, this.preferenceEvent.getSource());
@@ -352,7 +358,7 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
}
private boolean nodeHasAnyPrefListeners(Preferences node) throws Exception {
- PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.getFieldValue(node, "prefListeners");
+ PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.fieldValue(node, "prefListeners");
return prefListeners.length > 0;
}
@@ -361,9 +367,9 @@ public class PreferencePropertyValueModelTests extends PreferencesTestCase {
* Use this adapter to test out always passing through the new value
* to the preference.
*/
- private class AlwaysUpdatePreferencePropertyValueModel extends PreferencePropertyValueModel {
+ private class AlwaysUpdatePreferencePropertyValueModel<P> extends PreferencePropertyValueModel<P> {
- AlwaysUpdatePreferencePropertyValueModel(ValueModel preferencesHolder, String key) {
+ AlwaysUpdatePreferencePropertyValueModel(PropertyValueModel<Preferences> preferencesHolder, String key) {
super(preferencesHolder, key);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java
index 3faa9cd162..822af01989 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -24,16 +24,16 @@ import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.internal.model.listener.CollectionChangeListener;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencesCollectionValueModel;
public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
- private Map expectedValues;
- private PropertyValueModel nodeHolder;
- PreferencesCollectionValueModel preferencesAdapter;
+ private Map<String, String> expectedValues;
+ private WritablePropertyValueModel<Preferences> nodeHolder;
+ PreferencesCollectionValueModel<String> preferencesAdapter;
CollectionChangeEvent event;
CollectionChangeListener listener;
private PropertyChangeListener itemListener;
@@ -52,13 +52,13 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.expectedValues = new HashMap();
+ this.expectedValues = new HashMap<String, String>();
this.testNode.put(KEY_NAME_1, STRING_VALUE_1); this.expectedValues.put(KEY_NAME_1, STRING_VALUE_1);
this.testNode.put(KEY_NAME_2, STRING_VALUE_2); this.expectedValues.put(KEY_NAME_2, STRING_VALUE_2);
this.testNode.put(KEY_NAME_3, STRING_VALUE_3); this.expectedValues.put(KEY_NAME_3, STRING_VALUE_3);
- this.nodeHolder = new SimplePropertyValueModel(this.testNode);
- this.preferencesAdapter = new PreferencesCollectionValueModel(this.nodeHolder);
+ this.nodeHolder = new SimplePropertyValueModel<Preferences>(this.testNode);
+ this.preferencesAdapter = new PreferencesCollectionValueModel<String>(this.nodeHolder);
this.listener = this.buildCollectionChangeListener();
this.itemListener = this.buildItemListener();
this.preferencesAdapter.addCollectionChangeListener(CollectionValueModel.VALUES, this.listener);
@@ -114,18 +114,18 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
this.nodeHolder.setValue(anotherNode);
// collectionChanged does not pass any items in the this.event
- this.verifyEvent(Collections.EMPTY_MAP);
+ this.verifyEvent(Collections.<String, String>emptyMap());
this.verifyAdapter(this.preferencesAdapter);
this.event = null;
this.expectedValues.clear();
this.nodeHolder.setValue(null);
this.verifyEvent(this.expectedValues);
- assertFalse(((Iterator) this.preferencesAdapter.iterator()).hasNext());
+ assertFalse(this.preferencesAdapter.iterator().hasNext());
this.event = null;
this.nodeHolder.setValue(this.testNode);
- this.verifyEvent(Collections.EMPTY_MAP);
+ this.verifyEvent(Collections.<String, String>emptyMap());
this.expectedValues.clear();
this.expectedValues.put(KEY_NAME_1, STRING_VALUE_1);
this.expectedValues.put(KEY_NAME_2, STRING_VALUE_2);
@@ -141,7 +141,7 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
String ANOTHER_STRING_VALUE = "another string value";
this.testNode.put(ANOTHER_KEY_NAME, ANOTHER_STRING_VALUE);
this.waitForEventQueueToClear();
- Map expectedItems = new HashMap();
+ Map<String, String> expectedItems = new HashMap<String, String>();
expectedItems.put(ANOTHER_KEY_NAME, ANOTHER_STRING_VALUE);
this.verifyEvent(expectedItems);
this.expectedValues.put(ANOTHER_KEY_NAME, ANOTHER_STRING_VALUE);
@@ -159,7 +159,9 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
assertEquals(this.preferencesAdapter, this.event.getSource());
assertEquals(CollectionValueModel.VALUES, this.event.collectionName());
assertEquals(1, this.event.itemsSize());
- assertEquals(KEY_NAME_2, ((PreferencePropertyValueModel) this.event.items().next()).getKey());
+ @SuppressWarnings("unchecked")
+ String key = ((PreferencePropertyValueModel<String>) this.event.items().next()).key();
+ assertEquals(KEY_NAME_2, key);
this.expectedValues.remove(KEY_NAME_2);
this.verifyAdapter(this.preferencesAdapter);
@@ -235,12 +237,14 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
assertFalse(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES));
}
- private void verifyEvent(Map items) {
+ private void verifyEvent(Map<String, String> items) {
assertNotNull(this.event);
assertEquals(this.preferencesAdapter, this.event.getSource());
assertEquals(CollectionValueModel.VALUES, this.event.collectionName());
assertEquals(items.size(), this.event.itemsSize());
- this.verifyItems(items, this.event.items());
+ @SuppressWarnings("unchecked")
+ Iterator<PreferencePropertyValueModel<String>> eventItems = (Iterator<PreferencePropertyValueModel<String>>) this.event.items();
+ this.verifyItems(items, eventItems);
}
private void verifyNode(Preferences node) throws Exception {
@@ -251,22 +255,22 @@ public class PreferencesCollectionValueModelTests extends PreferencesTestCase {
}
}
- private void verifyAdapter(PreferencesCollectionValueModel cvm) {
+ private void verifyAdapter(PreferencesCollectionValueModel<String> cvm) {
assertEquals(this.expectedValues.size(), cvm.size());
- this.verifyItems(this.expectedValues, (Iterator) cvm.iterator());
+ this.verifyItems(this.expectedValues, cvm.iterator());
}
- private void verifyItems(Map expected, Iterator stream) {
+ private void verifyItems(Map<String, String> expected, Iterator<PreferencePropertyValueModel<String>> stream) {
while (stream.hasNext()) {
- PreferencePropertyValueModel model = (PreferencePropertyValueModel) stream.next();
- model.addPropertyChangeListener(ValueModel.VALUE, this.itemListener);
- assertEquals(expected.get(model.getKey()), model.value());
- model.removePropertyChangeListener(ValueModel.VALUE, this.itemListener);
+ PreferencePropertyValueModel<String> model = stream.next();
+ model.addPropertyChangeListener(PropertyValueModel.VALUE, this.itemListener);
+ assertEquals(expected.get(model.key()), model.value());
+ model.removePropertyChangeListener(PropertyValueModel.VALUE, this.itemListener);
}
}
private boolean nodeHasAnyPrefListeners(Preferences node) throws Exception {
- PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.getFieldValue(node, "prefListeners");
+ PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.fieldValue(node, "prefListeners");
return prefListeners.length > 0;
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java
index d2186909db..bca284a8fd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.utility.tests.internal.model.value.prefs;
+import java.util.EventObject;
import java.util.List;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.Preferences;
@@ -78,8 +79,9 @@ public abstract class PreferencesTestCase extends TestCase {
}
}
- private List preferencesEventQueue() {
- return (List) ClassTools.getStaticFieldValue(AbstractPreferences.class, "eventQueue");
+ @SuppressWarnings("unchecked")
+ private List<EventObject> preferencesEventQueue() {
+ return (List<EventObject>) ClassTools.staticFieldValue(AbstractPreferences.class, "eventQueue");
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java
index 023885bea6..867577eca5 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,16 +16,16 @@ import javax.swing.event.EventListenerList;
import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.CheckBoxModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class CheckBoxModelAdapterTests extends TestCase {
- private PropertyValueModel booleanHolder;
+ private WritablePropertyValueModel<Boolean> booleanHolder;
private ButtonModel buttonModelAdapter;
boolean eventFired;
@@ -36,7 +36,7 @@ public class CheckBoxModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.booleanHolder = new SimplePropertyValueModel(Boolean.TRUE);
+ this.booleanHolder = new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
this.buttonModelAdapter = new CheckBoxModelAdapter(this.booleanHolder) {
@Override
protected PropertyChangeListener buildBooleanChangeListener() {
@@ -98,27 +98,27 @@ public class CheckBoxModelAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localBooleanHolder = (SimplePropertyValueModel) this.booleanHolder;
- assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Boolean> localBooleanHolder = (SimplePropertyValueModel<Boolean>) this.booleanHolder;
+ assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.buttonModelAdapter);
ChangeListener listener = new TestChangeListener();
this.buttonModelAdapter.addChangeListener(listener);
- assertTrue(localBooleanHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.buttonModelAdapter);
this.buttonModelAdapter.removeChangeListener(listener);
- assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.buttonModelAdapter);
}
private void verifyHasNoListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.getFieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
assertEquals(0, listenerList.getListenerList().length);
}
private void verifyHasListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.getFieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
assertFalse(listenerList.getListenerList().length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java
index 041b65d5be..fd3deba8d7 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java
@@ -30,22 +30,21 @@ import javax.swing.WindowConstants;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.CheckBoxModelAdapter;
-
/**
* Play around with a set of check boxes.
*/
public class CheckBoxModelAdapterUITest {
private TestModel testModel;
- private PropertyValueModel testModelHolder;
- private PropertyValueModel flag1Holder;
- private PropertyValueModel flag2Holder;
- private PropertyValueModel notFlag2Holder;
+ private WritablePropertyValueModel<TestModel> testModelHolder;
+ private WritablePropertyValueModel<Boolean> flag1Holder;
+ private WritablePropertyValueModel<Boolean> flag2Holder;
+ private WritablePropertyValueModel<Boolean> notFlag2Holder;
private ButtonModel flag1ButtonModel;
private ButtonModel flag2ButtonModel;
private ButtonModel notFlag2ButtonModel;
@@ -60,7 +59,7 @@ public class CheckBoxModelAdapterUITest {
private void exec(String[] args) throws Exception {
this.testModel = new TestModel(true, true);
- this.testModelHolder = new SimplePropertyValueModel(this.testModel);
+ this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.flag1Holder = this.buildFlag1Holder(this.testModelHolder);
this.flag1ButtonModel = this.buildCheckBoxModelAdapter(this.flag1Holder);
this.flag2Holder = this.buildFlag2Holder(this.testModelHolder);
@@ -70,46 +69,46 @@ public class CheckBoxModelAdapterUITest {
this.openWindow();
}
- private PropertyValueModel buildFlag1Holder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.FLAG1_PROPERTY) {
+ private WritablePropertyValueModel<Boolean> buildFlag1Holder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Boolean>(vm, TestModel.FLAG1_PROPERTY) {
@Override
- protected Object buildValue_() {
- return Boolean.valueOf(((TestModel) this.subject).isFlag1());
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.isFlag1());
}
@Override
- protected void setValue_(Object value) {
- ((TestModel) this.subject).setFlag1(((Boolean) value).booleanValue());
+ protected void setValue_(Boolean value) {
+ this.subject.setFlag1(value.booleanValue());
}
};
}
- private PropertyValueModel buildFlag2Holder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.FLAG2_PROPERTY) {
+ private WritablePropertyValueModel<Boolean> buildFlag2Holder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Boolean>(vm, TestModel.FLAG2_PROPERTY) {
@Override
- protected Object buildValue_() {
- return Boolean.valueOf(((TestModel) this.subject).isFlag2());
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.isFlag2());
}
@Override
- protected void setValue_(Object value) {
- ((TestModel) this.subject).setFlag2(((Boolean) value).booleanValue());
+ protected void setValue_(Boolean value) {
+ this.subject.setFlag2(value.booleanValue());
}
};
}
- private PropertyValueModel buildNotFlag2Holder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.NOT_FLAG2_PROPERTY) {
+ private WritablePropertyValueModel<Boolean> buildNotFlag2Holder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Boolean>(vm, TestModel.NOT_FLAG2_PROPERTY) {
@Override
- protected Object buildValue_() {
- return Boolean.valueOf(((TestModel) this.subject).isNotFlag2());
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.isNotFlag2());
}
@Override
- protected void setValue_(Object value) {
- ((TestModel) this.subject).setNotFlag2(((Boolean) value).booleanValue());
+ protected void setValue_(Boolean value) {
+ this.subject.setNotFlag2(value.booleanValue());
}
};
}
- private ButtonModel buildCheckBoxModelAdapter(PropertyValueModel booleanHolder) {
+ private ButtonModel buildCheckBoxModelAdapter(WritablePropertyValueModel<Boolean> booleanHolder) {
return new CheckBoxModelAdapter(booleanHolder);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java
index 3514134ce7..4d58f274d3 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,11 +22,11 @@ import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ComboBoxModelAdapter;
import org.eclipse.jpt.utility.internal.swing.Displayable;
import org.eclipse.jpt.utility.internal.swing.SimpleDisplayable;
-import org.eclipse.jpt.utility.tests.internal.model.value.SynchronizedList;
+import org.eclipse.jpt.utility.tests.internal.model.value.CoordinatedList;
import junit.framework.TestCase;
@@ -51,25 +51,25 @@ public class ComboBoxModelAdapterTests extends TestCase {
public void testHasListeners() throws Exception {
SimpleListValueModel<Displayable> listHolder = this.buildListHolder();
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- SimplePropertyValueModel selectionHolder = new SimplePropertyValueModel(listHolder.iterator().next());
- assertFalse(selectionHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Object> selectionHolder = new SimplePropertyValueModel<Object>(listHolder.iterator().next());
+ assertFalse(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
ComboBoxModel comboBoxModel = new ComboBoxModelAdapter(listHolder, selectionHolder);
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- assertFalse(selectionHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(comboBoxModel);
- SynchronizedList<Displayable> synchList = new SynchronizedList<Displayable>(comboBoxModel);
+ CoordinatedList<Displayable> synchList = new CoordinatedList<Displayable>(comboBoxModel);
PropertyChangeListener selectionListener = this.buildSelectionListener();
- selectionHolder.addPropertyChangeListener(ValueModel.VALUE, selectionListener);
+ selectionHolder.addPropertyChangeListener(PropertyValueModel.VALUE, selectionListener);
assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- assertTrue(selectionHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(comboBoxModel);
comboBoxModel.removeListDataListener(synchList);
- selectionHolder.removePropertyChangeListener(ValueModel.VALUE, selectionListener);
+ selectionHolder.removePropertyChangeListener(PropertyValueModel.VALUE, selectionListener);
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- assertFalse(selectionHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(comboBoxModel);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java
index 3c7b9aa936..5e3d4cc418 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -35,10 +35,10 @@ import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ComboBoxModelAdapter;
import org.eclipse.jpt.utility.internal.swing.FilteringListBrowser;
import org.eclipse.jpt.utility.internal.swing.ListChooser;
@@ -55,8 +55,8 @@ public class ComboBoxModelAdapterUITest {
protected JFrame window;
private TestModel testModel;
- private PropertyValueModel testModelHolder;
- private PropertyValueModel colorHolder;
+ private WritablePropertyValueModel<TestModel> testModelHolder;
+ private WritablePropertyValueModel<Object> colorHolder;
private SimpleListValueModel<String> colorListHolder;
protected ComboBoxModel colorComboBoxModel;
private int nextColorNumber = 0;
@@ -76,22 +76,22 @@ public class ComboBoxModelAdapterUITest {
// UIManager.setLookAndFeel(com.sun.java.swing.plaf.motif.MotifLookAndFeel.class.getName());
// UIManager.setLookAndFeel(oracle.bali.ewt.olaf.OracleLookAndFeel.class.getName());
this.testModel = this.buildTestModel();
- this.testModelHolder = new SimplePropertyValueModel(this.testModel);
+ this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.colorHolder = this.buildColorHolder(this.testModelHolder);
this.colorListHolder = this.buildColorListHolder();
this.colorComboBoxModel = this.buildComboBoxModelAdapter(this.colorListHolder, this.colorHolder);
this.openWindow();
}
- private PropertyValueModel buildColorHolder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.COLOR_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildColorHolder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Object>(vm, TestModel.COLOR_PROPERTY) {
@Override
- protected Object buildValue_() {
- return ((TestModel) this.subject).getColor();
+ protected String buildValue_() {
+ return this.subject.getColor();
}
@Override
protected void setValue_(Object value) {
- ((TestModel) this.subject).setColor((String) value);
+ this.subject.setColor((String) value);
}
};
}
@@ -112,11 +112,11 @@ public class ComboBoxModelAdapterUITest {
// };
}
- protected ListValueModel uiColorListHolder() {
+ protected ListValueModel<String> uiColorListHolder() {
return this.colorListHolder;
}
- private ComboBoxModel buildComboBoxModelAdapter(ListValueModel listHolder, PropertyValueModel selectionHolder) {
+ private ComboBoxModel buildComboBoxModelAdapter(ListValueModel<String> listHolder, WritablePropertyValueModel<Object> selectionHolder) {
return new ComboBoxModelAdapter(listHolder, selectionHolder);
}
@@ -386,7 +386,7 @@ public class ComboBoxModelAdapterUITest {
}
@Override
protected ListBrowser buildBrowser() {
- return new FilteringListBrowser();
+ return new FilteringListBrowser<String>();
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java
index 35eaee3648..176bdc8373 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -40,9 +40,9 @@ public class ComboBoxModelAdapterUITest2 extends ComboBoxModelAdapterUITest {
* add a null to the front of the list
*/
@Override
- protected ListValueModel uiColorListHolder() {
+ protected ListValueModel<String> uiColorListHolder() {
// the default is to prepend the wrapped list with a null item
- return new ExtendedListValueModelWrapper(super.uiColorListHolder());
+ return new ExtendedListValueModelWrapper<String>(super.uiColorListHolder());
}
/**
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java
index 0e54bb9101..16864dc7fb 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,16 +16,16 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.DateSpinnerModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class DateSpinnerModelAdapterTests extends TestCase {
- private PropertyValueModel valueHolder;
+ private WritablePropertyValueModel<Object> valueHolder;
private SpinnerModel spinnerModelAdapter;
boolean eventFired;
@@ -36,7 +36,7 @@ public class DateSpinnerModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.valueHolder = new SimplePropertyValueModel(new Date());
+ this.valueHolder = new SimplePropertyValueModel<Object>(new Date());
this.spinnerModelAdapter = new DateSpinnerModelAdapter(this.valueHolder) {
@Override
protected PropertyChangeListener buildDateChangeListener() {
@@ -99,17 +99,17 @@ public class DateSpinnerModelAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localValueHolder = (SimplePropertyValueModel) this.valueHolder;
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder;
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
ChangeListener listener = new TestChangeListener();
this.spinnerModelAdapter.addChangeListener(listener);
- assertTrue(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.spinnerModelAdapter);
this.spinnerModelAdapter.removeChangeListener(listener);
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
}
@@ -123,7 +123,7 @@ public class DateSpinnerModelAdapterTests extends TestCase {
public void testNullInitialValue() {
Date today = new Date();
- this.valueHolder = new SimplePropertyValueModel();
+ this.valueHolder = new SimplePropertyValueModel<Object>();
this.spinnerModelAdapter = new DateSpinnerModelAdapter(this.valueHolder, today) {
@Override
protected PropertyChangeListener buildDateChangeListener() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java
index 3d7b80f015..a8dc1f645b 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,16 +16,16 @@ import javax.swing.text.Document;
import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.DocumentAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class DocumentAdapterTests extends TestCase {
- private PropertyValueModel stringHolder;
+ private WritablePropertyValueModel<String> stringHolder;
Document documentAdapter;
boolean eventFired;
@@ -36,7 +36,7 @@ public class DocumentAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.stringHolder = new SimplePropertyValueModel("0123456789");
+ this.stringHolder = new SimplePropertyValueModel<String>("0123456789");
this.documentAdapter = new DocumentAdapter(this.stringHolder) {
@Override
protected PropertyChangeListener buildStringListener() {
@@ -115,28 +115,28 @@ public class DocumentAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localStringHolder = (SimplePropertyValueModel) this.stringHolder;
- assertFalse(localStringHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<String> localStringHolder = (SimplePropertyValueModel<String>) this.stringHolder;
+ assertFalse(localStringHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.documentAdapter);
DocumentListener listener = new TestDocumentListener();
this.documentAdapter.addDocumentListener(listener);
- assertTrue(localStringHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localStringHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.documentAdapter);
this.documentAdapter.removeDocumentListener(listener);
- assertFalse(localStringHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localStringHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.documentAdapter);
}
private void verifyHasNoListeners(Object document) throws Exception {
- Object delegate = ClassTools.getFieldValue(document, "delegate");
+ Object delegate = ClassTools.fieldValue(document, "delegate");
Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getDocumentListeners");
assertEquals(0, listeners.length);
}
private void verifyHasListeners(Object document) throws Exception {
- Object delegate = ClassTools.getFieldValue(document, "delegate");
+ Object delegate = ClassTools.fieldValue(document, "delegate");
Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getDocumentListeners");
assertFalse(listeners.length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java
index 8ea83d49f4..7ce248efc6 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java
@@ -32,9 +32,9 @@ import javax.swing.text.PlainDocument;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.DocumentAdapter;
/**
@@ -44,8 +44,8 @@ public class DocumentAdapterUITest {
private TestModel testModel;
private static final String DEFAULT_NAME = "Scooby Doo";
- private PropertyValueModel testModelHolder;
- private PropertyValueModel nameHolder;
+ private WritablePropertyValueModel<TestModel> testModelHolder;
+ private WritablePropertyValueModel<String> nameHolder;
private Document nameDocument;
private Document upperCaseNameDocument;
@@ -59,31 +59,31 @@ public class DocumentAdapterUITest {
private void exec(String[] args) throws Exception {
this.testModel = new TestModel(DEFAULT_NAME);
- this.testModelHolder = new SimplePropertyValueModel(this.testModel);
+ this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.nameHolder = this.buildNameHolder(this.testModelHolder);
this.nameDocument = this.buildNameDocument(this.nameHolder);
this.upperCaseNameDocument = this.buildUpperCaseNameDocument(this.nameHolder);
this.openWindow();
}
- private PropertyValueModel buildNameHolder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.NAME_PROPERTY) {
+ private WritablePropertyValueModel<String> buildNameHolder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, String>(vm, TestModel.NAME_PROPERTY) {
@Override
- protected Object buildValue_() {
- return ((TestModel) this.subject).getName();
+ protected String buildValue_() {
+ return this.subject.getName();
}
@Override
- protected void setValue_(Object value) {
- ((TestModel) this.subject).setName((String) value);
+ protected void setValue_(String value) {
+ this.subject.setName(value);
}
};
}
- private Document buildNameDocument(PropertyValueModel stringHolder) {
+ private Document buildNameDocument(WritablePropertyValueModel<String> stringHolder) {
return new DocumentAdapter(stringHolder);
}
- private Document buildUpperCaseNameDocument(PropertyValueModel stringHolder) {
+ private Document buildUpperCaseNameDocument(WritablePropertyValueModel<String> stringHolder) {
return new DocumentAdapter(stringHolder, this.buildUpperCaseNameDocumentDelegate());
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java
index 5e7562914a..a5f49b12dd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -29,7 +29,7 @@ import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter;
-import org.eclipse.jpt.utility.tests.internal.model.value.SynchronizedList;
+import org.eclipse.jpt.utility.tests.internal.model.value.CoordinatedList;
import junit.framework.TestCase;
@@ -51,7 +51,7 @@ public class ListModelAdapterTests extends TestCase {
super.tearDown();
}
- private ListModelAdapter buildListModel(ListValueModel listHolder) {
+ private ListModelAdapter buildListModel(ListValueModel<String> listHolder) {
return new ListModelAdapter(listHolder) {
@Override
protected ListChangeListener buildListChangeListener() {
@@ -60,7 +60,7 @@ public class ListModelAdapterTests extends TestCase {
};
}
- private ListModel buildListModel(CollectionValueModel collectionHolder) {
+ private ListModel buildListModel(CollectionValueModel<String> collectionHolder) {
return new ListModelAdapter(collectionHolder) {
@Override
protected ListChangeListener buildListChangeListener() {
@@ -70,9 +70,9 @@ public class ListModelAdapterTests extends TestCase {
}
public void testCollectionSynchronization() {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
+ SimpleCollectionValueModel<String> collectionHolder = this.buildCollectionHolder();
ListModel listModel = this.buildListModel(collectionHolder);
- SynchronizedList synchList = new SynchronizedList(listModel);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
assertEquals(6, synchList.size());
this.compare(listModel, synchList);
@@ -92,9 +92,9 @@ public class ListModelAdapterTests extends TestCase {
}
public void testListSynchronization() {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<String> listHolder = this.buildListHolder();
ListModel listModel = this.buildListModel(listHolder);
- SynchronizedList synchList = new SynchronizedList(listModel);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
assertEquals(6, synchList.size());
this.compare(listModel, synchList);
@@ -114,28 +114,28 @@ public class ListModelAdapterTests extends TestCase {
}
public void testSetModel() {
- SimpleListValueModel listHolder1 = this.buildListHolder();
+ SimpleListValueModel<String> listHolder1 = this.buildListHolder();
ListModelAdapter listModel = this.buildListModel(listHolder1);
- SynchronizedList synchList = new SynchronizedList(listModel);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
assertTrue(listHolder1.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
assertEquals(6, synchList.size());
this.compare(listModel, synchList);
- SimpleListValueModel listHolder2 = this.buildListHolder2();
+ SimpleListValueModel<String> listHolder2 = this.buildListHolder2();
listModel.setModel(listHolder2);
assertEquals(3, synchList.size());
this.compare(listModel, synchList);
assertTrue(listHolder1.hasNoListChangeListeners(ListValueModel.LIST_VALUES));
assertTrue(listHolder2.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
- listModel.setModel(new SimpleListValueModel());
+ listModel.setModel(new SimpleListValueModel<String>());
assertEquals(0, synchList.size());
this.compare(listModel, synchList);
assertTrue(listHolder1.hasNoListChangeListeners(ListValueModel.LIST_VALUES));
assertTrue(listHolder2.hasNoListChangeListeners(ListValueModel.LIST_VALUES));
}
- private void compare(ListModel listModel, List list) {
+ private void compare(ListModel listModel, List<String> list) {
assertEquals(listModel.getSize(), list.size());
for (int i = 0; i < listModel.getSize(); i++) {
assertEquals(listModel.getElementAt(i), list.get(i));
@@ -158,19 +158,19 @@ public class ListModelAdapterTests extends TestCase {
this.verifyListSort(this.buildCustomComparator());
}
- private Comparator buildCustomComparator() {
+ private Comparator<String> buildCustomComparator() {
// sort with reverse order
- return new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) o2).compareTo(o1);
+ return new Comparator<String>() {
+ public int compare(String s1, String s2) {
+ return s2.compareTo(s1);
}
};
}
- private void verifyCollectionSort(Comparator comparator) {
- SimpleCollectionValueModel collectionHolder = this.buildCollectionHolder();
- ListModel listModel = this.buildListModel(new SortedListValueModelAdapter(collectionHolder, comparator));
- SynchronizedList synchList = new SynchronizedList(listModel);
+ private void verifyCollectionSort(Comparator<String> comparator) {
+ SimpleCollectionValueModel<String> collectionHolder = this.buildCollectionHolder();
+ ListModel listModel = this.buildListModel(new SortedListValueModelAdapter<String>(collectionHolder, comparator));
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
assertEquals(6, synchList.size());
this.compareSort(listModel, synchList, comparator);
@@ -187,10 +187,10 @@ public class ListModelAdapterTests extends TestCase {
this.compareSort(listModel, synchList, comparator);
}
- private void verifyListSort(Comparator comparator) {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListModel listModel = this.buildListModel(new SortedListValueModelAdapter(listHolder, comparator));
- SynchronizedList synchList = new SynchronizedList(listModel);
+ private void verifyListSort(Comparator<String> comparator) {
+ SimpleListValueModel<String> listHolder = this.buildListHolder();
+ ListModel listModel = this.buildListModel(new SortedListValueModelAdapter<String>(listHolder, comparator));
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
assertEquals(6, synchList.size());
this.compareSort(listModel, synchList, comparator);
@@ -208,26 +208,26 @@ public class ListModelAdapterTests extends TestCase {
this.compareSort(listModel, synchList, comparator);
}
- private void compareSort(ListModel listModel, List list, Comparator comparator) {
- SortedSet ss = new TreeSet(comparator);
+ private void compareSort(ListModel listModel, List<String> list, Comparator<String> comparator) {
+ SortedSet<String> ss = new TreeSet<String>(comparator);
for (int i = 0; i < listModel.getSize(); i++) {
- ss.add(listModel.getElementAt(i));
+ ss.add((String) listModel.getElementAt(i));
}
assertEquals(ss.size(), list.size());
- for (Iterator stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) {
+ for (Iterator<String> stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) {
assertEquals(stream1.next(), stream2.next());
}
}
public void testHasListeners() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<String> listHolder = this.buildListHolder();
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
ListModel listModel = this.buildListModel(listHolder);
assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
this.verifyHasNoListeners(listModel);
- SynchronizedList synchList = new SynchronizedList(listModel);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
this.verifyHasListeners(listModel);
@@ -237,12 +237,12 @@ public class ListModelAdapterTests extends TestCase {
}
public void testGetSize() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
+ SimpleListValueModel<String> listHolder = this.buildListHolder();
ListModel listModel = this.buildListModel(listHolder);
this.verifyHasNoListeners(listModel);
assertEquals(6, listModel.getSize());
- SynchronizedList synchList = new SynchronizedList(listModel);
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
this.verifyHasListeners(listModel);
assertEquals(6, listModel.getSize());
@@ -252,9 +252,9 @@ public class ListModelAdapterTests extends TestCase {
}
public void testGetElementAt() throws Exception {
- SimpleListValueModel listHolder = this.buildListHolder();
- ListModel listModel = this.buildListModel(new SortedListValueModelAdapter(listHolder));
- SynchronizedList synchList = new SynchronizedList(listModel);
+ SimpleListValueModel<String> listHolder = this.buildListHolder();
+ ListModel listModel = this.buildListModel(new SortedListValueModelAdapter<String>(listHolder));
+ CoordinatedList<String> synchList = new CoordinatedList<String>(listModel);
this.verifyHasListeners(listModel);
assertEquals("bar", listModel.getElementAt(0));
assertEquals("bar", synchList.get(0));
@@ -270,8 +270,8 @@ public class ListModelAdapterTests extends TestCase {
assertTrue(hasListeners);
}
- private SimpleCollectionValueModel buildCollectionHolder() {
- return new SimpleCollectionValueModel(this.buildCollection());
+ private SimpleCollectionValueModel<String> buildCollectionHolder() {
+ return new SimpleCollectionValueModel<String>(this.buildCollection());
}
private Collection<String> buildCollection() {
@@ -280,8 +280,8 @@ public class ListModelAdapterTests extends TestCase {
return bag;
}
- private SimpleListValueModel buildListHolder() {
- return new SimpleListValueModel(this.buildList());
+ private SimpleListValueModel<String> buildListHolder() {
+ return new SimpleListValueModel<String>(this.buildList());
}
private List<String> buildList() {
@@ -299,8 +299,8 @@ public class ListModelAdapterTests extends TestCase {
c.add("jaz");
}
- private SimpleListValueModel buildListHolder2() {
- return new SimpleListValueModel(this.buildList2());
+ private SimpleListValueModel<String> buildListHolder2() {
+ return new SimpleListValueModel<String>(this.buildList2());
}
private List<String> buildList2() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java
index 45d7436b7d..46bc80a32e 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -35,10 +35,11 @@ import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.WindowConstants;
+import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter;
@@ -49,7 +50,7 @@ import org.eclipse.jpt.utility.internal.swing.Displayable;
*/
public class ListModelAdapterUITest {
- private PropertyValueModel taskListHolder;
+ private WritablePropertyValueModel<TaskList> taskListHolder;
private TextField taskTextField;
public static void main(String[] args) throws Exception {
@@ -61,7 +62,7 @@ public class ListModelAdapterUITest {
}
private void exec(String[] args) throws Exception {
- this.taskListHolder = new SimplePropertyValueModel(new TaskList());
+ this.taskListHolder = new SimplePropertyValueModel<TaskList>(new TaskList());
this.openWindow();
}
@@ -143,11 +144,11 @@ public class ListModelAdapterUITest {
}
private ListModel buildStandardSortedPrimitiveListModel() {
- return new ListModelAdapter(new SortedListValueModelAdapter(this.buildPrimitiveTaskListAdapter()));
+ return new ListModelAdapter(new SortedListValueModelAdapter<String>(this.buildPrimitiveTaskListAdapter()));
}
private ListModel buildCustomSortedPrimitiveListModel() {
- return new ListModelAdapter(new SortedListValueModelAdapter(this.buildPrimitiveTaskListAdapter(), this.buildCustomStringComparator()));
+ return new ListModelAdapter(new SortedListValueModelAdapter<String>(this.buildPrimitiveTaskListAdapter(), this.buildCustomStringComparator()));
}
private ListModel buildUnsortedDisplayableListModel() {
@@ -155,11 +156,11 @@ public class ListModelAdapterUITest {
}
private ListModel buildStandardSortedDisplayableListModel() {
- return new ListModelAdapter(new SortedListValueModelAdapter(this.buildDisplayableTaskListAdapter()));
+ return new ListModelAdapter(new SortedListValueModelAdapter<Task>(this.buildDisplayableTaskListAdapter()));
}
private ListModel buildCustomSortedDisplayableListModel() {
- return new ListModelAdapter(new SortedListValueModelAdapter(this.buildDisplayableTaskListAdapter(), this.buildCustomTaskObjectComparator()));
+ return new ListModelAdapter(new SortedListValueModelAdapter<Task>(this.buildDisplayableTaskListAdapter(), this.buildCustomTaskObjectComparator()));
}
private Component buildListPanel(String label, ListModel listModel) {
@@ -183,28 +184,28 @@ public class ListModelAdapterUITest {
};
}
- private Comparator<TaskObject> buildCustomTaskObjectComparator() {
- return new Comparator<TaskObject>() {
- public int compare(TaskObject to1, TaskObject to2) {
+ private Comparator<Task> buildCustomTaskObjectComparator() {
+ return new Comparator<Task>() {
+ public int compare(Task to1, Task to2) {
return to2.compareTo(to1);
}
};
}
- private ListValueModel buildPrimitiveTaskListAdapter() {
- return new ListAspectAdapter(TaskList.TASKS_LIST, this.taskList()) {
+ private ListValueModel<String> buildPrimitiveTaskListAdapter() {
+ return new ListAspectAdapter<TaskList, String>(TaskList.TASK_NAMES_LIST, this.taskList()) {
@Override
protected ListIterator<String> listIterator_() {
- return ((TaskList) this.subject).tasks();
+ return this.subject.taskNames();
}
};
}
- private ListValueModel buildDisplayableTaskListAdapter() {
- return new ListAspectAdapter(TaskList.TASK_OBJECTS_LIST, this.taskList()) {
+ private ListValueModel<Task> buildDisplayableTaskListAdapter() {
+ return new ListAspectAdapter<TaskList, Task>(TaskList.TASKS_LIST, this.taskList()) {
@Override
- protected ListIterator<TaskObject> listIterator_() {
- return ((TaskList) this.subject).taskObjects();
+ protected ListIterator<Task> listIterator_() {
+ return this.subject.tasks();
}
};
}
@@ -229,7 +230,7 @@ public class ListModelAdapterUITest {
}
private TaskList taskList() {
- return (TaskList) this.taskListHolder.value();
+ return this.taskListHolder.value();
}
void addTask() {
@@ -298,50 +299,50 @@ public class ListModelAdapterUITest {
}
private class TaskList extends AbstractModel {
- private List<String> tasks = new ArrayList<String>();
- private List<TaskObject> taskObjects = new ArrayList<TaskObject>();
+ private List<String> taskNames = new ArrayList<String>();
+ private List<Task> taskObjects = new ArrayList<Task>();
+ public static final String TASK_NAMES_LIST = "taskNames";
public static final String TASKS_LIST = "tasks";
- public static final String TASK_OBJECTS_LIST = "taskObjects";
TaskList() {
super();
}
- public ListIterator<String> tasks() {
- return this.tasks.listIterator();
+ public ListIterator<String> taskNames() {
+ return this.taskNames.listIterator();
}
- public ListIterator<TaskObject> taskObjects() {
+ public ListIterator<Task> tasks() {
return this.taskObjects.listIterator();
}
- public void addTask(String task) {
- int index = this.tasks.size();
- this.tasks.add(index, task);
- this.fireItemAdded(TASKS_LIST, index, task);
+ public void addTask(String taskName) {
+ int index = this.taskNames.size();
+ this.taskNames.add(index, taskName);
+ this.fireItemAdded(TASK_NAMES_LIST, index, taskName);
- TaskObject taskObject = new TaskObject(task);
+ Task taskObject = new Task(taskName);
this.taskObjects.add(index, taskObject);
- this.fireItemAdded(TASK_OBJECTS_LIST, index, taskObject);
+ this.fireItemAdded(TASKS_LIST, index, taskObject);
}
- public void removeTask(String task) {
- int index = this.tasks.indexOf(task);
+ public void removeTask(String taskName) {
+ int index = this.taskNames.indexOf(taskName);
if (index != -1) {
- Object removedTask = this.tasks.remove(index);
- this.fireItemRemoved(TASKS_LIST, index, removedTask);
+ Object removedTask = this.taskNames.remove(index);
+ this.fireItemRemoved(TASK_NAMES_LIST, index, removedTask);
// assume the indexes match...
Object removedTaskObject = this.taskObjects.remove(index);
- this.fireItemRemoved(TASK_OBJECTS_LIST, index, removedTaskObject);
+ this.fireItemRemoved(TASKS_LIST, index, removedTaskObject);
}
}
public void clearTasks() {
- this.tasks.clear();
- this.fireListChanged(TASKS_LIST);
+ this.taskNames.clear();
+ this.fireListChanged(TASK_NAMES_LIST);
this.taskObjects.clear();
- this.fireListChanged(TASK_OBJECTS_LIST);
+ this.fireListChanged(TASKS_LIST);
}
}
- private class TaskObject extends AbstractModel implements Displayable {
+ private class Task extends AbstractModel implements Displayable {
private String name;
private Date creationTimeStamp;
- public TaskObject(String name) {
+ public Task(String name) {
this.name = name;
this.creationTimeStamp = new Date();
}
@@ -364,7 +365,7 @@ public class ListModelAdapterUITest {
}
@Override
public String toString() {
- return "TaskObject(" + this.displayString() + ")";
+ return StringTools.buildToStringFor(this, this.displayString());
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java
index e4335a10dc..c9548dfc71 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,16 +14,16 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ListSpinnerModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class ListSpinnerModelAdapterTests extends TestCase {
- private PropertyValueModel valueHolder;
+ private WritablePropertyValueModel<Object> valueHolder;
private SpinnerModel spinnerModelAdapter;
boolean eventFired;
private static final String[] VALUE_LIST = {"red", "green", "blue"};
@@ -36,7 +36,7 @@ public class ListSpinnerModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.valueHolder = new SimplePropertyValueModel(DEFAULT_VALUE);
+ this.valueHolder = new SimplePropertyValueModel<Object>(DEFAULT_VALUE);
this.spinnerModelAdapter = new ListSpinnerModelAdapter(this.valueHolder, VALUE_LIST) {
@Override
protected PropertyChangeListener buildValueChangeListener() {
@@ -100,17 +100,17 @@ public class ListSpinnerModelAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localValueHolder = (SimplePropertyValueModel) this.valueHolder;
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder;
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
ChangeListener listener = new TestChangeListener();
this.spinnerModelAdapter.addChangeListener(listener);
- assertTrue(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.spinnerModelAdapter);
this.spinnerModelAdapter.removeChangeListener(listener);
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java
index 10b22946bb..2f48ee864c 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,16 +14,16 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.NumberSpinnerModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class NumberSpinnerModelAdapterTests extends TestCase {
- private PropertyValueModel valueHolder;
+ private WritablePropertyValueModel<Number> valueHolder;
private SpinnerModel spinnerModelAdapter;
boolean eventFired;
@@ -34,7 +34,7 @@ public class NumberSpinnerModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.valueHolder = new SimplePropertyValueModel(new Integer(0));
+ this.valueHolder = new SimplePropertyValueModel<Number>(new Integer(0));
this.spinnerModelAdapter = new NumberSpinnerModelAdapter(this.valueHolder, -33, 33, 1) {
@Override
protected PropertyChangeListener buildNumberChangeListener() {
@@ -91,17 +91,17 @@ public class NumberSpinnerModelAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localValueHolder = (SimplePropertyValueModel) this.valueHolder;
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Number> localValueHolder = (SimplePropertyValueModel<Number>) this.valueHolder;
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
ChangeListener listener = new TestChangeListener();
this.spinnerModelAdapter.addChangeListener(listener);
- assertTrue(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.spinnerModelAdapter);
this.spinnerModelAdapter.removeChangeListener(listener);
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
}
@@ -114,7 +114,7 @@ public class NumberSpinnerModelAdapterTests extends TestCase {
}
public void testNullInitialValue() {
- this.valueHolder = new SimplePropertyValueModel();
+ this.valueHolder = new SimplePropertyValueModel<Number>();
this.spinnerModelAdapter = new NumberSpinnerModelAdapter(this.valueHolder, new Integer(-33), new Integer(33), new Integer(1), new Integer(0)) {
@Override
protected PropertyChangeListener buildNumberChangeListener() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java
index 13aea760de..1935068f27 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -56,22 +56,22 @@ public class ObjectListSelectionModelTests extends TestCase {
public void testListDataListener() {
this.selectionModel.addListSelectionListener(this.buildListSelectionListener());
this.selectionModel.setSelectionInterval(0, 0);
- assertEquals("foo", this.selectionModel.getSelectedValue());
+ assertEquals("foo", this.selectionModel.selectedValue());
this.listModel.set(0, "jar");
- assertEquals("jar", this.selectionModel.getSelectedValue());
+ assertEquals("jar", this.selectionModel.selectedValue());
}
public void testGetSelectedValue() {
this.selectionModel.setSelectionInterval(0, 0);
- assertEquals("foo", this.selectionModel.getSelectedValue());
+ assertEquals("foo", this.selectionModel.selectedValue());
}
public void testGetSelectedValues() {
this.selectionModel.setSelectionInterval(0, 0);
this.selectionModel.addSelectionInterval(2, 2);
- assertEquals(2, this.selectionModel.getSelectedValues().length);
- assertTrue(CollectionTools.contains(this.selectionModel.getSelectedValues(), "foo"));
- assertTrue(CollectionTools.contains(this.selectionModel.getSelectedValues(), "baz"));
+ assertEquals(2, this.selectionModel.selectedValues().length);
+ assertTrue(CollectionTools.contains(this.selectionModel.selectedValues(), "foo"));
+ assertTrue(CollectionTools.contains(this.selectionModel.selectedValues(), "baz"));
}
public void testSetSelectedValue() {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java
index 98a293aa4e..ca03eca987 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -63,31 +63,19 @@ public class PrimitiveListTreeModelTests extends TestCase {
};
}
- private ListValueModel buildListValueModel() {
- return new ListAspectAdapter(TestModel.NAMES_LIST, this.testModel) {
+ private ListValueModel<?> buildListValueModel() {
+ return new ListAspectAdapter<TestModel, String>(TestModel.NAMES_LIST, this.testModel) {
@Override
- protected ListIterator listIterator_() {
- return ((TestModel) this.subject).names();
+ protected ListIterator<String> listIterator_() {
+ return this.subject.names();
}
@Override
- public Object get(int index) {
- return ((TestModel) this.subject).getName(index);
+ public String get(int index) {
+ return this.subject.getName(index);
}
@Override
public int size() {
- return ((TestModel) this.subject).namesSize();
- }
- public void add(int index, Object item) {
- ((TestModel) this.subject).addName(index, (String) item);
- }
- public void addAll(int index, List items) {
- ((TestModel) this.subject).addNames(index, items);
- }
- public Object remove(int index) {
- return ((TestModel) this.subject).removeName(index);
- }
- public List remove(int index, int length) {
- return ((TestModel) this.subject).removeNames(index, length);
+ return this.subject.namesSize();
}
};
}
@@ -176,16 +164,16 @@ public class PrimitiveListTreeModelTests extends TestCase {
public void addName(String name) {
this.addName(this.namesSize(), name);
}
- public void addNames(int index, List list) {
+ public void addNames(int index, List<String> list) {
this.addItemsToList(index, this.names, list, NAMES_LIST);
}
- public void addNames(List list) {
+ public void addNames(List<String> list) {
this.addNames(this.namesSize(), list);
}
public String removeName(int index) {
- return (String) this.removeItemFromList(index, this.names, NAMES_LIST);
+ return this.removeItemFromList(index, this.names, NAMES_LIST);
}
- public List removeNames(int index, int length) {
+ public List<String> removeNames(int index, int length) {
return this.removeItemsFromList(index, length, this.names, NAMES_LIST);
}
public String replaceName(int index, String newName) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java
index 3aef932df8..3855fb82ce 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,16 +16,16 @@ import javax.swing.event.EventListenerList;
import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.RadioButtonModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class RadioButtonModelAdapterTests extends TestCase {
- private PropertyValueModel valueHolder;
+ private WritablePropertyValueModel<Object> valueHolder;
private ButtonModel redButtonModelAdapter;
private ChangeListener redListener;
@@ -52,7 +52,7 @@ public class RadioButtonModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.valueHolder = new SimplePropertyValueModel(null);
+ this.valueHolder = new SimplePropertyValueModel<Object>(null);
// buttonGroup = new ButtonGroup();
this.redButtonModelAdapter = this.buildButtonModel(this.valueHolder, RED);
@@ -85,7 +85,7 @@ public class RadioButtonModelAdapterTests extends TestCase {
this.clearFlags();
}
- private ButtonModel buildButtonModel(PropertyValueModel pvm, Object buttonValue) {
+ private ButtonModel buildButtonModel(WritablePropertyValueModel<Object> pvm, Object buttonValue) {
return new RadioButtonModelAdapter(pvm, buttonValue) {
@Override
protected PropertyChangeListener buildBooleanChangeListener() {
@@ -188,33 +188,33 @@ public class RadioButtonModelAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localValueHolder = (SimplePropertyValueModel) this.valueHolder;
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder;
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.redButtonModelAdapter);
this.verifyHasNoListeners(this.greenButtonModelAdapter);
this.verifyHasNoListeners(this.blueButtonModelAdapter);
ChangeListener listener = new TestChangeListener();
this.redButtonModelAdapter.addChangeListener(listener);
- assertTrue(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.redButtonModelAdapter);
this.verifyHasNoListeners(this.greenButtonModelAdapter);
this.verifyHasNoListeners(this.blueButtonModelAdapter);
this.redButtonModelAdapter.removeChangeListener(listener);
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.redButtonModelAdapter);
this.verifyHasNoListeners(this.greenButtonModelAdapter);
this.verifyHasNoListeners(this.blueButtonModelAdapter);
}
private void verifyHasNoListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.getFieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
assertEquals(0, listenerList.getListenerList().length);
}
private void verifyHasListeners(Object model) throws Exception {
- EventListenerList listenerList = (EventListenerList) ClassTools.getFieldValue(model, "listenerList");
+ EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList");
assertFalse(listenerList.getListenerList().length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java
index 05885bcd3d..dde90666fd 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -29,9 +29,9 @@ import javax.swing.WindowConstants;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.RadioButtonModelAdapter;
@@ -41,8 +41,8 @@ import org.eclipse.jpt.utility.internal.model.value.swing.RadioButtonModelAdapte
public class RadioButtonModelAdapterUITest {
private TestModel testModel;
- private PropertyValueModel testModelHolder;
- private PropertyValueModel colorHolder;
+ private WritablePropertyValueModel<TestModel> testModelHolder;
+ private WritablePropertyValueModel<Object> colorHolder;
private ButtonModel redButtonModel;
private ButtonModel greenButtonModel;
private ButtonModel blueButtonModel;
@@ -57,7 +57,7 @@ public class RadioButtonModelAdapterUITest {
private void exec(String[] args) throws Exception {
this.testModel = new TestModel();
- this.testModelHolder = new SimplePropertyValueModel(this.testModel);
+ this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.colorHolder = this.buildColorHolder(this.testModelHolder);
this.redButtonModel = this.buildRadioButtonModelAdapter(this.colorHolder, TestModel.RED);
this.greenButtonModel = this.buildRadioButtonModelAdapter(this.colorHolder, TestModel.GREEN);
@@ -65,20 +65,20 @@ public class RadioButtonModelAdapterUITest {
this.openWindow();
}
- private PropertyValueModel buildColorHolder(ValueModel subjectHolder) {
- return new PropertyAspectAdapter(subjectHolder, TestModel.COLOR_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildColorHolder(PropertyValueModel<TestModel> subjectHolder) {
+ return new PropertyAspectAdapter<TestModel, Object>(subjectHolder, TestModel.COLOR_PROPERTY) {
@Override
protected Object buildValue_() {
- return ((TestModel) this.subject).getColor();
+ return this.subject.getColor();
}
@Override
protected void setValue_(Object value) {
- ((TestModel) this.subject).setColor((String) value);
+ this.subject.setColor((String) value);
}
};
}
- private ButtonModel buildRadioButtonModelAdapter(PropertyValueModel colorPVM, String color) {
+ private ButtonModel buildRadioButtonModelAdapter(WritablePropertyValueModel<Object> colorPVM, String color) {
return new RadioButtonModelAdapter(colorPVM, color);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java
index 827b625b49..3bfb66f4ba 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -30,7 +30,7 @@ public class ReadOnlyTableModelAdapterUITest extends TableModelAdapterUITest {
protected ColumnAdapter buildColumnAdapter() {
return new PersonColumnAdapter() {
@Override
- public boolean isColumnEditable(int index) {
+ public boolean columnIsEditable(int index) {
return false;
}
};
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java
index 497fbfc9ac..a8d03e556a 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,16 +15,16 @@ import javax.swing.event.ChangeListener;
import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.SpinnerModelAdapter;
import org.eclipse.jpt.utility.tests.internal.TestTools;
import junit.framework.TestCase;
public class SpinnerModelAdapterTests extends TestCase {
- private PropertyValueModel valueHolder;
+ private WritablePropertyValueModel<Object> valueHolder;
SpinnerModel spinnerModelAdapter;
boolean eventFired;
@@ -35,7 +35,7 @@ public class SpinnerModelAdapterTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- this.valueHolder = new SimplePropertyValueModel(new Integer(0));
+ this.valueHolder = new SimplePropertyValueModel<Object>(new Integer(0));
this.spinnerModelAdapter = new SpinnerModelAdapter(this.valueHolder) {
@Override
protected PropertyChangeListener buildValueListener() {
@@ -80,28 +80,28 @@ public class SpinnerModelAdapterTests extends TestCase {
}
public void testHasListeners() throws Exception {
- SimplePropertyValueModel localValueHolder = (SimplePropertyValueModel) this.valueHolder;
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder;
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
ChangeListener listener = new TestChangeListener();
this.spinnerModelAdapter.addChangeListener(listener);
- assertTrue(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasListeners(this.spinnerModelAdapter);
this.spinnerModelAdapter.removeChangeListener(listener);
- assertFalse(localValueHolder.hasAnyPropertyChangeListeners(ValueModel.VALUE));
+ assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
this.verifyHasNoListeners(this.spinnerModelAdapter);
}
private void verifyHasNoListeners(Object adapter) throws Exception {
- Object delegate = ClassTools.getFieldValue(adapter, "delegate");
+ Object delegate = ClassTools.fieldValue(adapter, "delegate");
Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getChangeListeners");
assertEquals(0, listeners.length);
}
private void verifyHasListeners(Object adapter) throws Exception {
- Object delegate = ClassTools.getFieldValue(adapter, "delegate");
+ Object delegate = ClassTools.fieldValue(adapter, "delegate");
Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getChangeListeners");
assertFalse(listeners.length == 0);
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java
index 45a64beca5..742a218647 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -31,9 +31,9 @@ import javax.swing.WindowConstants;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.DateSpinnerModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.swing.ListSpinnerModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.swing.NumberSpinnerModelAdapter;
@@ -44,15 +44,15 @@ import org.eclipse.jpt.utility.internal.model.value.swing.NumberSpinnerModelAdap
public class SpinnerModelAdapterUITest {
private TestModel testModel;
- private PropertyValueModel testModelHolder;
+ private WritablePropertyValueModel<TestModel> testModelHolder;
- private PropertyValueModel birthDateHolder;
+ private WritablePropertyValueModel<Object> birthDateHolder;
private SpinnerModel birthDateSpinnerModel;
- private PropertyValueModel ageHolder;
+ private WritablePropertyValueModel<Number> ageHolder;
private SpinnerModel ageSpinnerModel;
- private PropertyValueModel eyeColorHolder;
+ private WritablePropertyValueModel<Object> eyeColorHolder;
private SpinnerModel eyeColorSpinnerModel;
@@ -66,7 +66,7 @@ public class SpinnerModelAdapterUITest {
private void exec(String[] args) throws Exception {
this.testModel = new TestModel();
- this.testModelHolder = new SimplePropertyValueModel(this.testModel);
+ this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel);
this.birthDateHolder = this.buildBirthDateHolder(this.testModelHolder);
this.birthDateSpinnerModel = this.buildBirthDateSpinnerModel(this.birthDateHolder);
@@ -80,54 +80,54 @@ public class SpinnerModelAdapterUITest {
this.openWindow();
}
- private PropertyValueModel buildBirthDateHolder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.BIRTH_DATE_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildBirthDateHolder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Object>(vm, TestModel.BIRTH_DATE_PROPERTY) {
@Override
protected Object buildValue_() {
- return ((TestModel) this.subject).getBirthDate();
+ return this.subject.getBirthDate();
}
@Override
protected void setValue_(Object value) {
- ((TestModel) this.subject).setBirthDate((Date) value);
+ this.subject.setBirthDate((Date) value);
}
};
}
- private SpinnerModel buildBirthDateSpinnerModel(PropertyValueModel valueHolder) {
+ private SpinnerModel buildBirthDateSpinnerModel(WritablePropertyValueModel<Object> valueHolder) {
return new DateSpinnerModelAdapter(valueHolder);
}
- private PropertyValueModel buildAgeHolder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.AGE_PROPERTY) {
+ private WritablePropertyValueModel<Number> buildAgeHolder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Number>(vm, TestModel.AGE_PROPERTY) {
@Override
- protected Object buildValue_() {
- return new Integer(((TestModel) this.subject).getAge());
+ protected Number buildValue_() {
+ return new Integer(this.subject.getAge());
}
@Override
- protected void setValue_(Object value) {
- ((TestModel) this.subject).setAge(((Number) value).intValue());
+ protected void setValue_(Number value) {
+ this.subject.setAge(value.intValue());
}
};
}
- private SpinnerModel buildAgeSpinnerModel(PropertyValueModel valueHolder) {
- return new NumberSpinnerModelAdapter(valueHolder, ((Integer) valueHolder.value()).intValue(), TestModel.MIN_AGE, TestModel.MAX_AGE, 1);
+ private SpinnerModel buildAgeSpinnerModel(WritablePropertyValueModel<Number> valueHolder) {
+ return new NumberSpinnerModelAdapter(valueHolder, valueHolder.value().intValue(), TestModel.MIN_AGE, TestModel.MAX_AGE, 1);
}
- private PropertyValueModel buildEyeColorHolder(ValueModel vm) {
- return new PropertyAspectAdapter(vm, TestModel.EYE_COLOR_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildEyeColorHolder(PropertyValueModel<TestModel> vm) {
+ return new PropertyAspectAdapter<TestModel, Object>(vm, TestModel.EYE_COLOR_PROPERTY) {
@Override
protected Object buildValue_() {
- return ((TestModel) this.subject).getEyeColor();
+ return this.subject.getEyeColor();
}
@Override
protected void setValue_(Object value) {
- ((TestModel) this.subject).setEyeColor((String) value);
+ this.subject.setEyeColor((String) value);
}
};
}
- private SpinnerModel buildEyeColorSpinnerModel(PropertyValueModel valueHolder) {
+ private SpinnerModel buildEyeColorSpinnerModel(WritablePropertyValueModel<Object> valueHolder) {
return new ListSpinnerModelAdapter(valueHolder, TestModel.VALID_EYE_COLORS);
}
@@ -334,6 +334,7 @@ public class SpinnerModelAdapterUITest {
this.eyeColor = eyeColor;
this.firePropertyChanged(EYE_COLOR_PROPERTY, old, eyeColor);
}
+ @Override
public String toString() {
return "TestModel(birth: " + this.getBirthDate() + " - eyes: " + this.eyeColor + ")";
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java
index 4786bbfd41..db1a77a9a5 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -31,7 +31,7 @@ import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.swing.ColumnAdapter;
import org.eclipse.jpt.utility.internal.model.value.swing.TableModelAdapter;
@@ -63,7 +63,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testGetRowCount() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
assertEquals(0, tableModelAdapter.getRowCount());
// we need to add a listener to wake up the adapter
tableModelAdapter.addTableModelListener(this.buildTableModelListener());
@@ -71,12 +71,12 @@ public class TableModelAdapterTests extends TestCase {
}
public void testGetColumnCount() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
assertEquals(PersonColumnAdapter.COLUMN_COUNT, tableModelAdapter.getColumnCount());
}
public void testGetValueAt() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
tableModelAdapter.addTableModelListener(this.buildTableModelListener());
List<String> sortedNames = this.sortedNames();
@@ -86,7 +86,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testSetValueAt() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
this.event = null;
tableModelAdapter.addTableModelListener(new TestTableModelListener() {
@Override
@@ -115,7 +115,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testAddRow() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
this.event = null;
tableModelAdapter.addTableModelListener(this.buildSingleEventListener());
// add a person to the end of the list so we only trigger one event
@@ -126,7 +126,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testRemoveRow() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
this.event = null;
tableModelAdapter.addTableModelListener(this.buildSingleEventListener());
// removing a person should only trigger one event, since a re-sort is not needed
@@ -137,7 +137,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testChangeCell() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
this.event = null;
tableModelAdapter.addTableModelListener(this.buildSingleEventListener());
// add a person to the end of the list so we only trigger one event
@@ -149,7 +149,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testLazyListListener() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
TableModelListener listener = this.buildTableModelListener();
assertTrue(this.crowd.hasNoCollectionChangeListeners(Crowd.PEOPLE_COLLECTION));
tableModelAdapter.addTableModelListener(listener);
@@ -159,7 +159,7 @@ public class TableModelAdapterTests extends TestCase {
}
public void testLazyCellListener() throws Exception {
- TableModelAdapter tableModelAdapter = this.buildTableModelAdapter();
+ TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter();
TableModelListener listener = this.buildTableModelListener();
Person person = this.crowd.personNamed("Gollum");
assertTrue(person.hasNoPropertyChangeListeners(Person.NAME_PROPERTY));
@@ -183,8 +183,8 @@ public class TableModelAdapterTests extends TestCase {
assertTrue(person.hasNoPropertyChangeListeners(Person.RANK_PROPERTY));
}
- private TableModelAdapter buildTableModelAdapter() {
- return new TableModelAdapter(this.buildSortedPeopleAdapter(), this.buildColumnAdapter()) {
+ private TableModelAdapter<Person> buildTableModelAdapter() {
+ return new TableModelAdapter<Person>(this.buildSortedPeopleAdapter(), this.buildColumnAdapter()) {
@Override
protected PropertyChangeListener buildCellListener() {
return this.buildCellListener_();
@@ -196,19 +196,19 @@ public class TableModelAdapterTests extends TestCase {
};
}
- private ListValueModel buildSortedPeopleAdapter() {
- return new SortedListValueModelAdapter(this.buildPeopleAdapter());
+ private ListValueModel<Person> buildSortedPeopleAdapter() {
+ return new SortedListValueModelAdapter<Person>(this.buildPeopleAdapter());
}
- private CollectionValueModel buildPeopleAdapter() {
- return new CollectionAspectAdapter(Crowd.PEOPLE_COLLECTION, this.crowd) {
+ private CollectionValueModel<Person> buildPeopleAdapter() {
+ return new CollectionAspectAdapter<Crowd, Person>(Crowd.PEOPLE_COLLECTION, this.crowd) {
@Override
protected Iterator<Person> iterator_() {
- return ((Crowd) this.subject).people();
+ return this.subject.people();
}
@Override
protected int size_() {
- return ((Crowd) this.subject).peopleSize();
+ return this.subject.peopleSize();
}
};
}
@@ -273,15 +273,15 @@ public class TableModelAdapterTests extends TestCase {
};
- public int getColumnCount() {
+ public int columnCount() {
return COLUMN_COUNT;
}
- public String getColumnName(int index) {
+ public String columnName(int index) {
return COLUMN_NAMES[index];
}
- public Class<?> getColumnClass(int index) {
+ public Class<?> columnClass(int index) {
switch (index) {
case NAME_COLUMN: return Object.class;
case BIRTH_DATE_COLUMN: return Date.class;
@@ -294,112 +294,113 @@ public class TableModelAdapterTests extends TestCase {
}
}
- public boolean isColumnEditable(int index) {
+ public boolean columnIsEditable(int index) {
return index != NAME_COLUMN;
}
- public PropertyValueModel[] cellModels(Object subject) {
+ public WritablePropertyValueModel<Object>[] cellModels(Object subject) {
Person person = (Person) subject;
- PropertyValueModel[] result = new PropertyValueModel[COLUMN_COUNT];
+ @SuppressWarnings("unchecked")
+ WritablePropertyValueModel<Object>[] result = new WritablePropertyValueModel[COLUMN_COUNT];
- result[NAME_COLUMN] = this.buildNameAdapter(person);
- result[BIRTH_DATE_COLUMN] = this.buildBirthDateAdapter(person);
- result[GONE_WEST_DATE_COLUMN] = this.buildGoneWestDateAdapter(person);
- result[EYE_COLOR_COLUMN] = this.buildEyeColorAdapter(person);
- result[EVIL_COLUMN] = this.buildEvilAdapter(person);
- result[RANK_COLUMN] = this.buildRankAdapter(person);
- result[ADVENTURE_COUNT_COLUMN] = this.buildAdventureCountAdapter(person);
+ result[NAME_COLUMN] = this.buildNameAdapter(person);
+ result[BIRTH_DATE_COLUMN] = this.buildBirthDateAdapter(person);
+ result[GONE_WEST_DATE_COLUMN] = this.buildGoneWestDateAdapter(person);
+ result[EYE_COLOR_COLUMN] = this.buildEyeColorAdapter(person);
+ result[EVIL_COLUMN] = this.buildEvilAdapter(person);
+ result[RANK_COLUMN] = this.buildRankAdapter(person);
+ result[ADVENTURE_COUNT_COLUMN] = this.buildAdventureCountAdapter(person);
return result;
}
- private PropertyValueModel buildNameAdapter(Person person) {
- return new PropertyAspectAdapter(Person.NAME_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildNameAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.NAME_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getName();
+ protected String buildValue_() {
+ return this.subject.getName();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setName((String) value);
+ this.subject.setName((String) value);
}
};
}
- private PropertyValueModel buildBirthDateAdapter(Person person) {
- return new PropertyAspectAdapter(Person.BIRTH_DATE_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildBirthDateAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.BIRTH_DATE_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getBirthDate();
+ protected Date buildValue_() {
+ return this.subject.getBirthDate();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setBirthDate((Date) value);
+ this.subject.setBirthDate((Date) value);
}
};
}
- private PropertyValueModel buildGoneWestDateAdapter(Person person) {
- return new PropertyAspectAdapter(Person.GONE_WEST_DATE_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildGoneWestDateAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.GONE_WEST_DATE_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getGoneWestDate();
+ protected Date buildValue_() {
+ return this.subject.getGoneWestDate();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setGoneWestDate((Date) value);
+ this.subject.setGoneWestDate((Date) value);
}
};
}
- private PropertyValueModel buildEyeColorAdapter(Person person) {
- return new PropertyAspectAdapter(Person.EYE_COLOR_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildEyeColorAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.EYE_COLOR_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getEyeColor();
+ protected String buildValue_() {
+ return this.subject.getEyeColor();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setEyeColor((String) value);
+ this.subject.setEyeColor((String) value);
}
};
}
- private PropertyValueModel buildEvilAdapter(Person person) {
- return new PropertyAspectAdapter(Person.EVIL_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildEvilAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.EVIL_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return Boolean.valueOf(((Person) this.subject).isEvil());
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.isEvil());
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setEvil(((Boolean) value).booleanValue());
+ this.subject.setEvil(((Boolean)value).booleanValue());
}
};
}
- private PropertyValueModel buildRankAdapter(Person person) {
- return new PropertyAspectAdapter(Person.RANK_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildRankAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.RANK_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return new Integer(((Person) this.subject).getRank());
+ protected Integer buildValue_() {
+ return new Integer(this.subject.getRank());
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setRank(((Integer) value).intValue());
+ this.subject.setRank(((Integer) value).intValue());
}
};
}
- private PropertyValueModel buildAdventureCountAdapter(Person person) {
- return new PropertyAspectAdapter(Person.ADVENTURE_COUNT_PROPERTY, person) {
+ private WritablePropertyValueModel<Object> buildAdventureCountAdapter(Person person) {
+ return new PropertyAspectAdapter<Person, Object>(Person.ADVENTURE_COUNT_PROPERTY, person) {
@Override
- protected Object buildValue_() {
- return new Integer(((Person) this.subject).getAdventureCount());
+ protected Integer buildValue_() {
+ return new Integer(this.subject.getAdventureCount());
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setAdventureCount(((Integer) value).intValue());
+ this.subject.setAdventureCount(((Integer) value).intValue());
}
};
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java
index ded0db6c75..59f60b1e23 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,6 +16,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
+import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -53,7 +54,7 @@ import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter;
@@ -88,10 +89,10 @@ import org.eclipse.jpt.utility.tests.internal.model.value.swing.TableModelAdapte
* list value model (the sorted people adapter)
*/
public class TableModelAdapterUITest {
- private SimpleCollectionValueModel eyeColorsHolder;
- private PropertyValueModel crowdHolder;
- private PropertyValueModel selectedPersonHolder;
- private ListValueModel sortedPeopleAdapter;
+ private SimpleCollectionValueModel<Object> eyeColorsHolder; // Object because it adapts to a combo-box
+ private WritablePropertyValueModel<Crowd> crowdHolder;
+ private WritablePropertyValueModel<Person> selectedPersonHolder;
+ private ListValueModel<Person> sortedPeopleAdapter;
private TableModel tableModel;
private ObjectListSelectionModel rowSelectionModel;
private Action removeAction;
@@ -116,12 +117,12 @@ public class TableModelAdapterUITest {
this.openWindow();
}
- private SimpleCollectionValueModel buildEyeColorCollectionHolder() {
- return new SimpleCollectionValueModel(Person.getValidEyeColors());
+ private SimpleCollectionValueModel<Object> buildEyeColorCollectionHolder() {
+ return new SimpleCollectionValueModel<Object>(new ArrayList<Object>(Person.getValidEyeColors()));
}
- private PropertyValueModel buildCrowdHolder() {
- return new SimplePropertyValueModel(this.buildCrowd());
+ private WritablePropertyValueModel<Crowd> buildCrowdHolder() {
+ return new SimplePropertyValueModel<Crowd>(this.buildCrowd());
}
private Crowd buildCrowd() {
@@ -151,34 +152,34 @@ public class TableModelAdapterUITest {
return crowd;
}
- private PropertyValueModel buildSelectedPersonHolder() {
- return new SimplePropertyValueModel();
+ private WritablePropertyValueModel<Person> buildSelectedPersonHolder() {
+ return new SimplePropertyValueModel<Person>();
}
- private ListValueModel buildSortedPeopleAdapter() {
- return new SortedListValueModelAdapter(this.buildPeopleNameAdapter());
+ private ListValueModel<Person> buildSortedPeopleAdapter() {
+ return new SortedListValueModelAdapter<Person>(this.buildPeopleNameAdapter());
}
// the list will need to be re-sorted if a name changes
- private ListValueModel buildPeopleNameAdapter() {
- return new ItemPropertyListValueModelAdapter(this.buildPeopleAdapter(), Person.NAME_PROPERTY);
+ private ListValueModel<Person> buildPeopleNameAdapter() {
+ return new ItemPropertyListValueModelAdapter<Person>(this.buildPeopleAdapter(), Person.NAME_PROPERTY);
}
- private CollectionValueModel buildPeopleAdapter() {
- return new CollectionAspectAdapter(this.crowdHolder, Crowd.PEOPLE_COLLECTION) {
+ private CollectionValueModel<Person> buildPeopleAdapter() {
+ return new CollectionAspectAdapter<Crowd, Person>(this.crowdHolder, Crowd.PEOPLE_COLLECTION) {
@Override
- protected Iterator iterator_() {
- return ((Crowd) this.subject).people();
+ protected Iterator<Person> iterator_() {
+ return this.subject.people();
}
@Override
protected int size_() {
- return ((Crowd) this.subject).peopleSize();
+ return this.subject.peopleSize();
}
};
}
private TableModel buildTableModel() {
- return new TableModelAdapter(this.sortedPeopleAdapter, this.buildColumnAdapter());
+ return new TableModelAdapter<Person>(this.sortedPeopleAdapter, this.buildColumnAdapter());
}
protected ColumnAdapter buildColumnAdapter() {
@@ -204,7 +205,7 @@ public class TableModelAdapterUITest {
}
void rowSelectionChanged(ListSelectionEvent e) {
- Object selection = this.rowSelectionModel.getSelectedValue();
+ Person selection = (Person) this.rowSelectionModel.selectedValue();
this.selectedPersonHolder.setValue(selection);
boolean personSelected = (selection != null);
this.removeAction.setEnabled(personSelected);
@@ -255,7 +256,7 @@ public class TableModelAdapterUITest {
SpinnerTableCellRenderer spinnerRenderer = this.buildDateSpinnerRenderer();
column.setCellRenderer(spinnerRenderer);
column.setCellEditor(new TableCellEditorAdapter(this.buildDateSpinnerRenderer()));
- rowHeight = Math.max(rowHeight, spinnerRenderer.getPreferredHeight());
+ rowHeight = Math.max(rowHeight, spinnerRenderer.preferredHeight());
// eye color column (combo-box)
// the jdk combo-box renderer looks like a text field
@@ -264,7 +265,7 @@ public class TableModelAdapterUITest {
ComboBoxTableCellRenderer eyeColorRenderer = this.buildEyeColorComboBoxRenderer();
column.setCellRenderer(eyeColorRenderer);
column.setCellEditor(new TableCellEditorAdapter(this.buildEyeColorComboBoxRenderer()));
- rowHeight = Math.max(rowHeight, eyeColorRenderer.getPreferredHeight());
+ rowHeight = Math.max(rowHeight, eyeColorRenderer.preferredHeight());
// evil (check box)
// the jdk check box renderer and editor suck - use a custom ones
@@ -272,25 +273,25 @@ public class TableModelAdapterUITest {
CheckBoxTableCellRenderer evilRenderer = new CheckBoxTableCellRenderer();
column.setCellRenderer(evilRenderer);
column.setCellEditor(new TableCellEditorAdapter(new CheckBoxTableCellRenderer()));
- rowHeight = Math.max(rowHeight, evilRenderer.getPreferredHeight());
+ rowHeight = Math.max(rowHeight, evilRenderer.preferredHeight());
// adventure count column (spinner)
column = table.getColumnModel().getColumn(PersonColumnAdapter.ADVENTURE_COUNT_COLUMN);
spinnerRenderer = this.buildNumberSpinnerRenderer();
column.setCellRenderer(spinnerRenderer);
column.setCellEditor(new TableCellEditorAdapter(this.buildNumberSpinnerRenderer()));
- rowHeight = Math.max(rowHeight, spinnerRenderer.getPreferredHeight());
+ rowHeight = Math.max(rowHeight, spinnerRenderer.preferredHeight());
table.setRowHeight(rowHeight);
return table;
}
private SpinnerTableCellRenderer buildDateSpinnerRenderer() {
- return new SpinnerTableCellRenderer(new DateSpinnerModelAdapter(new SimplePropertyValueModel()));
+ return new SpinnerTableCellRenderer(new DateSpinnerModelAdapter(new SimplePropertyValueModel<Object>()));
}
private SpinnerTableCellRenderer buildNumberSpinnerRenderer() {
- return new SpinnerTableCellRenderer(new NumberSpinnerModelAdapter(new SimplePropertyValueModel()));
+ return new SpinnerTableCellRenderer(new NumberSpinnerModelAdapter(new SimplePropertyValueModel<Number>()));
}
private ComboBoxTableCellRenderer buildEyeColorComboBoxRenderer() {
@@ -298,7 +299,7 @@ public class TableModelAdapterUITest {
}
private ComboBoxModel buildReadOnlyEyeColorComboBoxModel() {
- return new ComboBoxModelAdapter(this.eyeColorsHolder, new SimplePropertyValueModel());
+ return new ComboBoxModelAdapter(this.eyeColorsHolder, new SimplePropertyValueModel<Object>());
}
private ListCellRenderer buildEyeColorRenderer() {
@@ -443,7 +444,7 @@ public class TableModelAdapterUITest {
}
if ((eyeColor.length() == 0)) {
JOptionPane.showMessageDialog(null, "The eye color is required.", "Invalid Eye Color", JOptionPane.ERROR_MESSAGE);
- } else if (CollectionTools.contains((Iterator) this.eyeColorsHolder.iterator(), eyeColor)) {
+ } else if (CollectionTools.contains(this.eyeColorsHolder.iterator(), eyeColor)) {
JOptionPane.showMessageDialog(null, "The eye color already exists.", "Invalid Eye Color", JOptionPane.ERROR_MESSAGE);
} else {
return eyeColor;
@@ -532,15 +533,15 @@ public class TableModelAdapterUITest {
return new DocumentAdapter(this.buildNameAdapter());
}
- private PropertyValueModel buildNameAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.NAME_PROPERTY) {
+ private WritablePropertyValueModel<String> buildNameAdapter() {
+ return new PropertyAspectAdapter<Person, String>(this.selectedPersonHolder, Person.NAME_PROPERTY) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getName();
+ protected String buildValue_() {
+ return this.subject.getName();
}
@Override
- protected void setValue_(Object value) {
- ((Person) this.subject).setName((String) value);
+ protected void setValue_(String value) {
+ this.subject.setName(value);
}
};
}
@@ -556,15 +557,15 @@ public class TableModelAdapterUITest {
return new DateSpinnerModelAdapter(this.buildBirthDateAdapter());
}
- private PropertyValueModel buildBirthDateAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.BIRTH_DATE_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildBirthDateAdapter() {
+ return new PropertyAspectAdapter<Person, Object>(this.selectedPersonHolder, Person.BIRTH_DATE_PROPERTY) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getBirthDate();
+ protected Date buildValue_() {
+ return this.subject.getBirthDate();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setBirthDate((Date) value);
+ this.subject.setBirthDate((Date) value);
}
};
}
@@ -580,15 +581,15 @@ public class TableModelAdapterUITest {
return new DateSpinnerModelAdapter(this.buildGoneWestDateAdapter());
}
- private PropertyValueModel buildGoneWestDateAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.GONE_WEST_DATE_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildGoneWestDateAdapter() {
+ return new PropertyAspectAdapter<Person, Object>(this.selectedPersonHolder, Person.GONE_WEST_DATE_PROPERTY) {
@Override
- protected Object buildValue_() {
- return ((Person) this.subject).getGoneWestDate();
+ protected Date buildValue_() {
+ return this.subject.getGoneWestDate();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setGoneWestDate((Date) value);
+ this.subject.setGoneWestDate((Date) value);
}
};
}
@@ -604,15 +605,15 @@ public class TableModelAdapterUITest {
return new ComboBoxModelAdapter(this.eyeColorsHolder, this.buildEyeColorAdapter());
}
- private PropertyValueModel buildEyeColorAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.EYE_COLOR_PROPERTY) {
+ private WritablePropertyValueModel<Object> buildEyeColorAdapter() {
+ return new PropertyAspectAdapter<Person, Object>(this.selectedPersonHolder, Person.EYE_COLOR_PROPERTY) {
@Override
protected Object buildValue_() {
- return ((Person) this.subject).getEyeColor();
+ return this.subject.getEyeColor();
}
@Override
protected void setValue_(Object value) {
- ((Person) this.subject).setEyeColor((String) value);
+ this.subject.setEyeColor((String) value);
}
};
}
@@ -631,15 +632,15 @@ public class TableModelAdapterUITest {
return new CheckBoxModelAdapter(this.buildEvilAdapter());
}
- private PropertyValueModel buildEvilAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.EVIL_PROPERTY) {
+ private WritablePropertyValueModel<Boolean> buildEvilAdapter() {
+ return new PropertyAspectAdapter<Person, Boolean>(this.selectedPersonHolder, Person.EVIL_PROPERTY) {
@Override
- protected Object buildValue_() {
- return Boolean.valueOf(((Person) this.subject).isEvil());
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.isEvil());
}
@Override
- protected void setValue_(Object value) {
- ((Person) this.subject).setEvil(((Boolean) value).booleanValue());
+ protected void setValue_(Boolean value) {
+ this.subject.setEvil(value.booleanValue());
}
};
}
@@ -655,15 +656,15 @@ public class TableModelAdapterUITest {
return new NumberSpinnerModelAdapter(this.buildRankAdapter());
}
- private PropertyValueModel buildRankAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.RANK_PROPERTY) {
+ private WritablePropertyValueModel<Number> buildRankAdapter() {
+ return new PropertyAspectAdapter<Person, Number>(this.selectedPersonHolder, Person.RANK_PROPERTY) {
@Override
- protected Object buildValue_() {
- return new Integer(((Person) this.subject).getRank());
+ protected Number buildValue_() {
+ return new Integer(this.subject.getRank());
}
@Override
- protected void setValue_(Object value) {
- ((Person) this.subject).setRank(((Integer) value).intValue());
+ protected void setValue_(Number value) {
+ this.subject.setRank(value.intValue());
}
};
}
@@ -679,15 +680,15 @@ public class TableModelAdapterUITest {
return new NumberSpinnerModelAdapter(this.buildAdventureCountAdapter());
}
- private PropertyValueModel buildAdventureCountAdapter() {
- return new PropertyAspectAdapter(this.selectedPersonHolder, Person.ADVENTURE_COUNT_PROPERTY) {
+ private WritablePropertyValueModel<Number> buildAdventureCountAdapter() {
+ return new PropertyAspectAdapter<Person, Number>(this.selectedPersonHolder, Person.ADVENTURE_COUNT_PROPERTY) {
@Override
- protected Object buildValue_() {
- return new Integer(((Person) this.subject).getAdventureCount());
+ protected Number buildValue_() {
+ return new Integer(this.subject.getAdventureCount());
}
@Override
- protected void setValue_(Object value) {
- ((Person) this.subject).setAdventureCount(((Integer) value).intValue());
+ protected void setValue_(Number value) {
+ this.subject.setAdventureCount(value.intValue());
}
};
}
@@ -696,14 +697,14 @@ public class TableModelAdapterUITest {
// ********** queries **********
private Crowd crowd() {
- return (Crowd) this.crowdHolder.value();
+ return this.crowdHolder.value();
}
private Person selectedPerson() {
if (this.rowSelectionModel.isSelectionEmpty()) {
return null;
}
- return (Person) this.rowSelectionModel.getSelectedValue();
+ return (Person) this.rowSelectionModel.selectedValue();
}
private void setSelectedPerson(Person person) {
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java
index ddbf7a8ae8..89c1b7a234 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,6 @@ package org.eclipse.jpt.utility.tests.internal.model.value.swing;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
@@ -25,6 +24,7 @@ import javax.swing.tree.TreeModel;
import org.eclipse.jpt.utility.internal.HashBag;
import org.eclipse.jpt.utility.internal.IndentingPrintWriter;
+import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent;
@@ -39,13 +39,13 @@ import org.eclipse.jpt.utility.internal.model.value.ListValueModel;
import org.eclipse.jpt.utility.internal.model.value.NullListValueModel;
import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ReadOnlyPropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter;
+import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.TreeNodeValueModel;
-import org.eclipse.jpt.utility.internal.model.value.ValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.TreeModelAdapter;
import org.eclipse.jpt.utility.internal.swing.Displayable;
@@ -194,7 +194,7 @@ public class TreeModelAdapterTests extends TestCase {
}
public void testTreeStructureChanged() {
- PropertyValueModel nodeHolder = new SimplePropertyValueModel(this.buildSortedRootNode());
+ WritablePropertyValueModel<TreeNodeValueModel<Object>> nodeHolder = new SimplePropertyValueModel<TreeNodeValueModel<Object>>(this.buildSortedRootNode());
TreeModel treeModel = this.buildTreeModel(nodeHolder);
this.eventFired = false;
treeModel.addTreeModelListener(new TestTreeModelListener() {
@@ -290,7 +290,7 @@ public class TreeModelAdapterTests extends TestCase {
public static class TestModel extends AbstractModel {
// the parent is immutable; the root's parent is null
- private TestModel parent;
+ private final TestModel parent;
// the name is mutable; so I guess it isn't the "primary key" :-)
private String name;
@@ -301,13 +301,13 @@ public class TreeModelAdapterTests extends TestCase {
public TestModel(String name) { // root ctor
- super();
- this.name = name;
- this.children = new HashBag<TestModel>();
+ this(null, name);
}
private TestModel(TestModel parent, String name) {
- this(name);
+ super();
this.parent = parent;
+ this.name = name;
+ this.children = new HashBag<TestModel>();
}
public TestModel getParent() {
@@ -331,45 +331,28 @@ public class TreeModelAdapterTests extends TestCase {
}
public TestModel addChild(String childName) {
TestModel child = new TestModel(this, childName);
- this.children.add(child);
- this.fireItemAdded(CHILDREN_COLLECTION, child);
+ this.addItemToCollection(child, this.children, CHILDREN_COLLECTION);
return child;
}
public TestModel[] addChildren(String[] childNames) {
TestModel[] newChildren = new TestModel[childNames.length];
for (int i = 0; i < childNames.length; i++) {
- TestModel child = new TestModel(this, childNames[i]);
- this.children.add(child);
- newChildren[i] = child;
+ newChildren[i] = new TestModel(this, childNames[i]);
}
- this.fireItemsAdded(CHILDREN_COLLECTION, Arrays.asList(newChildren));
+ this.addItemsToCollection(newChildren, this.children, CHILDREN_COLLECTION);
return newChildren;
}
public void removeChild(TestModel child) {
- if (this.children.remove(child)) {
- this.fireItemRemoved(CHILDREN_COLLECTION, child);
- }
+ this.removeItemFromCollection(child, this.children, CHILDREN_COLLECTION);
}
public void removeChildren(TestModel[] testModels) {
- Collection<TestModel> removedChildren = new ArrayList<TestModel>();
- for (int i = 0; i < testModels.length; i++) {
- if (this.children.remove(testModels[i])) {
- removedChildren.add(testModels[i]);
- } else {
- throw new IllegalArgumentException(String.valueOf(testModels[i]));
- }
- }
- if ( ! removedChildren.isEmpty()) {
- this.fireItemsRemoved(CHILDREN_COLLECTION, removedChildren);
- }
+ this.removeItemsFromCollection(testModels, this.children, CHILDREN_COLLECTION);
}
public void clearChildren() {
- this.children.clear();
- this.fireCollectionChanged(CHILDREN_COLLECTION);
+ this.clearCollection(this.children, CHILDREN_COLLECTION);
}
public TestModel childNamed(String childName) {
- for (Iterator<TestModel> stream = this.children(); stream.hasNext(); ) {
- TestModel child = stream.next();
+ for (TestModel child : this.children) {
if (child.getName().equals(childName)) {
return child;
}
@@ -386,8 +369,8 @@ public class TreeModelAdapterTests extends TestCase {
public void dumpOn(IndentingPrintWriter writer) {
writer.println(this);
writer.indent();
- for (Iterator<TestModel> stream = this.children(); stream.hasNext(); ) {
- stream.next().dumpOn(writer);
+ for (TestModel child : this.children) {
+ child.dumpOn(writer);
}
writer.undent();
}
@@ -402,7 +385,7 @@ public class TreeModelAdapterTests extends TestCase {
@Override
public String toString() {
- return "TestModel(" + this.name + ")";
+ return StringTools.buildToStringFor(this, this.name);
}
}
@@ -415,18 +398,18 @@ public class TreeModelAdapterTests extends TestCase {
* TestModel's children into a ListValueModel of Nodes whose order is
* determined by subclass implementations.
*/
- public static abstract class TestNode extends AbstractTreeNodeValueModel implements Displayable {
+ public static abstract class TestNode extends AbstractTreeNodeValueModel<Object> implements Displayable {
/** the model object wrapped by this node */
- private TestModel testModel;
+ private final TestModel testModel;
/** this node's parent node; null for the root node */
- private TestNode parent;
+ private final TestNode parent;
/** this node's child nodes */
- private ListValueModel childrenModel;
+ private final ListValueModel<TreeNodeValueModel<Object>> childrenModel;
/** a listener that notifies us when the model object's "internal state" changes */
- private PropertyChangeListener testModelListener;
+ private final PropertyChangeListener testModelListener;
- // ********** constructors **********
+ // ********** constructors/initialization **********
/**
* root node constructor
@@ -440,15 +423,9 @@ public class TreeModelAdapterTests extends TestCase {
*/
public TestNode(TestNode parent, TestModel testModel) {
super();
- this.initialize(parent, testModel);
- }
-
-
- // ********** initialization **********
-
- @Override
- protected void initialize() {
- super.initialize();
+ this.parent = parent;
+ this.testModel = testModel;
+ this.childrenModel = this.buildChildrenModel(testModel);
this.testModelListener = this.buildTestModelListener();
}
@@ -460,26 +437,20 @@ public class TreeModelAdapterTests extends TestCase {
};
}
- protected void initialize(TestNode p, TestModel tm) {
- this.parent = p;
- this.testModel = tm;
- this.childrenModel = this.buildChildrenModel(tm);
- }
-
/**
* subclasses decide the order of the child nodes
*/
- protected abstract ListValueModel buildChildrenModel(TestModel model);
+ protected abstract ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel model);
/**
* used by subclasses;
* transform the test model children into nodes
*/
- protected ListValueModel buildNodeAdapter(TestModel model) {
- return new TransformationListValueModelAdapter(this.buildChildrenAdapter(model)) {
+ protected ListValueModel<TreeNodeValueModel<Object>> buildNodeAdapter(TestModel model) {
+ return new TransformationListValueModelAdapter<TestModel, TreeNodeValueModel<Object>>(this.buildChildrenAdapter(model)) {
@Override
- protected Object transformItem(Object item) {
- return TestNode.this.buildChildNode((TestModel) item);
+ protected TestNode transformItem(TestModel item) {
+ return TestNode.this.buildChildNode(item);
}
};
}
@@ -492,15 +463,15 @@ public class TreeModelAdapterTests extends TestCase {
/**
* return a collection value model on the specified model's children
*/
- protected CollectionValueModel buildChildrenAdapter(TestModel model) {
- return new CollectionAspectAdapter(TestModel.CHILDREN_COLLECTION, model) {
+ protected CollectionValueModel<TestModel> buildChildrenAdapter(TestModel model) {
+ return new CollectionAspectAdapter<TestModel, TestModel>(TestModel.CHILDREN_COLLECTION, model) {
@Override
- protected Iterator iterator_() {
- return ((TestModel) this.subject).children();
+ protected Iterator<TestModel> iterator_() {
+ return this.subject.children();
}
@Override
protected int size_() {
- return ((TestModel) this.subject).childrenSize();
+ return this.subject.childrenSize();
}
};
}
@@ -508,25 +479,15 @@ public class TreeModelAdapterTests extends TestCase {
// ********** TreeNodeValueModel implementation **********
- public Object value() {
+ public TestModel value() {
return this.testModel;
}
- /**
- * this will probably never be called...
- */
- @Override
- public void setValue(Object value) {
- Object old = this.testModel;
- this.testModel = (TestModel) value;
- this.firePropertyChanged(VALUE, old, this.testModel);
- }
-
- public TreeNodeValueModel parent() {
+ public TreeNodeValueModel<Object> parent() {
return this.parent;
}
- public ListValueModel childrenModel() {
+ public ListValueModel<TreeNodeValueModel<Object>> childrenModel() {
return this.childrenModel;
}
@@ -567,7 +528,8 @@ public class TreeModelAdapterTests extends TestCase {
public void dumpOn(IndentingPrintWriter writer) {
writer.println(this);
writer.indent();
- for (Iterator stream = this.childrenModel.iterator(); stream.hasNext(); ) {
+ for (Iterator<TreeNodeValueModel<Object>> stream = this.childrenModel.iterator(); stream.hasNext(); ) {
+ // cast to a TestNode (i.e. this won't work with a NameTestNode in the tree)
((TestNode) stream.next()).dumpOn(writer);
}
writer.undent();
@@ -607,10 +569,12 @@ public class TreeModelAdapterTests extends TestCase {
* testing convenience method
*/
public TestNode childNamed(String name) {
- for (Iterator stream = this.childrenModel.iterator(); stream.hasNext(); ) {
- TestNode childNode = (TestNode) stream.next();
- if (childNode.getTestModel().getName().equals(name)) {
- return childNode;
+ for (Iterator<TreeNodeValueModel<Object>> stream = this.childrenModel.iterator(); stream.hasNext(); ) {
+ TreeNodeValueModel<Object> childNode = stream.next();
+ if (childNode instanceof TestNode) {
+ if (((TestNode) childNode).getTestModel().getName().equals(name)) {
+ return (TestNode) childNode;
+ }
}
}
throw new IllegalArgumentException("child not found: " + name);
@@ -649,12 +613,12 @@ public class TreeModelAdapterTests extends TestCase {
// ********** initialization **********
/** the list should be sorted */
@Override
- protected ListValueModel buildChildrenModel(TestModel testModel) {
- return new SortedListValueModelAdapter(this.buildDisplayStringAdapter(testModel));
+ protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) {
+ return new SortedListValueModelAdapter<TreeNodeValueModel<Object>>(this.buildDisplayStringAdapter(testModel));
}
/** the display string (name) of each node can change */
- protected ListValueModel buildDisplayStringAdapter(TestModel testModel) {
- return new ItemPropertyListValueModelAdapter(this.buildNodeAdapter(testModel), DISPLAY_STRING_PROPERTY);
+ protected ListValueModel<TreeNodeValueModel<Object>> buildDisplayStringAdapter(TestModel testModel) {
+ return new ItemPropertyListValueModelAdapter<TreeNodeValueModel<Object>>(this.buildNodeAdapter(testModel), DISPLAY_STRING_PROPERTY);
}
/** children are also sorted nodes */
@Override
@@ -681,7 +645,7 @@ public class TreeModelAdapterTests extends TestCase {
// ********** initialization **********
/** the list should NOT be sorted */
@Override
- protected ListValueModel buildChildrenModel(TestModel testModel) {
+ protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) {
return this.buildNodeAdapter(testModel);
}
/** children are also unsorted nodes */
@@ -710,16 +674,16 @@ public class TreeModelAdapterTests extends TestCase {
// ********** initialization **********
/** return a different list of children for "node 3" */
@Override
- protected ListValueModel buildChildrenModel(TestModel testModel) {
+ protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) {
if (testModel.getName().equals("node 3")) {
return this.buildSpecialChildrenModel(testModel);
}
return super.buildChildrenModel(testModel);
}
- protected ListValueModel buildSpecialChildrenModel(TestModel testModel) {
- Object[] children = new Object[1];
+ protected ListValueModel<TreeNodeValueModel<Object>> buildSpecialChildrenModel(TestModel testModel) {
+ TreeNodeValueModel<Object>[] children = new NameTestNode[1];
children[0] = new NameTestNode(this);
- return new SimpleListValueModel(Arrays.asList(children));
+ return new SimpleListValueModel<TreeNodeValueModel<Object>>(Arrays.asList(children));
}
/** children are also special nodes */
@Override
@@ -730,21 +694,20 @@ public class TreeModelAdapterTests extends TestCase {
}
- public static class NameTestNode extends AbstractTreeNodeValueModel {
- private PropertyValueModel nameAdapter;
- private SpecialTestNode specialNode; // parent node
- private PropertyChangeListener nameListener;
+ public static class NameTestNode extends AbstractTreeNodeValueModel<Object> {
+ private final WritablePropertyValueModel<String> nameAdapter;
+ private final SpecialTestNode specialNode; // parent node
+ private final PropertyChangeListener nameListener;
+ private final ListValueModel<TreeNodeValueModel<Object>> childrenModel;
// ********** construction/initialization **********
public NameTestNode(SpecialTestNode specialNode) {
super();
- this.initialize(specialNode);
- }
- @Override
- protected void initialize() {
- super.initialize();
this.nameListener = this.buildNameListener();
+ this.specialNode = specialNode;
+ this.nameAdapter = this.buildNameAdapter();
+ this.childrenModel = new NullListValueModel<TreeNodeValueModel<Object>>();
}
protected PropertyChangeListener buildNameListener() {
return new PropertyChangeListener() {
@@ -753,20 +716,15 @@ public class TreeModelAdapterTests extends TestCase {
}
};
}
- protected void initialize(SpecialTestNode node) {
- this.specialNode = node;
- this.nameAdapter = this.buildNameAdapter();
- }
-
- protected PropertyValueModel buildNameAdapter() {
- return new PropertyAspectAdapter(TestModel.NAME_PROPERTY, this.getTestModel()) {
+ protected WritablePropertyValueModel<String> buildNameAdapter() {
+ return new PropertyAspectAdapter<TestModel, String>(TestModel.NAME_PROPERTY, this.getTestModel()) {
@Override
- protected Object buildValue_() {
- return ((TestModel) this.subject).getName();
+ protected String buildValue_() {
+ return this.subject.getName();
}
@Override
- protected void setValue_(Object value) {
- ((TestModel) this.subject).setName((String) value);
+ protected void setValue_(String value) {
+ this.subject.setName(value);
}
};
}
@@ -777,29 +735,29 @@ public class TreeModelAdapterTests extends TestCase {
// ********** TreeNodeValueModel implementation **********
- public Object value() {
+ public String value() {
return this.nameAdapter.value();
}
@Override
public void setValue(Object value) {
- this.nameAdapter.setValue(value);
+ this.nameAdapter.setValue((String) value);
}
- public TreeNodeValueModel parent() {
+ public TreeNodeValueModel<Object> parent() {
return this.specialNode;
}
- public ListValueModel childrenModel() {
- return NullListValueModel.instance();
+ public ListValueModel<TreeNodeValueModel<Object>> childrenModel() {
+ return this.childrenModel;
}
// ********** AbstractTreeNodeValueModel implementation **********
@Override
protected void engageValue() {
- this.nameAdapter.addPropertyChangeListener(ValueModel.VALUE, this.nameListener);
+ this.nameAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.nameListener);
}
@Override
protected void disengageValue() {
- this.nameAdapter.removePropertyChangeListener(ValueModel.VALUE, this.nameListener);
+ this.nameAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.nameListener);
}
// ********** behavior **********
@@ -810,12 +768,12 @@ public class TreeModelAdapterTests extends TestCase {
}
}
- private TreeModel buildTreeModel(TreeNodeValueModel root) {
- return this.buildTreeModel(new ReadOnlyPropertyValueModel(root));
+ private TreeModel buildTreeModel(TestNode root) {
+ return this.buildTreeModel(new StaticPropertyValueModel<TreeNodeValueModel<Object>>(root));
}
- private TreeModel buildTreeModel(PropertyValueModel rootHolder) {
- return new TreeModelAdapter(rootHolder) {
+ private TreeModel buildTreeModel(PropertyValueModel<TreeNodeValueModel<Object>> rootHolder) {
+ return new TreeModelAdapter<Object>(rootHolder) {
@Override
protected ListChangeListener buildChildrenListener() {
return this.buildChildrenListener_();
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
index 70420d6be3..d675eaef86 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,7 +20,6 @@ import java.awt.event.WindowListener;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.Iterator;
import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -39,8 +38,9 @@ import javax.swing.tree.TreeSelectionModel;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.EnumerationIterator;
-import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.TreeNodeValueModel;
+import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.TreeModelAdapter;
import org.eclipse.jpt.utility.internal.swing.Displayable;
import org.eclipse.jpt.utility.tests.internal.model.value.swing.TreeModelAdapterTests.SortedTestNode;
@@ -55,7 +55,7 @@ public class TreeModelAdapterUITest {
// hold the tree so we can restore its expansion state
private JTree tree;
- private PropertyValueModel rootNodeHolder;
+ private WritablePropertyValueModel<TreeNodeValueModel<Object>> rootNodeHolder;
private boolean sorted;
private TreeModel treeModel;
private TreeSelectionModel treeSelectionModel;
@@ -78,8 +78,8 @@ public class TreeModelAdapterUITest {
this.openWindow();
}
- private PropertyValueModel buildRootNodeHolder() {
- return new SimplePropertyValueModel(this.buildSortedRootNode());
+ private WritablePropertyValueModel<TreeNodeValueModel<Object>> buildRootNodeHolder() {
+ return new SimplePropertyValueModel<TreeNodeValueModel<Object>>(this.buildSortedRootNode());
}
private TestNode buildSortedRootNode() {
@@ -116,7 +116,7 @@ public class TreeModelAdapterUITest {
}
private TreeModel buildTreeModel() {
- return new TreeModelAdapter(this.rootNodeHolder);
+ return new TreeModelAdapter<Object>(this.rootNodeHolder);
}
private TreeSelectionModel buildTreeSelectionModel() {
@@ -226,7 +226,7 @@ public class TreeModelAdapterUITest {
if (this.treeSelectionModel.isSelectionEmpty()) {
return null;
}
- return (TestModel) this.selectedNode().value();
+ return this.selectedNode().value();
}
private TestNode rootNode() {
@@ -234,15 +234,15 @@ public class TreeModelAdapterUITest {
}
private TestModel root() {
- return (TestModel) this.rootNode().value();
+ return this.rootNode().value();
}
- private Collection expandedPaths() {
- Enumeration stream = this.tree.getExpandedDescendants(new TreePath(this.rootNode()));
+ private Collection<TreePath> expandedPaths() {
+ Enumeration<TreePath> stream = this.tree.getExpandedDescendants(new TreePath(this.rootNode()));
if (stream == null) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
- return CollectionTools.list(new EnumerationIterator(stream));
+ return CollectionTools.list(new EnumerationIterator<TreePath>(stream));
}
// ********** behavior **********
@@ -250,9 +250,9 @@ public class TreeModelAdapterUITest {
this.treeSelectionModel.setSelectionPath(new TreePath(selectedNode.path()));
}
- private void expandPaths(Collection paths) {
- for (Iterator stream = paths.iterator(); stream.hasNext(); ) {
- this.tree.expandPath((TreePath) stream.next());
+ private void expandPaths(Collection<TreePath> paths) {
+ for (TreePath path : paths) {
+ this.tree.expandPath(path);
}
}
@@ -280,7 +280,7 @@ public class TreeModelAdapterUITest {
if (selectedTestModel != null) {
String name = this.getName();
// save the expansion state and restore it after the add
- Collection paths = this.expandedPaths();
+ Collection<TreePath> paths = this.expandedPaths();
selectedTestModel.addChild(name);
@@ -360,7 +360,7 @@ public class TreeModelAdapterUITest {
// save the node and re-select it after the rename
TestNode selectedNode = this.selectedNode();
// save the expansion state and restore it after the rename
- Collection paths = this.expandedPaths();
+ Collection<TreePath> paths = this.expandedPaths();
selectedTestModel.setName(this.getName());

Back to the top