LRUCacheNode.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * See the NOTICE file distributed with this work for additional
  5. * information regarding copyright ownership.
  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 "LRUCacheNode.h"
  17. @interface LRUCacheNode ()
  18. @property (nonatomic, readwrite) id value;
  19. @property (nonatomic, readwrite) id<NSCopying> key;
  20. - (instancetype)initWithValue:(id)value key:(id<NSCopying>)key;
  21. @end
  22. @implementation LRUCacheNode
  23. - (instancetype)initWithValue:(id)value key:(id<NSCopying>)key
  24. {
  25. if (nil == value) {
  26. return nil;
  27. }
  28. if ((self = [super init])) {
  29. _value = value;
  30. _key = key;
  31. }
  32. return self;
  33. }
  34. + (instancetype)nodeWithValue:(id)value key:(id<NSCopying>)key
  35. {
  36. return [[LRUCacheNode alloc] initWithValue:value key:key];
  37. }
  38. - (NSString *)description
  39. {
  40. return [NSString stringWithFormat:@"%@ %@", self.value, self.next];
  41. }
  42. @end