-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNElements.cs
More file actions
56 lines (45 loc) · 1.31 KB
/
Copy pathNElements.cs
File metadata and controls
56 lines (45 loc) · 1.31 KB
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
using System.Text;
namespace ChemTools {
/// <summary> Represents a number of elements </summary>
public class NElements {
public readonly Element element;
private int n;
/// <param name="n"> Number </param>
/// <param name="e"> The Element </param>
public NElements(int n, Element e) {
this.n = n;
element = e;
}
/// <summary> Copy constructor. </summary>
/// <param name="ne"> The NElement to copy. </param>
public NElements(NElements ne) : this(ne.n, ne.element) {}
/// <summary> Amount of the element. </summary>
public int Number {
get {
return n;
}
set {
n = value;
}
}
/// <returns> true iff other is an NElement,
/// has the same Number, and the same Element </returns>
public override bool Equals(object other){
if(other is NElements) {
NElements ne = (NElements) other;
return n == ne.n && element.Equals(ne.element);
}
return false;
}
/// <returns> Integer representation
/// of this object. Not guaranteed unique. </returns>
public override int GetHashCode() {
return element.GetHashCode() ^ n;
}
/// <returns> Symbol + Number (if Number is not 1) </returns>
public override string ToString() {
string number = (n == 1 ? "" : n.ToString());
return new StringBuilder(element.symbol).Append(number).ToString();
}
}
}