
#import "TestObject.h"

@implementation TestObject

+ objectWithString:(NSString *)string
{
	return [[[self alloc] initWithString:string] autorelease];
}

- initWithString:(NSString *)string
{	
	NSCharacterSet *semicolonSet;
	NSScanner *scanner;
	int number;

	[super init];
	scanner = [NSScanner scannerWithString:string];
	semicolonSet = [NSCharacterSet characterSetWithCharactersInString:@";"];
	if([scanner scanInt:&number])
		theNumber = [[NSNumber numberWithInt:number] retain];
	else
		theNumber = [[NSNumber numberWithInt:0] retain];
	if(![scanner scanUpToCharactersFromSet:semicolonSet intoString:&theString])
		theString = [[NSString stringWithCString:"default"] retain];
        else
            	[theString retain];
	return self;
}

- (void)dealloc
{
	[theNumber release];
	[theString release];
	return [super dealloc];
}

- (NSString *)description
{
	return [NSString stringWithFormat:@"%@-%@", [theNumber description], [theString description]];
}

- (NSComparisonResult)compare:(TestObject *)otherObject
{
	if(!otherObject)
		return NSOrderedDescending;
	return [(NSNumber *)theNumber compare:otherObject->theNumber];
}	


@end