Skip to content

Commit

Permalink
Completed the exception package.
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofran committed Nov 17, 2011
1 parent c0cdfdf commit 9d08471
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 28 deletions.
12 changes: 12 additions & 0 deletions Apache.Commons.Math/Apache.Commons.Math.csproj
Expand Up @@ -41,6 +41,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Exceptions\ConvergenceException.cs" />
<Compile Include="Exceptions\NonMonotonicSequenceException.cs" />
<Compile Include="Exceptions\NotFiniteNumberException.cs" />
<Compile Include="Exceptions\NotPositiveException.cs" />
<Compile Include="Exceptions\NotStrictlyPositiveException.cs" />
<Compile Include="Exceptions\NullArgumentException.cs" />
<Compile Include="Exceptions\NumberIsTooLargeException.cs" />
<Compile Include="Exceptions\DimensionMismatchException.cs" />
<Compile Include="Exceptions\MathArgumentException.cs" />
<Compile Include="Exceptions\MathArithmeticException.cs" />
Expand All @@ -50,6 +56,11 @@
<Compile Include="Exceptions\MathParseException.cs" />
<Compile Include="Exceptions\MathNotSupportedException.cs" />
<Compile Include="Exceptions\MaxCountExceededException.cs" />
<Compile Include="Exceptions\MultiDimensionMismatchException.cs" />
<Compile Include="Exceptions\NoBracketingException.cs" />
<Compile Include="Exceptions\NoDataException.cs" />
<Compile Include="Exceptions\NumberIsTooSmallException.cs" />
<Compile Include="Exceptions\OutOfRangeException.cs" />
<Compile Include="Exceptions\TooManyEvaluationsException.cs" />
<Compile Include="Exceptions\Util\ArgUtils.cs" />
<Compile Include="Exceptions\Util\LocalizedFormat.cs" />
Expand All @@ -65,6 +76,7 @@
<DependentUpon>LocalizedFormats.resx</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util\OrderDirection.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Exceptions\Util\LocalizedFormats.resx">
Expand Down
12 changes: 2 additions & 10 deletions Apache.Commons.Math/Exceptions/DimensionMismatchException.cs
Expand Up @@ -31,7 +31,7 @@ public class DimensionMismatchException: MathIllegalNumberException<int>
/// <summary>
/// Correct dimension.
/// </summary>
private readonly int dimension;
public int Dimension { get; private set; }

/// <summary>
/// Construct an exception from the mismatched dimensions.
Expand All @@ -41,7 +41,7 @@ public class DimensionMismatchException: MathIllegalNumberException<int>
/// <param name="expected">Expected dimension.</param>
public DimensionMismatchException(ILocalizable specific, int wrong, int expected): base(specific, wrong, expected)
{
this.dimension = expected;
this.Dimension = expected;
}

/// <summary>
Expand All @@ -50,13 +50,5 @@ public DimensionMismatchException(ILocalizable specific, int wrong, int expected
/// <param name="wrong">Wrong dimension.</param>
/// <param name="expected">Expected dimension.</param>
public DimensionMismatchException(int wrong, int expected) : this(LocalizedFormat.DIMENSIONS_MISMATCH_SIMPLE, wrong, expected) { }

/// <summary>
/// The expected dimension.
/// </summary>
public int Dimension
{
get { return dimension; }
}
}
}
13 changes: 2 additions & 11 deletions Apache.Commons.Math/Exceptions/MathIllegalNumberException.cs
Expand Up @@ -34,7 +34,7 @@ public class MathIllegalNumberException<T>: MathArgumentException
/// <summary>
/// The argument.
/// </summary>
private readonly T argument;
public T Argument { get; private set; }

/// <summary>
/// Creates the exceptions.
Expand All @@ -45,16 +45,7 @@ public class MathIllegalNumberException<T>: MathArgumentException
protected MathIllegalNumberException(ILocalizable pattern, T wrong, params object[] arguments):
base(pattern, arguments)
{
this.argument = wrong;
}

/// <summary>
/// Gets the argument that has caused the exception.
/// </summary>
public virtual T Argument
{
get { return argument; }
this.Argument = wrong;
}
}

}
9 changes: 2 additions & 7 deletions Apache.Commons.Math/Exceptions/MaxCountExceededException.cs
Expand Up @@ -31,7 +31,7 @@ public class MaxCountExceededException: MathIllegalStateException
/// <summary>
/// Maximum number of evaluations.
/// </summary>
private readonly long max;
public long Max { get; private set; }

/// <summary>
/// Construct the exception.
Expand All @@ -48,12 +48,7 @@ public class MaxCountExceededException: MathIllegalStateException
public MaxCountExceededException(ILocalizable specific, int max, params object[] args)
{
Context.AddMessage(specific, max, args);
this.max = max;
}

public long Max
{
get { return max; }
this.Max = max;
}
}
}
61 changes: 61 additions & 0 deletions Apache.Commons.Math/Exceptions/MultiDimensionMismatchException.cs
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.Commons.Math.Exceptions.Util;

