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