001/*
002 * $Id$
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
024    protected int n;
025    protected boolean toZero = false;
026    protected boolean useCriterion4 = true;
027    protected boolean useCriterion3 = true;
028
029
030    /**
031     * Pair constructor.
032     * @param a polynomial i.
033     * @param b polynomial j.
034     * @param i first index.
035     * @param j second index.
036     */
037    public Pair(GenPolynomial<C> a, GenPolynomial<C> b, 
038                int i, int j) {
039        this(a,b,i,j,0);
040    }
041
042
043    /**
044     * Pair constructor.
045     * @param a polynomial i.
046     * @param b polynomial j.
047     * @param i first index.
048     * @param j second index.
049     * @param s maximal index.
050     */
051    public Pair(GenPolynomial<C> a, GenPolynomial<C> b, 
052                int i, int j, int s) {
053        this(a.leadingExpVector().lcm(b.leadingExpVector()),a,b,i,j,s);
054    }
055
056
057    /**
058     * Pair constructor.
059     * @param lcm of lt(a) lt(b).
060     * @param a polynomial i.
061     * @param b polynomial j.
062     * @param i first index.
063     * @param j second index.
064     */
065    public Pair(ExpVector lcm, GenPolynomial<C> a, GenPolynomial<C> b, 
066                int i, int j) {
067        this(lcm,a,b,i,j,0);
068    }
069
070
071    /**
072     * Pair constructor.
073     * @param lcm of lt(a) lt(b).
074     * @param a polynomial i.
075     * @param b polynomial j.
076     * @param i first index.
077     * @param j second index.
078     * @param s maximal index.
079     */
080    public Pair(ExpVector lcm, GenPolynomial<C> a, GenPolynomial<C> b, 
081                int i, int j, int s) {
082        super(lcm,a,b,i,j,s);
083        this.n = 0;
084        toZero = false; // ok
085    }
086
087
088    /**
089     * toString.
090     */
091    @Override
092    public String toString() {
093        return super.toString() + "[" + n  
094                           + ", r0=" + toZero  
095                           + ", c4=" + useCriterion4  
096                           + ", c3=" + useCriterion3 
097                           + "]";
098    }
099
100
101    /**
102     * Set removed pair number.
103     * @param n number of this pair generated in OrderedPairlist.
104     */
105    public void pairNumber(int n) {
106        this.n = n;
107    }
108
109
110    /**
111     * Get removed pair number.
112     * @return n number of this pair generated in OrderedPairlist.
113     */
114    public int getPairNumber() {
115        return n;
116    }
117
118
119    /**
120     * Set zero reduction.
121     * The S-polynomial of this Pair was reduced to zero.
122     */
123    public void setZero() {
124        toZero = true;
125    }
126
127
128    /**
129     * Is reduced to zero.
130     * @return true if the S-polynomial of this Pair was reduced to zero, else false.
131     */
132    public boolean isZero() {
133        return toZero;
134    }
135
136
137    /**
138     * equals.
139     * @param ob an Object.
140     * @return true if this is equal to o, else false.
141     */
142    @Override
143     public boolean equals(Object ob) {
144        if ( ! (ob instanceof Pair) ) {
145           return false;
146           // throw new ClassCastException("Pair "+n+" o "+o);
147        }
148        return 0 == compareTo( (Pair)ob );
149    }
150
151
152    /**
153     * compareTo used in TreeMap // not used at moment.
154     * Comparison is based on the number of the pairs.
155     * @param p a Pair.
156     * @return 1 if (this &lt; o), 0 if (this == o), -1 if (this &gt; o).
157     */
158    public int compareTo(Pair p) {
159        int x = p.getPairNumber();
160        if ( n > x ) { 
161           return 1;
162        }
163        if ( n < x ) { 
164           return -1;
165        }
166        return 0;
167    }
168
169
170    /**
171     * Hash code for this Pair.
172     * @see java.lang.Object#hashCode()
173     */
174    @Override
175    public int hashCode() {
176        return (i << 16) + j;
177    }
178
179
180    /**
181     * Set useCriterion4.
182     * @param c boolean value to set.
183     */
184    public void setUseCriterion4(boolean c) {
185        this.useCriterion4 = c;
186    }
187
188
189    /**
190     * Get useCriterion4.
191     * @return boolean value.
192     */
193    public boolean getUseCriterion4() {
194        return this.useCriterion4;
195    }
196
197
198    /**
199     * Set useCriterion3.
200     * @param c boolean value to set.
201     */
202    public void setUseCriterion3(boolean c) {
203        this.useCriterion3 = c;
204    }
205
206
207    /**
208     * Get useCriterion3.
209     * @return boolean value.
210     */
211    public boolean getUseCriterion3() {
212        return this.useCriterion3;
213    }
214
215}
216