| JGL - The Generic Collection Library for Java |
All Packages Class Hierarchy This Package Previous Next Index
Class com.objectspace.jgl.algorithms.Applying
java.lang.Object
|
+----com.objectspace.jgl.algorithms.Applying
- public final class Applying
- extends Object
The Applying class contains generic applying algorithms.
- See Also:
- Applying examples
-
forEach(Container, UnaryFunction)
- Apply a unary function to every element in a container.
-
forEach(InputIterator, InputIterator, UnaryFunction)
- Apply a unary function to every element in a specified range.
-
inject(Container, Object, BinaryFunction)
- Inject a container with a binary function and an initial value.
-
inject(InputIterator, InputIterator, Object, BinaryFunction)
- Inject a specified range with a binary function and an initial value.
forEach
public static UnaryFunction forEach(InputIterator first,
InputIterator last,
UnaryFunction function)
- Apply a unary function to every element in a specified range.
The time complexity is linear and the space complexity is constant.
- Parameters:
- first - An iterator positioned at the first element in the range.
- last - An iterator positioned immediately after the last element in the range.
- function - The unary function to apply.
- Returns:
- The unary function.
- Throws: IllegalArgumentException
- If the iterators are incompatible.
forEach
public static UnaryFunction forEach(Container container,
UnaryFunction function)
- Apply a unary function to every element in a container.
The time complexity is linear and the space complexity is constant.
- Parameters:
- container - The container.
- function - The unary function to apply.
- Returns:
- The unary function.
inject
public static Object inject(InputIterator first,
InputIterator last,
Object object,
BinaryFunction function)
- Inject a specified range with a binary function and an initial value.
Calculate the initial result by calling the function with the initial value as the
first parameter and the first element as the second parameter. Then apply the function
to the remaining elements, using the previous result as the first parameter and the
next element as the second parameter. Return the last result.
- Parameters:
- first - An iterator positioned at the first element in the range.
- last - An iterator positioned immediately after the last element in the range.
- object - An object to use as a starting result to the binary function.
- function - A binary function.
- Returns:
- The result of the last binary function call.
- Throws: IllegalArgumentException
- If the iterators are incompatible.
inject
public static Object inject(Container container,
Object object,
BinaryFunction function)
- Inject a container with a binary function and an initial value.
Calculate the initial result by calling the function with the initial value as the
first parameter and the first element as the second parameter. Then apply the function
to the remaining elements, using the previous result as the first parameter and the
next element as the second parameter. Return the last result.
- Parameters:
- container - A container.
- object - An object to use as a starting result to the binary function.
- function - A binary function.
- Returns:
- The result of the last binary function call.
All Packages Class Hierarchy This Package Previous Next Index