dst[i + offset] = bytes[i];
}
+
+
+ /**
+ * <p>Checks whether this <code>ClassID</code> is equal to another
+ * object.</p>
+ *
+ * @param o the object to compare this <code>PropertySet</code> with
+ * @return <code>true</code> if the objects are equal, else
+ * <code>false</code>.</p>
+ */
+ 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;
+ }
+
}
private static final int CP_UNICODE = 1200;
/** <p>The property's ID.</p> */
- private int id;
+ protected int id;
/**
/** <p>The property's type.</p> */
- private long type;
+ protected long type;
/**
/** <p>The property's value.</p> */
- private Object value;
+ protected Object value;
/**
+ /**
+ * <p>Creates an empty property. It must be filled using the set method to
+ * be usable.</p>
+ */
+ protected Property()
+ {}
+
+
+
/**
* <p>Reads a dictionary.</p>
*
throw new UnsupportedOperationException("FIXME: Not yet implemented.");
}
+
+
+ public boolean equals(Object o)
+ {
+ throw new UnsupportedOperationException("FIXME: Not yet implemented.");
+ }
+
}
*/
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;
return ((Section) sections.get(0));
}
+
+
+ /**
+ * <p>Returns <code>true</code> if the <code>PropertySet</code> is equal
+ * to the specified parameter, else <code>false</code>.</p>
+ *
+ * @param o the object to compare this <code>PropertySet</code> 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());
+ }
+
}
/**
* @see #getPropertyCount
*/
- protected int propertyCount;
+ private int propertyCount;
/**
/**
* @see #getProperties
*/
- protected Property[] properties;
+ private Property[] properties;
/**
return properties;
}
+ /**
+ * <p>Sets this section's properties.</p>
+ *
+ * @param properties This section's new properties.
+ */
+ protected void setProperties(final Property[] properties)
+ {
+ this.properties = properties;
+ }
+
/**
return s;
}
+
+
+ /**
+ * <p>Checks whether this section is equal to another object.</p>
+ *
+ * @param o The object to cpmpare this section with
+ * @return <code>true</code> if the objects are equal, <code>false</code> 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());
+ }
+
}
*/
package org.apache.poi.hpsf;
+import java.util.Collection;
import java.util.Date;
/**
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;
+ }
+
}