/***************************************************************** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. ****************************************************************/ #import "CAYNodePropertyChangeOperation.h" #import "CAYNodeDiff.h" #import "CAYUtil.h" @implementation CAYNodePropertyChangeOperation -(id)initWithNodeId:(NSObject *)nid property:(NSString *)prop oldValue:(NSObject *)oldVal newValue:(NSObject *)newVal { [super initWithNodeId:nid]; [self setProperty:prop]; [self setOldValue:oldVal]; [self setNewValue:newVal]; return self; } -(id)initWithNodeId:(NSObject *)nid property:(NSString *)prop oldValue:(NSObject *)oldVal newValue:(NSObject *)newVal diffId:(NSInteger)did { [self initWithNodeId:nid property:prop oldValue:oldVal newValue:newVal]; diffId = did; return self; } -(id)initWithCoder:(NSCoder*)coder { [super initWithCoder:coder]; [self setProperty:[coder decodeObjectForKey:@"property"]]; [self setOldValue:[coder decodeObjectForKey:@"oldValue"]]; [self setNewValue:[coder decodeObjectForKey:@"newValue"]]; return self; } -(void)encodeWithCoder:(NSCoder*)coder { [super encodeWithCoder:coder]; [coder encodeObject:property forKey:@"property"]; [coder encodeObject:oldValue forKey:@"oldValue"]; [coder encodeObject:newValue forKey:@"newValue"]; } -(void)setProperty:(NSString *)p { [p retain]; [property release]; property = p; } -(NSString *)property { return property; } -(void)setOldValue:(NSObject *)o { [o retain]; [oldValue release]; oldValue = o; } -(NSObject *)oldValue { return oldValue; } -(void)setNewValue:(NSObject *)o { [o retain]; [newValue release]; newValue = o; } -(NSObject *)newValue { return newValue; } -(BOOL)isOpposite:(CAYNodeDiff *)diff { if(![diff isKindOfClass:[self class]]) { return NO; } if(![[diff nodeId] isEqualTo:[self nodeId]]) { return NO; } CAYNodePropertyChangeOperation *other = (CAYNodePropertyChangeOperation *)diff; return ([CAYUtil nilSafe:[other newValue] isEqualTo:[self oldValue]] && [CAYUtil nilSafe:[other oldValue] isEqualTo:[self newValue]]); } -(NSString *)description { NSString *result; result = [[NSString alloc] initWithFormat:@"CAYNodePropertyChangeOperation {nodeId = %@; property = %@; oldValue = %@; newValue = %@}", [self nodeId], [self property], [self oldValue], [self newValue]]; [result autorelease]; return result; } -(void)dealloc { [self setProperty:nil]; [self setOldValue:nil]; [self setNewValue:nil]; [super dealloc]; } @end