Skip to content

Commit

Permalink
broke circular dependency AbstractExpandedDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
odahcam committed Mar 3, 2020
1 parent 9e15787 commit 343c72f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/core/oned/rss/expanded/RSSExpandedReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AbstractRSSReader from '../../rss/AbstractRSSReader';
import DataCharacter from '../../rss/DataCharacter';
import FinderPattern from '../../rss/FinderPattern';
import RSSUtils from '../../rss/RSSUtils';
import AbstractExpandedDecoder from '../expanded/decoders/AbstractExpandedDecoder';
import { createDecoder } from './decoders/AbstractExpandedDecoderComplement';
import ExpandedPair from './ExpandedPair';
import ExpandedRow from './ExpandedRow';
import BitArrayBuilder from './BitArrayBuilder';
Expand Down Expand Up @@ -359,7 +359,7 @@ export default class RSSExpandedReader extends AbstractRSSReader {
static constructResult(pairs:Array<ExpandedPair>){
let binary = BitArrayBuilder.buildBitArray(pairs);

let decoder = AbstractExpandedDecoder.createDecoder(binary);
let decoder = createDecoder(binary);
let resultingString = decoder.parseInformation();

let firstPoints = pairs[0].getFinderPattern().getResultPoints();
Expand Down
68 changes: 9 additions & 59 deletions src/core/oned/rss/expanded/decoders/AbstractExpandedDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,25 @@
import FormatException from '../../../../FormatException';
import NotFoundException from '../../../../NotFoundException';
import IllegalStateException from '../../../../IllegalStateException';
import BitArray from '../../../../common/BitArray';
import GeneralAppIdDecoder from './GeneralAppIdDecoder';
import AI01AndOtherAIs from './AI01AndOtherAIs';
import AnyAIDecoder from './AnyAIDecoder';
import AI013103decoder from './AI013103decoder';
import AI01320xDecoder from './AI01320xDecoder';
import AI01392xDecoder from './AI01392xDecoder';
import AI01393xDecoder from './AI01393xDecoder';
import AI013x0x1xDecoder from './AI013x0x1xDecoder';

export default abstract class AbstractExpandedDecoder{
export default abstract class AbstractExpandedDecoder {

private readonly information: BitArray;
private readonly generalDecoder: GeneralAppIdDecoder;

constructor(information:BitArray) {
constructor(information: BitArray) {
this.information = information;
this.generalDecoder = new GeneralAppIdDecoder(information)
this.generalDecoder = new GeneralAppIdDecoder(information);
}

protected getInformation():BitArray{
protected getInformation(): BitArray {
return this.information;
}

protected getGeneralDecoder():GeneralAppIdDecoder {
protected getGeneralDecoder(): GeneralAppIdDecoder {
return this.generalDecoder;
}

public abstract parseInformation(): string

public static createDecoder(information: BitArray): AbstractExpandedDecoder {
try {
if (information.get(1)) {
return new AI01AndOtherAIs(information);

}
if (!information.get(2)) {
return new AnyAIDecoder(information);
}

let fourBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 4);

switch (fourBitEncodationMethod) {
case 4: return new AI013103decoder(information);
case 5: return new AI01320xDecoder(information);
}

let fiveBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 5);
switch (fiveBitEncodationMethod) {
case 12: return new AI01392xDecoder(information);
case 13: return new AI01393xDecoder(information);
}

let sevenBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 7);
switch (sevenBitEncodationMethod) {
case 56: return new AI013x0x1xDecoder(information, "310", "11");
case 57: return new AI013x0x1xDecoder(information, "320", "11");
case 58: return new AI013x0x1xDecoder(information, "310", "13");
case 59: return new AI013x0x1xDecoder(information, "320", "13");
case 60: return new AI013x0x1xDecoder(information, "310", "15");
case 61: return new AI013x0x1xDecoder(information, "320", "15");
case 62: return new AI013x0x1xDecoder(information, "310", "17");
case 63: return new AI013x0x1xDecoder(information, "320", "17");
}
} catch (e) {
console.log(e);
throw new IllegalStateException("unknown decoder: " + information);
}


}
public abstract parseInformation(): string;

}
// createDecoder moved to own file due to circular dependency
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import IllegalStateException from '../../../../IllegalStateException';
import BitArray from '../../../../common/BitArray';
import GeneralAppIdDecoder from './GeneralAppIdDecoder';
import AI01AndOtherAIs from './AI01AndOtherAIs';
import AnyAIDecoder from './AnyAIDecoder';
import AI013103decoder from './AI013103decoder';
import AI01320xDecoder from './AI01320xDecoder';
import AI01392xDecoder from './AI01392xDecoder';
import AI01393xDecoder from './AI01393xDecoder';
import AI013x0x1xDecoder from './AI013x0x1xDecoder';
import AbstractExpandedDecoder from './AbstractExpandedDecoder';


export function createDecoder(information: BitArray): AbstractExpandedDecoder {
try {
if (information.get(1)) {
return new AI01AndOtherAIs(information);

}
if (!information.get(2)) {
return new AnyAIDecoder(information);
}

let fourBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 4);

switch (fourBitEncodationMethod) {
case 4: return new AI013103decoder(information);
case 5: return new AI01320xDecoder(information);
}

let fiveBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 5);
switch (fiveBitEncodationMethod) {
case 12: return new AI01392xDecoder(information);
case 13: return new AI01393xDecoder(information);
}

let sevenBitEncodationMethod = GeneralAppIdDecoder.extractNumericValueFromBitArray(information, 1, 7);
switch (sevenBitEncodationMethod) {
case 56: return new AI013x0x1xDecoder(information, '310', '11');
case 57: return new AI013x0x1xDecoder(information, '320', '11');
case 58: return new AI013x0x1xDecoder(information, '310', '13');
case 59: return new AI013x0x1xDecoder(information, '320', '13');
case 60: return new AI013x0x1xDecoder(information, '310', '15');
case 61: return new AI013x0x1xDecoder(information, '320', '15');
case 62: return new AI013x0x1xDecoder(information, '310', '17');
case 63: return new AI013x0x1xDecoder(information, '320', '17');
}
} catch (e) {
console.log(e);
throw new IllegalStateException('unknown decoder: ' + information);
}


}
11 changes: 7 additions & 4 deletions src/core/oned/rss/expanded/decoders/AnyAIDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import BitArray from '../../../../common/BitArray';
import StringBuilder from '../../../../util/StringBuilder';
import AbstractExpandedDecoder from './AbstractExpandedDecoder';


export default class AnyAIDecoder extends AbstractExpandedDecoder {

private static readonly HEADER_SIZE:number = 2 + 1 + 2;
constructor(information:BitArray) {
private static readonly HEADER_SIZE: number = 2 + 1 + 2;

constructor(information: BitArray) {
super(information);
}

public parseInformation():string {
public parseInformation(): string {
let buf = new StringBuilder();
return this.getGeneralDecoder().decodeAllCodes(buf, AnyAIDecoder.HEADER_SIZE);
}
}
}

0 comments on commit 343c72f

Please sign in to comment.