5 // Created by mshio on 11/02/28.
6 // Copyright 2011 mshio. All rights reserved.
9 #import "HistoryRing.h"
12 @implementation HistoryRing
14 - (void) setArray: (NSMutableArray*) anArray {
18 + (HistoryRing*) instance {
19 static HistoryRing* _instance = nil;
21 _instance = [[HistoryRing alloc] init];
29 array = [[NSMutableArray alloc] initWithCapacity: 99];
30 pointer = [array count];
35 - (BOOL) append: (NSString*) item {
37 int count = [array count];
40 last = [array objectAtIndex: count - 1];
42 if (! last || (last && ! [last isEqualToString: item])) {
43 if (count >= 99) [array removeObjectAtIndex: 0];
44 [array addObject: item];
45 pointer = [array count];
51 - (NSString*) previous {
53 if (pointer - 1 >= 0) {
54 ret = [array objectAtIndex: --pointer];
61 NSUInteger max = [array count];
63 ret = [array objectAtIndex: pointer++];