001/*
002 * $Id: ExpVectorPair.java 1888 2008-07-12 13:37:34Z kredel $
003 */
004
005package edu.jas.poly;
006
007import java.io.Serializable;
008
009
010/**
011 * ExpVectorPair 
012 * implements pairs of exponent vectors for S-polynomials.
013 * Objects of this class are immutable.
014 * @author Heinz Kredel
015 */
016
017
018public class ExpVectorPair implements Serializable {
019
020    private final ExpVector e1;
021    private final ExpVector e2;
022
023
024    /**
025     * Constructors for ExpVectorPair.
026     * @param e first part.
027     * @param f second part.
028     */
029    public ExpVectorPair(ExpVector e, ExpVector f) {
030        e1 = e;
031        e2 = f;
032    }
033
034
035    /**
036     * @return first part.
037     */
038    public ExpVector getFirst() {
039        return e1;
040    } 
041
042
043    /**
044     * @return second part.
045     */
046    public ExpVector getSecond() {
047        return e2;
048    } 
049
050
051    /**
052     * toString.
053     */
054    @Override
055     public String toString() {
056        StringBuffer s = new StringBuffer("ExpVectorPair[");
057        s.append(e1.toString());
058        s.append(",");
059        s.append(e2.toString());
060        s.append("]");
061        return s.toString();
062    }
063
064
065    /**
066     * equals.
067     * @param B other.
068     * @return true, if this == b, else false.
069     */
070    @Override
071     public boolean equals(Object B) { 
072       if ( ! (B instanceof ExpVectorPair) ) return false;
073       return equals( (ExpVectorPair)B );
074    }
075
076
077    /**
078     * equals.
079     * @param b other.
080     * @return true, if this == b, else false.
081     */
082    public boolean equals(ExpVectorPair b) { 
083       boolean t = e1.equals( b.getFirst() ); 
084       t = t && e2.equals( b.getSecond() ); 
085       return t;
086    }
087
088
089    /** hash code.
090     * @see java.lang.Object#hashCode()
091     */
092    @Override
093    public int hashCode() {
094       return (e1.hashCode() << 16) + e2.hashCode();
095    }
096
097        
098    /**
099     * isMultiple.
100     * @param p other.
101     * @return true, if this is a multiple of b, else false.
102     */
103    public boolean isMultiple(ExpVectorPair p) {
104       boolean w =  e1.multipleOf( p.getFirst() );
105       if ( !w ) {
106           return w;
107       }
108       w =  e2.multipleOf( p.getSecond() );
109       if ( !w ) {
110           return w;
111       }
112       return true;
113    }
114
115}