001    /*
002     * Created on Apr 3, 2009
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005     * in compliance with the License. You may obtain a copy of the License at
006     *
007     * http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software distributed under the License
010     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011     * or implied. See the License for the specific language governing permissions and limitations under
012     * the License.
013     *
014     * Copyright @2009 the original author or authors.
015     */
016    package org.fest.swing.junit.xml;
017    
018    import static org.fest.util.Collections.list;
019    import static org.fest.util.Objects.*;
020    import static org.fest.util.Strings.concat;
021    
022    import java.util.*;
023    
024    /**
025     * Understands a collection of attributes of a <code>{@link XmlNode}</code>. This class is intended for internal use
026     * only. It only provides the necessary functionality needed by the FEST-Swing JUnit extension.
027     *
028     * @author Alex Ruiz
029     */
030    public class XmlAttributes implements Iterable<XmlAttribute> {
031    
032      private final List<XmlAttribute> attributes = new ArrayList<XmlAttribute>();
033    
034      /**
035       * Creates a new <code>{@link XmlAttributes}</code>.
036       * @param attributes the actual attributes.
037       * @return the created <code>XmlAttributes</code>.
038       */
039      public static XmlAttributes attributes(XmlAttribute...attributes) {
040        return new XmlAttributes(attributes);
041      }
042    
043      private XmlAttributes(XmlAttribute...attributes) {
044        this.attributes.addAll(list(attributes));
045      }
046    
047      /**
048       * Returns an iterator containing all the <code>{@link XmlAttribute}</code>s in this collection.
049       * @return an iterator containing all the <code>XmlAttribute</code>s in this collection.
050       */
051      public Iterator<XmlAttribute> iterator() {
052        return attributes.iterator();
053      }
054    
055      @Override public boolean equals(Object obj) {
056        if (this == obj) return true;
057        if (obj == null) return false;
058        if (getClass() != obj.getClass()) return false;
059        XmlAttributes other = (XmlAttributes) obj;
060        return areEqual(attributes, other.attributes);
061      }
062    
063      @Override public int hashCode() {
064        int result = 1;
065        result = HASH_CODE_PRIME * result + hashCodeFor(attributes);
066        return result;
067      }
068    
069      @Override public String toString() {
070        return concat(
071            getClass().getSimpleName(), "[",
072            "attributes=", attributes, "]"
073        );
074      }
075    }