001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hpsf;
019:
020: /**
021: * <p>This class represents custum properties in the document summary
022: * information stream. The difference to normal properties is that custom
023: * properties have an optional name. If the name is not <code>null</code> it
024: * will be maintained in the section's dictionary.</p>
025: *
026: * @author Rainer Klute <a
027: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
028: * @since 2006-02-09
029: * @version $Id$
030: */
031: public class CustomProperty extends MutableProperty {
032:
033: private String name;
034:
035: /**
036: * <p>Creates an empty {@link CustomProperty}. The set methods must be
037: * called to make it usable.</p>
038: */
039: public CustomProperty() {
040: this .name = null;
041: }
042:
043: /**
044: * <p>Creates a {@link CustomProperty} without a name by copying the
045: * underlying {@link Property}' attributes.</p>
046: *
047: * @param property the property to copy
048: */
049: public CustomProperty(final Property property) {
050: this (property, null);
051: }
052:
053: /**
054: * <p>Creates a {@link CustomProperty} with a name.</p>
055: *
056: * @param property This property's attributes are copied to the new custom
057: * property.
058: * @param name The new custom property's name.
059: */
060: public CustomProperty(final Property property, final String name) {
061: super (property);
062: this .name = name;
063: }
064:
065: /**
066: * <p>Gets the property's name.</p>
067: *
068: * @return the property's name.
069: */
070: public String getName() {
071: return name;
072: }
073:
074: /**
075: * <p>Sets the property's name.</p>
076: *
077: * @param name The name to set.
078: */
079: public void setName(final String name) {
080: this .name = name;
081: }
082:
083: /**
084: * <p>Compares two custom properties for equality. The method returns
085: * <code>true</code> if all attributes of the two custom properties are
086: * equal.</p>
087: *
088: * @param o The custom property to compare with.
089: * @return <code>true</code> if both custom properties are equal, else
090: * <code>false</code>.
091: *
092: * @see java.util.AbstractSet#equals(java.lang.Object)
093: */
094: public boolean equalsContents(final Object o) {
095: final CustomProperty c = (CustomProperty) o;
096: final String name1 = c.getName();
097: final String name2 = this .getName();
098: boolean equalNames = true;
099: if (name1 == null)
100: equalNames = name2 == null;
101: else
102: equalNames = name1.equals(name2);
103: return equalNames && c.getID() == this .getID()
104: && c.getType() == this .getType()
105: && c.getValue().equals(this .getValue());
106: }
107:
108: /**
109: * @see java.util.AbstractSet#hashCode()
110: */
111: public int hashCode() {
112: return (int) this.getID();
113: }
114:
115: }
|