Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please take a look at the todo part and help with the following code! Thank you so much! package fp; import java.math.BigDecimal; import java.util.ArrayList; import

Please take a look at the todo part and help with the following code! Thank you so much!
package fp;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;
import java.util.function.
*
;
import java.util.stream.Collectors;
import java.util.List;
class ExerciseNotCompletedException extends RuntimeException
{
public ExerciseNotCompletedException
(
)
{
super
(
"
Exercise is not completed yet"
)
;
}
}
/
*
*
*
{
@link HW
}
is an exercise class. Each method returns a functional interface and it should be implemented
*
using either lambda or a method reference. Every method that is not implemented yet throws
*
{
@link ExerciseNotCompletedException
}
.
*
*
TODO: remove exception and implement each method of this class using lambda or method reference
*
/**
* Returns a {@link BiFunction} which first parameter is a {@link Map} where key is a function name, and value is some
*{@link IntUnaryOperator}, and second parameter is a {@link String} which is a function name. If the map contains a
* function by a given name then it is returned by high order function otherwise an identity() is returned.
*
* @return a high-order function that fetches a function from a function map by a given name or returns identity()
*/
public static BiFunction, String, IntUnaryOperator> functionLoader(){
throw new ExerciseNotCompletedException();
}
/**
* Returns a comparator of type T that is comparing values extracted using the provided mapper function.
*
* E.g. imagine you need to compare accounts by their balance values.
*
* PLEASE NOTE, that @{@link Comparator} is a functional interface, and you should manually write a lambda expression
* to implement it.
*
* @param mapper a mapper function that allows to map an object to a comparable value
* @return a comparator instance
*/
public static > Comparator comparing(Function mapper){
throw new ExerciseNotCompletedException();
}
/**
* Returns a comparator of type T that uses a provided comparator to compare objects, and only if they are equal
* it's comparing values extracted using the provided mapper function.
*
* E.g. suppose you want to compare accounts by balance, but in case two people have the same balance you want to
* compare their first names:
*
*
* @param comparator an initial comparator
* @param mapper a mapper function that is used to extract values when initial comparator returns zero
* @return a comparator instance
*/
public static > Comparator thenComparing(
Comparator comparator, Function mapper){
throw new ExerciseNotCompletedException();
}
/**
* Returns {@link Supplier} of {@link Supplier} of {@link Supplier} of {@link String} "WELL DONE!".
*
* @return a supplier instance
*/
public static Supplier>> trickyWellDoneSupplier(){
throw new ExerciseNotCompletedException();
}
public static void main(String[] args){
ArrayList l = new ArrayList<>();
l.add("a");
l.add("bc");
l.add("dcf");
System.out.println(map(l,(String x)->{ return x.length();}));
// U = String, V = Integer [1,2,3]
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

explain the concept of strategy formulation

Answered: 1 week ago