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.

ListProperty.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo.properties;
  19. import java.util.List;
  20. import org.apache.fop.fo.FObj;
  21. import org.apache.fop.fo.PropertyList;
  22. import org.apache.fop.fo.expr.PropertyException;
  23. import org.apache.fop.util.CompareUtil;
  24. /**
  25. * Superclass for properties that are lists of other properties
  26. */
  27. public class ListProperty extends Property {
  28. /**
  29. * Inner class for creating instances of {@code ListProperty}
  30. */
  31. public static class Maker extends PropertyMaker {
  32. /**
  33. * Create a maker for the given property id.
  34. * @param propId ID of the property for which Maker should be created
  35. */
  36. public Maker(int propId) {
  37. super(propId);
  38. }
  39. /** {@inheritDoc} */
  40. @Override
  41. public Property convertProperty(Property p,
  42. PropertyList propertyList, FObj fo)
  43. throws PropertyException {
  44. if (p instanceof ListProperty) {
  45. return p;
  46. } else {
  47. return new ListProperty(p);
  48. }
  49. }
  50. }
  51. /** Vector containing the list of sub-properties */
  52. protected final List<Property> list = new java.util.Vector<Property>();
  53. /**
  54. * Simple constructor used by subclasses to do some special processing.
  55. */
  56. protected ListProperty() {
  57. //nop
  58. }
  59. /**
  60. * Create a new instance, using the given {@link Property} as the first
  61. * element in the list.
  62. * @param prop the first property to be added to the list
  63. */
  64. public ListProperty(Property prop) {
  65. this();
  66. addProperty(prop);
  67. }
  68. /**
  69. * Add a new property to the list
  70. * @param prop Property to be added to the list
  71. */
  72. public void addProperty(Property prop) {
  73. list.add(prop);
  74. }
  75. /**
  76. * Return the {@code java.util.List} of {@link Property} instances
  77. * contained in this property.
  78. * @return the list of properties contained in this instance
  79. */
  80. @Override
  81. public List<Property> getList() {
  82. return list;
  83. }
  84. /**
  85. * Return the {@code java.util.List} of {@link Property} instances,
  86. * cast as a {@code java.lang.Object}.
  87. * @return this.list cast as an Object
  88. */
  89. @Override
  90. public Object getObject() {
  91. return list;
  92. }
  93. @Override
  94. public int hashCode() {
  95. return list.hashCode();
  96. }
  97. @Override
  98. public boolean equals(Object obj) {
  99. if (this == obj) {
  100. return true;
  101. }
  102. if (!(obj instanceof ListProperty)) {
  103. return false;
  104. }
  105. ListProperty other = (ListProperty) obj;
  106. return CompareUtil.equal(list, other.list);
  107. }
  108. }