001/*
002 * $Id: Pair.java 4098 2012-08-12 16:39:41Z kredel $
003 */
004
005package edu.jas.gb;
006
007import java.io.Serializable;
008
009import edu.jas.structure.RingElem;
010
011import edu.jas.poly.ExpVector;
012import edu.jas.poly.GenPolynomial;
013
014
015/**
016 * Serializable subclass to hold pairs of polynomials.
017 * @param <C> coefficient type
018 * @author Heinz Kredel.
019 */
020public class Pair<C extends RingElem<C> > extends AbstractPair<C>
021             implements Comparable<Pair> {
022
023    protected int n;
024    protected boolean toZero = false;
025    protected boolean useCriterion4 = true;
026    protected boolean useCriterion3 = true;
027
028
029    /**
030     * Pair constructor.
031     * @param a polynomial i (must be castable to GenPolynomial&lt;C&gt;).
032     * @param b polynomial j.
033     * @param i first index.
034     * @param j second index.
035     */
036    public Pair(Object a, GenPolynomial<C> b, int i, int j) {
037        this( (GenPolynomial<C>)a, b, i, j); 
038    }
039
040
041    /**
042     * Pair constructor.
043     * @param a polynomial i.
044     * @param b polynomial j.
045     * @param i first index.
046     * @param j second index.
047     */
048    public Pair(GenPolynomial<C> a, GenPolynomial<C> b, 
049                int i, int j) {
050        super(a,b,i,j);
051        this.n = 0;
052        toZero = false; // ok
053    }
054
055
056    /**
057     * Pair constructor.
058     * @param lcm of lt(a) lt(b).
059     * @param a polynomial i.
060     * @param b polynomial j.
061     * @param i first index.
062     * @param j second index.
063     */
064    public Pair(ExpVector lcm, GenPolynomial<C> a, GenPolynomial<C> b, 
065                int i, int j) {
066        super(lcm,a,b,i,j);
067        this.n = 0;
068        toZero = false; // ok
069    }
070
071
072    /**
073     * toString.
074     */
075    @Override
076     public String toString() {
077        return super.toString() + "[" + n  
078                           + ", r0=" + toZero  
079                           + ", c4=" + useCriterion4  
080                           + ", c3=" + useCriterion3 
081                           + "]";
082    }
083
084
085    /**
086     * Set removed pair number.
087     * @param n number of this pair generated in OrderedPairlist.
088     */
089    public void pairNumber(int n) {
090        this.n = n;
091    }
092
093
094    /**
095     * Get removed pair number.
096     * @return n number of this pair generated in OrderedPairlist.
097     */
098    public int getPairNumber() {
099        return n;
100    }
101
102
103    /**
104     * Set zero reduction.
105     * The S-polynomial of this Pair was reduced to zero.
106     */
107    public void setZero() {
108        toZero = true;
109    }
110
111
112    /**
113     * Is reduced to zero.
114     * @return true if the S-polynomial of this Pair was reduced to zero, else false.
115     */
116    public boolean isZero() {
117        return toZero;
118    }
119
120
121    /**
122     * equals.
123     * @param ob an Object.
124     * @return true if this is equal to o, else false.
125     */
126    @Override
127     public boolean equals(Object ob) {
128        if ( ! (ob instanceof Pair) ) {
129           return false;
130           // throw new ClassCastException("Pair "+n+" o "+o);
131        }
132        return 0 == compareTo( (Pair)ob );
133    }
134
135
136    /**
137     * compareTo used in TreeMap // not used at moment.
138     * Comparison is based on the number of the pairs.
139     * @param p a Pair.
140     * @return 1 if (this &lt; o), 0 if (this == o), -1 if (this &gt; o).
141     */
142    public int compareTo(Pair p) {
143        int x = p.getPairNumber();
144        if ( n > x ) { 
145           return 1;
146        }
147        if ( n < x ) { 
148           return -1;
149        }
150        return 0;
151    }
152
153
154    /**
155     * Hash code for this Pair.
156     * @see java.lang.Object#hashCode()
157     */
158    @Override
159    public int hashCode() {
160        return (i << 16) + j;
161    }
162
163
164    /**
165     * Set useCriterion4.
166     * @param c boolean value to set.
167     */
168    public void setUseCriterion4(boolean c) {
169        this.useCriterion4 = c;
170    }
171
172
173    /**
174     * Get useCriterion4.
175     * @return boolean value.
176     */
177    public boolean getUseCriterion4() {
178        return this.useCriterion4;
179    }
180
181
182    /**
183     * Set useCriterion3.
184     * @param c boolean value to set.
185     */
186    public void setUseCriterion3(boolean c) {
187        this.useCriterion3 = c;
188    }
189
190
191    /**
192     * Get useCriterion3.
193     * @return boolean value.
194     */
195    public boolean getUseCriterion3() {
196        return this.useCriterion3;
197    }
198
199}
200