Skip to content

Commit

Permalink
Port current version of RSSExpandedReader
Browse files Browse the repository at this point in the history
Based on zxing commit 2dfb2054af1e1872ac5354e6d8218931fb88e021.
  • Loading branch information
opl- committed Nov 25, 2024
1 parent 0e68da8 commit 08500d5
Show file tree
Hide file tree
Showing 29 changed files with 580 additions and 576 deletions.
4 changes: 3 additions & 1 deletion src/core/oned/rss/FinderPattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import ResultPoint from '../../ResultPoint';

export default class FinderPattern {

private value: number;
private startEnd: number[];
private resultPoints: Array<ResultPoint>;

public constructor(private value: number, private startEnd: number[], start: number, end: number, rowNumber: number) {
public constructor(value: number, startEnd: number[], start: number, end: number, rowNumber: number) {
this.value = value;
this.startEnd = startEnd;
this.resultPoints = new Array<ResultPoint>();
Expand Down
8 changes: 4 additions & 4 deletions src/core/oned/rss/expanded/BitArrayBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ExpandedPair from './ExpandedPair';
export default class BitArrayBuilder {
static buildBitArray(pairs: Array<ExpandedPair>): BitArray {
let charNumber: number = pairs.length * 2 - 1;
if (pairs[pairs.length - 1].getRightChar() == null) {
if (pairs[pairs.length - 1].getRightChar() === null) {
charNumber -= 1;
}

Expand All @@ -23,9 +23,9 @@ export default class BitArrayBuilder {
}

for (let i = 1; i < pairs.length; ++i) {
let currentPair: ExpandedPair = pairs[i];
const currentPair: ExpandedPair = pairs[i];

let leftValue = currentPair.getLeftChar().getValue();
const leftValue = currentPair.getLeftChar().getValue();
for (let j = 11; j >= 0; --j) {
if ((leftValue & (1 << j)) !== 0) {
binary.set(accPos);
Expand All @@ -34,7 +34,7 @@ export default class BitArrayBuilder {
}

if (currentPair.getRightChar() !== null) {
let rightValue = currentPair.getRightChar().getValue();
const rightValue = currentPair.getRightChar().getValue();
for (let j = 11; j >= 0; --j) {
if ((rightValue & (1 << j)) !== 0) {
binary.set(accPos);
Expand Down
70 changes: 34 additions & 36 deletions src/core/oned/rss/expanded/ExpandedPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,56 @@ import DataCharacter from '../../rss/DataCharacter';
import FinderPattern from '../../rss/FinderPattern';

export default class ExpandedPair {
private readonly maybeLast: boolean;
private readonly leftchar: DataCharacter;
private readonly rightchar: DataCharacter;
private readonly finderpattern: FinderPattern;
private readonly leftChar: DataCharacter | null;
private readonly rightChar: DataCharacter | null;
private readonly finderPattern: FinderPattern | null;

constructor(leftChar: DataCharacter, rightChar: DataCharacter, finderPatter: FinderPattern, mayBeLast: boolean) {
this.leftchar = leftChar;
this.rightchar = rightChar;
this.finderpattern = finderPatter;
this.maybeLast = mayBeLast;
constructor(
leftChar: DataCharacter | null,
rightChar: DataCharacter | null,
finderPatter: FinderPattern | null,
) {
this.leftChar = leftChar;
this.rightChar = rightChar;
this.finderPattern = finderPatter;
}

mayBeLast(): boolean {
return this.maybeLast;
getLeftChar(): DataCharacter | null {
return this.leftChar;
}
getLeftChar(): DataCharacter {
return this.leftchar;
}
getRightChar(): DataCharacter {
return this.rightchar;

getRightChar(): DataCharacter | null {
return this.rightChar;
}
getFinderPattern(): FinderPattern {
return this.finderpattern;

getFinderPattern(): FinderPattern | null {
return this.finderPattern;
}
mustBeLast() {
return this.rightchar == null;

mustBeLast(): boolean {
return this.rightChar === null;
}

toString(): String {
return '[ ' + this.leftchar + ', ' + this.rightchar + ' : ' + (this.finderpattern == null ? 'null' : this.finderpattern.getValue()) + ' ]';
return '[ ' + this.leftChar + ', ' + this.rightChar + ' : ' + (this.finderPattern === null ? 'null' : this.finderPattern.getValue()) + ' ]';
}

static equals(o1: any, o2: any): boolean {
if (!(o1 instanceof ExpandedPair)) {
static equals(o1: ExpandedPair | null, o2: any): boolean {
if (o2 === null) return o1 === null;
if (!(o2 instanceof ExpandedPair)) {
return false;
}
return ExpandedPair.equalsOrNull(o1.leftchar, o2.leftchar) &&
ExpandedPair.equalsOrNull(o1.rightchar, o2.rightchar) &&
ExpandedPair.equalsOrNull(o1.finderpattern, o2.finderpattern);
return (o1.leftChar === null ? o2.leftChar === null : o1.leftChar.equals(o2.leftChar)) &&
(o1.rightChar === null ? o2.rightChar === null : o1.rightChar.equals(o2.rightChar)) &&
(o1.finderPattern === null ? o2.finderPattern === null : o1.finderPattern.equals(o2.finderPattern));
}

private static equalsOrNull(o1: any, o2: any): boolean {
return o1 === null ? o2 === null : ExpandedPair.equals(o1, o2);
hashCode(): number {
return ExpandedPair.hashNotNull(this.leftChar) ^ ExpandedPair.hashNotNull(this.rightChar) ^ ExpandedPair.hashNotNull(this.finderPattern);
}

hashCode(): any {
// return ExpandedPair.hashNotNull(leftChar) ^ hashNotNull(rightChar) ^ hashNotNull(finderPattern);
let value = this.leftchar.getValue() ^ this.rightchar.getValue() ^ this.finderpattern.getValue();
return value;
private static hashNotNull(o: { hashCode(): number }): number {
return o === null ? 0 : o.hashCode();
}
// To do - Re check the implementation
// private static hashNotNull(o: ExpandedPair): number {
// return o === null ? 0 : o.hashCode();
// }
}

46 changes: 13 additions & 33 deletions src/core/oned/rss/expanded/ExpandedRow.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import ExpandedPair from './ExpandedPair';


export default class ExpandedRow {
private readonly pairs: Array<ExpandedPair>;
private readonly rowNumber: number;
private readonly wasReversed: boolean;

constructor(pairs: Array<ExpandedPair>, rowNumber: number, wasReversed: boolean) {
constructor(pairs: Array<ExpandedPair>, rowNumber: number) {
this.pairs = pairs;
this.rowNumber = rowNumber;
this.wasReversed = wasReversed;
}

getPairs(): Array<ExpandedPair> {
Expand All @@ -20,15 +17,9 @@ export default class ExpandedRow {
return this.rowNumber;
}

isReversed(): boolean {
return this.wasReversed;
}
// check implementation

isEquivalent(otherPairs: Array<ExpandedPair>): boolean {
return this.checkEqualitity(this, otherPairs);
return ExpandedRow.listEquals(this.getPairs(), otherPairs);
}
// @Override

public toString(): String {
return '{ ' + this.pairs + ' }';
Expand All @@ -38,31 +29,20 @@ export default class ExpandedRow {
* Two rows are equal if they contain the same pairs in the same order.
*/
// @Override
// check implementation
public equals(o1: ExpandedRow, o2: ExpandedRow): boolean {
if (!(o1 instanceof ExpandedRow)) {
public static equals(o1: ExpandedRow | null, o2: any): boolean {
if (o1 === null) return o2 === null;
if (!(o2 instanceof ExpandedRow)) {
return false;
}
return this.checkEqualitity(o1, o2) && o1.wasReversed === o2.wasReversed;
return ExpandedRow.listEquals(o1.pairs, o2.getPairs());
}
checkEqualitity(pair1: any, pair2: any): boolean {
if (!pair1 || !pair2) return;
let result;
pair1.forEach((e1, i) => {
pair2.forEach(e2 => {
if (e1.getLeftChar().getValue() === e2.getLeftChar().getValue() && e1.getRightChar().getValue() === e2.getRightChar().getValue() && e1.getFinderPatter().getValue() === e2.getFinderPatter().getValue()) {
result = true;
}
});

static listEquals(pairs1: Array<ExpandedPair>, pairs2: Array<ExpandedPair>): boolean {
if (!pairs1 || !pairs2) return false;
if (pairs1.length !== pairs2.length) return false;
return pairs1.every((pair1, index) => {
const pair2 = pairs2[index];
return ExpandedPair.equals(pair1, pair2);
});
return result;
}

// @Override
// check implementation
// public int hashCode(): number {
// let hash = this.pairs.values ^ this.wasReversed
// //return pairs.hashCode() ^ Boolean.valueOf(wasReversed).hashCode();
// }

}
Loading

0 comments on commit 08500d5

Please sign in to comment.