mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
remove spacing from head of polynomial string (#1032)
This commit is contained in:
parent
fc057169cd
commit
15b09aeda5
|
@ -225,15 +225,19 @@ final class GenericGFPoly {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (getDegree() == 0) {
|
if (isZero()) {
|
||||||
return Integer.toString(getCoefficient(0));
|
return "0";
|
||||||
}
|
}
|
||||||
StringBuilder result = new StringBuilder(8 * getDegree());
|
StringBuilder result = new StringBuilder(8 * getDegree());
|
||||||
for (int degree = getDegree(); degree >= 0; degree--) {
|
for (int degree = getDegree(); degree >= 0; degree--) {
|
||||||
int coefficient = getCoefficient(degree);
|
int coefficient = getCoefficient(degree);
|
||||||
if (coefficient != 0) {
|
if (coefficient != 0) {
|
||||||
if (coefficient < 0) {
|
if (coefficient < 0) {
|
||||||
|
if (degree == getDegree()) {
|
||||||
|
result.append("-");
|
||||||
|
} else {
|
||||||
result.append(" - ");
|
result.append(" - ");
|
||||||
|
}
|
||||||
coefficient = -coefficient;
|
coefficient = -coefficient;
|
||||||
} else {
|
} else {
|
||||||
if (result.length() > 0) {
|
if (result.length() > 0) {
|
||||||
|
|
|
@ -32,6 +32,8 @@ public final class GenericGFPolyTestCase extends Assert {
|
||||||
assertEquals("-1", FIELD.buildMonomial(0, -1).toString());
|
assertEquals("-1", FIELD.buildMonomial(0, -1).toString());
|
||||||
GenericGFPoly p = new GenericGFPoly(FIELD, new int[] {3, 0, -2, 1, 1});
|
GenericGFPoly p = new GenericGFPoly(FIELD, new int[] {3, 0, -2, 1, 1});
|
||||||
assertEquals("a^25x^4 - ax^2 + x + 1", p.toString());
|
assertEquals("a^25x^4 - ax^2 + x + 1", p.toString());
|
||||||
|
p = new GenericGFPoly(FIELD, new int[] {3});
|
||||||
|
assertEquals("a^25", p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue