Mercurial > repos > IBBoard
changeset 57:44bc5bd5c2f3
Re #24: Add limit objects
* Create base interface
* Create marker interface for percentage and numeric limits
* Make classes implement appropriate interfaces
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Oct 2009 15:42:05 +0000 |
parents | 1e5080813ac5 |
children | 8290adbbc7c4 |
files | IBBoard.csproj Limits/AbsoluteNumericLimit.cs Limits/AbstractLimit.cs Limits/ILimit.cs Limits/INumericLimit.cs Limits/IPercentageLimit.cs Limits/NumericSizeConstrainedLimit.cs Limits/SimpleRoundedPercentageLimit.cs Limits/UnlimitedLimit.cs |
diffstat | 9 files changed, 65 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/IBBoard.csproj Sat Oct 24 15:33:00 2009 +0000 +++ b/IBBoard.csproj Sat Oct 24 15:42:05 2009 +0000 @@ -131,6 +131,9 @@ <Compile Include="Limits\AbstractLimit.cs" /> <Compile Include="Limits\AbsoluteNumericLimit.cs" /> <Compile Include="Limits\UnlimitedLimit.cs" /> + <Compile Include="Limits\ILimit.cs" /> + <Compile Include="Limits\IPercentageLimit.cs" /> + <Compile Include="Limits\INumericLimit.cs" /> </ItemGroup> <ItemGroup> <Content Include="libs\log4net.dll" />
--- a/Limits/AbsoluteNumericLimit.cs Sat Oct 24 15:33:00 2009 +0000 +++ b/Limits/AbsoluteNumericLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -9,7 +9,7 @@ /// <summary> /// A limit of a specified number that does not vary with the number it is limited against. /// </summary> - public class AbsoluteNumericLimit : AbstractLimit + public class AbsoluteNumericLimit : AbstractLimit, INumericLimit { public AbsoluteNumericLimit (int numericLimit) : base(numericLimit) {
--- a/Limits/AbstractLimit.cs Sat Oct 24 15:33:00 2009 +0000 +++ b/Limits/AbstractLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -9,7 +9,7 @@ /// <summary> /// The abstract base class for all limits /// </summary> - public abstract class AbstractLimit + public abstract class AbstractLimit : ILimit { private double limit; @@ -26,23 +26,14 @@ } } - /// <summary> - /// Gets the limited number, based on the limit that this <code>Limit</code> represents and the number it is limiting (<code>size</code>). - /// </summary> - /// <param name="size"> - /// The number to be limited - /// </param> - /// <returns> - /// the limited number, as defined by the implementation of the limit - /// </returns> - public abstract int GetLimit(int size); - public override int GetHashCode () { int hash = GetType().GetHashCode(); hash+= Limit.GetHashCode(); return hash; } + + public abstract int GetLimit(int size); public override bool Equals (object obj) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Limits/ILimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -0,0 +1,25 @@ +// This file (ILimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; + +namespace IBBoard.Limits +{ + /// <summary> + /// The interface for all limits + /// </summary> + public interface ILimit + { + /// <summary> + /// Gets the limited number, based on the limit that this <code>Limit</code> represents and the number it is limiting (<code>size</code>). + /// </summary> + /// <param name="size"> + /// The number to be limited + /// </param> + /// <returns> + /// the limited number, as defined by the implementation of the limit + /// </returns> + int GetLimit(int size); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Limits/INumericLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -0,0 +1,15 @@ +// This file (INumericLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; + +namespace IBBoard.Limits +{ + /// <summary> + /// A marker interface for limits that represent a numeric limit + /// </summary> + public interface INumericLimit : ILimit + { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Limits/IPercentageLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -0,0 +1,15 @@ +// This file (IPercentageLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; + +namespace IBBoard.Limits +{ + /// <summary> + /// A marker interface for limits that represent a percentage restriction + /// </summary> + public interface IPercentageLimit : ILimit + { + } +}
--- a/Limits/NumericSizeConstrainedLimit.cs Sat Oct 24 15:33:00 2009 +0000 +++ b/Limits/NumericSizeConstrainedLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -9,7 +9,7 @@ /// <summary> /// A limit of a specified number, or the number it is limited against, whichever is smaller. /// </summary> - public class NumericSizeConstrainedLimit : AbstractLimit + public class NumericSizeConstrainedLimit : AbstractLimit, INumericLimit { public NumericSizeConstrainedLimit (int numericLimit) : base(numericLimit) {
--- a/Limits/SimpleRoundedPercentageLimit.cs Sat Oct 24 15:33:00 2009 +0000 +++ b/Limits/SimpleRoundedPercentageLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -10,7 +10,7 @@ /// <summary> /// A percentage-based limit that always either rounds up or down to the closest integer /// </summary> - public class SimpleRoundedPercentageLimit : AbstractLimit + public class SimpleRoundedPercentageLimit : AbstractLimit, IPercentageLimit { private bool roundUp;
--- a/Limits/UnlimitedLimit.cs Sat Oct 24 15:33:00 2009 +0000 +++ b/Limits/UnlimitedLimit.cs Sat Oct 24 15:42:05 2009 +0000 @@ -9,7 +9,7 @@ /// <summary> /// A special case "infinite" limit that always returns the integer number closest to infinity. /// </summary> - public class UnlimitedLimit : AbstractLimit + public class UnlimitedLimit : AbstractLimit, INumericLimit { public UnlimitedLimit () : base(double.PositiveInfinity) {