You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZXExpandedProductParsedResult.m 5.0KB

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