/***
 * Excerpted from "Domain-Driven Design Using Naked Objects",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/dhnako for more book information.
***/
package com.pragprog.dhnako.carserv.dom.vehicle;

import java.util.List;

import org.nakedobjects.applib.AbstractFactoryAndRepository;
import org.nakedobjects.applib.Filter;
import org.nakedobjects.applib.annotation.Exploration;
import org.nakedobjects.applib.annotation.Named;
import org.nakedobjects.applib.annotation.RegEx;

@Named("Cars")
public class CarRepository extends AbstractFactoryAndRepository {

	// {{ Identification
	public String iconName() {
		return "Car";
	}
	// }}


	// {{ FindByRegistrationNumber
	public Car findByRegistrationNumber(
	        @RegEx(validation="[A-Z0-9]+")
	        @Named("Registration Number")
	        final String registrationNumber) {
	    return firstMatch(Car.class, new Filter<Car>() {
	        public boolean accept(final Car car) {
	            return car.getRegistrationNumber().equals(registrationNumber);
	        }});
	}
	// }}
	
	
	// {{ all Cars
	@Exploration
	public List<Car> allCars() {
		return allInstances(Car.class);
	}
	// }}


}
