11package com .bobocode ;
22
33import java .math .BigDecimal ;
4+ import java .util .concurrent .ThreadLocalRandom ;
45import java .util .function .*;
56
67public class CrazyLambdas {
@@ -11,7 +12,7 @@ public class CrazyLambdas {
1112 * @return a string supplier
1213 */
1314 public static Supplier <String > helloSupplier () {
14- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
15+ return () -> "Hello" ;
1516 }
1617
1718 /**
@@ -20,7 +21,7 @@ public static Supplier<String> helloSupplier() {
2021 * @return a string predicate
2122 */
2223 public static Predicate <String > isEmptyPredicate () {
23- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
24+ return String :: isEmpty ;
2425 }
2526
2627 /**
@@ -30,7 +31,7 @@ public static Predicate<String> isEmptyPredicate() {
3031 * @return function that converts adds dollar sign
3132 */
3233 public static Function <BigDecimal , String > toDollarStringFunction () {
33- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
34+ return bigDecimal -> "$" + bigDecimal ;
3435 }
3536
3637 /**
@@ -42,7 +43,7 @@ public static Function<BigDecimal, String> toDollarStringFunction() {
4243 * @return a string predicate
4344 */
4445 public static Predicate <String > lengthInRangePredicate (int min , int max ) {
45- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
46+ return str -> str . length () >= min && str . length () < max ;
4647 }
4748
4849 /**
@@ -51,7 +52,7 @@ public static Predicate<String> lengthInRangePredicate(int min, int max) {
5152 * @return int supplier
5253 */
5354 public static IntSupplier randomIntSupplier () {
54- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
55+ return () -> ThreadLocalRandom . current (). nextInt ();
5556 }
5657
5758
@@ -61,7 +62,7 @@ public static IntSupplier randomIntSupplier() {
6162 * @return int operation
6263 */
6364 public static IntUnaryOperator boundedRandomIntSupplier () {
64- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
65+ return bound -> ThreadLocalRandom . current (). nextInt ( bound );
6566 }
6667
6768 /**
@@ -70,7 +71,7 @@ public static IntUnaryOperator boundedRandomIntSupplier() {
7071 * @return square operation
7172 */
7273 public static IntUnaryOperator intSquareOperation () {
73- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
74+ return a -> a * a ;
7475 }
7576
7677 /**
@@ -79,7 +80,7 @@ public static IntUnaryOperator intSquareOperation() {
7980 * @return binary sum operation
8081 */
8182 public static LongBinaryOperator longSumOperation () {
82- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
83+ return ( a , b ) -> a + b ;
8384 }
8485
8586 /**
@@ -88,7 +89,7 @@ public static LongBinaryOperator longSumOperation() {
8889 * @return string to int converter
8990 */
9091 public static ToIntFunction <String > stringToIntConverter () {
91- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
92+ return Integer :: parseInt ;
9293 }
9394
9495 /**
@@ -99,9 +100,10 @@ public static ToIntFunction<String> stringToIntConverter() {
99100 * @return a function supplier
100101 */
101102 public static Supplier <IntUnaryOperator > nMultiplyFunctionSupplier (int n ) {
102- throw new UnsupportedOperationException ( "It's your job to implement this method" ); // todo
103+ return () -> a -> n * a ;
103104 }
104105
105106
106107}
107108
109+
0 commit comments