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.

ZXRSSExpandedPair.m 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "ZXRSSDataCharacter.h"
  17. #import "ZXRSSExpandedPair.h"
  18. #import "ZXRSSFinderPattern.h"
  19. @implementation ZXRSSExpandedPair
  20. - (id)initWithLeftChar:(ZXRSSDataCharacter *)leftChar rightChar:(ZXRSSDataCharacter *)rightChar
  21. finderPattern:(ZXRSSFinderPattern *)finderPattern mayBeLast:(BOOL)mayBeLast {
  22. if (self = [super init]) {
  23. _leftChar = leftChar;
  24. _rightChar = rightChar;
  25. _finderPattern = finderPattern;
  26. _mayBeLast = mayBeLast;
  27. }
  28. return self;
  29. }
  30. - (BOOL)mustBeLast {
  31. return self.rightChar == nil;
  32. }
  33. - (NSString *)description {
  34. return [NSString stringWithFormat:@"[ %@, %@ : %@ ]",
  35. self.leftChar, self.rightChar,
  36. self.finderPattern == nil ? @"null" : [NSString stringWithFormat:@"%d", self.finderPattern.value]];
  37. }
  38. - (BOOL)isEqual:(id)object {
  39. if (![object isKindOfClass:[ZXRSSExpandedPair class]]) {
  40. return NO;
  41. }
  42. ZXRSSExpandedPair *that = (ZXRSSExpandedPair *)object;
  43. return [ZXRSSExpandedPair isEqualOrNil:self.leftChar toObject:that.leftChar] &&
  44. [ZXRSSExpandedPair isEqualOrNil:self.rightChar toObject:that.rightChar] &&
  45. [ZXRSSExpandedPair isEqualOrNil:self.finderPattern toObject:that.finderPattern];
  46. }
  47. + (BOOL)isEqualOrNil:(id)o1 toObject:(id)o2 {
  48. return o1 == nil ? o2 == nil : [o1 isEqual:o2];
  49. }
  50. - (NSUInteger)hash {
  51. return [self hashNotNil:self.leftChar] ^ [self hashNotNil:self.rightChar] ^ [self hashNotNil:self.finderPattern];
  52. }
  53. - (NSUInteger)hashNotNil:(NSObject *)o {
  54. return o == nil ? 0 : o.hash;
  55. }
  56. @end