namespace Apache.Commons.Math.Exceptions
{
/// <summary>
/// Exception thrown when two sets of dimensions differ.
/// </summary>
[Serializable]
public class MultiDimensionMismatchException: MathArgumentException
{
/// <summary>
/// Wrong dimensions.
/// </summary>
public int[] WrongDimensions { get; private set; }
/// <summary>
/// Correct dimensions.
/// </summary>
public int[] ExpectedDimensions { get; private set; }

/// <summary>
/// Constructs an exception from the mismatched dimensions.
/// </summary>
/// <param name="wrong">Wrong dimensions.</param>
/// <param name="expected">Expected dimensions.</param>
public MultiDimensionMismatchException(int[] wrong, int[] expected) :
this(LocalizedFormat.DIMENSIONS_MISMATCH, wrong, expected) { }

/// <summary>
/// Construct an exception from the mismatched dimensions.
/// </summary>
/// <param name="specific">Message pattern providing the specific context of the error.</param>
/// <param name="wrong">Wrong dimensions.</param>
/// <param name="expected">Expected dimensions.</param>
public MultiDimensionMismatchException(ILocalizable specific, int[] wrong, int[] expected):
base(specific, wrong, expected)
{
this.WrongDimensions = wrong.Clone() as int[];
this.ExpectedDimensions = expected.Clone() as int[];
}
}
}
76 changes: 76 additions & 0 deletions Apache.Commons.Math/Exceptions/NoBracketingException.cs
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.Commons.Math.Exceptions.Util;

namespace Apache.Commons.Math.Exceptions
{
/// <summary>
/// Exception to be thrown when function values have the same sign at both ends of an interval.
/// </summary>
[Serializable]
public class NoBracketingException: MathArgumentException
{
/// <summary>
/// Lower end of the interval.
/// </summary>
public double Lo { get; private set; }
/// <summary>
/// Higher end of the interval.
/// </summary>
public double Hi { get; private set; }
/// <summary>
/// Value at the lower end of the interval.
/// </summary>
public double Flo { get; private set; }
/// <summary>
/// Value at the upper end of the interval.
/// </summary>
public double Fhi { get; private set; }

/// <summary>
/// Construct the exception.
/// </summary>
/// <param name="lo">Lower end of the interval.</param>
/// <param name="hi">Higher end of the interval.</param>
/// <param name="fLo">Value at the lower end of the interval.</param>
/// <param name="fHi">Value at the higher end of the interval.</param>
public NoBracketingException(double lo, double hi, double fLo, double fHi) :
this(LocalizedFormat.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi) { }

/// <summary>
/// Construct the exception.
/// </summary>
/// <param name="specific">Contextual information on what caused the exception.</param>
/// <param name="lo">Lower end of the interval.</param>
/// <param name="hi">Higher end of the interval.</param>
/// <param name="fLo">Value at the lower end of the interval.</param>
/// <param name="fHi">Value at the higher end of the interval.</param>
/// <param name="args">Additional arguments.</param>
public NoBracketingException(ILocalizable specific, double lo, double hi, double fLo, double fHi, params object[] args) :
base(specific, lo, hi, fLo, fHi, args)
{
this.Lo = lo;
this.Hi = hi;
this.Flo = fLo;
this.Fhi = fHi;
}
}
}
42 changes: 42 additions & 0 deletions Apache.Commons.Math/Exceptions/NoDataException.cs
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.Commons.Math.Exceptions.Util;

namespace Apache.Commons.Math.Exceptions
{
/// <summary>
/// Exception to be thrown when the required data is missing.
/// </summary>
[Serializable]
public class NoDataException: MathArgumentException
{
/// <summary>
/// Default constructor.
/// </summary>
public NoDataException() : this(LocalizedFormat.NO_DATA) { }

/// <summary>
/// Construct the exception with a specific context.
/// </summary>
/// <param name="specific">Contextual information on what caused the exception.</param>
public NoDataException(ILocalizable specific) : base(specific) { }
}
}
73 changes: 73 additions & 0 deletions Apache.Commons.Math/Exceptions/NonMonotonicSequenceException.cs
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.Commons.Math.Util;
using Apache.Commons.Math.Exceptions.Util;

namespace Apache.Commons.Math.Exceptions
{
/// <summary>
/// Exception to be thrown when a sequence of values is not monotonically increasing or decreasing.
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public class NonMonotonicSequenceException<T>: MathIllegalNumberException<T>
{
/// <summary>
/// Direction (positive for increasing, negative for decreasing).
/// </summary>
public OrderDirection Direction { get; private set; }
/// <summary>
/// Whether the sequence must be strictly increasing or decreasing.
/// </summary>
public bool Strict { get; private set; }
/// <summary>
/// Index of the wrong value.
/// </summary>
public int Index { get; private set; }
/// <summary>
/// Previous value.
/// </summary>
public T Previous { get; private set; }

/// <summary>
/// Construct the exception.
/// <para>This constructor used default values assuming that the sequence should
/// have been strictly increasing.</para>
/// </summary>
/// <param name="wrong">The value that did not match the requirements.</param>
/// <param name="previous">Previous value in the sequence.</param>
/// <param name="index">Index of the value that did not match the sequence.</param>
public NonMonotonicSequenceException(T wrong, T previous, int index) :
this(wrong, previous, index, OrderDirection.Increasing, true) { }

public NonMonotonicSequenceException(T wrong, T previous, int index, OrderDirection direction, bool strict):
base(direction == OrderDirection.Increasing ?
(strict ? LocalizedFormat.NOT_STRICTLY_INCREASING_SEQUENCE : LocalizedFormat.NOT_INCREASING_SEQUENCE) :
(strict ? LocalizedFormat.NOT_STRICTLY_DECREASING_SEQUENCE : LocalizedFormat.NOT_DECREASING_SEQUENCE),
wrong, previous, index, index - 1)
{
this.Direction = direction;
this.Strict = strict;
this.Index = index;
this.Previous = previous;
}
}
}

0 comments on commit 9d08471

Please sign in to comment.