Permalink
Browse files

[GSCOLLECT-620] Replace all instances of ProcedureWithInt with Object…

…IntProcedure

git-svn-id: svn+ssh://gscollections.svn.services.gs.com/svnroot/gscollections-svn/trunk@12 d5c9223b-1aff-41ac-aadd-f810b4a99ac4
  • Loading branch information...
1 parent 108b5ba commit d9e55c40e64ff6b428c72fe3598c24d7edf17086 Donald Raab committed Feb 8, 2012
Showing with 99 additions and 43 deletions.
  1. +1 −1 collections-api/src/main/java/com/gs/collections/api/bag/Bag.java
  2. +1 −1 collections-api/src/main/java/com/gs/collections/api/list/ListIterable.java
  3. +3 −3 collections/src/main/java/com/gs/collections/impl/block/factory/Functions.java
  4. +9 −0 collections/src/main/java/com/gs/collections/impl/block/factory/Procedures.java
  5. +1 −1 collections/src/main/java/com/gs/collections/impl/block/procedure/IfObjectIntProcedure.java
  6. +28 −0 collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/IntIntProcedure.java
  7. +5 −2 collections/src/main/java/com/gs/collections/impl/block/procedure/primitive/IntProcedureWithInt.java
  8. +21 −5 collections/src/main/java/com/gs/collections/impl/list/Interval.java
  9. +1 −1 collections/src/main/java/com/gs/collections/impl/list/mutable/CompositeFastList.java
  10. +1 −1 collections/src/main/java/com/gs/collections/impl/parallel/ObjectIntProcedureFactory.java
  11. +5 −5 collections/src/main/java/com/gs/collections/impl/parallel/ParallelIterate.java
  12. +1 −1 collections/src/main/java/com/gs/collections/impl/parallel/PassThruObjectIntProcedureFactory.java
  13. +1 −1 collections/src/main/java/com/gs/collections/impl/utility/ArrayListIterate.java
  14. +4 −4 collections/src/main/java/com/gs/collections/impl/utility/ListIterate.java
  15. +5 −5 collections/src/main/java/com/gs/collections/impl/utility/internal/RandomAccessListIterate.java
  16. +1 −1 serialization-tests/src/test/java/com/gs/collections/impl/block/factory/ProceduresTest.java
  17. +5 −5 unit-tests/src/test/java/com/gs/collections/impl/block/CheckedBlocksTest.java
  18. +1 −1 unit-tests/src/test/java/com/gs/collections/impl/block/procedure/ObjectIntProceduresTest.java
  19. +2 −2 unit-tests/src/test/java/com/gs/collections/impl/block/procedure/ProceduresTest.java
  20. +1 −1 unit-tests/src/test/java/com/gs/collections/impl/block/procedure/checked/CheckedProcedureTest.java
  21. +2 −2 unit-tests/src/test/java/com/gs/collections/impl/parallel/ObjectIntProcedureFJTaskRunnerTest.java
