MATH-1362: Removed class that is not used anymore within "Commons Math".

This commit is contained in:
Gilles Sadowski 2019-12-24 13:04:51 +01:00
parent 8091c4fe83
commit ef4596df33
3 changed files with 4 additions and 323 deletions

View File

@ -54,8 +54,11 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>
<release version="4.0" date="XXXX-XX-XX" description="">
<action dev="erans" type="update" issue="MATH-1362">
Removed deprecated class "Incrementor" (replaced by "IntegerSequence.Incrementor").
</action>
<action dev="erans" type="update" issue="MATH-1506">
Removed class "MultiDimensionalCounter" (ported to "Commons Numbers").
Removed class "MultidimensionalCounter" (ported to "Commons Numbers").
</action>
<action dev="erans" type="update" issue="MATH-1504">
Removed class "BigFraction" (ported to "Commons Numbers").

View File

@ -1,183 +0,0 @@
/*
* 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.
*/
package org.apache.commons.math4.util;
import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.NullArgumentException;
/**
* Utility that increments a counter until a maximum is reached, at
* which point, the instance will by default throw a
* {@link MaxCountExceededException}.
* However, the user is able to override this behaviour by defining a
* custom {@link MaxCountExceededCallback callback}, in order to e.g.
* select which exception must be thrown.
*
* @since 3.0
*
* @deprecated Use {@link IntegerSequence.Incrementor} instead.
*/
@Deprecated
public class Incrementor {
/**
* Upper limit for the counter.
*/
private int maximalCount;
/**
* Current count.
*/
private int count = 0;
/**
* Function called at counter exhaustion.
*/
private final MaxCountExceededCallback maxCountCallback;
/**
* Default constructor.
* For the new instance to be useful, the maximal count must be set
* by calling {@link #setMaximalCount(int) setMaximalCount}.
*/
public Incrementor() {
this(0);
}
/**
* Defines a maximal count.
*
* @param max Maximal count.
*/
public Incrementor(int max) {
this(max,
new MaxCountExceededCallback() {
/** {@inheritDoc} */
@Override
public void trigger(int max) throws MaxCountExceededException {
throw new MaxCountExceededException(max);
}
});
}
/**
* Defines a maximal count and a callback method to be triggered at
* counter exhaustion.
*
* @param max Maximal count.
* @param cb Function to be called when the maximal count has been reached.
* @throws NullArgumentException if {@code cb} is {@code null}
*/
public Incrementor(int max, MaxCountExceededCallback cb)
throws NullArgumentException {
if (cb == null){
throw new NullArgumentException();
}
maximalCount = max;
maxCountCallback = cb;
}
/**
* Sets the upper limit for the counter.
* This does not automatically reset the current count to zero (see
* {@link #resetCount()}).
*
* @param max Upper limit of the counter.
*/
public void setMaximalCount(int max) {
maximalCount = max;
}
/**
* Gets the upper limit of the counter.
*
* @return the counter upper limit.
*/
public int getMaximalCount() {
return maximalCount;
}
/**
* Gets the current count.
*
* @return the current count.
*/
public int getCount() {
return count;
}
/**
* Checks whether a single increment is allowed.
*
* @return {@code false} if the next call to {@link #incrementCount(int)
* incrementCount} will trigger a {@code MaxCountExceededException},
* {@code true} otherwise.
*/
public boolean canIncrement() {
return count < maximalCount;
}
/**
* Performs multiple increments.
* See the other {@link #incrementCount() incrementCount} method).
*
* @param value Number of increments.
* @throws MaxCountExceededException at counter exhaustion.
*/
public void incrementCount(int value) throws MaxCountExceededException {
for (int i = 0; i < value; i++) {
incrementCount();
}
}
/**
* Adds one to the current iteration count.
* At counter exhaustion, this method will call the
* {@link MaxCountExceededCallback#trigger(int) trigger} method of the
* callback object passed to the
* {@link #Incrementor(int,MaxCountExceededCallback) constructor}.
* If not explictly set, a default callback is used that will throw
* a {@code MaxCountExceededException}.
*
* @throws MaxCountExceededException at counter exhaustion, unless a
* custom {@link MaxCountExceededCallback callback} has been set at
* construction.
*/
public void incrementCount() throws MaxCountExceededException {
if (++count > maximalCount) {
maxCountCallback.trigger(maximalCount);
}
}
/**
* Resets the counter to 0.
*/
public void resetCount() {
count = 0;
}
/**
* Defines a method to be called at counter exhaustion.
* The {@link #trigger(int) trigger} method should usually throw an exception.
*/
public interface MaxCountExceededCallback {
/**
* Function called when the maximal count has been reached.
*
* @param maximalCount Maximal count.
* @throws MaxCountExceededException at counter exhaustion
*/
void trigger(int maximalCount) throws MaxCountExceededException;
}
}

