//
//  ElementProvider.m
//  NowPlayingSaver
//
//  Created by Juri Pakaste on 13.10.09.
//  Copyright (c) 2009, Juri Pakaste. All rights reserved.
//  For licensing details see the file COPYING.
//

#import "ElementProvider.h"


@implementation ElementProvider

@synthesize elements;

-(id)initWithElements:(NSArray *)elems
{
    if ((self = [super init]))
    {
        self.elements = elems;
    }
    return self;
}


-(id)element
{
    return [elements lastObject];
}

@end


#pragma mark -


@implementation RandomElementProvider

-(id)element
{
    NSInteger noe = self.elements.count;
    long rn = arc4random();
    NSInteger ai = rn % noe;
    id e = [self.elements objectAtIndex:ai];
    return e;
}

@end



#pragma mark -


@implementation SequentialElementProvider

-(id)initWithElements:(NSArray *)elems
{
    if ((self = [super initWithElements:elems]))
    {
        mIndex = 0;
    }
    return self;
}


-(id)element
{
    return [self.elements objectAtIndex:mIndex++ % self.elements.count];
}

@end
