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.poifs.filesystem;
019:
020: /**
021: * Class DocumentDescriptor
022: *
023: * @author Marc Johnson (mjohnson at apache dot org)
024: * @version %I%, %G%
025: */
026:
027: public class DocumentDescriptor {
028: private POIFSDocumentPath path;
029: private String name;
030: private int hashcode = 0;
031:
032: /**
033: * Trivial constructor
034: *
035: * @param path the Document path
036: * @param name the Document name
037: */
038:
039: public DocumentDescriptor(final POIFSDocumentPath path,
040: final String name) {
041: if (path == null) {
042: throw new NullPointerException("path must not be null");
043: }
044: if (name == null) {
045: throw new NullPointerException("name must not be null");
046: }
047: if (name.length() == 0) {
048: throw new IllegalArgumentException("name cannot be empty");
049: }
050: this .path = path;
051: this .name = name;
052: }
053:
054: /**
055: * equality. Two DocumentDescriptor instances are equal if they
056: * have equal paths and names
057: *
058: * @param o the object we're checking equality for
059: *
060: * @return true if the object is equal to this object
061: */
062:
063: public boolean equals(final Object o) {
064: boolean rval = false;
065:
066: if ((o != null) && (o.getClass() == this .getClass())) {
067: if (this == o) {
068: rval = true;
069: } else {
070: DocumentDescriptor descriptor = (DocumentDescriptor) o;
071:
072: rval = this .path.equals(descriptor.path)
073: && this .name.equals(descriptor.name);
074: }
075: }
076: return rval;
077: }
078:
079: /**
080: * calculate and return the hashcode
081: *
082: * @return hashcode
083: */
084:
085: public int hashCode() {
086: if (hashcode == 0) {
087: hashcode = path.hashCode() ^ name.hashCode();
088: }
089: return hashcode;
090: }
091:
092: public String toString() {
093: StringBuffer buffer = new StringBuffer(40 * (path.length() + 1));
094:
095: for (int j = 0; j < path.length(); j++) {
096: buffer.append(path.getComponent(j)).append("/");
097: }
098: buffer.append(name);
099: return buffer.toString();
100: }
101: } // end public class DocumentDescriptor
|