001 /*
002 * $Id: Pair.java 3315 2010-09-05 18:26:34Z kredel $
003 */
004
005 package edu.jas.ps;
006
007
008 import java.io.Serializable;
009
010 import 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 */
018 public 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 < o), 0 if (this == o), -1 if (this > 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 * Set useCriterion4.
143 * @param c boolean value to set.
144 */
145 public void setUseCriterion4(boolean c) {
146 this.useCriterion4 = c;
147 }
148
149
150 /**
151 * Get useCriterion4.
152 * @return boolean value.
153 */
154 public boolean getUseCriterion4() {
155 return this.useCriterion4;
156 }
157
158
159 /**
160 * Set useCriterion3.
161 * @param c boolean value to set.
162 */
163 public void setUseCriterion3(boolean c) {
164 this.useCriterion3 = c;
165 }
166
167
168 /**
169 * Get useCriterion3.
170 * @return boolean value.
171 */
172 public boolean getUseCriterion3() {
173 return this.useCriterion3;
174 }
175
176 }