Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 11, 2024
1 parent bc8ad80 commit 7ec4e0c
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/collections4/Closure.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* {@link ClosureUtils}. These include method invocation and for/while loops.
* </p>
*
* @param <T> the type that the closure acts on
* @param <T> the type of the input to the operation.
* @since 1.0
* @deprecated Use {@link Consumer}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
* }
* </pre>
*
* @param <T> the type of the input to the operation.
* @since 4.0
*/
public abstract class CatchAndRethrowClosure<E> implements Closure<E> {
public abstract class CatchAndRethrowClosure<T> implements Closure<T> {

/**
* Execute this closure on the specified input object.
Expand All @@ -55,7 +56,7 @@ public abstract class CatchAndRethrowClosure<E> implements Closure<E> {
* checked exception.
*/
@Override
public void execute(final E input) {
public void execute(final T input) {
try {
executeAndThrow(input);
} catch (final RuntimeException ex) {
Expand All @@ -72,5 +73,5 @@ public void execute(final E input) {
* @throws Throwable if the closure execution resulted in a checked
* exception.
*/
protected abstract void executeAndThrow(E input) throws Throwable;
protected abstract void executeAndThrow(T input) throws Throwable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
/**
* Closure implementation that chains the specified closures together.
*
* @param <T> the type of the input to the operation.
* @since 3.0
*/
public class ChainedClosure<E> implements Closure<E>, Serializable {
public class ChainedClosure<T> implements Closure<T>, Serializable {

/** Serial version UID */
private static final long serialVersionUID = -3520677225766901240L;
Expand Down Expand Up @@ -77,15 +78,15 @@ public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<?
}

/** The closures to call in turn */
private final Closure<? super E>[] iClosures;
private final Closure<? super T>[] iClosures;

/**
* Hidden constructor for the use by the static factory methods.
*
* @param clone if {@code true} the input argument will be cloned
* @param closures the closures to chain, no nulls
*/
private ChainedClosure(final boolean clone, final Closure<? super E>... closures) {
private ChainedClosure(final boolean clone, final Closure<? super T>... closures) {
iClosures = clone ? FunctorUtils.copy(closures) : closures;
}

Expand All @@ -95,7 +96,7 @@ private ChainedClosure(final boolean clone, final Closure<? super E>... closures
*
* @param closures the closures to chain, copied, no nulls
*/
public ChainedClosure(final Closure<? super E>... closures) {
public ChainedClosure(final Closure<? super T>... closures) {
this(true, closures);
}

Expand All @@ -105,8 +106,8 @@ public ChainedClosure(final Closure<? super E>... closures) {
* @param input the input object passed to each closure
*/
@Override
public void execute(final E input) {
for (final Closure<? super E> iClosure : iClosures) {
public void execute(final T input) {
for (final Closure<? super T> iClosure : iClosures) {
iClosure.accept(input);
}
}
Expand All @@ -117,7 +118,7 @@ public void execute(final E input) {
* @return a copy of the closures
* @since 3.1
*/
public Closure<? super E>[] getClosures() {
public Closure<? super T>[] getClosures() {
return FunctorUtils.copy(iClosures);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
/**
* Closure implementation that always throws an exception.
*
* @param <T> the type of the input to the operation.
* @since 3.0
*/
public final class ExceptionClosure<E> implements Closure<E>, Serializable {
public final class ExceptionClosure<T> implements Closure<T>, Serializable {

/** Serial version UID */
private static final long serialVersionUID = 7179106032121985545L;
Expand All @@ -38,11 +39,11 @@ public final class ExceptionClosure<E> implements Closure<E>, Serializable {
/**
* Factory returning the singleton instance.
*
* @param <E> the type that the closure acts on
* @param <T> the type of the input to the operation.
* @return the singleton instance
* @since 3.1
*/
public static <E> Closure<E> exceptionClosure() {
public static <T> Closure<T> exceptionClosure() {
return INSTANCE;
}

Expand All @@ -59,7 +60,7 @@ private ExceptionClosure() {
* @throws FunctorException always
*/
@Override
public void execute(final E input) {
public void execute(final T input) {
throw new FunctorException("ExceptionClosure invoked");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
* for more details.
* </p>
*
* @param <T> the type of the input to the operation.
* @since 3.0
*/
public class ForClosure<E> implements Closure<E> {
public class ForClosure<T> implements Closure<T> {

/**
* Factory method that performs validation.
Expand All @@ -56,7 +57,7 @@ public static <E> Closure<E> forClosure(final int count, final Closure<? super E
private final int iCount;

/** The closure to call */
private final Closure<? super E> iClosure;
private final Closure<? super T> iClosure;

/**
* Constructor that performs no validation.
Expand All @@ -65,7 +66,7 @@ public static <E> Closure<E> forClosure(final int count, final Closure<? super E
* @param count the number of times to execute the closure
* @param closure the closure to execute, not null
*/
public ForClosure(final int count, final Closure<? super E> closure) {
public ForClosure(final int count, final Closure<? super T> closure) {
iCount = count;
iClosure = closure;
}
Expand All @@ -76,7 +77,7 @@ public ForClosure(final int count, final Closure<? super E> closure) {
* @param input the input object
*/
@Override
public void execute(final E input) {
public void execute(final T input) {
for (int i = 0; i < iCount; i++) {
iClosure.accept(input);
}
Expand All @@ -88,7 +89,7 @@ public void execute(final E input) {
* @return the closure
* @since 3.1
*/
public Closure<? super E> getClosure() {
public Closure<? super T> getClosure() {
return iClosure;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
* Closure implementation acts as an if statement calling one or other closure
* based on a predicate.
*
* @param <T> the type of the input to the operation.
* @since 3.0
*/
public class IfClosure<E> implements Closure<E>, Serializable {
public class IfClosure<T> implements Closure<T>, Serializable {

/** Serial version UID */
private static final long serialVersionUID = 3518477308466486130L;
Expand Down Expand Up @@ -67,13 +68,13 @@ public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate,
Objects.requireNonNull(falseClosure, "falseClosure"));
}
/** The test */
private final Predicate<? super E> iPredicate;
private final Predicate<? super T> iPredicate;

/** The closure to use if true */
private final Closure<? super E> iTrueClosure;
private final Closure<? super T> iTrueClosure;

/** The closure to use if false */
private final Closure<? super E> iFalseClosure;
private final Closure<? super T> iFalseClosure;

/**
* Constructor that performs no validation.
Expand All @@ -86,7 +87,7 @@ public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate,
* @param trueClosure closure used if true, not null
* @since 3.2
*/
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure) {
public IfClosure(final Predicate<? super T> predicate, final Closure<? super T> trueClosure) {
this(predicate, trueClosure, NOPClosure.nopClosure());
}

Expand All @@ -98,8 +99,8 @@ public IfClosure(final Predicate<? super E> predicate, final Closure<? super E>
* @param trueClosure closure used if true, not null
* @param falseClosure closure used if false, not null
*/
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure,
final Closure<? super E> falseClosure) {
public IfClosure(final Predicate<? super T> predicate, final Closure<? super T> trueClosure,
final Closure<? super T> falseClosure) {
iPredicate = predicate;
iTrueClosure = trueClosure;
iFalseClosure = falseClosure;
Expand All @@ -111,7 +112,7 @@ public IfClosure(final Predicate<? super E> predicate, final Closure<? super E>
* @param input the input object
*/
@Override
public void execute(final E input) {
public void execute(final T input) {
if (iPredicate.test(input)) {
iTrueClosure.accept(input);
} else {
Expand All @@ -125,7 +126,7 @@ public void execute(final E input) {
* @return the closure
* @since 3.1
*/
public Closure<? super E> getFalseClosure() {
public Closure<? super T> getFalseClosure() {
return iFalseClosure;
}

Expand All @@ -135,7 +136,7 @@ public Closure<? super E> getFalseClosure() {
* @return the predicate
* @since 3.1
*/
public Predicate<? super E> getPredicate() {
public Predicate<? super T> getPredicate() {
return iPredicate;
}

Expand All @@ -145,7 +146,7 @@ public Predicate<? super E> getPredicate() {
* @return the closure
* @since 3.1
*/
public Closure<? super E> getTrueClosure() {
public Closure<? super T> getTrueClosure() {
return iTrueClosure;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
/**
* Closure implementation that does nothing.
*
* @param <T> the type of the input to the operation.
* @since 3.0
*/
public final class NOPClosure<E> implements Closure<E>, Serializable {
public final class NOPClosure<T> implements Closure<T>, Serializable {

/** Serial version UID */
private static final long serialVersionUID = 3518477308466486130L;
Expand Down Expand Up @@ -57,7 +58,7 @@ private NOPClosure() {
* @param input the input object
*/
@Override
public void execute(final E input) {
public void execute(final T input) {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
* Closure implementation calls the closure whose predicate returns true,
* like a switch statement.
*
* @param <T> the type of the input to the operation.
* @since 3.0
*/
public class SwitchClosure<E> implements Closure<E>, Serializable {
public class SwitchClosure<T> implements Closure<T>, Serializable {

/** Serial version UID */
private static final long serialVersionUID = 3518477308466486130L;
Expand Down Expand Up @@ -98,13 +99,13 @@ public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicat
return new SwitchClosure<>(predicates, closures, defaultClosure);
}
/** The tests to consider */
private final Predicate<? super E>[] iPredicates;
private final Predicate<? super T>[] iPredicates;

/** The matching closures to call */
private final Closure<? super E>[] iClosures;
private final Closure<? super T>[] iClosures;

/** The default closure to call if no tests match */
private final Closure<? super E> iDefault;
private final Closure<? super T> iDefault;

/**
* Hidden constructor for the use by the static factory methods.
Expand All @@ -114,11 +115,11 @@ public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicat
* @param closures matching array of closures, no nulls
* @param defaultClosure the closure to use if no match, null means nop
*/
private SwitchClosure(final boolean clone, final Predicate<? super E>[] predicates,
final Closure<? super E>[] closures, final Closure<? super E> defaultClosure) {
private SwitchClosure(final boolean clone, final Predicate<? super T>[] predicates,
final Closure<? super T>[] closures, final Closure<? super T> defaultClosure) {
iPredicates = clone ? FunctorUtils.copy(predicates) : predicates;
iClosures = clone ? FunctorUtils.copy(closures) : closures;
iDefault = defaultClosure == null ? NOPClosure.<E>nopClosure() : defaultClosure;
iDefault = defaultClosure == null ? NOPClosure.<T>nopClosure() : defaultClosure;
}

/**
Expand All @@ -129,8 +130,8 @@ private SwitchClosure(final boolean clone, final Predicate<? super E>[] predicat
* @param closures matching array of closures, cloned, no nulls
* @param defaultClosure the closure to use if no match, null means nop
*/
public SwitchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures,
final Closure<? super E> defaultClosure) {
public SwitchClosure(final Predicate<? super T>[] predicates, final Closure<? super T>[] closures,
final Closure<? super T> defaultClosure) {
this(true, predicates, closures, defaultClosure);
}

Expand All @@ -140,7 +141,7 @@ public SwitchClosure(final Predicate<? super E>[] predicates, final Closure<? su
* @param input the input object
*/
@Override
public void execute(final E input) {
public void execute(final T input) {
for (int i = 0; i < iPredicates.length; i++) {
if (iPredicates[i].test(input)) {
iClosures[i].accept(input);
Expand All @@ -156,7 +157,7 @@ public void execute(final E input) {
* @return a copy of the closures
* @since 3.1
*/
public Closure<? super E>[] getClosures() {
public Closure<? super T>[] getClosures() {
return FunctorUtils.copy(iClosures);
}

Expand All @@ -166,7 +167,7 @@ public Closure<? super E>[] getClosures() {
* @return the default closure
* @since 3.1
*/
public Closure<? super E> getDefaultClosure() {
public Closure<? super T> getDefaultClosure() {
return iDefault;
}

Expand All @@ -176,7 +177,7 @@ public Closure<? super E> getDefaultClosure() {
* @return a copy of the predicates
* @since 3.1
*/
public Predicate<? super E>[] getPredicates() {
public Predicate<? super T>[] getPredicates() {
return FunctorUtils.copy(iPredicates);
}

Expand Down
Loading

0 comments on commit 7ec4e0c

Please sign in to comment.