/***
 * 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.io.Serializable;

import org.nakedobjects.applib.annotation.MustSatisfy;
import org.nakedobjects.applib.annotation.RegEx;
import org.nakedobjects.applib.annotation.Value;

@Value(semanticsProviderClass=RegistrationNumberValueSemanticsProvider.class)
@RegEx(validation="[A-Z0-9]+")
@MustSatisfy(RegistrationNumberSpecification.class)
public final class RegistrationNumber implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public RegistrationNumber(String value) {
        this.value = value;
    }
	
    private final String value;
    public String getValue() {
        return value;
    }
    
    @Override
    public boolean equals(final Object other) {
        return other != null &&
               RegistrationNumber.class == other.getClass() &&
               equals((RegistrationNumber)other);
    }
    public boolean equals(final RegistrationNumber other) {
        return other != null &&
               getValue().equals(other.getValue());
    }
    
    @Override
    public int hashCode() {
        return getValue().hashCode();
    }
    
    @Override
    public String toString() {
        return getValue();
    }
}