summaryrefslogtreecommitdiff
path: root/slips/src/app/Marina/Domain/Boat.cs
blob: 3f071743c5ee17b4696bfb15cda5d78a0247a03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using Marina.Domain.Interfaces;

namespace Marina.Domain {
	public class Boat : DomainObject, IBoat, IEquatable< Boat > {
		public Boat( string registrationNumber, string manufacturer, DateTime yearOfModel, long length )
			: this( -1, registrationNumber, manufacturer, yearOfModel, length ) {}

		public Boat( long id, string registrationNumber, string manufacturer, DateTime yearOfModel, long length )
			: base( id ) {
			_registrationNumber = registrationNumber;
			_manufacturer = manufacturer;
			_yearOfModel = yearOfModel;
			_length = length;
		}

		public string RegistrationNumber() {
			return _registrationNumber;
		}

		public string Manufacturer() {
			return _manufacturer;
		}

		public DateTime YearOfModel() {
			return _yearOfModel;
		}

		public long LengthInFeet() {
			return _length;
		}

		public bool Equals( Boat boat ) {
			if ( boat == null ) {
				return false;
			}
			if ( !Equals( _registrationNumber, boat._registrationNumber ) ) {
				return false;
			}
			if ( !Equals( _manufacturer, boat._manufacturer ) ) {
				return false;
			}
			if ( !Equals( _yearOfModel, boat._yearOfModel ) ) {
				return false;
			}
			if ( _length != boat._length ) {
				return false;
			}
			return true;
		}

		public override bool Equals( object obj ) {
			if ( ReferenceEquals( this, obj ) ) {
				return true;
			}
			return Equals( obj as Boat );
		}

		public override int GetHashCode() {
			int result = _registrationNumber != null ? _registrationNumber.GetHashCode( ) : 0;
			result = 29*result + ( _manufacturer != null ? _manufacturer.GetHashCode( ) : 0 );
			result = 29*result + _yearOfModel.GetHashCode( );
			result = 29*result + ( int )_length;
			return result;
		}

		private readonly string _registrationNumber;
		private readonly string _manufacturer;
		private readonly DateTime _yearOfModel;
		private readonly long _length;
	}
}