annotate Limits/AbstractCompositeLimit.cs @ 108:27b6aa1e98e8

Re #12: Document classes and methods * Document the Constants (Also - test new Hg repo and hooks)
author IBBoard <dev@ibboard.co.uk>
date Sun, 14 Aug 2011 14:34:12 +0100
parents 0fc997256e65
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (AbstractCompositeLimit.cs) is a part of the IBBoard project and is copyright 2010 IBBoard
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System.Collections.Generic;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using IBBoard.Collections;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 namespace IBBoard.Limits
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 /// <summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 /// Abstract implementation of a limit that is a composition of one or more other limits
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// </summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 public abstract class AbstractCompositeLimit : ILimit
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 private SimpleSet<ILimit> limits;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 private AbstractCompositeLimit()
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 limits = new SimpleSet<ILimit>();
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 /// <summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 /// Creates a composite limit based on one initial limit
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 /// </summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 /// <param name="initialLimit">
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 /// The initial <see cref="ILimit"/>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 /// </param>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 public AbstractCompositeLimit(ILimit initialLimit) : this()
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 AddLimit(initialLimit);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 /// <summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 /// Creates a composite limit based on a collection of initial limits
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 /// </summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 /// <param name="initialLimit">
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 /// The initial <see cref="ILimit"/>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 /// </param>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 public AbstractCompositeLimit(ICollection<ILimit> initialLimits) : this()
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 AddLimits(initialLimits);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 /// <summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 /// Adds an <see cref="ILimit"/> to the set of limits included in the composition
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 /// </summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 /// <param name="limit">
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 /// The <see cref="ILimit"/> to add
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 /// </param>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 public void AddLimit(ILimit limit)
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 limits.Add(limit);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 /// <summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 /// Adds a collection of <see cref="ILimit"/> to the set of limits included in the composition
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 /// </summary>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 /// <param name="limit">
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 /// The <see cref="ILimit"/>s to add
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 /// </param>
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 public void AddLimits(ICollection<ILimit> newLimits)
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 limits.AddRange(newLimits);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 protected SimpleSet<ILimit> Limits
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 get { return limits; }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 public int GetLimit(int size)
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 int limit = 0;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 if (limits.Count > 0)
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 limit = CalculateLimit(size);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 return limit;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 protected abstract int CalculateLimit(int size);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 public override int GetHashCode()
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 int hash = GetType().GetHashCode();
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 hash += limits.GetHashCode();
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 return hash;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 public override bool Equals(object obj)
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 bool equal = false;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 if (obj != null && GetType().Equals(obj.GetType()))
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 {
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 equal = Limits.Equals(((AbstractCompositeLimit)obj).Limits);
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 return equal;
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 }
0fc997256e65 Re #45: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106