/**
 * 
 */
package datastructures;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @author Pavel Nichita
 *
 */
public class AttributeJoint implements Iterable<Attribute> {
    private ArrayList<Attribute> joint;

    /**
     * Constructs a Null list of Attribute.
     */
    public AttributeJoint() {
        // Manually generated default constructor.
    }

    /**
     * Constructs an ordered list of Attributes from strings.
     * 
     * With every string in stringArray creates an Attribute object,
     * after that adds it in a list. In the end sorts the list.
     * 
     * @param stringArray An array of String object.
     */
    public AttributeJoint(String [] stringArray) {
        joint = new ArrayList<>();
        for (String attr : stringArray)
            joint.add(new Attribute(attr));
        sort();
    }

    /**
     * Constructs an ordered list of Attributes from joint object
     * with Attribute objects.
     * 
     * Adds every Attribute object to a list. In the end sorts the list.
     * 
     * @param joint An ArrayList of Attribute objects.
     */
    public AttributeJoint(List<Attribute> joint) {
        this.joint = new ArrayList<>(joint) ;
        sort();
    }

    /**
     * Constructs an ordered list of Attributes from another
     * AttributeJoint object.
     *
     * Assigns the list from obj to this AttributeJoint object.
     *
     * @param obj An AttributeJoint object.
     */
    public AttributeJoint(AttributeJoint obj) {
        this.joint = new ArrayList<>(obj.getAttributeJoint());
    }

    /**
     * Returns a list of Attribute objects.
     * 
     * @return a list of Attribute objects.
     */
    public List<Attribute> getAttributeJoint() {
        return this.joint;
    }

    /**
     * Sets the list joint.
     * 
     * @param joint A list with Attribute objects.
     */
    public void setAttributeJoint(List<Attribute> joint) {
        this.joint = new ArrayList<>(joint);
    }

    /**
     * Removes Attribute objects that appear more than one time
     * in the list.
     */
    public void removeDuplicatedAttribute() {
        int j;
        for (int i = 0; i < joint.size(); i++){
            j = i + 1;
            while (j < joint.size()) {
                if (joint.get(i).equals(joint.get(j))) {
                    joint.remove(j);
                    j--;
                }
                j++;
            }
        }
    }

    /**
     * Returns the value of this AttributeJoint object in string format.
     * 
     * The format being used is <i>{obj, obj, ...}</i>.
     * 
     * @return a string representing this object, if the list is empty or
     * null returns "null" string. 
     */
    @Override
    public String toString() {
        if (this.joint == null || this.joint.isEmpty())
            return "null";
        
        String stringJoint = "{" + joint.get(0).toString();
        for (int i = 1; i < joint.size(); i++)
            stringJoint = stringJoint + ", " + joint.get(i).toString();
        return stringJoint + "}";
    }

    /**
     * Sorts the list of Attribute objects according to lexicographically
     * order.
     */
    public void sort() {
        Collections.sort(joint);
    }

    /**
     * Returns an Iterator other the Attribute objects list.
     * 
     * @return an iterator other the Attribute objects list.
     */
    @Override
    public Iterator<Attribute> iterator() {
        return this.joint.iterator();
    }

}

@@ -3111,32 +3111,1223 @@
 t + %22%7D%22;%0A    %7D%0A%0A
+    /**%0A     * Adds an Attribute object to this list.%0A     * %0A     * If this list is not initialized, initializes it, checks if %7B@code attr%7D%0A     * is already in the list, if it's not adds it, and sort this list.%0A     * %0A     * @param attr Attribute object to add to the list.%0A     */%0A    public void addAttributes(Attribute attr) %7B%0A        if (joint == null)%0A            joint = new ArrayList%3C%3E();%0A        %0A        if (joint.indexOf(attr) == -1)%0A            joint.add(attr);%0A        %0A        sort();%0A    %7D%0A%0A    /**%0A     * Adds another AttributeJoint Attribute objects to this.%0A     * %0A     * If this list is not initialized, initializes it, checks if %7B@code attrJoint%7D%0A     * has Attribute objects, if it not, calls %7B@link datastructures.AttributeJoint#addAttributes(Attribute)%7D %0A     * for every Attribute object of %7B@code attrJoint%7D.%0A     * %0A     * @param attrJoint The AttributeJoint to add to this.%0A     */%0A    public void addAttributes(AttributeJoint attrJoint) %7B%0A        if (joint == null)%0A            joint = new ArrayList%3C%3E();%0A        %0A        if (attrJoint.getAttributeJoint() != null)      %0A            for (Attribute attr : attrJoint)%0A                addAttributes(attr);%0A    %7D%0A%0A
     /**%0A     * S

Add method addAttributes to AttributeJoint