mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -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
|
||||
public String toString() {
|
||||
if (getDegree() == 0) {
|
||||
return Integer.toString(getCoefficient(0));
|
||||
if (isZero()) {
|
||||
return "0";
|
||||
}
|
||||
StringBuilder result = new StringBuilder(8 * getDegree());
|
||||
for (int degree = getDegree(); degree >= 0; degree--) {
|
||||
int coefficient = getCoefficient(degree);
|
||||
if (coefficient != 0) {
|
||||
if (coefficient < 0) {
|
||||
result.append(" - ");
|
||||
if (degree == getDegree()) {
|
||||
result.append("-");
|
||||
} else {
|
||||
result.append(" - ");
|
||||
}
|
||||
coefficient = -coefficient;
|
||||
} else {
|
||||
if (result.length() > 0) {
|
||||
|
|
|
@ -32,6 +32,8 @@ public final class GenericGFPolyTestCase extends Assert {
|
|||
assertEquals("-1", FIELD.buildMonomial(0, -1).toString());
|
||||
GenericGFPoly p = new GenericGFPoly(FIELD, new int[] {3, 0, -2, 1, 1});
|
||||
assertEquals("a^25x^4 - ax^2 + x + 1", p.toString());
|
||||
p = new GenericGFPoly(FIELD, new int[] {3});
|
||||
assertEquals("a^25", p.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue