148 lines
5.0 KiB
Objective-C
148 lines
5.0 KiB
Objective-C
/*
|
|
Copyright (c) 2015, Apple Inc. All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimer in the documentation and/or
|
|
other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
|
may be used to endorse or promote products derived from this software without
|
|
specific prior written permission. No license is granted to the trademarks of
|
|
the copyright holders even if such marks are included in this software.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
|
|
#import "ORKTappingIntervalResult.h"
|
|
|
|
#import "ORKResult_Private.h"
|
|
#import "ORKHelpers_Internal.h"
|
|
|
|
|
|
@implementation ORKTappingSample
|
|
|
|
+ (BOOL)supportsSecureCoding {
|
|
return YES;
|
|
}
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
|
ORK_ENCODE_DOUBLE(aCoder, timestamp);
|
|
ORK_ENCODE_DOUBLE(aCoder, duration);
|
|
ORK_ENCODE_CGPOINT(aCoder, location);
|
|
ORK_ENCODE_ENUM(aCoder, buttonIdentifier);
|
|
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
|
|
self = [super init];
|
|
if (self) {
|
|
ORK_DECODE_DOUBLE(aDecoder, duration);
|
|
ORK_DECODE_DOUBLE(aDecoder, timestamp);
|
|
ORK_DECODE_CGPOINT(aDecoder, location);
|
|
ORK_DECODE_ENUM(aDecoder, buttonIdentifier);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isEqual:(id)object {
|
|
if ([self class] != [object class]) {
|
|
return NO;
|
|
}
|
|
|
|
__typeof(self) castObject = object;
|
|
|
|
return ((self.timestamp == castObject.timestamp) &&
|
|
(self.duration == castObject.duration) &&
|
|
CGPointEqualToPoint(self.location, castObject.location) &&
|
|
(self.buttonIdentifier == castObject.buttonIdentifier));
|
|
}
|
|
|
|
- (instancetype)copyWithZone:(NSZone *)zone {
|
|
ORKTappingSample *sample = [[[self class] allocWithZone:zone] init];
|
|
sample.timestamp = self.timestamp;
|
|
sample.duration = self.duration;
|
|
sample.location = self.location;
|
|
sample.buttonIdentifier = self.buttonIdentifier;
|
|
return sample;
|
|
}
|
|
|
|
- (NSString *)description {
|
|
return [NSString stringWithFormat:@"<%@: %p; button: %@; timestamp: %.03f; timestamp: %.03f; location: %@>", self.class.description, self, @(self.buttonIdentifier), self.timestamp, self.duration, NSStringFromCGPoint(self.location)];
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation ORKTappingIntervalResult
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
|
[super encodeWithCoder:aCoder];
|
|
ORK_ENCODE_OBJ(aCoder, samples);
|
|
ORK_ENCODE_CGRECT(aCoder, buttonRect1);
|
|
ORK_ENCODE_CGRECT(aCoder, buttonRect2);
|
|
ORK_ENCODE_CGSIZE(aCoder, stepViewSize);
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
|
|
self = [super initWithCoder:aDecoder];
|
|
if (self) {
|
|
ORK_DECODE_OBJ_ARRAY(aDecoder, samples, ORKTappingSample);
|
|
ORK_DECODE_CGRECT(aDecoder, buttonRect1);
|
|
ORK_DECODE_CGRECT(aDecoder, buttonRect2);
|
|
ORK_DECODE_CGSIZE(aDecoder, stepViewSize);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
+ (BOOL)supportsSecureCoding {
|
|
return YES;
|
|
}
|
|
|
|
- (BOOL)isEqual:(id)object {
|
|
BOOL isParentSame = [super isEqual:object];
|
|
|
|
__typeof(self) castObject = object;
|
|
return (isParentSame &&
|
|
ORKEqualObjects(self.samples, castObject.samples) &&
|
|
CGRectEqualToRect(self.buttonRect1, castObject.buttonRect1) &&
|
|
CGRectEqualToRect(self.buttonRect2, castObject.buttonRect2) &&
|
|
CGSizeEqualToSize(self.stepViewSize, castObject.stepViewSize));
|
|
}
|
|
|
|
- (NSUInteger)hash {
|
|
return super.hash ^ self.samples.hash;
|
|
}
|
|
|
|
- (instancetype)copyWithZone:(NSZone *)zone {
|
|
ORKTappingIntervalResult *result = [super copyWithZone:zone];
|
|
result.samples = [self.samples copy];
|
|
result.buttonRect1 = self.buttonRect1;
|
|
result.buttonRect2 = self.buttonRect2;
|
|
result.stepViewSize = self.stepViewSize;
|
|
return result;
|
|
}
|
|
|
|
- (NSString *)descriptionWithNumberOfPaddingSpaces:(NSUInteger)numberOfPaddingSpaces {
|
|
return [NSString stringWithFormat:@"%@; samples: %@%@", [self descriptionPrefixWithNumberOfPaddingSpaces:numberOfPaddingSpaces], self.samples, self.descriptionSuffix];
|
|
}
|
|
|
|
@end
|
|
|
|
|