PageRenderTime 125ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/poifs/filesystem/DocumentDescriptor.java

http://github.com/openmicroscopy/bioformats
Java | 139 lines | 60 code | 16 blank | 63 comment | 16 complexity | 7435ded9cbe9f607bd81e481f9e72aec MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.poifs.filesystem;
  38. /**
  39. * Class DocumentDescriptor
  40. *
  41. * @author Marc Johnson (mjohnson at apache dot org)
  42. * @version %I%, %G%
  43. */
  44. public class DocumentDescriptor
  45. {
  46. private POIFSDocumentPath path;
  47. private String name;
  48. private int hashcode = 0;
  49. /**
  50. * Trivial constructor
  51. *
  52. * @param path the Document path
  53. * @param name the Document name
  54. */
  55. public DocumentDescriptor(final POIFSDocumentPath path, final String name)
  56. {
  57. if (path == null)
  58. {
  59. throw new NullPointerException("path must not be null");
  60. }
  61. if (name == null)
  62. {
  63. throw new NullPointerException("name must not be null");
  64. }
  65. if (name.length() == 0)
  66. {
  67. throw new IllegalArgumentException("name cannot be empty");
  68. }
  69. this.path = path;
  70. this.name = name;
  71. }
  72. /**
  73. * equality. Two DocumentDescriptor instances are equal if they
  74. * have equal paths and names
  75. *
  76. * @param o the object we're checking equality for
  77. *
  78. * @return true if the object is equal to this object
  79. */
  80. public boolean equals(final Object o)
  81. {
  82. boolean rval = false;
  83. if ((o != null) && (o.getClass() == this.getClass()))
  84. {
  85. if (this == o)
  86. {
  87. rval = true;
  88. }
  89. else
  90. {
  91. DocumentDescriptor descriptor = ( DocumentDescriptor ) o;
  92. rval = this.path.equals(descriptor.path)
  93. && this.name.equals(descriptor.name);
  94. }
  95. }
  96. return rval;
  97. }
  98. /**
  99. * calculate and return the hashcode
  100. *
  101. * @return hashcode
  102. */
  103. public int hashCode()
  104. {
  105. if (hashcode == 0)
  106. {
  107. hashcode = path.hashCode() ^ name.hashCode();
  108. }
  109. return hashcode;
  110. }
  111. public String toString()
  112. {
  113. StringBuffer buffer = new StringBuffer(40 * (path.length() + 1));
  114. for (int j = 0; j < path.length(); j++)
  115. {
  116. buffer.append(path.getComponent(j)).append("/");
  117. }
  118. buffer.append(name);
  119. return buffer.toString();
  120. }
  121. } // end public class DocumentDescriptor