JLChen
2021-11-04 d3713a9e02760ac9f5c0551ca72be0bdda3ba91c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * Copyright 2012 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#import "ZXExpandedProductParsedResult.h"
 
NSString * const ZX_KILOGRAM = @"KG";
NSString * const ZX_POUND = @"LB";
 
@implementation ZXExpandedProductParsedResult
 
- (id)init {
  return [self initWithRawText:@"" productID:@"" sscc:@"" lotNumber:@"" productionDate:@"" packagingDate:@""
                bestBeforeDate:@"" expirationDate:@"" weight:@"" weightType:@"" weightIncrement:@"" price:@""
                priceIncrement:@"" priceCurrency:@"" uncommonAIs:[NSMutableDictionary dictionary]];
}
 
- (id)initWithRawText:(NSString *)rawText productID:(NSString *)productID sscc:(NSString *)sscc
            lotNumber:(NSString *)lotNumber productionDate:(NSString *)productionDate
        packagingDate:(NSString *)packagingDate bestBeforeDate:(NSString *)bestBeforeDate
       expirationDate:(NSString *)expirationDate weight:(NSString *)weight weightType:(NSString *)weightType
      weightIncrement:(NSString *)weightIncrement price:(NSString *)price priceIncrement:(NSString *)priceIncrement
        priceCurrency:(NSString *)priceCurrency uncommonAIs:(NSMutableDictionary *)uncommonAIs {
  if (self = [super initWithType:kParsedResultTypeProduct]) {
    _rawText = rawText;
    _productID = productID;
    _sscc = sscc;
    _lotNumber = lotNumber;
    _productionDate = productionDate;
    _packagingDate = packagingDate;
    _bestBeforeDate = bestBeforeDate;
    _expirationDate = expirationDate;
    _weight = weight;
    _weightType = weightType;
    _weightIncrement = weightIncrement;
    _price = price;
    _priceIncrement = priceIncrement;
    _priceCurrency = priceCurrency;
    _uncommonAIs = uncommonAIs;
  }
 
  return self;
}
 
+ (id)expandedProductParsedResultWithRawText:(NSString *)rawText productID:(NSString *)productID sscc:(NSString *)sscc
                                   lotNumber:(NSString *)lotNumber productionDate:(NSString *)productionDate
                               packagingDate:(NSString *)packagingDate bestBeforeDate:(NSString *)bestBeforeDate
                              expirationDate:(NSString *)expirationDate weight:(NSString *)weight
                                  weightType:(NSString *)weightType weightIncrement:(NSString *)weightIncrement
                                       price:(NSString *)price priceIncrement:(NSString *)priceIncrement
                               priceCurrency:(NSString *)priceCurrency uncommonAIs:(NSMutableDictionary *)uncommonAIs {
  return [[self alloc] initWithRawText:rawText productID:productID sscc:sscc lotNumber:lotNumber
                        productionDate:productionDate packagingDate:packagingDate bestBeforeDate:bestBeforeDate
                        expirationDate:expirationDate weight:weight weightType:weightType
                       weightIncrement:weightIncrement price:price priceIncrement:priceIncrement
                         priceCurrency:priceCurrency uncommonAIs:uncommonAIs];
}
 
- (BOOL)isEqual:(id)o {
  if (![o isKindOfClass:[self class]]) {
    return NO;
  }
 
  ZXExpandedProductParsedResult *other = (ZXExpandedProductParsedResult *)o;
 
  return [self equalsOrNil:self.productID o2:other.productID]
    && [self equalsOrNil:self.sscc o2:other.sscc]
    && [self equalsOrNil:self.lotNumber o2:other.lotNumber]
    && [self equalsOrNil:self.productionDate o2:other.productionDate]
    && [self equalsOrNil:self.bestBeforeDate o2:other.bestBeforeDate]
    && [self equalsOrNil:self.expirationDate o2:other.expirationDate]
    && [self equalsOrNil:self.weight o2:other.weight]
    && [self equalsOrNil:self.weightType o2:other.weightType]
    && [self equalsOrNil:self.weightIncrement o2:other.weightIncrement]
    && [self equalsOrNil:self.price o2:other.price]
    && [self equalsOrNil:self.priceIncrement o2:other.priceIncrement]
    && [self equalsOrNil:self.priceCurrency o2:other.priceCurrency]
    && [self equalsOrNil:self.uncommonAIs o2:other.uncommonAIs];
}
 
- (BOOL)equalsOrNil:(id)o1 o2:(id)o2 {
  return o1 == nil ? o2 == nil : [o1 isEqual:o2];
}
 
- (NSUInteger)hash {
  int hash = 0;
  hash ^= [self.productID hash];
  hash ^= [self.sscc hash];
  hash ^= [self.lotNumber hash];
  hash ^= [self.productionDate hash];
  hash ^= [self.bestBeforeDate hash];
  hash ^= [self.expirationDate hash];
  hash ^= [self.weight hash];
  hash ^= [self.weightType hash];
  hash ^= [self.weightIncrement hash];
  hash ^= [self.price hash];
  hash ^= [self.priceIncrement hash];
  hash ^= [self.priceCurrency hash];
  hash ^= [self.uncommonAIs hash];
  return hash;
}
 
- (NSString *)displayResult {
  return self.rawText;
}
 
@end