/*
 * Copyright 2009 Lari Natri <lari.natri@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package compid.report;

import compid.data.tuples.Tuple;
import java.util.Collection;

/**
 *
 * @author Lari Natri
 */
public class TupleCollectionPair<T extends Tuple> {
    private TupleCollection<T> leftCollection = null;
    private TupleCollection<T> rightCollection = null;
    
    TupleCollectionPair(Collection<T> leftColl, Collection<T> rightColl, String leftName, String rightName) {
        this.leftCollection = new TupleCollection<T>(leftColl, leftName);
        this.rightCollection = new TupleCollection<T>(rightColl, rightName);
    }
    
    public TupleCollectionPair(T leftTuple, T rightTuple, String leftName, String rightName) {
        this(leftName,rightName);
        this.addToLeft(leftTuple);
        this.addToRight(rightTuple);
    }
    
    public TupleCollectionPair(String leftName, String rightName) {
        this.leftCollection = new TupleCollection<T>(leftName);
        this.rightCollection = new TupleCollection<T>(rightName);
    }
    
    public void addToLeft(T tuple) {
        this.leftCollection.add(tuple);
    }

    public void addToRight(T tuple) {
        this.rightCollection.add(tuple);
    }
    
    public Collection<T> getLeft() {
        return this.leftCollection.getCollection();
    }

    public Collection<T> getRight() {
        return this.rightCollection.getCollection();
    }

    public TupleCollection<T> getLeftWithName() {
        return this.leftCollection;
    }

    public TupleCollection<T> getRightWithName() {
        return this.rightCollection;
    }

    
    
    public String getLeftName() {
        return this.leftCollection.getName();
    }
    
    public String getRightName() {
        return this.rightCollection.getName();
    }

    @SuppressWarnings("unchecked") @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TupleCollectionPair<T> other = (TupleCollectionPair<T>) obj;
        if (this.leftCollection != other.leftCollection && (this.leftCollection == null || !this.leftCollection.equals(other.leftCollection))) {
            return false;
        }
        if (this.rightCollection != other.rightCollection && (this.rightCollection == null || !this.rightCollection.equals(other.rightCollection))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.leftCollection != null ? this.leftCollection.hashCode() : 0);
        hash = 79 * hash + (this.rightCollection != null ? this.rightCollection.hashCode() : 0);
        return hash;
    }
    
}
