make list function descriptions follow a pattern

This commit is contained in:
Jonathan Shook 2020-07-07 11:40:26 -05:00
parent 0de0cc7d69
commit 6a22d411a0
6 changed files with 53 additions and 44 deletions

View File

@ -13,10 +13,13 @@ import java.util.function.LongFunction;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
/** /**
* Create a {@code List} from a long input * Create a List from a long input based on a set of provided functions.
* based on list of functions without any size boundaries, *
* each function in the list functions populate the list with * As a 'Pair-wise' function, the size of the resulting collection is determined directly by the
* object value. * number of provided element functions.
*
* As neither a 'Stepped' nor a 'Hashed' function, the input value used by each element function is the same
* as that provided to the outer function.
*/ */
@Categories({Category.collections}) @Categories({Category.collections})
@ThreadSafeMapper @ThreadSafeMapper
@ -26,8 +29,8 @@ public class ListFunctions implements LongFunction<java.util.List<Object>> {
private final int size; private final int size;
@Example({ @Example({
"ListFunctions(NumberNameToString(),NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString(),NumberNameToString())",
"Create a list of object values of each function output. ListFunctions output ['one','one','one']" "Create a list of object values of each function output. Produces values like ['one','one','one']"
}) })
public ListFunctions(LongFunction<? extends Object>... funcs) { public ListFunctions(LongFunction<? extends Object>... funcs) {
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
@ -43,9 +46,9 @@ public class ListFunctions implements LongFunction<java.util.List<Object>> {
this.size = building.size(); this.size = building.size();
} }
public ListFunctions(Function<Long,Object>... funcs) { public ListFunctions(Function<Long, Object>... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (Function<Long,Object> func : funcs) { for (Function<Long, Object> func : funcs) {
building.add(func::apply); building.add(func::apply);
} }
this.valueFuncs = building; this.valueFuncs = building;

View File

@ -15,10 +15,12 @@ import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
/** /**
* Create a {@code List} from a long input * Create a List from a long input based on a set of provided functions.
* based on pseudo-randomly hash list of functions without any size boundaries, *
* each function in the list functions populate the hash list with * As a 'Pair-wise' function, the size of the resulting collection is determined directly by the
* object value. * number of provided element functions.
*
* As a 'Hashed' function, the input value is hashed again before being used by each element function.
*/ */
@Categories({Category.collections}) @Categories({Category.collections})
@ThreadSafeMapper @ThreadSafeMapper
@ -29,8 +31,8 @@ public class ListHashed implements LongFunction<List<Object>> {
private final Hash hasher = new Hash(); private final Hash hasher = new Hash();
@Example({ @Example({
"ListHashed(long->ToString(), long->WeightedStrings('text:1'))", "ListHashed(ToString(), WeightedStrings('text:1'))",
"Create a hash list of object values of each function output. ListHashed output ['2945182322382062539','text']" "Create a hash list of object values of each function output. ListHashed output ['2945182322382062539','text']"
}) })
public ListHashed(LongFunction<? extends Object>... funcs) { public ListHashed(LongFunction<? extends Object>... funcs) {
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
@ -46,9 +48,9 @@ public class ListHashed implements LongFunction<List<Object>> {
this.size = building.size(); this.size = building.size();
} }
public ListHashed(Function<Long,Object>... funcs) { public ListHashed(Function<Long, Object>... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (Function<Long,Object> func : funcs) { for (Function<Long, Object> func : funcs) {
building.add(func::apply); building.add(func::apply);
} }
this.valueFuncs = building; this.valueFuncs = building;

View File

@ -14,10 +14,14 @@ import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
/** /**
* Create a {@code List} from a long input * Create a List from a long input based on a set of provided functions.
* based on at least two functions, the first function to *
* determine the list functions size, and the remaining functions onwards to populate * As a 'Sized' function, the first argument is a function which determines the size of the resulting list.
* the list with object values till the end of the list size. * Additional functions provided are used to generate the elements to add to the collection. If the size
* is larger than the number of provided functions, the last provided function is used repeatedly as needed.
*
* As neither a 'Stepped' nor a 'Hashed' function, the input value used by each element function is the same
* as that provided to the outer function.
*/ */
@Categories({Category.collections}) @Categories({Category.collections})
@ThreadSafeMapper @ThreadSafeMapper
@ -27,10 +31,10 @@ public class ListSized implements LongFunction<List<Object>> {
private final LongToIntFunction sizeFunc; private final LongToIntFunction sizeFunc;
@Example({ @Example({
"ListSized(FixedValue(5), NumberNameToString(),NumberNameToString(), WeightedStrings('text:1'))", "ListSized(FixedValue(5), NumberNameToString(),NumberNameToString(), WeightedStrings('text:1'))",
"Create a sized list of object values of each function output. List size function will recursively call the last function till" + "Create a sized list of object values of each function output. List size function will recursively call the last function till" +
"end of the list size functions", "end of the list size functions",
"ListSized output ['one','one','text','text','text']" "ListSized output ['one','one','text','text','text']"
}) })
public ListSized(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) { public ListSized(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
@ -46,9 +50,9 @@ public class ListSized implements LongFunction<List<Object>> {
this.valueFuncs = building; this.valueFuncs = building;
} }
public ListSized(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) { public ListSized(LongToIntFunction sizeFunc, Function<Long, Object>... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (Function<Long,Object> func : funcs) { for (Function<Long, Object> func : funcs) {
building.add(func::apply); building.add(func::apply);
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;

View File

@ -15,10 +15,13 @@ import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
/** /**
* Create a {@code List} from a long input * Create a List from a long input based on a set of provided functions.
* based on at least two functions, the first function to *
* determine the list functions size, and the remaining functions onwards to populate * As a 'Sized' function, the first argument is a function which determines the size of the resulting list.
* the list with object values till the end of the list size. * Additional functions provided are used to generate the elements to add to the collection. If the size
* is larger than the number of provided functions, the last provided function is used repeatedly as needed.
*
* As a 'Hashed' function, the input value is hashed again before being used by each element function.
*/ */
@Categories({Category.collections}) @Categories({Category.collections})
@ThreadSafeMapper @ThreadSafeMapper

View File

@ -15,14 +15,13 @@ import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
/** /**
* Create a {@code List} from a long input * Create a List from a long input based on a set of provided functions.
* based on two functions, the first to
* determine the list size, and the second to populate the list with
* object values. The input fed to the second function is incremented
* between elements.
* *
* To directly create Lists of Strings from the String version of the same * As a 'Sized' function, the first argument is a function which determines the size of the resulting list.
* mapping functions, simply use {@link StringList} instead. * Additional functions provided are used to generate the elements to add to the collection. If the size
* is larger than the number of provided functions, the last provided function is used repeatedly as needed.
*
* As a 'Stepped' function, the input value is incremented before being used by each element function.
*/ */
@Categories({Category.collections}) @Categories({Category.collections})
@ThreadSafeMapper @ThreadSafeMapper

View File

@ -14,14 +14,12 @@ import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator; import java.util.function.LongUnaryOperator;
/** /**
* Create a {@code List} from a long input * Create a List from a long input based on a set of provided functions.
* based on two functions, the first to
* determine the list size, and the second to populate the list with
* object values. The input fed to the second function is incremented
* between elements.
* *
* To directly create Lists of Strings from the String version of the same * As a 'Pair-wise' function, the size of the resulting collection is determined directly by the
* mapping functions, simply use {@link StringList} instead. * number of provided element functions.
*
* As a 'Stepped' function, the input value is incremented before being used by each element function.
*/ */
@Categories({Category.collections}) @Categories({Category.collections})
@ThreadSafeMapper @ThreadSafeMapper