# HG changeset patch # User IBBoard # Date 1256398925 0 # Node ID 44bc5bd5c2f386790372c19bf9da8db2f221597c # Parent 1e5080813ac5f1040d640b1db23032b564ec53c4 Re #24: Add limit objects * Create base interface * Create marker interface for percentage and numeric limits * Make classes implement appropriate interfaces diff -r 1e5080813ac5 -r 44bc5bd5c2f3 IBBoard.csproj --- 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 @@ + + + diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/AbsoluteNumericLimit.cs --- 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 @@ /// /// A limit of a specified number that does not vary with the number it is limited against. /// - public class AbsoluteNumericLimit : AbstractLimit + public class AbsoluteNumericLimit : AbstractLimit, INumericLimit { public AbsoluteNumericLimit (int numericLimit) : base(numericLimit) { diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/AbstractLimit.cs --- 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 @@ /// /// The abstract base class for all limits /// - public abstract class AbstractLimit + public abstract class AbstractLimit : ILimit { private double limit; @@ -26,23 +26,14 @@ } } - /// - /// Gets the limited number, based on the limit that this Limit represents and the number it is limiting (size). - /// - /// - /// The number to be limited - /// - /// - /// the limited number, as defined by the implementation of the limit - /// - 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) { diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/ILimit.cs --- /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 +{ + /// + /// The interface for all limits + /// + public interface ILimit + { + /// + /// Gets the limited number, based on the limit that this Limit represents and the number it is limiting (size). + /// + /// + /// The number to be limited + /// + /// + /// the limited number, as defined by the implementation of the limit + /// + int GetLimit(int size); + } +} diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/INumericLimit.cs --- /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 +{ + /// + /// A marker interface for limits that represent a numeric limit + /// + public interface INumericLimit : ILimit + { + } +} diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/IPercentageLimit.cs --- /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 +{ + /// + /// A marker interface for limits that represent a percentage restriction + /// + public interface IPercentageLimit : ILimit + { + } +} diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/NumericSizeConstrainedLimit.cs --- 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 @@ /// /// A limit of a specified number, or the number it is limited against, whichever is smaller. /// - public class NumericSizeConstrainedLimit : AbstractLimit + public class NumericSizeConstrainedLimit : AbstractLimit, INumericLimit { public NumericSizeConstrainedLimit (int numericLimit) : base(numericLimit) { diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/SimpleRoundedPercentageLimit.cs --- 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 @@ /// /// A percentage-based limit that always either rounds up or down to the closest integer /// - public class SimpleRoundedPercentageLimit : AbstractLimit + public class SimpleRoundedPercentageLimit : AbstractLimit, IPercentageLimit { private bool roundUp; diff -r 1e5080813ac5 -r 44bc5bd5c2f3 Limits/UnlimitedLimit.cs --- 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 @@ /// /// A special case "infinite" limit that always returns the integer number closest to infinity. /// - public class UnlimitedLimit : AbstractLimit + public class UnlimitedLimit : AbstractLimit, INumericLimit { public UnlimitedLimit () : base(double.PositiveInfinity) {