diff --git a/src/java/org/apache/poi/hpsf/ClassID.java b/src/java/org/apache/poi/hpsf/ClassID.java index 1aff51b9b..898364fce 100644 --- a/src/java/org/apache/poi/hpsf/ClassID.java +++ b/src/java/org/apache/poi/hpsf/ClassID.java @@ -205,4 +205,27 @@ public class ClassID dst[i + offset] = bytes[i]; } + + + /** + *
Checks whether this ClassID
is equal to another
+ * object.
PropertySet
with
+ * @return true
if the objects are equal, else
+ * false
.
+ */
+ public boolean equals(final Object o)
+ {
+ if (o == null || !(o instanceof ClassID))
+ return false;
+ final ClassID cid = (ClassID) o;
+ if (bytes.length != cid.bytes.length)
+ return false;
+ for (int i = 0; i < bytes.length; i++)
+ if (bytes[i] != cid.bytes[i])
+ return false;
+ return true;
+ }
+
}
diff --git a/src/java/org/apache/poi/hpsf/Property.java b/src/java/org/apache/poi/hpsf/Property.java
index b6d92ebeb..227f69d16 100644
--- a/src/java/org/apache/poi/hpsf/Property.java
+++ b/src/java/org/apache/poi/hpsf/Property.java
@@ -100,7 +100,7 @@ public class Property
private static final int CP_UNICODE = 1200;
/** The property's ID.
*/ - private int id; + protected int id; /** @@ -116,7 +116,7 @@ public class Property /**The property's type.
*/ - private long type; + protected long type; /** @@ -132,7 +132,7 @@ public class Property /**The property's value.
*/ - private Object value; + protected Object value; /** @@ -191,6 +191,15 @@ public class Property + /** + *Creates an empty property. It must be filled using the set method to + * be usable.
+ */ + protected Property() + {} + + + /** *Reads a dictionary.
* @@ -275,4 +284,11 @@ public class Property throw new UnsupportedOperationException("FIXME: Not yet implemented."); } + + + public boolean equals(Object o) + { + throw new UnsupportedOperationException("FIXME: Not yet implemented."); + } + } diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index a0b2f9bc3..a039ff9bc 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -54,10 +54,12 @@ */ package org.apache.poi.hpsf; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; + import org.apache.poi.hpsf.wellknown.SectionIDMap; import org.apache.poi.util.LittleEndian; @@ -636,4 +638,38 @@ public class PropertySet return ((Section) sections.get(0)); } + + + /** + *Returns true
if the PropertySet
is equal
+ * to the specified parameter, else false
.
PropertySet
with
+ */
+ public boolean equals(final Object o)
+ {
+ if (o == null || !(o instanceof PropertySet))
+ return false;
+ final PropertySet ps = (PropertySet) o;
+ int byteOrder1 = ps.getByteOrder();
+ int byteOrder2 = getByteOrder();
+ ClassID classId1 = ps.getClassID();
+ ClassID classID2 = getClassID();
+ int format1 = ps.getFormat();
+ int format2 = getFormat();
+ int osVersion1 = ps.getOSVersion();
+ int osVersion2 = getOSVersion();
+ int sectionCount1 = ps.getSectionCount();
+ int sectionCount2 = getSectionCount();
+ if (byteOrder1 != byteOrder2 ||
+ !classId1.equals(classID2) ||
+ format1 != format2 ||
+ osVersion1 != osVersion2 ||
+ sectionCount1 != sectionCount2)
+ return false;
+
+ /* Compare the sections: */
+ return Util.equals(getSections(), ps.getSections());
+ }
+
}
diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java
index bd8bcf0d6..abeed3a7c 100644
--- a/src/java/org/apache/poi/hpsf/Section.java
+++ b/src/java/org/apache/poi/hpsf/Section.java
@@ -138,7 +138,7 @@ public class Section
/**
* @see #getPropertyCount
*/
- protected int propertyCount;
+ private int propertyCount;
/**
@@ -156,7 +156,7 @@ public class Section
/**
* @see #getProperties
*/
- protected Property[] properties;
+ private Property[] properties;
/**
@@ -169,6 +169,16 @@ public class Section
return properties;
}
+ /**
+ * Sets this section's properties.
+ * + * @param properties This section's new properties. + */ + protected void setProperties(final Property[] properties) + { + this.properties = properties; + } + /** @@ -423,4 +433,25 @@ public class Section return s; } + + + /** + *Checks whether this section is equal to another object.
+ * + * @param o The object to cpmpare this section with + * @returntrue
if the objects are equal, false
if
+ * not
+ */
+ public boolean equals(final Object o)
+ {
+ if (o == null || !(o instanceof Section))
+ return false;
+ final Section s = (Section) o;
+ if (!s.getFormatID().equals(getFormatID()))
+ return false;
+ if (s.getPropertyCount() != getPropertyCount())
+ return false;
+ return Util.equals(s.getProperties(), getProperties());
+ }
+
}
diff --git a/src/java/org/apache/poi/hpsf/Util.java b/src/java/org/apache/poi/hpsf/Util.java
index 00182e225..4a92633d0 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);
}
+
+
+ /**
+ * Checks whether two collections are equal. Two collections + * C1 and C2 are equal, if the following conditions + * are true:
+ * + *For each c1i (element of C1) there + * is a c2j (element of C2), and + * c1i equals c2j.
For each c2i (element of C2) there + * is a c1j (element of C1) and + * c2i equals c1j.
true
if the collections are equal, else
+ * false
.
+ */
+ 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;
+ }
+
}