forked from kyordhel/GPSRCmdGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Location.cs
151 lines (130 loc) · 4.79 KB
/
Location.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace GPSRCmdGen
{
[Serializable, XmlRoot("location")]
[XmlInclude(typeof(Room)), XmlInclude(typeof(SpecificLocation)), XmlInclude(typeof(SpecificLocation))]
public abstract class Location : INameable, IComparable<Location>, IEquatable<Location>
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GPSRCmdGen.Location"/> class.
/// </summary>
/// <remarks>Intended for serialization purposes only</remarks>
public Location() : this(String.Empty) { }
/// <summary>
/// Initializes a new instance of the <see cref="GPSRCmdGen.Location"/> class.
/// </summary>
/// <param name="name">The name of the location.</param>
public Location(string name) : this(name, false, false)
{
this.Name = name;
}
/// <summary>
/// Initializes a new instance of the <see cref="GPSRCmdGen.Location"/> class.
/// </summary>
/// <param name="name">The name of the location.</param>
/// <param name="placement">Indicates whether the location is
/// suitable for placing objects.</param>
/// <param name="beacon">Indicates whether the location is
/// suitable for placing objects.</param>
public Location(string name, bool placement, bool beacon)
{
this.Name = name;
this.IsPlacement = placement;
this.IsBeacon = beacon;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the name of the location
/// </summary>
[XmlAttribute("name")]
public string Name { get; set; }
/// <summary>
/// Gets a value indicating whether the location is
/// suitable for placing a person.
/// </summary>
[XmlIgnore]
public abstract bool IsBeacon { get; set; }
/// <summary>
/// Gets a value indicating whether the location is
/// suitable for placing objects.
/// </summary>
[XmlIgnore]
public abstract bool IsPlacement { get; set; }
public int CompareTo(Location other)
{
if (other == null)
return -1;
return String.Compare(this.Name, other.Name, true);
}
/// <summary>
/// Determines whether the specified <see cref="GPSRCmdGen.Location"/> is equal to the current <see cref="GPSRCmdGen.Location"/> by comparing their names.
/// </summary>
/// <param name="other">The <see cref="GPSRCmdGen.Location"/> to compare with the current <see cref="GPSRCmdGen.Location"/>.</param>
/// <returns><c>true</c> if the specified <see cref="GPSRCmdGen.Location"/> is equal to the current
/// <see cref="GPSRCmdGen.Location"/>; otherwise, <c>false</c>.</returns>
public bool Equals(Location other)
{
return String.Compare(this.Name, other.Name, true) == 0;
}
/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="GPSRCmdGen.Location"/> at object level.
/// </summary>
/// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="GPSRCmdGen.Location"/>.</param>
/// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current
/// <see cref="GPSRCmdGen.Location"/>; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
return base.Equals(obj);
}
/// <summary>
/// Serves as a hash function for a <see cref="GPSRCmdGen.Location"/> object.
/// </summary>
/// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.</returns>
public override int GetHashCode()
{
return this.Name.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="GPSRCmdGen.Location"/>.
/// </summary>
/// <returns>A <see cref="System.String"/> that represents the current <see cref="GPSRCmdGen.Location"/>.</returns>
public override string ToString()
{
return this.Name;
}
#endregion
#region Static Members
/// <summary>
/// Compares two locations for equality based on the values of their names
/// </summary>
/// <param name="a">A location.</param>
/// <param name="b">A location.</param>
public static bool operator ==(Location a, Location b)
{
if (Object.Equals(a, null) && Object.Equals(b, null))
return true;
if (Object.Equals(a, null) || Object.Equals(b, null))
return false;
return String.Compare(a.Name, b.Name, true) == 0;
}
/// <summary>
/// Compares two locations for inequality based on the values of their names
/// </summary>
/// <param name="a">A location.</param>
/// <param name="b">A location.</param>
public static bool operator !=(Location a, Location b)
{
if (Object.Equals(a, null) && Object.Equals(b, null))
return false;
if (Object.Equals(a, null) || Object.Equals(b, null))
return true;
return String.Compare(a.Name, b.Name, true) != 0;
}
#endregion
}
}