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