Desktop tool for browsing account info from EVE-Online
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.

ElementFilter.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*--
  2. $Id: ElementFilter.java,v 1.20 2007/11/10 05:29:00 jhunter Exp $
  3. Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions, and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions, and the disclaimer that follows
  12. these conditions in the documentation and/or other materials
  13. provided with the distribution.
  14. 3. The name "JDOM" must not be used to endorse or promote products
  15. derived from this software without prior written permission. For
  16. written permission, please contact <request_AT_jdom_DOT_org>.
  17. 4. Products derived from this software may not be called "JDOM", nor
  18. may "JDOM" appear in their name, without prior written permission
  19. from the JDOM Project Management <request_AT_jdom_DOT_org>.
  20. In addition, we request (but do not require) that you include in the
  21. end-user documentation provided with the redistribution and/or in the
  22. software itself an acknowledgement equivalent to the following:
  23. "This product includes software developed by the
  24. JDOM Project (http://www.jdom.org/)."
  25. Alternatively, the acknowledgment may be graphical using the logos
  26. available at http://www.jdom.org/images/logos.
  27. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  28. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  34. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38. SUCH DAMAGE.
  39. This software consists of voluntary contributions made by many
  40. individuals on behalf of the JDOM Project and was originally
  41. created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
  42. Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
  43. on the JDOM Project, please see <http://www.jdom.org/>.
  44. */
  45. package org.jdom.filter;
  46. import java.io.*;
  47. import org.jdom.*;
  48. /**
  49. * A Filter that only matches {@link org.jdom.Element} objects.
  50. *
  51. * @version $Revision: 1.20 $, $Date: 2007/11/10 05:29:00 $
  52. * @author Jools Enticknap
  53. * @author Bradley S. Huffman
  54. */
  55. public class ElementFilter extends AbstractFilter {
  56. private static final String CVS_ID =
  57. "@(#) $RCSfile: ElementFilter.java,v $ $Revision: 1.20 $ $Date: 2007/11/10 05:29:00 $ $Name: jdom_1_1 $";
  58. /** The element name */
  59. private String name;
  60. /** The element namespace */
  61. private transient Namespace namespace;
  62. /**
  63. * Select only the Elements.
  64. */
  65. public ElementFilter() {}
  66. /**
  67. * Select only the Elements with the supplied name in any Namespace.
  68. *
  69. * @param name The name of the Element.
  70. */
  71. public ElementFilter(String name) {
  72. this.name = name;
  73. }
  74. /**
  75. * Select only the Elements with the supplied Namespace.
  76. *
  77. * @param namespace The namespace the Element lives in.
  78. */
  79. public ElementFilter(Namespace namespace) {
  80. this.namespace = namespace;
  81. }
  82. /**
  83. * Select only the Elements with the supplied name and Namespace.
  84. *
  85. * @param name The name of the Element.
  86. * @param namespace The namespace the Element lives in.
  87. */
  88. public ElementFilter(String name, Namespace namespace) {
  89. this.name = name;
  90. this.namespace = namespace;
  91. }
  92. /**
  93. * Check to see if the object matches a predefined set of rules.
  94. *
  95. * @param obj The object to verify.
  96. * @return <code>true</code> if the objected matched a predfined
  97. * set of rules.
  98. */
  99. public boolean matches(Object obj) {
  100. if (obj instanceof Element) {
  101. Element el = (Element) obj;
  102. return
  103. (this.name == null || this.name.equals(el.getName())) &&
  104. (this.namespace == null || this.namespace.equals(el.getNamespace()));
  105. }
  106. return false;
  107. }
  108. /**
  109. * Returns whether the two filters are equivalent (i&#46;e&#46; the
  110. * matching names and namespace are equivalent).
  111. *
  112. * @param obj the object to compare against
  113. * @return whether the two filters are equal
  114. */
  115. public boolean equals(Object obj) {
  116. // Generated by IntelliJ
  117. if (this == obj) return true;
  118. if (!(obj instanceof ElementFilter)) return false;
  119. final ElementFilter filter = (ElementFilter) obj;
  120. if (name != null ? !name.equals(filter.name) : filter.name != null) return false;
  121. if (namespace != null ? !namespace.equals(filter.namespace) : filter.namespace != null) return false;
  122. return true;
  123. }
  124. public int hashCode() {
  125. // Generated by IntelliJ
  126. int result;
  127. result = (name != null ? name.hashCode() : 0);
  128. result = 29 * result + (namespace != null ? namespace.hashCode() : 0);
  129. return result;
  130. }
  131. // Support a custom Namespace serialization so no two namespace
  132. // object instances may exist for the same prefix/uri pair
  133. private void writeObject(ObjectOutputStream out) throws IOException {
  134. out.defaultWriteObject();
  135. // We use writeObject() and not writeUTF() to minimize space
  136. // This allows for writing pointers to already written strings
  137. if (namespace != null) {
  138. out.writeObject(namespace.getPrefix());
  139. out.writeObject(namespace.getURI());
  140. }
  141. else {
  142. out.writeObject(null);
  143. out.writeObject(null);
  144. }
  145. }
  146. private void readObject(ObjectInputStream in)
  147. throws IOException, ClassNotFoundException {
  148. in.defaultReadObject();
  149. Object prefix = in.readObject();
  150. Object uri = in.readObject();
  151. if (prefix != null) { // else leave namespace null here
  152. namespace = Namespace.getNamespace((String) prefix, (String) uri);
  153. }
  154. }
  155. }