您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ZXPDF417BarcodeValue.m 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2013 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 "ZXPDF417BarcodeValue.h"
  17. #import "ZXPDF417Common.h"
  18. @interface ZXPDF417BarcodeValue ()
  19. @property (nonatomic, strong, readonly) NSMutableDictionary *values;
  20. @end
  21. @implementation ZXPDF417BarcodeValue
  22. - (id)init {
  23. self = [super init];
  24. if (self) {
  25. _values = [NSMutableDictionary dictionary];
  26. }
  27. return self;
  28. }
  29. - (void)setValue:(int)value {
  30. NSNumber *confidence = self.values[@(value)];
  31. if (!confidence) {
  32. confidence = @0;
  33. }
  34. confidence = @([confidence intValue] + 1);
  35. self.values[@(value)] = confidence;
  36. }
  37. - (ZXIntArray *)value {
  38. int maxConfidence = -1;
  39. NSMutableArray *result = [NSMutableArray array];
  40. for (NSNumber *key in [self.values allKeys]) {
  41. NSNumber *value = self.values[key];
  42. if ([value intValue] > maxConfidence) {
  43. maxConfidence = [value intValue];
  44. [result removeAllObjects];
  45. [result addObject:key];
  46. } else if ([value intValue] == maxConfidence) {
  47. [result addObject:key];
  48. }
  49. }
  50. NSArray *array = [[[result sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];
  51. return [ZXPDF417Common toIntArray:array];
  52. }
  53. - (NSNumber *)confidence:(int)value {
  54. return self.values[@(value)];
  55. }
  56. @end