001    /*
002     * $Id: CPair.java 3426 2010-12-24 13:17:58Z kredel $
003     */
004    
005    package edu.jas.application;
006    
007    
008    import java.io.Serializable;
009    
010    import edu.jas.structure.RingElem;
011    
012    
013    /**
014     * Serializable subclass to hold pairs of colored polynomials.
015     * @param <C> coefficient type
016     * @author Heinz Kredel.
017     */
018    public class CPair<C extends RingElem<C>> implements Serializable, Comparable<CPair<C>> {
019    
020    
021        public final ColorPolynomial<C> pi;
022    
023    
024        public final ColorPolynomial<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 = true;
040    
041    
042        protected boolean useCriterion3 = true;
043    
044    
045        /**
046         * Pair constructor.
047         * @param a polynomial i.
048         * @param b polynomial j.
049         * @param i first index.
050         * @param j second index.
051         */
052        public CPair(ColorPolynomial<C> a, ColorPolynomial<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 + "{" + pi.length() + "}," + j + "{" + pj.length()
068                    + "}" + ", r0=" + toZero + ", c4=" + useCriterion4 + ", c3="
069                    + useCriterion3 + ")";
070        }
071    
072    
073        /**
074         * Set removed pair number.
075         * @param n number of this pair generated in OrderedPairlist.
076         */
077        public void pairNumber(int n) {
078            this.n = n;
079        }
080    
081    
082        /**
083         * Get removed pair number.
084         * @return n number of this pair generated in OrderedPairlist.
085         */
086        public int getPairNumber() {
087            return n;
088        }
089    
090    
091        /**
092         * Set zero reduction. The S-polynomial of this Pair was reduced to zero.
093         */
094        public void setZero() {
095            toZero = true;
096        }
097    
098    
099        /**
100         * Is reduced to zero.
101         * @return true if the S-polynomial of this Pair was reduced to zero, else
102         *         false.
103         */
104        public boolean isZero() {
105            return toZero;
106        }
107    
108    
109        /**
110         * equals.
111         * @param ob an Object.
112         * @return true if this is equal to ob, else false.
113         */
114        @Override
115        @SuppressWarnings("unchecked")
116        public boolean equals(Object ob) {
117            CPair<C> cp = null;
118            try {
119                cp = (CPair<C>) ob;
120            } catch ( ClassCastException e) {
121                return false;
122            }
123            if ( cp == null ) {
124                return false;
125            }
126            return 0 == compareTo(cp);
127        }
128    
129    
130        /**
131         * compareTo used in TreeMap. 
132         * Comparison is based on the number of the pairs.
133         * @param p a Pair.
134         * @return 1 if (this &lt; p), 0 if (this == o), -1 if (this &gt; p).
135         */
136        public int compareTo(CPair<C> p) { // not used at moment
137            int x = p.getPairNumber();
138            if (n > x) {
139                return 1;
140            }
141            if (n < x) {
142                return -1;
143            }
144            return 0;
145        }
146    
147    
148        /**
149         * Hash code for this pair.
150         * @see java.lang.Object#hashCode()
151         */
152        @Override
153        public int hashCode() {
154            int h;
155            h = getPairNumber();
156            return h;
157        }
158    
159    
160        /**
161         * Set useCriterion4.
162         * @param c boolean value to set.
163         */
164        public void setUseCriterion4(boolean c) {
165            this.useCriterion4 = c;
166        }
167    
168    
169        /**
170         * Get useCriterion4.
171         * @return boolean value.
172         */
173        public boolean getUseCriterion4() {
174            return this.useCriterion4;
175        }
176    
177    
178        /**
179         * Set useCriterion3.
180         * @param c boolean value to set.
181         */
182        public void setUseCriterion3(boolean c) {
183            this.useCriterion3 = c;
184        }
185    
186    
187        /**
188         * Get useCriterion3.
189         * @return boolean value.
190         */
191        public boolean getUseCriterion3() {
192            return this.useCriterion3;
193        }
194    
195    }