001/*
002 * $Id$
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     * @return total degree of both parts.
053     */
054    public long totalDeg() {
055        return e1.totalDeg() + e2.totalDeg();
056    } 
057
058
059    /**
060     * toString.
061     */
062    @Override
063     public String toString() {
064        StringBuffer s = new StringBuffer("ExpVectorPair[");
065        s.append(e1.toString());
066        s.append(",");
067        s.append(e2.toString());
068        s.append("]");
069        return s.toString();
070    }
071
072
073    /**
074     * equals.
075     * @param B other.
076     * @return true, if this == b, else false.
077     */
078    @Override
079     public boolean equals(Object B) { 
080       if ( ! (B instanceof ExpVectorPair) ) return false;
081       return equals( (ExpVectorPair)B );
082    }
083
084
085    /**
086     * equals.
087     * @param b other.
088     * @return true, if this == b, else false.
089     */
090    public boolean equals(ExpVectorPair b) { 
091       boolean t = e1.equals( b.getFirst() ); 
092       t = t && e2.equals( b.getSecond() ); 
093       return t;
094    }
095
096
097    /** hash code.
098     * @see java.lang.Object#hashCode()
099     */
100    @Override
101    public int hashCode() {
102       return (e1.hashCode() << 16) + e2.hashCode();
103    }
104
105        
106    /**
107     * isMultiple.
108     * @param p other.
109     * @return true, if this is a multiple of b, else false.
110     */
111    public boolean isMultiple(ExpVectorPair p) {
112       boolean w =  e1.multipleOf( p.getFirst() );
113       if ( !w ) {
114           return w;
115       }
116       w =  e2.multipleOf( p.getSecond() );
117       if ( !w ) {
118           return w;
119       }
120       return true;
121    }
122
123}