|
| 1 | +package com.bobocode.lambdas; |
| 2 | + |
| 3 | +import com.bobocode.util.ExerciseNotCompletedException; |
| 4 | + |
| 5 | +import java.math.BigDecimal; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.function.*; |
| 8 | + |
| 9 | +public class CrazyLambdas { |
| 10 | + |
| 11 | + /** |
| 12 | + * Returns {@link Supplier} that always supply "Hello" |
| 13 | + * |
| 14 | + * @return a string supplier |
| 15 | + */ |
| 16 | + public static Supplier<String> helloSupplier() { |
| 17 | + throw new ExerciseNotCompletedException(); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * Returns a {@link Predicate} of string that checks if string is empty |
| 22 | + * |
| 23 | + * @return a string predicate |
| 24 | + */ |
| 25 | + public static Predicate<String> isEmptyPredicate() { |
| 26 | + throw new ExerciseNotCompletedException(); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Return a {@link Function} that accepts {@link String} and returns that string repeated n time, where n is passed |
| 31 | + * as function argument |
| 32 | + * |
| 33 | + * @return function that repeats Strings |
| 34 | + */ |
| 35 | + public static BiFunction<String, Integer, String> stringMultiplier() { |
| 36 | + throw new ExerciseNotCompletedException(); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Returns a {@link Function} that converts a {@link BigDecimal} number into a {@link String} that start with |
| 41 | + * a dollar sign and then gets a value |
| 42 | + * |
| 43 | + * @return function that converts adds dollar sign |
| 44 | + */ |
| 45 | + public static Function<BigDecimal, String> toDollarStringFunction() { |
| 46 | + throw new ExerciseNotCompletedException(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Receives two parameter that represent a range and returns a {@link Predicate<String>} that verifies if string |
| 51 | + * length is in the specified range. E.g. min <= length < max |
| 52 | + * |
| 53 | + * @param min min length |
| 54 | + * @param max max length |
| 55 | + * @return a string predicate |
| 56 | + */ |
| 57 | + public static Predicate<String> lengthInRangePredicate(int min, int max) { |
| 58 | + throw new ExerciseNotCompletedException(); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Returns a {@link Supplier} of random integers |
| 63 | + * |
| 64 | + * @return int supplier |
| 65 | + */ |
| 66 | + public static IntSupplier randomIntSupplier() { |
| 67 | + throw new ExerciseNotCompletedException(); |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns an {@link IntUnaryOperator} that receives an int as a bound parameter, and returns a random int |
| 73 | + * |
| 74 | + * @return int operation |
| 75 | + */ |
| 76 | + public static IntUnaryOperator boundedRandomIntSupplier() { |
| 77 | + throw new ExerciseNotCompletedException(); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Returns {@link IntUnaryOperator} that calculates an integer square |
| 82 | + * |
| 83 | + * @return square operation |
| 84 | + */ |
| 85 | + public static IntUnaryOperator intSquareOperation() { |
| 86 | + throw new ExerciseNotCompletedException(); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns a {@link LongBinaryOperator} sum operation. |
| 91 | + * |
| 92 | + * @return binary sum operation |
| 93 | + */ |
| 94 | + public static LongBinaryOperator longSumOperation() { |
| 95 | + throw new ExerciseNotCompletedException(); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns a {@link ToIntFunction<String>} that converts string to integer. |
| 100 | + * |
| 101 | + * @return string to int converter |
| 102 | + */ |
| 103 | + public static ToIntFunction<String> stringToIntConverter() { |
| 104 | + throw new ExerciseNotCompletedException(); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Receives int parameter n, and returns a {@link Supplier} that supplies {@link IntUnaryOperator} |
| 109 | + * that is a function f(x) = n * x |
| 110 | + * |
| 111 | + * @param n a multiplier |
| 112 | + * @return a function supplier |
| 113 | + */ |
| 114 | + public static Supplier<IntUnaryOperator> nMultiplyFunctionSupplier(int n) { |
| 115 | + throw new ExerciseNotCompletedException(); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Returns a {@link UnaryOperator} that accepts str to str function and returns the same function composed with trim |
| 120 | + * |
| 121 | + * @return function that composes functions with trim() function |
| 122 | + */ |
| 123 | + public static UnaryOperator<Function<String, String>> composeWithTrimFunction() { |
| 124 | + throw new ExerciseNotCompletedException(); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Receives a {@link Runnable} parameter, and returns a {@link Supplier<Thread>}. The thread will be started only |
| 129 | + * when you call supplier method {@link Supplier#get()} |
| 130 | + * |
| 131 | + * @param runnable the code you want to tun in new thread |
| 132 | + * @return a thread supplier |
| 133 | + */ |
| 134 | + public static Supplier<Thread> runningThreadSupplier(Runnable runnable) { |
| 135 | + throw new ExerciseNotCompletedException(); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Returns a {@link Consumer} that accepts {@link Runnable} as a parameter and runs in in a new thread. |
| 140 | + * |
| 141 | + * @return a runnable consumer |
| 142 | + */ |
| 143 | + public static Consumer<Runnable> newThreadRunnableConsumer() { |
| 144 | + throw new ExerciseNotCompletedException(); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Returns a {@link Function} that accepts an instance of {@link Runnable} and returns a {@link Supplier} of a |
| 149 | + * started {@link Thread} that is created from a given {@link Runnable} |
| 150 | + * |
| 151 | + * @return a function that transforms runnable into a thread supplier |
| 152 | + */ |
| 153 | + public static Function<Runnable, Supplier<Thread>> runnableToThreadSupplierFunction() { |
| 154 | + throw new ExerciseNotCompletedException(); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Returns a {@link BiFunction} that has two parameters. First is {@link IntUnaryOperator} which is some integer function. |
| 159 | + * Second is {@link IntPredicate} which is some integer condition. And the third is {@link IntUnaryOperator} which is |
| 160 | + * a new composed function that uses provided predicate (second parameter of binary function) to verify its input |
| 161 | + * parameter. If predicate returns {@code true} it applies a provided integer function |
| 162 | + * (first parameter of binary function) and returns a result value, otherwise it returns an element itself. |
| 163 | + * |
| 164 | + * @return a binary function that receiver predicate and function and compose them to create a new function |
| 165 | + */ |
| 166 | + public static BiFunction<IntUnaryOperator, IntPredicate, IntUnaryOperator> functionToConditionalFunction() { |
| 167 | + throw new ExerciseNotCompletedException(); |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Returns a {@link BiFunction} which first parameter is a {@link Map} where key is a function name, and value is some |
| 172 | + * {@link IntUnaryOperator}, and second parameter is a {@link String} which is a function name. If the map contains a |
| 173 | + * function by a given name then it is returned by high order function otherwise an identity() is returned. |
| 174 | + * |
| 175 | + * @return a high-order function that fetches a function from a function map by a given name or returns identity() |
| 176 | + */ |
| 177 | + public static BiFunction<Map<String, IntUnaryOperator>, String, IntUnaryOperator> functionLoader() { |
| 178 | + throw new ExerciseNotCompletedException(); |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Returns {@link Supplier} of {@link Supplier} of {@link Supplier} of {@link String} "WELL DONE". |
| 183 | + * |
| 184 | + * @return a supplier instance |
| 185 | + */ |
| 186 | + public static Supplier<Supplier<Supplier<String>>> trickyWellDoneSupplier() { |
| 187 | + throw new ExerciseNotCompletedException(); |
| 188 | + } |
| 189 | +} |
| 190 | + |
0 commit comments