You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/03/26 00:12:17 UTC

svn commit: r758461 [4/47] - in /incubator/pivot/branches: ./ 1.1/ 1.1/charts-test/ 1.1/charts-test/src/ 1.1/charts-test/src/pivot/ 1.1/charts-test/src/pivot/charts/ 1.1/charts-test/src/pivot/charts/test/ 1.1/charts/ 1.1/charts/lib/ 1.1/charts/src/ 1.1...

Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ResourcesTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ResourcesTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ResourcesTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/ResourcesTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,134 @@
+package pivot.core.test;
+
+import java.util.MissingResourceException;
+
+import junit.framework.TestCase;
+import pivot.collections.List;
+import pivot.collections.Map;
+import pivot.serialization.SerializationException;
+import pivot.util.Resources;
+
+public class ResourcesTest extends TestCase {
+
+    public void testReadDefaultLocale() throws Exception {
+
+        Resources res = new Resources("resources.test1");
+        assertResources(res, "SGML", "Standard Generalized Markup Language");
+    }
+
+    /**
+     * The resource overrides the term for the country.
+     *
+     * @throws Exception
+     */
+    public void testRead_GB_Locale() throws Exception {
+        Resources res = new Resources("resources.test2");
+        assertResources(res, "SGML",
+                "How Do, Youth, Standard Generalized Markup Language");
+
+    }
+
+    /**
+     * The resource overrides the term for the country and the acronym for the
+     * language.
+     *
+     * @throws Exception
+     */
+    public void testRead_GB_en_Locale() throws Exception {
+        Resources res = new Resources("resources.test3");
+        assertResources(res, "XSGML",
+                "How Do, Youth, Standard Generalized Markup Language");
+
+    }
+
+    /**
+     * The resource overrides the term and the acronym for the country.
+     *
+     * @throws Exception
+     */
+    public void testRead_GB_en_LocaleExtraOverride() throws Exception {
+        Resources res = new Resources("resources.test6");
+        assertResources(res, "XSGML",
+                "eXtra Standard Generalized Markup Language");
+
+    }
+
+    public void testSerialisationException() throws Exception {
+
+        try {
+            new Resources("resources.test4");
+            fail("Expected SerialisationException");
+        } catch (SerializationException e) {
+        }
+
+    }
+
+    public void testMissingResource() throws Exception {
+
+        // resource doesn't exist...
+        try {
+            new Resources("resources.test5");
+            fail("Expected IllegalArgumentException");
+        } catch (MissingResourceException e) {
+        }
+
+    }
+
+    public void testNullLocale() throws Exception {
+        // resource exists, but locale is null
+        try {
+            new Resources("resources.test1");
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+    }
+
+    public void testNullBaseName() throws Exception {
+        try {
+            new Resources(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void assertResources(Resources res, String acronym,
+            String term) {
+        assertTrue(res.containsKey("glossary"));
+
+        Map<String, Object> glossary = (Map<String, Object>) res
+                .get("glossary");
+        assertNotNull(glossary);
+        assertTrue(glossary.containsKey("GlossDiv"));
+
+        Map<String, Object> glossDiv = (Map<String, Object>) glossary
+                .get("GlossDiv");
+        assertNotNull(glossDiv);
+
+        assertEquals("S", glossDiv.get("title"));
+
+        assertTrue(glossDiv.containsKey("GlossList"));
+        Map<String, Object> glossList = (Map<String, Object>) glossDiv
+                .get("GlossList");
+        assertNotNull(glossList);
+
+        assertTrue(glossList.containsKey("GlossEntry"));
+        Map<String, Object> glossEntry = (Map<String, Object>) glossList
+                .get("GlossEntry");
+        assertNotNull(glossEntry);
+
+        assertEquals(acronym, glossEntry.get("Acronym"));
+        assertEquals(term, glossEntry.get("GlossTerm"));
+
+        assertTrue(glossEntry.containsKey("GlossDef"));
+        Map<String, Object> glossDef = (Map<String, Object>) glossEntry
+                .get("GlossDef");
+        assertNotNull(glossDef);
+
+        assertTrue(glossDef.containsKey("GlossSeeAlso"));
+        List<String> list = (List<String>) glossDef.get("GlossSeeAlso");
+        assertNotNull(list);
+        assertEquals(2, list.getLength());
+    }
+
+}

Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/TaskTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/TaskTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/TaskTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/TaskTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,101 @@
+package pivot.core.test;
+
+import pivot.util.concurrent.Task;
+import pivot.util.concurrent.TaskGroup;
+import pivot.util.concurrent.TaskListener;
+import pivot.util.concurrent.TaskSequence;
+
+public class TaskTest {
+    public static class SleepTask extends Task<Void> {
+        private long timeout = 0;
+
+        public SleepTask(long timeout) {
+            this.timeout = timeout;
+        }
+
+        @Override
+        public Void execute() {
+            System.out.println("Starting task " + this + "...");
+
+            try {
+                Thread.sleep(timeout);
+            } catch (InterruptedException exception) {
+                System.out.println(exception);
+            }
+
+            System.out.println("...done");
+
+            return null;
+        }
+
+        @Override
+        public String toString() {
+            return Long.toString(timeout);
+        }
+    }
+
+    public static void main(String[] args) {
+        TaskListener<Void> taskListener = new TaskListener<Void>() {
+            public synchronized void taskExecuted(Task<Void> task) {
+                System.out.println("EXECUTED");
+                notify();
+            }
+
+            public synchronized void executeFailed(Task<Void> task) {
+                System.out.println("FAILED: " + task.getFault());
+                notify();
+            }
+        };
+
+        testTaskSequence(taskListener);
+        testTaskGroup(taskListener);
+    }
+
+    private static void testTaskSequence(TaskListener<Void> taskListener) {
+        System.out.println("Testing task sequence");
+
+        TaskSequence<Void> taskSequence = new TaskSequence<Void>();
+
+        SleepTask task1 = new SleepTask(2000);
+        taskSequence.add(task1);
+
+        SleepTask task2 = new SleepTask(500);
+        taskSequence.add(task2);
+
+        SleepTask task3 = new SleepTask(1000);
+        taskSequence.add(task3);
+
+        synchronized (taskListener) {
+            taskSequence.execute(taskListener);
+
+            try {
+                taskListener.wait();
+            } catch (InterruptedException exception) {
+            }
+        }
+    }
+
+    private static void testTaskGroup(TaskListener<Void> taskListener) {
+        System.out.println("Testing task group");
+
+        TaskGroup<Void> taskGroup = new TaskGroup<Void>();
+
+        SleepTask task1 = new SleepTask(2000);
+        taskGroup.add(task1);
+
+        SleepTask task2 = new SleepTask(500);
+        taskGroup.add(task2);
+
+        SleepTask task3 = new SleepTask(1000);
+        taskGroup.add(task3);
+
+        synchronized (taskListener) {
+            taskGroup.execute(taskListener);
+
+            try {
+                taskListener.wait();
+            } catch (InterruptedException exception) {
+            }
+        }
+    }
+}

Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/VersionTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/VersionTest.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/VersionTest.java (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/VersionTest.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,22 @@
+package pivot.core.test;
+
+import pivot.util.Version;
+
+public class VersionTest {
+    public static void main(String[] args) {
+        Version version = Version.decode(System.getProperty("java.version"));
+        System.out.println(version);
+
+        Version version_1_5_0_13 = new Version(1, 5, 0, 13);
+        System.out.println(version.compareTo(version_1_5_0_13));
+
+        Version version_1_4_1_5 = new Version(1, 4, 1, 5);
+        System.out.println(version.compareTo(version_1_4_1_5));
+
+        Version version_1_6_0_10 = new Version(1, 6, 0, 10);
+        System.out.println(version.compareTo(version_1_6_0_10));
+
+        Version maxVersion = new Version(0x7f, 0xff, 0xff, 0xff);
+        System.out.println(maxVersion.compareTo(version));
+    }
+}

Added: incubator/pivot/branches/1.1/core-test/src/pivot/core/test/json_serializer_test.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/pivot/core/test/json_serializer_test.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/pivot/core/test/json_serializer_test.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/pivot/core/test/json_serializer_test.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,4 @@
+{   foo:"ABCD",
+    bar:"\u0041\u0042\u0043\u0044"
+}
+

Added: incubator/pivot/branches/1.1/core-test/src/resources/test1.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test1.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test1.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test1.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,24 @@
+
+{
+    "glossary": {
+        "title": "example glossary",
+		"GlossDiv": {
+            "title": "S",
+			"GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+					"SortAs": "SGML",
+					"GlossTerm": "Standard Generalized Markup Language",
+					"Acronym": "SGML",
+					"Abbrev": "ISO 8879:1986",
+					"GlossDef": {
+                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
+						"GlossSeeAlso": ["GML", "XML"]
+                    },
+					"GlossSee": "markup"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test2.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test2.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test2.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test2.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,24 @@
+
+{
+    "glossary": {
+        "title": "example glossary",
+		"GlossDiv": {
+            "title": "S",
+			"GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+					"SortAs": "SGML",
+					"GlossTerm": "Standard Generalized Markup Language",
+					"Acronym": "SGML",
+					"Abbrev": "ISO 8879:1986",
+					"GlossDef": {
+                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
+						"GlossSeeAlso": ["GML", "XML"]
+                    },
+					"GlossSee": "markup"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test2_en.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test2_en.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test2_en.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test2_en.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,13 @@
+
+{
+    "glossary": {
+		"GlossDiv": {
+			"GlossList": {
+                "GlossEntry": {
+					"GlossTerm": "How Do, Youth, Standard Generalized Markup Language",
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test3.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test3.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test3.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test3.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,24 @@
+
+{
+    "glossary": {
+        "title": "example glossary",
+		"GlossDiv": {
+            "title": "S",
+			"GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+					"SortAs": "SGML",
+					"GlossTerm": "Standard Generalized Markup Language",
+					"Acronym": "SGML",
+					"Abbrev": "ISO 8879:1986",
+					"GlossDef": {
+                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
+						"GlossSeeAlso": ["GML", "XML"]
+                    },
+					"GlossSee": "markup"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test3_en.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test3_en.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test3_en.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test3_en.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,13 @@
+
+{
+    "glossary": {
+		"GlossDiv": {
+			"GlossList": {
+                "GlossEntry": {
+					"GlossTerm": "How Do, Youth, Standard Generalized Markup Language",
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test3_en_GB.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test3_en_GB.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test3_en_GB.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test3_en_GB.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,13 @@
+
+{
+    "glossary": {
+		"GlossDiv": {
+			"GlossList": {
+                "GlossEntry": {
+					"Acronym": "XSGML"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test4.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test4.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test4.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test4.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,24 @@
+
+{
+    "glossary"x: {
+        "title": "example glossary",
+		"GlossDiv": {
+            "title": "S",
+			"GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+					"SortAs": "SGML",
+					"GlossTerm": "Standard Generalized Markup Language",
+					"Acronym": "SGML",
+					"Abbrev": "ISO 8879:1986",
+					"GlossDef": {
+                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
+						"GlossSeeAlso": ["GML", "XML"]
+                    },
+					"GlossSee": "markup"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test6.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test6.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test6.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test6.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,24 @@
+
+{
+    "glossary": {
+        "title": "example glossary",
+		"GlossDiv": {
+            "title": "S",
+			"GlossList": {
+                "GlossEntry": {
+                    "ID": "SGML",
+					"SortAs": "SGML",
+					"GlossTerm": "Standard Generalized Markup Language",
+					"Acronym": "SGML",
+					"Abbrev": "ISO 8879:1986",
+					"GlossDef": {
+                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
+						"GlossSeeAlso": ["GML", "XML"]
+                    },
+					"GlossSee": "markup"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test6_en.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test6_en.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test6_en.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test6_en.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,13 @@
+
+{
+    "glossary": {
+		"GlossDiv": {
+			"GlossList": {
+                "GlossEntry": {
+					"GlossTerm": "How Do, Youth, Standard Generalized Markup Language",
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core-test/src/resources/test6_en_GB.json
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core-test/src/resources/test6_en_GB.json?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core-test/src/resources/test6_en_GB.json (added)
+++ incubator/pivot/branches/1.1/core-test/src/resources/test6_en_GB.json Wed Mar 25 23:08:38 2009
@@ -0,0 +1,14 @@
+
+{
+    "glossary": {
+		"GlossDiv": {
+			"GlossList": {
+                "GlossEntry": {
+					"Acronym": "XSGML",
+					"GlossTerm": "eXtra Standard Generalized Markup Language"
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/pivot/branches/1.1/core/.classpath
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/.classpath?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/.classpath (added)
+++ incubator/pivot/branches/1.1/core/.classpath Wed Mar 25 23:08:38 2009
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: incubator/pivot/branches/1.1/core/.project
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/.project?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/.project (added)
+++ incubator/pivot/branches/1.1/core/.project Wed Mar 25 23:08:38 2009
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>core</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: incubator/pivot/branches/1.1/core/src/pivot/beans/BeanDictionary.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/beans/BeanDictionary.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/beans/BeanDictionary.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/beans/BeanDictionary.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,416 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.beans;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import pivot.collections.Dictionary;
+
+/**
+ * Exposes Java bean properties of an object via the {@link Dictionary}
+ * interface. A call to {@link Dictionary#get(Object)} invokes the getter for
+ * the corresponding property, and a call to
+ * {@link Dictionary#put(Object, Object)} invokes the property's setter.
+ * <p>
+ * Properties may provide multiple setters; the appropriate setter to invoke
+ * is determined by the type of the value being set. If the value is
+ * <tt>null</tt>, the return type of the getter method is used.
+ *
+ * @author gbrown
+ */
+public class BeanDictionary implements Dictionary<String, Object>, Iterable<String> {
+    /**
+     * Property iterator. Walks the list of methods defined by the bean and
+     * returns a value for each getter method.
+     */
+    private class PropertyIterator implements Iterator<String> {
+        private Method[] methods = null;
+
+        int i = 0;
+        private String nextProperty = null;
+
+        public PropertyIterator() {
+            Class<?> type = bean.getClass();
+            methods = type.getMethods();
+            nextProperty();
+        }
+
+        public boolean hasNext() {
+            return (nextProperty != null);
+        }
+
+        public String next() {
+            if (!hasNext()) {
+                throw new NoSuchElementException();
+            }
+
+            String nextProperty = this.nextProperty;
+            nextProperty();
+
+            return nextProperty;
+        }
+
+        private void nextProperty() {
+            nextProperty = null;
+
+            while (i < methods.length
+                && nextProperty == null) {
+                Method method = methods[i++];
+
+                if (method.getParameterTypes().length == 0
+                    && (method.getModifiers() & Modifier.STATIC) == 0) {
+                    String methodName = method.getName();
+
+                    String prefix = null;
+                    if (methodName.startsWith(GET_PREFIX)) {
+                        prefix = GET_PREFIX;
+                    } else {
+                        if (methodName.startsWith(IS_PREFIX)) {
+                            prefix = IS_PREFIX;
+                        }
+                    }
+
+                    if (prefix != null) {
+                        int propertyOffset = prefix.length();
+                        nextProperty = Character.toLowerCase(methodName.charAt(propertyOffset))
+                            + methodName.substring(propertyOffset + 1);
+                    }
+
+                    if (nextProperty != null
+                        && ignoreReadOnlyProperties
+                        && isReadOnly(nextProperty)) {
+                        nextProperty = null;
+                    }
+                }
+            }
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    private Object bean;
+    private boolean ignoreReadOnlyProperties;
+
+    public static final String GET_PREFIX = "get";
+    public static final String IS_PREFIX = "is";
+    public static final String SET_PREFIX = "set";
+    public static final String LISTENERS_SUFFIX = "Listeners";
+
+    /**
+     * Creates a new bean dictionary.
+     *
+     * @param bean
+     * The bean object to wrap.
+     */
+    public BeanDictionary(Object bean) {
+        this(bean, false);
+    }
+
+    /**
+     * Creates a new bean dictionary.
+     *
+     * @param bean
+     * The bean object to wrap.
+     */
+    public BeanDictionary(Object bean, boolean ignoreReadOnlyProperties) {
+        if (bean == null) {
+            throw new IllegalArgumentException("bean is null.");
+        }
+
+        this.bean = bean;
+        this.ignoreReadOnlyProperties = ignoreReadOnlyProperties;
+    }
+
+    /**
+     * Returns the bean object this dictionary wraps.
+     */
+    public Object getBean() {
+    	return bean;
+    }
+
+    /**
+     * Invokes the getter method for the given property.
+     *
+     * @param key
+     * The property name.
+     *
+     * @return
+     * The value returned by the method, or <tt>null</tt> if no such method
+     * exists.
+     */
+    public Object get(String key) {
+        if (key == null) {
+            throw new IllegalArgumentException("key is null.");
+        }
+
+        Object value = null;
+
+        Method getterMethod = getGetterMethod(key);
+
+        if (getterMethod != null) {
+            try {
+                value = getterMethod.invoke(bean, new Object[] {});
+            } catch(IllegalAccessException exception) {
+                // No-op
+            } catch(InvocationTargetException exception) {
+                // No-op
+            }
+        }
+
+        return value;
+    }
+
+    /**
+     * Invokes the a setter method for the given property. The method
+     * signature is determined by the type of the value. If the value is
+     * <tt>null</tt>, the return type of the getter method is used.
+     *
+     * @param key
+     * The property name.
+     *
+     * @param value
+     * The new property value.
+     *
+     * @return
+     * Returns <tt>null</tt>, since returning the previous value would require
+     * a call to the getter method, which may not be an efficient operation.
+     *
+     * @throws PropertyNotFoundException
+     * If the given property does not exist or is read-only.
+     */
+    public Object put(String key, Object value) {
+        if (key == null) {
+            throw new IllegalArgumentException("key is null.");
+        }
+
+        Class<?> valueType = null;
+
+        if (value == null) {
+            Method getterMethod = getGetterMethod(key);
+            if (getterMethod == null) {
+                throw new PropertyNotFoundException("Property \"" + key + "\"" +
+                    " does not exist.");
+            }
+
+            valueType = getterMethod.getReturnType();
+        } else {
+            valueType = value.getClass();
+        }
+
+        Method setterMethod = getSetterMethod(key, valueType);
+
+        if (setterMethod == null) {
+            throw new PropertyNotFoundException("Property \"" + key + "\""
+                + " of type " + valueType.getName()
+                + " does not exist or is read-only.");
+        }
+
+        try {
+            setterMethod.invoke(bean, new Object[] {value});
+        } catch(IllegalAccessException exception) {
+            throw new IllegalArgumentException(exception);
+        } catch(InvocationTargetException exception) {
+            throw new IllegalArgumentException(exception);
+        }
+
+        return null;
+    }
+
+    /**
+     * @throws UnsupportedOperationException
+     * This method is not supported.
+     */
+    public Object remove(String key) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Verifies the existence of a property. The property must have a getter
+     * method; write-only properties are not supported.
+     *
+     * @param key
+     * The property name.
+     *
+     * @return
+     * <tt>true</tt> if the property exists; <tt>false</tt>, otherwise.
+     */
+    public boolean containsKey(String key) {
+        if (key == null) {
+            throw new IllegalArgumentException("key is null.");
+        }
+
+        return (getGetterMethod(key) != null);
+    }
+
+    /**
+     * Verifies that the bean contains at least one property.
+     */
+    public boolean isEmpty() {
+        return !iterator().hasNext();
+    }
+
+    /**
+     * Tests the read-only state of a property.
+     *
+     * @param key
+     * The property name.
+     *
+     * @return
+     * <tt>true</tt> if the property is read-only; <tt>false</tt>, otherwise.
+     */
+    public boolean isReadOnly(String key) {
+        if (key == null) {
+            throw new IllegalArgumentException("key is null.");
+        }
+
+        return (getSetterMethod(key, getType(key)) == null);
+    }
+
+    /**
+     * Returns the type of a property.
+     *
+     * @param key
+     * The property name.
+     *
+     * @return
+     * The type of the property.
+     */
+    public Class<?> getType(String key) {
+        if (key == null) {
+            throw new IllegalArgumentException("key is null.");
+        }
+
+        Method getterMethod = getGetterMethod(key);
+
+        return (getterMethod == null) ? null : getterMethod.getReturnType();
+    }
+
+    /**
+     * Returns an iterator over the bean's properties.
+     *
+     * @return
+     * A property iterator for this bean.
+     */
+    public Iterator<String> iterator() {
+        return new PropertyIterator();
+    }
+
+    /**
+     * Returns the getter method for a property.
+     *
+     * @param key
+     * The property name.
+     *
+     * @return
+     * The getter method, or <tt>null</tt> if the method does not exist.
+     */
+    private Method getGetterMethod(String key) {
+        Class<?> type = bean.getClass();
+
+        // Upper-case the first letter
+        key = Character.toUpperCase(key.charAt(0)) + key.substring(1);
+        Method method = null;
+
+        try {
+            method = type.getMethod(GET_PREFIX + key, new Class<?>[] {});
+        } catch(NoSuchMethodException exception) {
+            // No-op
+        }
+
+        if (method == null) {
+            try {
+                method = type.getMethod(IS_PREFIX + key, new Class<?>[] {});
+            } catch(NoSuchMethodException exception) {
+                // No-op
+            }
+        }
+
+        return method;
+    }
+
+    /**
+     * Returns the setter method for a property.
+     *
+     * @param key
+     * The property name.
+     *
+     * @return
+     * The getter method, or <tt>null</tt> if the method does not exist.
+     */
+    private Method getSetterMethod(String key, Class<?> valueType) {
+        Class<?> type = bean.getClass();
+        Method method = null;
+
+        if (valueType != null) {
+            // Upper-case the first letter and prepend the "set" prefix to
+            // determine the method name
+            key = Character.toUpperCase(key.charAt(0)) + key.substring(1);
+            final String methodName = SET_PREFIX + key;
+
+            try {
+                method = type.getMethod(methodName, new Class<?>[] {valueType});
+            } catch(NoSuchMethodException exception) {
+                // No-op
+            }
+
+            if (method == null) {
+                // Look for a match on the value's super type
+                Class<?> superType = valueType.getSuperclass();
+                method = getSetterMethod(key, superType);
+            }
+
+            if (method == null) {
+                // If value type is a primitive wrapper, look for a method
+                // signature with the corresponding primitive type
+                try {
+                    Field primitiveTypeField = valueType.getField("TYPE");
+                    Class<?> primitiveValueType = (Class<?>)primitiveTypeField.get(this);
+
+                    try {
+                        method = type.getMethod(methodName, new Class<?>[] {primitiveValueType});
+                    } catch(NoSuchMethodException exception) {
+                        // No-op
+                    }
+                } catch(NoSuchFieldException exception) {
+                    // No-op; not a wrapper type
+                } catch(IllegalAccessException exception) {
+                    // No-op
+                }
+            }
+
+            if (method == null) {
+                // Walk the interface graph to find a matching method
+                Class<?>[] interfaces = valueType.getInterfaces();
+
+                int i = 0, n = interfaces.length;
+                while (method == null
+                    && i < n) {
+                    Class<?> interfaceType = interfaces[i++];
+                    method = getSetterMethod(key, interfaceType);
+                }
+            }
+        }
+
+        return method;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/beans/PropertyNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/beans/PropertyNotFoundException.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/beans/PropertyNotFoundException.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/beans/PropertyNotFoundException.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.beans;
+
+/**
+ * Thrown when a caller attempts to set the value of a non-existent bean
+ * property.
+ *
+ * @author gbrown
+ */
+public class PropertyNotFoundException extends RuntimeException {
+    private static final long serialVersionUID = 0;
+
+    public PropertyNotFoundException() {
+        this(null, null);
+    }
+
+    public PropertyNotFoundException(String message) {
+        this(message, null);
+    }
+
+    public PropertyNotFoundException(Throwable cause) {
+        this(null, cause);
+    }
+
+    public PropertyNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/beans/package.html
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/beans/package.html?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/beans/package.html (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/beans/package.html Wed Mar 25 23:08:38 2009
@@ -0,0 +1,6 @@
+<html>
+<head></head>
+<body>
+<p>Contains classes that provide access to the Java bean properties of an object via a dictionary interface.</p>
+</body>
+</html>

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayList.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayList.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayList.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import pivot.util.ListenerList;
+
+/**
+ * Implementation of the {@link List} interface that is backed by an
+ * array.
+ * <p>
+ * TODO We're temporarily using a java.util.ArrayList to back this list.
+ * Eventually, we'll replace this with an internal array representation.
+ *
+ * @author gbrown
+ */
+public class ArrayList<T> implements List<T>, Serializable {
+    private static final long serialVersionUID = 0;
+
+    protected java.util.ArrayList<T> arrayList = null;
+
+    private Comparator<T> comparator = null;
+    private transient ListListenerList<T> listListeners = new ListListenerList<T>();
+
+    public ArrayList() {
+        arrayList = new java.util.ArrayList<T>();
+    }
+
+    public ArrayList(T[] items) {
+        arrayList = new java.util.ArrayList<T>(items.length);
+        for (int i = 0; i < items.length; i++) {
+            arrayList.add(items[i]);
+        }
+    }
+
+    public ArrayList(Sequence<T> sequence) {
+        this(sequence, 0, sequence.getLength());
+    }
+
+    public ArrayList(Sequence<T> sequence, int index, int count) {
+        arrayList = new java.util.ArrayList<T>(count);
+
+        for (int i = index, n = index + count; i < n; i++) {
+            T item = sequence.get(i);
+            arrayList.add(item);
+        }
+    }
+
+    public ArrayList(Comparator<T> comparator) {
+        arrayList = new java.util.ArrayList<T>();
+        this.comparator = comparator;
+    }
+
+    public ArrayList(int initialCapacity) {
+        arrayList = new java.util.ArrayList<T>(initialCapacity);
+    }
+
+    public int add(T item) {
+        int index = -1;
+
+        if (comparator == null) {
+            index = getLength();
+        }
+        else {
+            // Perform a binary search to find the insertion point
+            index = Search.binarySearch(this, item, comparator);
+            if (index < 0) {
+                index = -(index + 1);
+            }
+        }
+
+        arrayList.add(index, item);
+
+        listListeners.itemInserted(this, index);
+
+        return index;
+    }
+
+    public void insert(T item, int index) {
+        if (comparator != null
+            && Search.binarySearch(this, item, comparator) != -(index + 1)) {
+            throw new IllegalArgumentException("Illegal insertion point.");
+        }
+
+        arrayList.add(index, item);
+
+        listListeners.itemInserted(this, index);
+    }
+
+    public T update(int index, T item) {
+        if (comparator != null
+            && Search.binarySearch(this, item, comparator) != index) {
+            throw new IllegalArgumentException("Illegal item modification.");
+        }
+
+        T previousItem = arrayList.get(index);
+        arrayList.set(index, item);
+
+        listListeners.itemUpdated(this, index, previousItem);
+
+        return previousItem;
+    }
+
+    public int remove (T item) {
+        int index = indexOf(item);
+
+        if (index == -1) {
+            throw new IllegalArgumentException("item is not an element of this list.");
+        }
+
+        remove(index, 1);
+
+        return index;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Sequence<T> remove(int index, int count) {
+        ArrayList<T> removed = new ArrayList<T>();
+
+        // Remove the items from the array list
+        // TODO Allocate the array list size first, or use a linked list
+        for (int i = count - 1; i >= 0; i--) {
+            removed.insert(arrayList.remove(index + i), 0);
+        }
+
+        listListeners.itemsRemoved(this, index, removed);
+
+        return removed;
+    }
+
+    public void clear() {
+        arrayList.clear();
+        listListeners.itemsRemoved(this, 0, null);
+    }
+
+    public T get(int index) {
+        return arrayList.get(index);
+    }
+
+    public int indexOf(T item) {
+        int index = -1;
+        if (comparator == null) {
+            // TODO Ensure that we use the equals() method here when
+            // managing list contents internally
+            index = arrayList.indexOf(item);
+        }
+        else {
+            // Perform a binary search to find the index
+            index = Search.binarySearch(this, item, comparator);
+            if (index < 0) {
+                index = -1;
+            }
+        }
+
+        return index;
+    }
+
+    public int getLength() {
+        return arrayList.size();
+    }
+
+    @SuppressWarnings("unchecked")
+    public T[] toArray() {
+        T[] array = null;
+
+        int n = getLength();
+        if (n > 0) {
+            Class<?> type = get(0).getClass();
+            array = (T[])Array.newInstance(type, n);
+
+            for (int i = 0; i < n; i++) {
+                array[i] = get(i);
+            }
+        }
+
+        return array;
+    }
+
+    public Comparator<T> getComparator() {
+        return comparator;
+    }
+
+    public void setComparator(Comparator<T> comparator) {
+        Comparator<T> previousComparator = this.comparator;
+
+        if (previousComparator != comparator) {
+            if (comparator != null) {
+            	Collections.sort(arrayList, comparator);
+            }
+
+            this.comparator = comparator;
+
+            listListeners.comparatorChanged(this, previousComparator);
+        }
+    }
+
+    public Iterator<T> iterator() {
+        // TODO Return a fail-fast iterator, similar to java.util.ArrayList
+        // We can use a modificationCount value; each call to a mutator method can
+        // increment the count - the iterator will retain a copy of the modifier count
+        // when it is created. We can potentially reset the modifier count when all
+        // outstanding iterators are finalized.
+
+    	// TODO Alternatively, we could just return an immutable iterator
+
+        return arrayList.iterator();
+    }
+
+    public ListenerList<ListListener<T>> getListListeners() {
+        return listListeners;
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("[");
+
+        for (int i = 0, n = getLength(); i < n; i++) {
+            if (i > 0) {
+                sb.append(", ");
+            }
+
+            sb.append(get(i));
+        }
+
+        sb.append("]");
+
+        return sb.toString();
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayQueue.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayQueue.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayQueue.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayQueue.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Implementation of the {@link Queue} interface that is backed by an
+ * array.
+ * <p>
+ * TODO The current implementation is not optimal, since it requires shifting
+ * all elements on every call to enqueue(). Use an approach that maintains
+ * rotating headIndex and tailIndex values and override List methods to use
+ * these as offsets from the current capacity value. When the capacity needs
+ * to increase, we'll copy the elements in a contiguous block to the new array
+ * (we may want to make this operation a protected method so ArrayList can call
+ * it polymorphically).
+ *
+ * @author gbrown
+ */
+public class ArrayQueue<T> extends ArrayList<T> implements Queue<T> {
+    private static final long serialVersionUID = 0;
+
+    public ArrayQueue() {
+        super();
+    }
+
+    public ArrayQueue(List<T> items) {
+        super(items);
+    }
+
+    public void enqueue(T item) {
+        insert(item, getComparator() == null ? 0 : -1);
+    }
+
+    public T dequeue() {
+        // TODO Throw if empty
+        return remove(getLength() - 1, 1).get(0);
+    }
+
+    public T peek() {
+        // TODO Return null if empty
+        return get(0);
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayStack.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayStack.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayStack.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/ArrayStack.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Implementation of the {@link Stack} interface that is backed by an
+ * array.
+ *
+ * @author gbrown
+ */
+public class ArrayStack<T> extends ArrayList<T> implements Stack<T> {
+    private static final long serialVersionUID = 0;
+
+    public ArrayStack() {
+        super();
+    }
+
+    public ArrayStack(List<T> items) {
+        super(items);
+    }
+
+    public void push(T item) {
+        insert(item, getComparator() == null ? getLength() : -1);
+    }
+
+    public T pop() {
+        int length = getLength();
+        if (length == 0) {
+            throw new IllegalStateException();
+        }
+
+        return remove(length - 1, 1).get(0);
+    }
+
+    public T peek() {
+        int length = getLength();
+
+        return (length == 0) ? null : get(length - 1);
+    }
+
+    public T poke(T item) {
+        int length = getLength();
+        if (length == 0) {
+            throw new IllegalStateException();
+        }
+
+        return update(length - 1, item);
+    }
+
+    public int getRemainingCapacity() {
+        return -1;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/Collection.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/Collection.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/Collection.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/Collection.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.util.Comparator;
+
+/**
+ * Root interface in collection hierarchy. Defines operations common to all
+ * collections.
+ *
+ * @author gbrown
+ */
+public interface Collection<T> extends Iterable<T> {
+    /**
+     * Removes all elements from the collection.
+     */
+    public void clear();
+
+    /**
+     * Returns the collection's sort order.
+     *
+     * @return
+     * The comparator used to order elements in the collection, or <tt>null</tt>
+     * if the sort order is undefined.
+     *
+     * @see #setComparator(Comparator)
+     */
+    public Comparator<T> getComparator();
+
+    /**
+     * Sets the collection's sort order, re-ordering the collection's contents
+     * and ensuring that new entries preserve the sort order.
+     *
+     * @param comparator
+     * The comparator used to order elements in the collection, or null if the
+     * collection is unsorted.
+     */
+    public void setComparator(Comparator<T> comparator);
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/Dictionary.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/Dictionary.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/Dictionary.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/Dictionary.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Interface representing a set of key/value pairs.
+ *
+ * @author gbrown
+ */
+public interface Dictionary<K, V> {
+    /**
+     * Retrieves the value for the given key.
+     *
+     * @param key
+     * The key whose value is to be returned.
+     *
+     * @return
+     * The value corresponding to <tt>key</tt>, or null if the key does not
+     * exist. Will also return null if the key refers to a null value.
+     * Use <tt>containsKey()</tt> to distinguish between these two cases.
+     */
+    public V get(K key);
+
+    /**
+     * Sets the value of the given key, creating a new entry or replacing the
+     * existing value.
+     *
+     * @param key
+     * The key whose value is to be set.
+     *
+     * @param value
+     * The value to be associated with the given key.
+     */
+    public V put(K key, V value);
+
+    /**
+     * Removes a key/value pair from the map.
+     *
+     * @param key
+     * The key whose mapping is to be removed.
+     *
+     * @return
+     * The value that was removed.
+     */
+    public V remove(K key);
+
+    /**
+     * Tests the existence of a key in the dictionary.
+     *
+     * @param key
+     * The key whose presence in the dictionary is to be tested.
+     *
+     * @return
+     * <tt>true</tt> if the key exists in the dictionary; <tt>false</tt>,
+     * otherwise.
+     */
+    public boolean containsKey(K key);
+
+    /**
+     * Tests the emptiness of the dictionary.
+     *
+     * @return
+     * <tt>true</tt> if the dictionary contains no keys; <tt>false</tt>,
+     * otherwise.
+     */
+    public boolean isEmpty();
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/EnumSet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/EnumSet.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/EnumSet.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/EnumSet.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,56 @@
+package pivot.collections;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import pivot.util.ListenerList;
+
+/**
+ * Implementation of the {@link Set} interface that is backed by a bitfield
+ * representing enum values. Enum values are mapped to the bitfield by their
+ * ordinal value.
+ */
+public class EnumSet<E extends Enum<E>> implements Set<E>, Serializable {
+    private static final long serialVersionUID = 0;
+
+    private int bitSet = 0;
+    private SetListenerList<E> setListeners = new SetListenerList<E>();
+
+    public void add(E element) {
+        bitSet |= (1 << element.ordinal());
+    }
+
+    public void remove(E element) {
+        bitSet &= ~(1 << element.ordinal());
+    }
+
+    public void clear() {
+        bitSet = 0;
+    }
+
+    public boolean contains(E element) {
+        return (bitSet & (1 << element.ordinal())) > 0;
+    }
+
+    public boolean isEmpty() {
+        return bitSet > 0;
+    }
+
+    public ListenerList<SetListener<E>> getSetListeners() {
+        return setListeners;
+    }
+
+    public Comparator<E> getComparator() {
+        return null;
+    }
+
+    public void setComparator(Comparator<E> comparator) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator<E> iterator() {
+        // TODO
+        return null;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/Group.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/Group.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/Group.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/Group.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Interface representing a group of unique elements.
+ *
+ * @author gbrown
+ */
+public interface Group<E> {
+    /**
+     * Adds an element to the group.
+     *
+     * @param element
+     * The element to add to the group.
+     */
+    public void add(E element);
+
+    /**
+     * Removes an element from the group.
+     *
+     * @param element
+     * The element to remove from the set.
+     */
+    public void remove(E element);
+
+    /**
+     * Tests the existence of an element in the group.
+     *
+     * @param element
+     * The element whose presence in the group is to be tested.
+     *
+     * @return
+     * <tt>true</tt> if the element exists in the group; <tt>false</tt>,
+     * otherwise.
+     */
+    public boolean contains(E element);
+
+    /**
+     * Tests the emptiness of the group.
+     *
+     * @return
+     * <tt>true</tt> if the group contains no elements; <tt>false</tt>,
+     * otherwise.
+     */
+    public boolean isEmpty();
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/HashMap.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/HashMap.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/HashMap.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/HashMap.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import pivot.util.ImmutableIterator;
+import pivot.util.ListenerList;
+
+/**
+ * Implementation of the {@link Map} interface that is backed by a
+ * hashtable.
+ * <p>
+ * TODO We're temporarily using a java.util.HashMap to back this map.
+ * Eventually, we'll replace this with an internal map representation.
+ */
+public class HashMap<K, V> implements Map<K, V>, Serializable {
+    private static final long serialVersionUID = 0;
+
+    protected java.util.Map<K, V> hashMap = null;
+
+    private Comparator<K> comparator = null;
+    private transient MapListenerList<K, V> mapListeners = new MapListenerList<K, V>();
+
+    public HashMap() {
+        this(false, null);
+    }
+
+    public HashMap(boolean weak) {
+        this(weak, null);
+    }
+
+    public HashMap(Map<K, V> map) {
+        this(false, map);
+    }
+
+    public HashMap(boolean weak, Map<K, V> map) {
+        hashMap = (weak) ? new java.util.WeakHashMap<K, V>() : new java.util.HashMap<K, V>();
+
+        if (map != null) {
+            for (K key : map) {
+                put(key, map.get(key));
+            }
+        }
+    }
+
+    public HashMap(Comparator<K> comparator) {
+        // TODO
+        throw new UnsupportedOperationException("HashMap auto-sorting is not yet supported.");
+
+        // this.comparator = comparator;
+    }
+
+    public V get(K key) {
+        return hashMap.get(key);
+    }
+
+    public V put(K key, V value) {
+        boolean update = hashMap.containsKey(key);
+        V previousValue = hashMap.put(key, value);
+
+        if (update) {
+            mapListeners.valueUpdated(this, key, previousValue);
+        }
+        else {
+            mapListeners.valueAdded(this, key);
+        }
+
+        return previousValue;
+    }
+
+    public V remove(K key) {
+        V value = null;
+
+        if (hashMap.containsKey(key)) {
+            value = hashMap.remove(key);
+            mapListeners.valueRemoved(this, key, value);
+        }
+
+        return value;
+    }
+
+    public void clear() {
+        hashMap.clear();
+        mapListeners.mapCleared(this);
+    }
+
+    public boolean containsKey(K key) {
+        return hashMap.containsKey(key);
+    }
+
+    public boolean isEmpty() {
+        return hashMap.isEmpty();
+    }
+
+    public Comparator<K> getComparator() {
+        return comparator;
+    }
+
+    public void setComparator(Comparator<K> comparator) {
+        // TODO
+        throw new UnsupportedOperationException("HashMap auto-sorting is not yet supported.");
+    }
+
+    public Iterator<K> iterator() {
+        // TODO Return an iterator that supports modification?
+        return new ImmutableIterator<K>(hashMap.keySet().iterator());
+    }
+
+    public ListenerList<MapListener<K, V>> getMapListeners() {
+        return mapListeners;
+    }
+
+    public String toString() {
+        return hashMap.toString();
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/HashSet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/HashSet.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/HashSet.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/HashSet.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import pivot.util.ImmutableIterator;
+import pivot.util.ListenerList;
+
+/**
+ * Implementation of the {@link Set} interface that is backed by a
+ * hashtable.
+ * <p>
+ * TODO We're temporarily using a java.util.HashSet to back this set.
+ * Eventually, we'll replace this with an internal set representation.
+ */
+public class HashSet<E> implements Set<E>, Serializable {
+    private static final long serialVersionUID = 0;
+
+    protected java.util.HashSet<E> hashSet = null;
+
+    private Comparator<E> comparator = null;
+    private transient SetListenerList<E> setListeners = new SetListenerList<E>();
+
+    public HashSet() {
+        hashSet = new java.util.HashSet<E>();
+    }
+
+    public HashSet(Set<E> set) {
+        hashSet = new java.util.HashSet<E>();
+
+        for (E element : set) {
+            add(element);
+        }
+    }
+
+    public HashSet(Comparator<E> comparator) {
+        throw new UnsupportedOperationException("HashSet auto-sorting is not yet supported.");
+
+        // this.comparator = comparator;
+    }
+
+    public void add(E element) {
+        if (!hashSet.contains(element)) {
+            hashSet.add(element);
+            setListeners.elementAdded(this, element);
+        }
+    }
+
+    public void remove(E element) {
+        if (hashSet.contains(element)) {
+            hashSet.remove(element);
+            setListeners.elementRemoved(this, element);
+        }
+    }
+
+    public void clear() {
+        hashSet.clear();
+        setListeners.setCleared(this);
+    }
+
+    public boolean contains(E element) {
+        return hashSet.contains(element);
+    }
+
+    public boolean isEmpty() {
+        return hashSet.isEmpty();
+    }
+
+    public Comparator<E> getComparator() {
+        return comparator;
+    }
+
+    public void setComparator(Comparator<E> comparator) {
+        // TODO
+        throw new UnsupportedOperationException("HashSet auto-sorting is not yet supported.");
+    }
+
+    public Iterator<E> iterator() {
+        // TODO Return an iterator that supports modification?
+        return new ImmutableIterator<E>(hashSet.iterator());
+    }
+
+    public ListenerList<SetListener<E>> getSetListeners() {
+        return setListeners;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedList.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedList.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedList.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import pivot.util.ListenerList;
+
+/**
+ * Implementation of the {@link List} interface that is backed by a linked
+ * list.
+ * <p>
+ * TODO This class is currently incomplete.
+ */
+public class LinkedList<T> implements List<T>, Serializable {
+    private static final long serialVersionUID = 0;
+
+    public int add(T item) {
+        // TODO
+        return 0;
+    }
+
+    public void insert(T item, int index) {
+        // TODO Auto-generated method stub
+    }
+
+    public T update(int index, T item) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int remove (T item) {
+        // TODO
+        return -1;
+    }
+
+    public Sequence<T> remove(int index, int count) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void clear() {
+        // TODO
+    }
+
+    public T get(int index) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int indexOf(T item) {
+        // TODO
+        return -1;
+    }
+
+    public int getLength() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public Comparator<T> getComparator() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void setComparator(Comparator<T> comparator) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Iterator<T> iterator() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public ListenerList<ListListener<T>> getListListeners() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedQueue.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedQueue.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedQueue.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedQueue.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Implementation of the {@link Queue} interface that is backed by a linked
+ * list.
+ * <p>
+ * TODO This class is currently incomplete.
+ */
+public class LinkedQueue<T> extends LinkedList<T> implements Queue<T> {
+    private static final long serialVersionUID = 0;
+
+    public void enqueue(T item) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public T dequeue() {
+        // TODO Auto-generated method stub
+        // TODO Throw if empty
+        return null;
+    }
+
+    public T peek() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedStack.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedStack.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedStack.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/LinkedStack.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Implementation of the {@link Stack} interface that is backed by a linked
+ * list.
+ * <p>
+ * TODO This class is currently incomplete.
+ */
+public class LinkedStack<T> extends LinkedList<T> implements Stack<T> {
+    private static final long serialVersionUID = 0;
+
+    public void push(T item) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public T pop() {
+        // TODO Auto-generated method stub
+        // TODO Throw if empty
+        return null;
+    }
+
+    public T peek() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public T poke(T item) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/List.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/List.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/List.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/List.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.util.Comparator;
+import pivot.util.ListenerList;
+
+/**
+ * Collection interface representing an ordered sequence of items.
+ *
+ * @author gbrown
+ */
+public interface List<T> extends Sequence<T>, Collection<T> {
+    /**
+     * List listener list implementation.
+     *
+     * @author gbrown
+     */
+    public static class ListListenerList<T>
+        extends ListenerList<ListListener<T>> implements ListListener<T> {
+        public void itemInserted(List<T> list, int index) {
+            for (ListListener<T> listener : this) {
+                listener.itemInserted(list, index);
+            }
+        }
+
+        public void itemsRemoved(List<T> list, int index, Sequence<T> items) {
+            for (ListListener<T> listener : this) {
+                listener.itemsRemoved(list, index, items);
+            }
+        }
+
+        public void itemUpdated(List<T> list, int index, T previousItem) {
+            for (ListListener<T> listener : this) {
+                listener.itemUpdated(list, index, previousItem);
+            }
+        }
+
+        public void comparatorChanged(List<T> list, Comparator<T> previousComparator) {
+            for (ListListener<T> listener : this) {
+                listener.comparatorChanged(list, previousComparator);
+            }
+        }
+    }
+
+    /**
+     * Adds an item to the list. If the list is unsorted, the item is appended
+     * to the end of the list. Otherwise, it is inserted at the appropriate
+     * index.
+     *
+     * @see pivot.collections.ListListener#itemInserted(List, int)
+     *
+     * @return
+     * The index at which the item was added.
+     */
+    public int add(T item);
+
+    /**
+     * Inserts an item into the list.
+     *
+     * @param item
+     * The item to be added to the list.
+     *
+     * @param index
+     * The index at which the item should be inserted. Must be a value between
+     * <tt>0</tt> and <tt>getLength()</tt>.
+     *
+     * @throws IllegalArgumentException
+     * If the list is sorted and the insertion point of the item does not match
+     * the given index.
+     *
+     * @see ListListener#itemInserted(List, int)
+     */
+    public void insert(T item, int index);
+
+    /**
+     * Updates the item at the given index.
+     *
+     * @param index
+     * The index of the item to update.
+     *
+     * @param item
+     * The item that will replace any existing value at the given index.
+     *
+     * @throws IllegalArgumentException
+     * If the list is sorted and the index of the updated item would be
+     * different than its current index.
+     *
+     * @see ListListener#itemUpdated(List, int, Object)
+     */
+    public T update(int index, T item);
+
+    /**
+     * @see ListListener#itemsRemoved(List, int, Sequence)
+     */
+    public Sequence<T> remove(int index, int count);
+
+    /**
+     * @see ListListener#itemsRemoved(List, int, Sequence)
+     */
+    public void clear();
+
+    /**
+     * Returns the length of the list.
+     *
+     * @return The number of items in the list, or -1 if the list's length is
+     * not known. In this case, the iterator must be used to retrieve the
+     * contents of the list.
+     */
+    public int getLength();
+
+    /**
+     * @see ListListener#comparatorChanged(List, Comparator)
+     */
+    public void setComparator(Comparator<T> comparator);
+
+    /**
+     * Returns the list listener list.
+     */
+    public ListenerList<ListListener<T>> getListListeners();
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/ListListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/ListListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/ListListener.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/ListListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.util.Comparator;
+
+/**
+ * List listener interface.
+ *
+ * @author gbrown
+ */
+public interface ListListener<T> {
+    /**
+     * Called when an item has been inserted into a list.
+     *
+     * @param list
+     * The source of the list event.
+     *
+     * @param index
+     * The index at which the item was added.
+     */
+    public void itemInserted(List<T> list, int index);
+
+    /**
+     * Called when items have been removed from a list.
+     *
+     * @param list
+     * The source of the list event.
+     *
+     * @param index
+     * The starting index from which items have been removed.
+     *
+     * @param items
+     * The items that were removed from the list, or <tt>null</tt> if the list
+     * was cleared.
+     */
+    public void itemsRemoved(List<T> list, int index, Sequence<T> items);
+
+    /**
+     * Called when a list item has been updated.
+     *
+     * @param list
+     * The source of the list event.
+     *
+     * @param index
+     * The index of the item that was updated.
+     *
+     * @param previousItem
+     * The item that was previously stored at <tt>index</tt>.
+     */
+    public void itemUpdated(List<T> list, int index, T previousItem);
+
+    /**
+     * Called when a list's comparator has changed.
+     *
+     * @param list
+     * The source of the event.
+     *
+     * @param previousComparator
+     * The previous comparator value.
+     */
+    public void comparatorChanged(List<T> list, Comparator<T> previousComparator);
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/Map.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/Map.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/Map.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/Map.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.util.Comparator;
+
+import pivot.util.ListenerList;
+
+/**
+ * Collection interface representing set of key/value pairs.
+ *
+ * @author gbrown
+ */
+public interface Map<K, V> extends Dictionary<K, V>, Collection<K> {
+    /**
+     * Map listener list implementation.
+     *
+     * @author gbrown
+     */
+    public static class MapListenerList<K, V>
+        extends ListenerList<MapListener<K, V>> implements MapListener<K, V> {
+        public void valueAdded(Map<K, V> map, K key) {
+            for (MapListener<K, V> listener : this) {
+                listener.valueAdded(map, key);
+            }
+        }
+
+        public void valueRemoved(Map<K, V> map, K key, V value) {
+            for (MapListener<K, V> listener : this) {
+                listener.valueRemoved(map, key, value);
+            }
+        }
+
+        public void valueUpdated(Map<K, V> map, K key, V previousValue) {
+            for (MapListener<K, V> listener : this) {
+                listener.valueUpdated(map, key, previousValue);
+            }
+        }
+
+        public void mapCleared(Map<K, V> map) {
+            for (MapListener<K, V> listener : this) {
+                listener.mapCleared(map);
+            }
+        }
+
+        public void comparatorChanged(Map<K, V> map, Comparator<K> previousComparator) {
+            for (MapListener<K, V> listener : this) {
+                listener.comparatorChanged(map, previousComparator);
+            }
+        }
+    }
+
+    /**
+     * Sets the value of the given key, creating a new entry or replacing the
+     * existing value, and firing a corresponding event.
+     *
+     * @param key
+     * The key whose value is to be set.
+     *
+     * @param value
+     * The value to be associated with the given key.
+     *
+     * @see MapListener#valueAdded(Map, Object)
+     * @see MapListener#valueUpdated(Map, Object, Object)
+     */
+    public V put(K key, V value);
+
+    /**
+     * @see MapListener#valueRemoved(Map, Object, Object)
+     */
+    public V remove(K key);
+
+    /**
+     * Removes all entries in the map.
+     *
+     * @see MapListener#mapCleared(Map)
+     */
+    public void clear();
+
+    /**
+     * @see MapListener#comparatorChanged(Map, Comparator)
+     */
+    public void setComparator(Comparator<K> comparator);
+
+    /**
+     * Returns the map listener collection.
+     */
+    public ListenerList<MapListener<K, V>> getMapListeners();
+}

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/MapListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/MapListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/MapListener.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/MapListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+import java.util.Comparator;
+
+/**
+ * Map listener interface.
+ *
+ * @author gbrown
+ */
+public interface MapListener<K, V> {
+    /**
+     * Called when a key/value pair has been added to a map.
+     *
+     * @param map
+     * The source of the map event.
+     *
+     * @param key
+     * The key that was added to the map.
+     */
+    public void valueAdded(Map<K, V> map, K key);
+
+    /**
+     * Called when a map value has been updated.
+     *
+     * @param map
+     * The source of the map event.
+     *
+     * @param key
+     * The key whose value was updated.
+     *
+     * @param previousValue
+     * The value that was previously associated with the key.
+     */
+    public void valueUpdated(Map<K, V> map, K key, V previousValue);
+
+    /**
+     * Called when a key/value pair has been removed from a map.
+     *
+     * @param map
+     * The source of the map event.
+     *
+     * @param key
+     * The key that was removed.
+     *
+     * @param value
+     * The value that was removed.
+     */
+    public void valueRemoved(Map<K, V> map, K key, V value);
+
+    /**
+     * Called when map data has been reset.
+     *
+     * @param map
+     * The source of the map event.
+     */
+    public void mapCleared(Map<K, V> map);
+
+    /**
+     * Called when a map's comparator has changed.
+     *
+     * @param map
+     * The source of the event.
+     *
+     * @param previousComparator
+     * The previous comparator value.
+     */
+    public void comparatorChanged(Map<K, V> map, Comparator<K> previousComparator);
+}
+

Added: incubator/pivot/branches/1.1/core/src/pivot/collections/Queue.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/core/src/pivot/collections/Queue.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/core/src/pivot/collections/Queue.java (added)
+++ incubator/pivot/branches/1.1/core/src/pivot/collections/Queue.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.collections;
+
+/**
+ * Interface representing a first-in, first-out (FIFO) queue when unsorted, and
+ * a priority queue when sorted.
+ *
+ * @author gbrown
+ */
+public interface Queue<T> extends List<T> {
+    /**
+     * Enqueues an item. If the queue is unsorted, the item is added at the
+     * tail of the queue (index <tt>0</tt>). Otherwise, it is inserted at the
+     * appropriate index.
+     *
+     * @param item
+     * The item to add to the queue.
+     */
+    public void enqueue(T item);
+
+    /**
+     * Removes the item from the head of the queue and returns it. Calling this
+     * method should have the same effect as:
+     *
+     * <code>remove(getLength() - 1, 1);</code>
+     */
+    public T dequeue();
+
+    /**
+     * Returns the item at the head of the queue without removing it from the
+     * queue. Returns null if the queue contains no items. Will also return null
+     * if the head item in the queue is null. <tt>getLength()</tt> can be used
+     * to distinguish between these two cases.
+     */
+    public T peek();
+}