Skip to content

Commit

Permalink
[GSCOLLECT-620] Replace all instances of ProcedureWithInt with Object…
Browse files Browse the repository at this point in the history
…IntProcedure

git-svn-id: svn+ssh://gscollections.svn.services.gs.com/svnroot/gscollections-svn/trunk@12 d5c9223b-1aff-41ac-aadd-f810b4a99ac4
  • Loading branch information
Donald Raab committed Feb 8, 2012
1 parent 108b5ba commit d9e55c4
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 43 deletions.
Expand Up @@ -81,7 +81,7 @@ public interface Bag<T>
* <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)
* {
Expand Down
Expand Up @@ -64,7 +64,7 @@ public interface ListIterable<T>
* <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)
* {
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -45,7 +45,16 @@ public static <T> Procedure<T> append(Appendable appendable)
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);
}
Expand Down
Expand Up @@ -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>
Expand Down
@@ -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);
}
Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Expand Up @@ -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);
}
}

Expand Down
Expand Up @@ -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<?>>
{
Expand Down
Expand Up @@ -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)
* {
Expand All @@ -96,12 +96,12 @@ public static <T> void forEachWithIndex(

/**
* 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)
* {
Expand All @@ -124,7 +124,7 @@ public static <T, BT extends ObjectIntProcedure<? super T>> void forEachWithInde

/**
* 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.
Expand Down
Expand Up @@ -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>
{
Expand Down
Expand Up @@ -438,7 +438,7 @@ public static <T> void forEach(ArrayList<T> list, int from, int to, Procedure<?
/**
* 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/>
Expand Down
Expand Up @@ -323,7 +323,7 @@ public static <T> void reverseForEach(List<T> list, Procedure<? super T> procedu
}

/**
* 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/>
Expand Down Expand Up @@ -371,15 +371,15 @@ public static <T> void forEach(List<T> list, int from, int to, Procedure<? super
}

/**
* 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)
* {
Expand Down
Expand Up @@ -327,7 +327,7 @@ public static <T> void forEach(List<T> list, Procedure<? super T> procedure)
}

/**
* 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/>
Expand Down Expand Up @@ -368,15 +368,15 @@ public static <T> void forEach(List<T> list, int from, int to, Procedure<? super
}

/**
* 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)
* {
Expand Down Expand Up @@ -435,7 +435,7 @@ public static <T1, T2> void forEachInBoth(List<T1> list1, List<T2> list2, Proced

/**
* 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)
{
Expand Down
Expand Up @@ -63,6 +63,6 @@ public void asProcedure()
+ "T2JqZWN0SW50UHJvY2VkdXJlQWRhcHRlcgAAAAAAAAABAgACSQAFY291bnRMABJvYmplY3RJbnRQ\n"
+ "cm9jZWR1cmV0ADtMY29tL2dzL2NvbGxlY3Rpb25zL2FwaS9ibG9jay9wcm9jZWR1cmUvT2JqZWN0\n"
+ "SW50UHJvY2VkdXJlO3hwAAAAAHA=",
Procedures.fromProcedureWithInt(null));
Procedures.fromObjectIntProcedure(null));
}
}
Expand Up @@ -167,7 +167,7 @@ public void safeValue(String object)
}

@Test
public void checkedProcedureWithIntCheckedException()
public void checkedObjectIntProcedureCheckedException()
{
Verify.assertThrowsWithCause(RuntimeException.class, IOException.class, new Runnable()
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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>()
{
Expand All @@ -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>()
{
Expand All @@ -495,7 +495,7 @@ public void safeValue(Object object, int index)
}

@Test
public void procedureWithIntSuccess()
public void objectIntProcedureSuccess()
{
ObjectIntProcedure<Object> block = new CheckedObjectIntProcedure<Object>()
{
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -69,7 +69,7 @@ public void append()
}

@Test
public void fromProcedureWithInt()
public void fromObjectIntProcedure()
{
ImmutableList<String> expectedResults = Lists.immutable.of("zero0", "one1", "two2");

Expand All @@ -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);
Expand Down
Expand Up @@ -74,7 +74,7 @@ public void safeValue(Map<String, String> map)
}

@Test
public void checkedProcedureWithInt()
public void checkedObjectIntProcedure()
{
boolean success = false;
try
Expand Down

0 comments on commit d9e55c4

Please sign in to comment.