comparison Limits/CompositeMaximumLimit.cs @ 84:0fc997256e65

Re #45: Create composite limit * Create abstract implementation of a composite limit * Create limits based on minimum and maximum of composition
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Jun 2010 10:57:43 +0000
parents
children
comparison
equal deleted inserted replaced
83:13f0ffb012cb 84:0fc997256e65
1 // This file (CompositeMaximumLimit.cs) is a part of the IBBoard project and is copyright 2010 IBBoard
2 //
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.
4 using System;
5 using System.Collections.Generic;
6
7 namespace IBBoard.Limits
8 {
9 /// <summary>
10 /// A composite limit that returns the maximum of all contained limits
11 /// </summary>
12 public class CompositeMaximumLimit : AbstractCompositeLimit
13 {
14 /// <summary>
15 /// Creates a composite limit based on one initial limit
16 /// </summary>
17 /// <param name="initialLimit">
18 /// The initial <see cref="ILimit"/>
19 /// </param>
20 public CompositeMaximumLimit(ILimit initialLimit) : base(initialLimit)
21 {
22 //Do nothing extra
23 }
24
25 /// <summary>
26 /// Creates a composite limit based on a collection of initial limits
27 /// </summary>
28 /// <param name="initialLimit">
29 /// The initial <see cref="ILimit"/>
30 /// </param>
31 public CompositeMaximumLimit(ICollection<ILimit> initialLimits) : base(initialLimits)
32 {
33 //Do nothing extra
34 }
35
36 protected override int CalculateLimit(int size)
37 {
38 int limitedNumber = 0;
39
40 foreach (ILimit limit in Limits)
41 {
42 limitedNumber = Math.Max(limitedNumber, limit.GetLimit(size));
43 }
44
45 return limitedNumber;
46 }
47 }
48 }
49