diff --git a/ucalc/Data/Billing.cs b/ucalc/Data/Billing.cs index 73d39a9..fdd9489 100644 --- a/ucalc/Data/Billing.cs +++ b/ucalc/Data/Billing.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -65,30 +63,6 @@ namespace UCalc.Data City = ""; Postcode = ""; } - - private bool Equals(Address other) - { - return Street == other.Street && HouseNumber == other.HouseNumber && City == other.City && - Postcode == other.Postcode; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Address) obj); - } - - public Address Clone() - { - return new Address - { - Street = Street, - HouseNumber = HouseNumber, - City = City, - Postcode = Postcode - }; - } } public class BankAccount @@ -108,28 +82,6 @@ namespace UCalc.Data Bic = ""; BankName = ""; } - - private bool Equals(BankAccount other) - { - return Iban == other.Iban && Bic == other.Bic && BankName == other.BankName; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((BankAccount) obj); - } - - public BankAccount Clone() - { - return new BankAccount - { - Iban = Iban, - Bic = Bic, - BankName = BankName - }; - } } public class Flat @@ -167,23 +119,10 @@ namespace UCalc.Data return Id.GetHashCode(); // ReSharper restore NonReadonlyMemberInGetHashCode } - - public Flat Clone() - { - return new Flat - { - Id = Id, - Name = Name, - Size = Size - }; - } } public class Tenant { - [JsonProperty(PropertyName = "id"), JsonRequired] - public Guid Id { get; set; } - [JsonProperty(PropertyName = "salutation"), JsonRequired, JsonConverter(typeof(StringEnumConverter))] public Salutation Salutation { get; set; } @@ -216,47 +155,12 @@ namespace UCalc.Data public Tenant() { - Id = Guid.NewGuid(); Name = ""; BankAccount = new BankAccount(); RentedFlats = new HashSet(); CustomMessage1 = ""; CustomMessage2 = ""; } - - private bool Equals(Tenant other) - { - return Id.Equals(other.Id) && Salutation == other.Salutation && Name == other.Name && - PersonCount == other.PersonCount && Equals(BankAccount, other.BankAccount) && - Nullable.Equals(EntryDate, other.EntryDate) && Nullable.Equals(DepartureDate, other.DepartureDate) && - RentedFlats.SequenceEqual(other.RentedFlats) && PaidRent == other.PaidRent && - CustomMessage1 == other.CustomMessage1 && CustomMessage2 == other.CustomMessage2; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Tenant) obj); - } - - public Tenant Clone(Dictionary flatMapper) - { - return new Tenant - { - Id = Id, - Salutation = Salutation, - Name = Name, - PersonCount = PersonCount, - BankAccount = BankAccount.Clone(), - EntryDate = EntryDate, - DepartureDate = DepartureDate, - RentedFlats = new HashSet(RentedFlats.Select(flat => flatMapper[flat])), - PaidRent = PaidRent, - CustomMessage1 = CustomMessage1, - CustomMessage2 = CustomMessage2 - }; - } } public class Landlord @@ -288,32 +192,6 @@ namespace UCalc.Data Address = new Address(); BankAccount = new BankAccount(); } - - private bool Equals(Landlord other) - { - return Salutation == other.Salutation && Name == other.Name && MailAddress == other.MailAddress && - Phone == other.Phone && Equals(Address, other.Address) && Equals(BankAccount, other.BankAccount); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Landlord) obj); - } - - public Landlord Clone() - { - return new Landlord - { - Salutation = Salutation, - Name = Name, - MailAddress = MailAddress, - Phone = Phone, - Address = Address.Clone(), - BankAccount = BankAccount.Clone() - }; - } } public class House @@ -329,27 +207,6 @@ namespace UCalc.Data Address = new Address(); Flats = new List(); } - - private bool Equals(House other) - { - return Equals(Address, other.Address) && Flats.SequenceEqual(other.Flats); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((House) obj); - } - - public House Clone() - { - return new House - { - Address = Address.Clone(), - Flats = new List(Flats.Select(flat => flat.Clone())) - }; - } } public class CostEntryDetails @@ -367,29 +224,6 @@ namespace UCalc.Data { DiscountsInUnits = new List(); } - - private bool Equals(CostEntryDetails other) - { - return TotalAmount == other.TotalAmount && UnitCount == other.UnitCount && - DiscountsInUnits.SequenceEqual(other.DiscountsInUnits); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((CostEntryDetails) obj); - } - - public CostEntryDetails Clone() - { - return new CostEntryDetails - { - TotalAmount = TotalAmount, - UnitCount = UnitCount, - DiscountsInUnits = new List(DiscountsInUnits) - }; - } } public class CostEntry @@ -410,30 +244,6 @@ namespace UCalc.Data { Details = new CostEntryDetails(); } - - private bool Equals(CostEntry other) - { - return StartDate.Equals(other.StartDate) && EndDate.Equals(other.EndDate) && Amount == other.Amount && - Details.Equals(other.Details); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((CostEntry) obj); - } - - public CostEntry Clone() - { - return new CostEntry - { - StartDate = StartDate, - EndDate = EndDate, - Amount = Amount, - Details = Details?.Clone() - }; - } } public enum CostDivision @@ -490,34 +300,6 @@ namespace UCalc.Data AffectedFlats = new HashSet(); Entries = new List(); } - - private bool Equals(Cost other) - { - return Name == other.Name && Division == other.Division && AffectsAll == other.AffectsAll && - ShiftUnrented == other.ShiftUnrented && AffectedFlats.SequenceEqual(other.AffectedFlats) && - Entries.SequenceEqual(other.Entries) && DisplayInBill == other.DisplayInBill; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Cost) obj); - } - - public Cost Clone(Dictionary flatMapper) - { - return new Cost - { - Name = Name, - Division = Division, - AffectsAll = AffectsAll, - ShiftUnrented = ShiftUnrented, - AffectedFlats = new HashSet(AffectedFlats.Select(flat => flatMapper[flat])), - Entries = new List(Entries.Select(entry => entry.Clone())), - DisplayInBill = DisplayInBill - }; - } } public class Billing @@ -547,54 +329,5 @@ namespace UCalc.Data Tenants = new List(); Costs = new List(); } - - private bool Equals(Billing other) - { - return StartDate.Equals(other.StartDate) && EndDate.Equals(other.EndDate) && - Landlord.Equals(other.Landlord) && House.Equals(other.House) && - Tenants.SequenceEqual(other.Tenants) && Costs.SequenceEqual(other.Costs); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - return obj.GetType() == GetType() && Equals((Billing) obj); - } - - public Billing Clone() - { - var house = House.Clone(); - var flatMapper = new Dictionary(new ObjectReferenceEqualityComparer()); - - for (var i = 0; i < House.Flats.Count; ++i) - { - flatMapper.Add(House.Flats[i], house.Flats[i]); - } - - return new Billing - { - StartDate = StartDate, - EndDate = EndDate, - Landlord = Landlord.Clone(), - House = House, - Tenants = new List(Tenants.Select(tenant => tenant.Clone(flatMapper))), - Costs = new List(Costs.Select(cost => cost.Clone(flatMapper))) - }; - } - } - - public class ObjectReferenceEqualityComparer : EqualityComparer - where T : class - { - public override bool Equals(T x, T y) - { - return ReferenceEquals(x, y); - } - - public override int GetHashCode(T obj) - { - return RuntimeHelpers.GetHashCode(obj); - } } } \ No newline at end of file