You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DocumentDescriptor.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.poifs.filesystem;
  16. /**
  17. * Class DocumentDescriptor
  18. */
  19. public class DocumentDescriptor
  20. {
  21. private POIFSDocumentPath path;
  22. private String name;
  23. private int hashcode;
  24. /**
  25. * Trivial constructor
  26. *
  27. * @param path the Document path
  28. * @param name the Document name
  29. */
  30. public DocumentDescriptor(final POIFSDocumentPath path, final String name)
  31. {
  32. if (path == null)
  33. {
  34. throw new NullPointerException("path must not be null");
  35. }
  36. if (name == null)
  37. {
  38. throw new NullPointerException("name must not be null");
  39. }
  40. if (name.length() == 0)
  41. {
  42. throw new IllegalArgumentException("name cannot be empty");
  43. }
  44. this.path = path;
  45. this.name = name;
  46. }
  47. /**
  48. * equality. Two DocumentDescriptor instances are equal if they
  49. * have equal paths and names
  50. *
  51. * @param o the object we're checking equality for
  52. *
  53. * @return true if the object is equal to this object
  54. */
  55. public boolean equals(final Object o)
  56. {
  57. boolean rval = false;
  58. if ((o != null) && (o.getClass() == this.getClass()))
  59. {
  60. if (this == o)
  61. {
  62. rval = true;
  63. }
  64. else
  65. {
  66. DocumentDescriptor descriptor = ( DocumentDescriptor ) o;
  67. rval = this.path.equals(descriptor.path)
  68. && this.name.equals(descriptor.name);
  69. }
  70. }
  71. return rval;
  72. }
  73. /**
  74. * calculate and return the hashcode
  75. *
  76. * @return hashcode
  77. */
  78. public int hashCode()
  79. {
  80. if (hashcode == 0)
  81. {
  82. hashcode = path.hashCode() ^ name.hashCode();
  83. }
  84. return hashcode;
  85. }
  86. public String toString()
  87. {
  88. StringBuilder buffer = new StringBuilder(40 * (path.length() + 1));
  89. for (int j = 0; j < path.length(); j++)
  90. {
  91. buffer.append(path.getComponent(j)).append("/");
  92. }
  93. buffer.append(name);
  94. return buffer.toString();
  95. }
  96. } // end public class DocumentDescriptor