Add convenience static methods for getting a CommonAttributeType Tristate, BooleanAndUndefined,IdReference and IdReferenceList

Review by: jlabanca@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10916 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/aria/client/CommonAttributeTypes.java b/user/src/com/google/gwt/aria/client/CommonAttributeTypes.java
index 02862b7..b729fd0 100644
--- a/user/src/com/google/gwt/aria/client/CommonAttributeTypes.java
+++ b/user/src/com/google/gwt/aria/client/CommonAttributeTypes.java
@@ -33,7 +33,7 @@
   // This class cannot be instanted
   private CommonAttributeTypes() {
   }
-  
+
   /**
    * Interface that is and needs to be implemented by ALL non primitive attribute types
    */
@@ -47,6 +47,10 @@
   public static enum Tristate implements AriaAttributeType {
     TRUE(TRUE_VALUE), FALSE(FALSE_VALUE), MIXED(MIXED_TRISTATE_VALUE);
 
+    public static Tristate of(boolean value) {
+      return value ? TRUE : FALSE;
+    }
+
     private final String value;
 
     private Tristate(String value) {
@@ -65,6 +69,10 @@
   public static enum BooleanAndUndefined implements AriaAttributeType {
     TRUE(TRUE_VALUE), FALSE(FALSE_VALUE), UNDEFINED(UNDEFINED_VALUE);
 
+    public static BooleanAndUndefined of(boolean value) {
+      return value ? TRUE : FALSE;
+    }
+
     private final String value;
 
     private BooleanAndUndefined(String value) {
@@ -81,6 +89,10 @@
    * Id reference type
    */
   public static class IdReference implements AriaAttributeType {
+    public static IdReference of(String value) {
+      return new IdReference(value);
+    }
+
     private final String id;
 
     /**
@@ -88,7 +100,7 @@
      *
      * @param value String id value
      */
-    public IdReference(String value) {
+    private IdReference(String value) {
       this.id = value;
     }
 
@@ -102,6 +114,10 @@
    * Id reference list type
    */
   public static class IdReferenceList implements AriaAttributeType {
+    public static IdReferenceList of(String... values) {
+      return new IdReferenceList(values);
+    }
+
     private final String ids;
 
     /**
@@ -109,7 +125,7 @@
      *
      * @param values String ids array
      */
-    public IdReferenceList(String... values) {
+    private IdReferenceList(String... values) {
       assert values.length > 0 : "The ids cannot be empty";
       StringBuffer ariaValue = new StringBuffer();
       for (String value : values) {
diff --git a/user/test/com/google/gwt/aria/client/CommonAttributeTypesTest.java b/user/test/com/google/gwt/aria/client/CommonAttributeTypesTest.java
index 7bf22d7..c5485e6 100644
--- a/user/test/com/google/gwt/aria/client/CommonAttributeTypesTest.java
+++ b/user/test/com/google/gwt/aria/client/CommonAttributeTypesTest.java
@@ -23,15 +23,13 @@
  */
 public class CommonAttributeTypesTest extends GWTTestCase {
   public void testIdReference() {
-    IdReference idReference = new IdReference("test1");
-    assertEquals("test1", idReference.getAriaValue());
+    assertEquals("test1", IdReference.of("test1").getAriaValue());
   }
-  
+
   public void testIdReferenceList() {
-    IdReferenceList idReferenceList = new IdReferenceList("test1", "test2");
-    assertEquals("test1 test2", idReferenceList.getAriaValue());
+    assertEquals("test1 test2", IdReferenceList.of("test1", "test2").getAriaValue());
   }
-  
+
   @Override
   public String getModuleName() {
     return "com.google.gwt.aria.Aria";
diff --git a/user/test/com/google/gwt/aria/client/RoleTest.java b/user/test/com/google/gwt/aria/client/RoleTest.java
index 3004d91..51c6f6f 100644
--- a/user/test/com/google/gwt/aria/client/RoleTest.java
+++ b/user/test/com/google/gwt/aria/client/RoleTest.java
@@ -23,12 +23,12 @@
 import com.google.gwt.junit.client.GWTTestCase;
 
 /**
- * Tests {@link Role} ARIA classes 
+ * Tests {@link Role} ARIA classes
  */
 public class RoleTest extends GWTTestCase {
   private Element div;
   private RegionRole regionRole;
-  
+
   public void testSetGetRemoveRole() {
     assertEquals("", regionRole.get(div));
     regionRole.set(div);
@@ -36,35 +36,35 @@
     regionRole.remove(div);
     assertEquals("", regionRole.get(div));
   }
-  
+
   public void testSetGetRemoveProperty() {
-    IdReferenceList idRefs = new IdReferenceList("test1");
+    IdReferenceList idRefs = IdReferenceList.of("test1");
     assertEquals("", regionRole.getAriaLabelledbyProperty(div));
     regionRole.setAriaLabelledbyProperty(div, idRefs);
     assertEquals("test1", regionRole.getAriaLabelledbyProperty(div));
     regionRole.removeAriaLabelledbyProperty(div);
     assertEquals("", regionRole.getAriaLabelledbyProperty(div));
   }
-  
+
   public void testSetGetRemoveNmtokensProperty() {
     ButtonRole buttonRole = Roles.getButtonRole();
     assertEquals("", buttonRole.getAriaDropeffectProperty(div));
-    regionRole.setAriaDropeffectProperty(div, new DropeffectTokenList(DropeffectToken.COPY, 
+    regionRole.setAriaDropeffectProperty(div, new DropeffectTokenList(DropeffectToken.COPY,
         DropeffectToken.MOVE));
     assertEquals("copy move", regionRole.getAriaDropeffectProperty(div));
     regionRole.removeAriaDropeffectProperty(div);
     assertEquals("", regionRole.getAriaDropeffectProperty(div));
   }
-  
+
   public void testSetGetRemoveState() {
     assertEquals("", regionRole.getAriaInvalidState(div));
     regionRole.setAriaInvalidState(div, StateTokenTypes.InvalidToken.GRAMMAR);
-    assertEquals(StateTokenTypes.InvalidToken.GRAMMAR.getAriaValue(), 
+    assertEquals(StateTokenTypes.InvalidToken.GRAMMAR.getAriaValue(),
         regionRole.getAriaInvalidState(div));
     regionRole.removeAriaInvalidState(div);
     assertEquals("", regionRole.getAriaInvalidState(div));
   }
-  
+
   public void testSetGetRemoveExtraAttributes() {
     // Older versions of IE do not support tabIndex on divs, so use an anchor
     // element instead.
@@ -72,23 +72,23 @@
     Document.get().getBody().appendChild(anchor);
 
     // Some versions of IE default to "0" instead of ""
-    assertTrue("".equals(regionRole.getTabindexExtraAttribute(div)) 
+    assertTrue("".equals(regionRole.getTabindexExtraAttribute(div))
         || "0".equals(regionRole.getTabindexExtraAttribute(div)));
     regionRole.setTabindexExtraAttribute(anchor, 1);
     assertEquals("1", regionRole.getTabindexExtraAttribute(anchor));
     regionRole.removeTabindexExtraAttribute(anchor);
     // Some versions of IE default to "0" instead of ""
-    assertTrue("".equals(regionRole.getTabindexExtraAttribute(div)) 
+    assertTrue("".equals(regionRole.getTabindexExtraAttribute(div))
         || "0".equals(regionRole.getTabindexExtraAttribute(div)));
 
     anchor.removeFromParent();
   }
-  
+
   @Override
   public String getModuleName() {
     return "com.google.gwt.aria.Aria";
   }
-  
+
   @Override
   protected void gwtSetUp() throws Exception {
     super.gwtSetUp();
@@ -97,7 +97,7 @@
     Document.get().getBody().appendChild(div);
     regionRole = Roles.getRegionRole();
   }
-  
+
   @Override
   protected void gwtTearDown() throws Exception {
     super.gwtTearDown();