View File

@ -1,139 +0,0 @@
/*
* 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.
*/
package org.apache.commons.math4.util;
import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.TooManyEvaluationsException;
import org.apache.commons.math4.util.Incrementor;
import org.junit.Assert;
import org.junit.Test;
/**
* Test for {@link Incrementor}.
*/
public class IncrementorTest {
@Test
public void testConstructor1() {
final Incrementor i = new Incrementor();
Assert.assertEquals(0, i.getMaximalCount());
Assert.assertEquals(0, i.getCount());
}
@Test
public void testConstructor2() {
final Incrementor i = new Incrementor(10);
Assert.assertEquals(10, i.getMaximalCount());
Assert.assertEquals(0, i.getCount());
}
@Test
public void testCanIncrement1() {
final Incrementor i = new Incrementor(3);
Assert.assertTrue(i.canIncrement());
i.incrementCount();
Assert.assertTrue(i.canIncrement());
i.incrementCount();
Assert.assertTrue(i.canIncrement());
i.incrementCount();
Assert.assertFalse(i.canIncrement());
}
@Test
public void testCanIncrement2() {
final Incrementor i = new Incrementor(3);
while (i.canIncrement()) {
i.incrementCount();
}
// Must keep try/catch because the exception must be generated here,
// and not in the previous loop.
try {
i.incrementCount();
Assert.fail("MaxCountExceededException expected");
} catch (MaxCountExceededException e) {
// Expected.
}
}
@Test
public void testAccessor() {
final Incrementor i = new Incrementor();
i.setMaximalCount(10);
Assert.assertEquals(10, i.getMaximalCount());
Assert.assertEquals(0, i.getCount());
}
@Test
public void testBelowMaxCount() {
final Incrementor i = new Incrementor();
i.setMaximalCount(3);
i.incrementCount();
i.incrementCount();
i.incrementCount();
Assert.assertEquals(3, i.getCount());
}
@Test(expected=MaxCountExceededException.class)
public void testAboveMaxCount() {
final Incrementor i = new Incrementor();
i.setMaximalCount(3);
i.incrementCount();
i.incrementCount();
i.incrementCount();
i.incrementCount();
}
@Test(expected=TooManyEvaluationsException.class)
public void testAlternateException() {
final Incrementor.MaxCountExceededCallback cb
= new Incrementor.MaxCountExceededCallback() {
/** {@inheritDoc} */
@Override
public void trigger(int max) {
throw new TooManyEvaluationsException(max);
}
};
final Incrementor i = new Incrementor(0, cb);
i.incrementCount();
}
@Test
public void testReset() {
final Incrementor i = new Incrementor();
i.setMaximalCount(3);
i.incrementCount();
i.incrementCount();
i.incrementCount();
Assert.assertEquals(3, i.getCount());
i.resetCount();
Assert.assertEquals(0, i.getCount());
}
@Test
public void testBulkIncrement() {
final Incrementor i = new Incrementor();
i.setMaximalCount(3);
i.incrementCount(2);
Assert.assertEquals(2, i.getCount());
i.incrementCount(1);
Assert.assertEquals(3, i.getCount());
}
}