PageRenderTime 65ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hpsf/CustomProperty.java

http://github.com/openmicroscopy/bioformats
Java | 147 lines | 44 code | 13 blank | 90 comment | 8 complexity | 4228c372b89c70ef386e873ba9e64467 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.hpsf;
  38. /**
  39. * <p>This class represents custum properties in the document summary
  40. * information stream. The difference to normal properties is that custom
  41. * properties have an optional name. If the name is not <code>null</code> it
  42. * will be maintained in the section's dictionary.</p>
  43. *
  44. * @author Rainer Klute <a
  45. * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  46. * @since 2006-02-09
  47. * @version $Id$
  48. */
  49. public class CustomProperty extends MutableProperty
  50. {
  51. private String name;
  52. /**
  53. * <p>Creates an empty {@link CustomProperty}. The set methods must be
  54. * called to make it usable.</p>
  55. */
  56. public CustomProperty()
  57. {
  58. this.name = null;
  59. }
  60. /**
  61. * <p>Creates a {@link CustomProperty} without a name by copying the
  62. * underlying {@link Property}' attributes.</p>
  63. *
  64. * @param property the property to copy
  65. */
  66. public CustomProperty(final Property property)
  67. {
  68. this(property, null);
  69. }
  70. /**
  71. * <p>Creates a {@link CustomProperty} with a name.</p>
  72. *
  73. * @param property This property's attributes are copied to the new custom
  74. * property.
  75. * @param name The new custom property's name.
  76. */
  77. public CustomProperty(final Property property, final String name)
  78. {
  79. super(property);
  80. this.name = name;
  81. }
  82. /**
  83. * <p>Gets the property's name.</p>
  84. *
  85. * @return the property's name.
  86. */
  87. public String getName()
  88. {
  89. return name;
  90. }
  91. /**
  92. * <p>Sets the property's name.</p>
  93. *
  94. * @param name The name to set.
  95. */
  96. public void setName(final String name)
  97. {
  98. this.name = name;
  99. }
  100. /**
  101. * <p>Compares two custom properties for equality. The method returns
  102. * <code>true</code> if all attributes of the two custom properties are
  103. * equal.</p>
  104. *
  105. * @param o The custom property to compare with.
  106. * @return <code>true</code> if both custom properties are equal, else
  107. * <code>false</code>.
  108. *
  109. * @see java.util.AbstractSet#equals(java.lang.Object)
  110. */
  111. public boolean equalsContents(final Object o)
  112. {
  113. final CustomProperty c = (CustomProperty) o;
  114. final String name1 = c.getName();
  115. final String name2 = this.getName();
  116. boolean equalNames = true;
  117. if (name1 == null)
  118. equalNames = name2 == null;
  119. else
  120. equalNames = name1.equals(name2);
  121. return equalNames && c.getID() == this.getID()
  122. && c.getType() == this.getType()
  123. && c.getValue().equals(this.getValue());
  124. }
  125. /**
  126. * @see java.util.AbstractSet#hashCode()
  127. */
  128. public int hashCode()
  129. {
  130. return (int) this.getID();
  131. }
  132. }