diff options
author | Rainer Klute <klute@apache.org> | 2003-08-03 20:16:46 +0000 |
---|---|---|
committer | Rainer Klute <klute@apache.org> | 2003-08-03 20:16:46 +0000 |
commit | 73e9bc7c93a61fb9f5320757b43d6850533d2482 (patch) | |
tree | ee39f1123069b6a44d17fdf7ab33075c710b0048 /src/java/org/apache/poi/hpsf/Util.java | |
parent | 4b9a5a046ded478ef93fb355a24e62729ff64673 (diff) | |
download | poi-73e9bc7c93a61fb9f5320757b43d6850533d2482.tar.gz poi-73e9bc7c93a61fb9f5320757b43d6850533d2482.zip |
Writing preparations
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353285 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hpsf/Util.java')
-rw-r--r-- | src/java/org/apache/poi/hpsf/Util.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/hpsf/Util.java b/src/java/org/apache/poi/hpsf/Util.java index 00182e2259..4a92633d0b 100644 --- a/src/java/org/apache/poi/hpsf/Util.java +++ b/src/java/org/apache/poi/hpsf/Util.java @@ -54,6 +54,7 @@ */ package org.apache.poi.hpsf; +import java.util.Collection; import java.util.Date; /** @@ -190,4 +191,59 @@ public class Util return new Date(ms_since_19700101); } + + + /** + * <p>Checks whether two collections are equal. Two collections + * C<sub>1</sub> and C<sub>2</sub> are equal, if the following conditions + * are true:</p> + * + * <ul> + * + * <li><p>For each c<sub>1<em>i</em></sub> (element of C<sub>1</sub>) there + * is a c<sub>2<em>j</em></sub> (element of C<sub>2</sub>), and + * c<sub>1<em>i</em></sub> equals c<sub>2<em>j</em></sub>.</p></li> + * + * <li><p>For each c<sub>2<em>i</em></sub> (element of C<sub>2</sub>) there + * is a c<sub>1<em>j</em></sub> (element of C<sub>1</sub>) and + * c<sub>2<em>i</em></sub> equals c<sub>1<em>j</em></sub>.</p></li> + * + * </ul> + * + * @param c1 the first collection + * @param c2 the second collection + * @return <code>true</code> if the collections are equal, else + * <code>false</code>. + */ + public static boolean equals(final Collection c1, final Collection c2) + { + final Object[] o1 = c1.toArray(); + final Object[] o2 = c2.toArray(); + return internalEquals(o1, o2); + } + + public static boolean equals(final Object[] c1, final Object[] c2) + { + final Object[] o1 = (Object[]) c1.clone(); + final Object[] o2 = (Object[]) c2.clone(); + return internalEquals(o1, o2); + } + + private static boolean internalEquals(final Object[] o1, final Object[] o2) + { + for (int i1 = 0; i1 < o1.length; i1++) + { + boolean matchFound = false; + for (int i2 = 0; !matchFound && i2 < o1.length; i2++) + if (o1[i1].equals(o2[i2])) + { + matchFound = true; + o2[i2] = null; + } + if (!matchFound) + return false; + } + return true; + } + } |