@@ -2,58 +2,56 @@ import DataCharacter from '../../rss/DataCharacter';
22import FinderPattern from '../../rss/FinderPattern' ;
33
44export default class ExpandedPair {
5- private readonly maybeLast : boolean ;
6- private readonly leftchar : DataCharacter ;
7- private readonly rightchar : DataCharacter ;
8- private readonly finderpattern : FinderPattern ;
5+ private readonly leftChar : DataCharacter | null ;
6+ private readonly rightChar : DataCharacter | null ;
7+ private readonly finderPattern : FinderPattern | null ;
98
10- constructor ( leftChar : DataCharacter , rightChar : DataCharacter , finderPatter : FinderPattern , mayBeLast : boolean ) {
11- this . leftchar = leftChar ;
12- this . rightchar = rightChar ;
13- this . finderpattern = finderPatter ;
14- this . maybeLast = mayBeLast ;
9+ constructor (
10+ leftChar : DataCharacter | null ,
11+ rightChar : DataCharacter | null ,
12+ finderPatter : FinderPattern | null ,
13+ ) {
14+ this . leftChar = leftChar ;
15+ this . rightChar = rightChar ;
16+ this . finderPattern = finderPatter ;
1517 }
1618
17- mayBeLast ( ) : boolean {
18- return this . maybeLast ;
19+ getLeftChar ( ) : DataCharacter | null {
20+ return this . leftChar ;
1921 }
20- getLeftChar ( ) : DataCharacter {
21- return this . leftchar ;
22- }
23- getRightChar ( ) : DataCharacter {
24- return this . rightchar ;
22+
23+ getRightChar ( ) : DataCharacter | null {
24+ return this . rightChar ;
2525 }
26- getFinderPattern ( ) : FinderPattern {
27- return this . finderpattern ;
26+
27+ getFinderPattern ( ) : FinderPattern | null {
28+ return this . finderPattern ;
2829 }
29- mustBeLast ( ) {
30- return this . rightchar == null ;
30+
31+ mustBeLast ( ) : boolean {
32+ return this . rightChar === null ;
3133 }
34+
3235 toString ( ) : String {
33- return '[ ' + this . leftchar + ', ' + this . rightchar + ' : ' + ( this . finderpattern == null ? 'null' : this . finderpattern . getValue ( ) ) + ' ]' ;
36+ return '[ ' + this . leftChar + ', ' + this . rightChar + ' : ' + ( this . finderPattern === null ? 'null' : this . finderPattern . getValue ( ) ) + ' ]' ;
3437 }
3538
36- static equals ( o1 : any , o2 : any ) : boolean {
37- if ( ! ( o1 instanceof ExpandedPair ) ) {
39+ static equals ( o1 : ExpandedPair | null , o2 : any ) : boolean {
40+ if ( o2 === null ) return o1 === null ;
41+ if ( ! ( o2 instanceof ExpandedPair ) ) {
3842 return false ;
3943 }
40- return ExpandedPair . equalsOrNull ( o1 . leftchar , o2 . leftchar ) &&
41- ExpandedPair . equalsOrNull ( o1 . rightchar , o2 . rightchar ) &&
42- ExpandedPair . equalsOrNull ( o1 . finderpattern , o2 . finderpattern ) ;
44+ return ( o1 . leftChar === null ? o2 . leftChar === null : o1 . leftChar . equals ( o2 . leftChar ) ) &&
45+ ( o1 . rightChar === null ? o2 . rightChar === null : o1 . rightChar . equals ( o2 . rightChar ) ) &&
46+ ( o1 . finderPattern === null ? o2 . finderPattern === null : o1 . finderPattern . equals ( o2 . finderPattern ) ) ;
4347 }
4448
45- private static equalsOrNull ( o1 : any , o2 : any ) : boolean {
46- return o1 === null ? o2 === null : ExpandedPair . equals ( o1 , o2 ) ;
49+ hashCode ( ) : number {
50+ return ExpandedPair . hashNotNull ( this . leftChar ) ^ ExpandedPair . hashNotNull ( this . rightChar ) ^ ExpandedPair . hashNotNull ( this . finderPattern ) ;
4751 }
4852
49- hashCode ( ) : any {
50- // return ExpandedPair.hashNotNull(leftChar) ^ hashNotNull(rightChar) ^ hashNotNull(finderPattern);
51- let value = this . leftchar . getValue ( ) ^ this . rightchar . getValue ( ) ^ this . finderpattern . getValue ( ) ;
52- return value ;
53+ private static hashNotNull ( o : { hashCode ( ) : number } ) : number {
54+ return o === null ? 0 : o . hashCode ( ) ;
5355 }
54- // To do - Re check the implementation
55- // private static hashNotNull(o: ExpandedPair): number {
56- // return o === null ? 0 : o.hashCode();
57- // }
5856}
5957
0 commit comments