001 /*
002 * $Id: Pair.java 3373 2010-11-28 16:42:49Z kredel $
003 */
004
005 package edu.jas.gb;
006
007 import java.io.Serializable;
008
009 import edu.jas.structure.RingElem;
010
011 import edu.jas.poly.ExpVector;
012 import 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 */
020 public class Pair<C extends RingElem<C> > extends AbstractPair<C>
021 implements Serializable, 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<C>).
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 < o), 0 if (this == o), -1 if (this > 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 * Set useCriterion4.
156 * @param c boolean value to set.
157 */
158 public void setUseCriterion4(boolean c) {
159 this.useCriterion4 = c;
160 }
161
162
163 /**
164 * Get useCriterion4.
165 * @return boolean value.
166 */
167 public boolean getUseCriterion4() {
168 return this.useCriterion4;
169 }
170
171
172 /**
173 * Set useCriterion3.
174 * @param c boolean value to set.
175 */
176 public void setUseCriterion3(boolean c) {
177 this.useCriterion3 = c;
178 }
179
180
181 /**
182 * Get useCriterion3.
183 * @return boolean value.
184 */
185 public boolean getUseCriterion3() {
186 return this.useCriterion3;
187 }
188
189
190 /*
191 * what is this for?
192 public MiniPair toMiniPair() {
193 return new MiniPair(i,j);
194 }
195 */
196
197 }
198