Goktug Gokdogan has submitted this change and it was merged.

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


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

Fixes issue 7550

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, 29 insertions(+), 9 deletions(-)

Approvals:
  Colin Alworth: Looks good to me, but someone else must approve
  Leeroy Jenkins: Verified
  Goktug Gokdogan: Looks good to me, approved



diff --git a/user/src/com/google/gwt/dom/client/Element.java b/user/src/com/google/gwt/dom/client/Element.java
index 7d1fd5b..f8768e4 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 = trimClassName(className);

     // Get the current style string.
     String oldClassName = getClassName();
@@ -498,6 +495,18 @@
   }

   /**
+   * 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 = trimClassName(className);
+    int idx = indexOfName(getClassName(), className);
+    return idx != -1;
+  }
+
+  /**
    * Determines whether this element has the given tag name.
    *
    * @param tagName the tag name, including namespace-prefix (if present)
@@ -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 = trimClassName(className);

     // Get the current style string.
     String oldStyle = getClassName();
@@ -581,6 +587,13 @@
     return idx;
   }

+  private static String trimClassName(String className) {
+    assert (className != null) : "Unexpectedly null class name";
+    className = className.trim();
+    assert !className.isEmpty() : "Unexpectedly empty class name";
+    return className;
+  }
+
   /**
    * Replace one class name with another.
    *
diff --git a/user/test/com/google/gwt/dom/client/ElementTest.java b/user/test/com/google/gwt/dom/client/ElementTest.java
index a1e6145..907f736 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,13 @@

     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"));
+    assertTrue(div.hasClassName("bar"));
   }

   public void testIndexOfName() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia09567b8c58cac02f8126c33ef169b26def3d19c
Gerrit-PatchSet: 6
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Andrey Korzhevskiy <a.korzhevs...@gmail.com>
Gerrit-Reviewer: Colin Alworth <niloc...@gmail.com>
Gerrit-Reviewer: Daniel Kurka <danku...@google.com>
Gerrit-Reviewer: Goktug Gokdogan <gok...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jenk...@gwtproject.org>
Gerrit-Reviewer: Stephen Haberman <stephen.haber...@gmail.com>
Gerrit-Reviewer: Thomas Broyer <t.bro...@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