@@ -81,7 +81,7 @@
* <p/>
* <pre>
* final IntegerSum sum = new IntegerSum(0);
- * this.forEachWithOccurrences(new ProcedureWithInt<T>()
+ * this.forEachWithOccurrences(new ObjectIntProcedure<T>()
* {
* public void value(T each, int count)
* {
@@ -64,7 +64,7 @@
* <p/>
* <pre>e.g.
* ListIterable<People> people = FastList.newListWith(ted, mary, bob, sally)
- * people.forEachWithIndex(0, 1, new ProcedureWithInt<Person>()
+ * people.forEachWithIndex(0, 1, new ObjectIntProcedure<Person>()
* {
* public void value(Person person, int index)
* {
@@ -285,11 +285,11 @@ public void value(T1 each)
}
/**
- * Bind the input of a ProcedureWithInt to the result of an function, returning a new ProcedureWithInt.
+ * Bind the input of a ObjectIntProcedure to the result of an function, returning a new ObjectIntProcedure.
*
- * @param delegate The ProcedureWithInt to delegate the invocation to.
+ * @param delegate The ObjectIntProcedure to delegate the invocation to.
* @param function The Function that will create the input for the delegate
- * @return A new ProcedureWithInt
+ * @return A new ObjectIntProcedure
*/
public static <T1, T2> ObjectIntProcedure<T1> bind(
final ObjectIntProcedure<? super T2> delegate,
@@ -45,7 +45,16 @@ private Procedures()
return new AppendProcedure<T>(appendable);
}
+ /**
+ * @deprecated since 1.2 - Inlineable
+ */
+ @Deprecated
public static <T> Procedure<T> fromProcedureWithInt(ObjectIntProcedure<? super T> objectIntProcedure)
+ {
+ return Procedures.fromObjectIntProcedure(objectIntProcedure);
+ }
+
+ public static <T> Procedure<T> fromObjectIntProcedure(ObjectIntProcedure<? super T> objectIntProcedure)
{
return new ObjectIntProcedureAdapter<T>(objectIntProcedure);
}
@@ -22,7 +22,7 @@
import com.gs.collections.impl.Counter;
/**
- * A conditional ProcedureWithInt that effectively filters which objects should be used
+ * A conditional ObjectIntProcedure that effectively filters which objects should be used
*/
public final class IfObjectIntProcedure<T>
implements Procedure<T>
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011 Goldman Sachs.
+ *
+ * Licensed 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 com.gs.collections.impl.block.procedure.primitive;
+
+import java.io.Serializable;
+
+/**
+ * An IntIntProcedure is a two argument Closure which has no return argument and takes an int as the first and
+ * second arguments.
+ */
+public interface IntIntProcedure extends Serializable
+{
+ void value(int each, int index);
+}
@@ -19,9 +19,12 @@
import java.io.Serializable;
/**
- * A ProcedureWithInt is a single argument Closure which has no return argument and takes an int as a second
- * argument which is usually the index of the current element of a collection.
+ * A IntProcedureWithInt is a two argument Closure which has no return argument and takes an int as a first and second
+ * argument. The second argument is usually the index of the current element of a collection.
+ *
+ * @deprecated since 1.2 use {@link IntIntProcedure}
*/
+@Deprecated
public interface IntProcedureWithInt extends Serializable
{
void value(int each, int index);
@@ -45,6 +45,7 @@
import com.gs.collections.impl.block.procedure.CollectionAddProcedure;
import com.gs.collections.impl.block.procedure.RejectProcedure;
import com.gs.collections.impl.block.procedure.SelectProcedure;
+import com.gs.collections.impl.block.procedure.primitive.IntIntProcedure;
import com.gs.collections.impl.block.procedure.primitive.IntObjectProcedure;
import com.gs.collections.impl.block.procedure.primitive.IntProcedure;
import com.gs.collections.impl.block.procedure.primitive.IntProcedureWithInt;
@@ -379,28 +380,43 @@ private void failIfOutOfFactorialRange()
}
}
- public void forEachWithIndex(IntProcedureWithInt procedureWithInt1)
+ /**
+ * @deprecated since 1.2 - Use {@link #forEachWithIndex(IntIntProcedure)}
+ */
+ @Deprecated
+ public void forEachWithIndex(final IntProcedureWithInt procedureWithInt)
+ {
+ this.forEachWithIndex(new IntIntProcedure()
+ {
+ public void value(int each, int index)
+ {
+ procedureWithInt.value(each, index);
+ }
+ });
+ }
+
+ public void forEachWithIndex(IntIntProcedure procedure)
{
int index = 0;
if (this.from <= this.to)
{
for (int i = this.from; i <= this.to; i += this.step)
{
- procedureWithInt1.value(i, index++);
+ procedure.value(i, index++);
}
}
else
{
for (int i = this.from; i >= this.to; i += this.step)
{
- procedureWithInt1.value(i, index++);
+ procedure.value(i, index++);
}
}
}
public void forEachWithIndex(final ObjectIntProcedure<? super Integer> objectIntProcedure)
{
- this.forEachWithIndex(new IntProcedureWithInt()
+ this.forEachWithIndex(new IntIntProcedure()
{
public void value(int each, int index)
{
@@ -801,7 +817,7 @@ public void value(Integer each, int index)
public int[] toIntArray()
{
final int[] result = new int[this.size()];
- this.forEachWithIndex(new IntProcedureWithInt()
+ this.forEachWithIndex(new IntIntProcedure()
{
public void value(int each, int index)
{
@@ -187,7 +187,7 @@ public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? su
}
else
{
- this.optimizedForwardForEach(Procedures.fromProcedureWithInt(objectIntProcedure), fromIndex, toIndex);
+ this.optimizedForwardForEach(Procedures.fromObjectIntProcedure(objectIntProcedure), fromIndex, toIndex);
}
}
@@ -19,7 +19,7 @@
import com.gs.collections.api.block.procedure.ObjectIntProcedure;
/**
- * ObjectIntProcedureFactory is used by parallel iterators as a factory for stateful ProcedureWithInt instances.
+ * ObjectIntProcedureFactory is used by parallel iterators as a factory for stateful ObjectIntProcedure instances.
*/
public interface ObjectIntProcedureFactory<T extends ObjectIntProcedure<?>>
{
@@ -73,12 +73,12 @@ static void shutdownExecutor()
/**
* Iterate over the collection specified, in parallel batches using default runtime parameter values. The
- * {@code ProcedureWithInt} used must be stateless, or use concurrent aware objects if they are to be shared.
+ * {@code ObjectIntProcedure} used must be stateless, or use concurrent aware objects if they are to be shared.
* <p/>
* e.g.
* <pre>
* {@code final Map<Integer,Object> chm = new ConcurrentHashMap<Integer,Object>();}
- * ParallelIterate.<b>forEachWithIndex</b>(collection, new ProcedureWithInt()
+ * ParallelIterate.<b>forEachWithIndex</b>(collection, new ObjectIntProcedure()
* {
* public void value(Object object, int index)
* {
@@ -96,12 +96,12 @@ static void shutdownExecutor()
/**
* Iterate over the collection specified in parallel batches using the default runtime parameters. The
- * ProcedureWithInt used must be stateless, or use concurrent aware objects if they are to be shared. The code
+ * ObjectIntProcedure used must be stateless, or use concurrent aware objects if they are to be shared. The code
* is executed against the specified executor.
* <p/>
* <pre>e.g.
* {@code final Map<Integer,Object> chm = new ConcurrentHashMap<Integer,Object>();}
- * ParallelIterate.<b>forEachWithIndex</b>(collection, new ProcedureWithInt()
+ * ParallelIterate.<b>forEachWithIndex</b>(collection, new ObjectIntProcedure()
* {
* public void value(Object object, int index)
* {
@@ -124,7 +124,7 @@ static void shutdownExecutor()
/**
* Iterate over the collection specified in parallel batches. The
- * ProcedureWithInt used must be stateless, or use concurrent aware objects if they are to be shared. The
+ * ObjectIntProcedure used must be stateless, or use concurrent aware objects if they are to be shared. The
* specified minimum fork size and task count are used instead of the default values.
*
* @param minForkSize Only run in parallel if input collection is longer than this.
@@ -19,7 +19,7 @@
import com.gs.collections.api.block.procedure.ObjectIntProcedure;
/**
- * This class acts as a no op factory for a ProcedureWithInt which gets passed in and returned out.
+ * This class acts as a no op factory for a ObjectIntProcedure which gets passed in and returned out.
*/
public final class PassThruObjectIntProcedureFactory<BT extends ObjectIntProcedure<?>> implements ObjectIntProcedureFactory<BT>
{
@@ -438,7 +438,7 @@ private ArrayListIterate()
/**
* Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
* from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the
- * list is iterated in the reverse order. The index passed into the ProcedureWithInt is the actual index of the
+ * list is iterated in the reverse order. The index passed into the ObjectIntProcedure is the actual index of the
* range.
* <p/>
* <p/>
@@ -323,7 +323,7 @@ private ListIterate()
}
/**
- * Interates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
+ * Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
* from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the
* list is iterated in the reverse order.
* <p/>
@@ -371,15 +371,15 @@ private ListIterate()
}
/**
- * Interates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
+ * Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
* from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the
- * list is iterated in the reverse order. The index passed into the ProcedureWithInt is the actual index of the
+ * list is iterated in the reverse order. The index passed into the ObjectIntProcedure is the actual index of the
* range.
* <p/>
* <p/>
* <pre>e.g.
* MutableList<People> people = FastList.newListWith(ted, mary, bob, sally);
- * ListIterate.forEachWithIndex(people, 0, 1, new ProcedureWithInt<Person>()
+ * ListIterate.forEachWithIndex(people, 0, 1, new ObjectIntProcedure<Person>()
* {
* public void value(Person person, int index)
* {
@@ -327,7 +327,7 @@ private RandomAccessListIterate()
}
/**
- * Interates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
+ * Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
* from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the
* list is iterated in the reverse order.
* <p/>
@@ -368,15 +368,15 @@ private RandomAccessListIterate()
}
/**
- * Interates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
+ * Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the
* from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the
- * list is iterated in the reverse order. The index passed into the ProcedureWithInt is the actual index of the
+ * list is iterated in the reverse order. The index passed into the ObjectIntProcedure is the actual index of the
* range.
* <p/>
* <p/>
* <pre>e.g.
* MutableList<People> people = FastList.newListWith(ted, mary, bob, sally);
- * ListIterate.forEachWithIndex(people, 0, 1, new ProcedureWithInt<Person>()
+ * ListIterate.forEachWithIndex(people, 0, 1, new ObjectIntProcedure<Person>()
* {
* public void value(Person person, int index)
* {
@@ -435,7 +435,7 @@ private RandomAccessListIterate()
/**
* Iterates over a collection passing each element and the current relative int index to the specified instance of
- * ProcedureWithInt.
+ * ObjectIntProcedure.
*/
public static <T> void forEachWithIndex(List<T> list, ObjectIntProcedure<? super T> objectIntProcedure)
{
@@ -63,6 +63,6 @@ public void asProcedure()
+ "T2JqZWN0SW50UHJvY2VkdXJlQWRhcHRlcgAAAAAAAAABAgACSQAFY291bnRMABJvYmplY3RJbnRQ\n"
+ "cm9jZWR1cmV0ADtMY29tL2dzL2NvbGxlY3Rpb25zL2FwaS9ibG9jay9wcm9jZWR1cmUvT2JqZWN0\n"
+ "SW50UHJvY2VkdXJlO3hwAAAAAHA=",
- Procedures.fromProcedureWithInt(null));
+ Procedures.fromObjectIntProcedure(null));
}
}
@@ -167,7 +167,7 @@ public void safeValue(String object)
}
@Test
- public void checkedProcedureWithIntCheckedException()
+ public void checkedObjectIntProcedureCheckedException()
{
Verify.assertThrowsWithCause(RuntimeException.class, IOException.class, new Runnable()
{
@@ -187,7 +187,7 @@ public void safeValue(String object, int index) throws IOException
}
@Test
- public void checkedProcedureWithIntRuntimeException()
+ public void checkedObjectIntProcedureRuntimeException()
{
Verify.assertThrows(LocalException.class, new Runnable()
{
@@ -467,7 +467,7 @@ public void safeValue(Object object)
}
@Test(expected = RuntimeException.class)
- public void procedureWithIntFailure()
+ public void objectIntProcedureFailure()
{
ObjectIntProcedure<Object> block = new CheckedObjectIntProcedure<Object>()
{
@@ -481,7 +481,7 @@ public void safeValue(Object object, int index) throws InterruptedException
}
@Test(expected = RuntimeException.class)
- public void procedureWithIntRuntimeException()
+ public void objectIntProcedureRuntimeException()
{
ObjectIntProcedure<Object> block = new CheckedObjectIntProcedure<Object>()
{
@@ -495,7 +495,7 @@ public void safeValue(Object object, int index)
}
@Test
- public void procedureWithIntSuccess()
+ public void objectIntProcedureSuccess()
{
ObjectIntProcedure<Object> block = new CheckedObjectIntProcedure<Object>()
{
@@ -25,7 +25,7 @@
public class ObjectIntProceduresTest
{
@Test
- public void fromProcedureWithInt()
+ public void fromObjectIntProcedure()
{
CollectionAddProcedure<Integer> procedure = CollectionAddProcedure.on(FastList.<Integer>newList());
ObjectIntProcedure<Integer> objectIntProcedure = ObjectIntProcedures.fromProcedure(procedure);
@@ -69,7 +69,7 @@ public void append()
}
@Test
- public void fromProcedureWithInt()
+ public void fromObjectIntProcedure()
{
ImmutableList<String> expectedResults = Lists.immutable.of("zero0", "one1", "two2");
@@ -83,7 +83,7 @@ public void value(String each, int index)
};
ImmutableList<String> numberStrings = Lists.immutable.of("zero", "one", "two");
- Procedure procedure = Procedures.fromProcedureWithInt(objectIntProcedure);
+ Procedure procedure = Procedures.fromObjectIntProcedure(objectIntProcedure);
numberStrings.forEach(procedure);
Assert.assertEquals(expectedResults, actualResults);
@@ -74,7 +74,7 @@ public void safeValue(Map<String, String> map)
}
@Test
- public void checkedProcedureWithInt()
+ public void checkedObjectIntProcedure()
{
boolean success = false;
try
Oops, something went wrong.

0 comments on commit d9e55c4

Please sign in to comment.