// // JSRunEvent.m // JSRun Import Framework // // Created by Jonathan on 8/29/06. // Copyright 2006 Jonathan Saggau. All rights reserved. // NSPredicate * makePredicate(NSString * attributeName, NSString * attributeValue) { return [NSPredicate predicateWithFormat:@"%K like %@", attributeName, attributeValue]; } #import "JSRunEvent.h" @implementation JSRunEvent - (id)init { self = [self initWithType:nil durations:[[[NSMutableArray alloc] init] autorelease] distances:[[[NSMutableArray alloc] init] autorelease]]; return self; } - (id)initWithType:(NSString *) aType durations:(NSMutableArray *) dur distances:(NSMutableArray *) dist; { self = [super init]; if (self != nil) { [aType retain]; type = aType; [dur retain]; durations = dur; [dist retain]; distances = dist; } return self; } #pragma mark - #pragma mark accessors //=========================================================== // type //=========================================================== - (NSString *)type { return type; } - (void)setType:(NSString *)aType { if (type != aType) { [aType retain]; [type release]; type = aType; } } //=========================================================== // durations //=========================================================== - (NSMutableArray *)durations { return durations; } - (void)setDurations:(NSMutableArray *)aDurations { if (durations != aDurations) { [aDurations retain]; [durations release]; durations = aDurations; } } - (void)addDuration:(NSNumber *)aDuration { //NSLog(@"addDuration == %@", aDuration); [[self durations] addObject:aDuration]; } - (void)removeDuration:(NSNumber *)aDuration { [[self durations] removeObject:aDuration]; } //=========================================================== // distances //=========================================================== - (NSMutableArray *)distances { return distances; } - (void)setDistances:(NSMutableArray *)aDistances { if (distances != aDistances) { [aDistances retain]; [distances release]; distances = aDistances; } } - (void)addDistance:(NSNumber *)aDistance { //NSLog(@"addDistance == %@", aDistance); [[self distances] addObject:aDistance]; } - (void)removeDistance:(NSNumber *)aDistance { [[self distances] removeObject:aDistance]; } //=========================================================== // dealloc //=========================================================== - (void)dealloc { [self setType:nil]; [self setDurations:nil]; [self setDistances:nil]; [super dealloc]; } #pragma mark - #pragma mark pretty discription method - (NSString *)description { NSMutableString *desc = [NSMutableString stringWithFormat:@"Simple Description = %@ \n", [super description]]; [desc appendFormat:@"type = %@ \n", [self type]]; [desc appendFormat:@"durations = %@ \n", [self durations]]; [desc appendFormat:@"distances = %@ \n", [self distances]]; return desc; } #pragma mark - #pragma mark NSPredicates to filter RunEvent collections // AUTORELEASED + (NSPredicate *)split; { return makePredicate(@"type", @"*Split"); } + (NSPredicate *)kmSplit; { return makePredicate(@"type", @"kmSplit"); } + (NSPredicate *)miSplit; { return makePredicate(@"type", @"mileSplit"); } + (NSPredicate *)pause; { return makePredicate(@"type", @"pause"); } + (NSPredicate *)reportToUser; { return makePredicate(@"type", @"onDemandVP"); } + (NSPredicate *)powerSong; { return makePredicate(@"type", @"powerSong"); } @end