Andrey Korzhevskiy has uploaded a new change for review.

  https://gwt-review.googlesource.com/3070


Change subject: Add hasClassName method in com.google.gwt.dom.client.Element
......................................................................

Add hasClassName method in com.google.gwt.dom.client.Element

Change-Id: Ia09567b8c58cac02f8126c33ef169b26def3d19c
---
M user/src/com/google/gwt/dom/client/Element.java
M user/test/com/google/gwt/dom/client/ElementTest.java
2 files changed, 36 insertions(+), 9 deletions(-)



diff --git a/user/src/com/google/gwt/dom/client/Element.java b/user/src/com/google/gwt/dom/client/Element.java
index 7d1fd5b..dd0abd5 100644
--- a/user/src/com/google/gwt/dom/client/Element.java
+++ b/user/src/com/google/gwt/dom/client/Element.java
@@ -89,10 +89,7 @@
    * @see #setClassName(String)
    */
   public final boolean addClassName(String className) {
-    assert (className != null) : "Unexpectedly null class name";
-
-    className = className.trim();
-    assert (className.length() != 0) : "Unexpectedly empty class name";
+    className = checkClassName(className);

     // Get the current style string.
     String oldClassName = getClassName();
@@ -108,6 +105,18 @@
       return true;
     }
     return false;
+  }
+
+  /**
+   * Checks if this element's class property contains specified class name.
+   *
+   * @param className the class name to be added
+   * @return <code>true</code> if this element has the specified class name
+   */
+  public final boolean hasClassName(String className) {
+    className = checkClassName(className);
+    int idx = indexOfName(getClassName(), className);
+    return idx != -1;
   }

   /**
@@ -524,10 +533,7 @@
    * @see #setClassName(String)
    */
   public final boolean removeClassName(String className) {
-    assert (className != null) : "Unexpectedly null class name";
-
-    className = className.trim();
-    assert (className.length() != 0) : "Unexpectedly empty class name";
+    className = checkClassName(className);

     // Get the current style string.
     String oldStyle = getClassName();
@@ -582,6 +588,21 @@
   }

   /**
+   * Checks if className is valid and trims it.
+   *
+   * @param className a non-empty string
+   * @return trimmed class name string
+   */
+  static String checkClassName(String className) {
+    assert (className != null) : "Unexpectedly null class name";
+
+    className = className.trim();
+    assert (className.length() != 0) : "Unexpectedly empty class name";
+
+    return className;
+  }
+
+  /**
    * Replace one class name with another.
    *
    * @param oldClassName the class name to be replaced
diff --git a/user/test/com/google/gwt/dom/client/ElementTest.java b/user/test/com/google/gwt/dom/client/ElementTest.java
index a1e6145..b79a784 100644
--- a/user/test/com/google/gwt/dom/client/ElementTest.java
+++ b/user/test/com/google/gwt/dom/client/ElementTest.java
@@ -34,7 +34,7 @@
     return "com.google.gwt.dom.DOMTest";
   }

-  public void testAddRemoveReplaceClassName() {
+  public void testAddRemoveReplaceHasClassName() {
     DivElement div = Document.get().createDivElement();

     div.setClassName("foo");
@@ -64,6 +64,12 @@

     assertTrue(div.removeClassName("foo"));
     assertEquals("", div.getClassName());
+
+    div.setClassName("foo bar");
+    assertTrue(div.hasClassName("bar"));
+    assertTrue(div.hasClassName("foo"));
+    div.removeClassName("foo");
+    assertFalse(div.hasClassName("foo"));
   }

   public void testIndexOfName() {

--
To view, visit https://gwt-review.googlesource.com/3070
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia09567b8c58cac02f8126c33ef169b26def3d19c
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Andrey Korzhevskiy <a.korzhevs...@gmail.com>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to