Questions tagged [supplier]

70 questions
0
votes
0 answers

Unsing Java's Supplier interface to facilitate mock behavior for unit tests

I recently had to refactor a class [X] and improve its unit test and in doing so discovered that in order to get full coverage of the class from the tests I was going to need to mock out the behaviour of 3 different components of the class. For…
Chris Danson
  • 247
  • 4
  • 13
0
votes
1 answer

How to create a "Custom Injection Provider" (factory) without jersey

Is there a way to achieve the same result described here not depending on jersey but pure jax-rs? I'd like to create a Custom Injection Provider like Jersey so I can inject MyClass extracting custom data from HttpServletRequest @Inject protected…
RegRog
  • 373
  • 2
  • 12
-1
votes
1 answer

Supplier Functional Interface

As we know Consumer functional interface is used in forEach() so similarly does Java has a use case for Supplier other than the custom ones?
-1
votes
1 answer

Convert from Boolean to BooleanSupplier

I have this function a: public void a(BooleanSupplier param){} that is called by function b: public void b(Boolean param){ a(param) } The problem is that function "a" is expecting a BooleanSupplier but function b is sending a Boolean. I think I…
Catarina Nogueira
  • 1,024
  • 2
  • 12
  • 28
-1
votes
1 answer

Reusing Stream by Supplier

I need to use one stream mutliple times. I tried something like this: public static void main(String[] args) { Stream stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7, 8}); Supplier> saved =…
-2
votes
1 answer

Turning a Map into a SortedMap with different keys

im having a hard time understanding Maps and i was asked to make a SortedMap with a different key and value out of another map using a comparator and a supplier. Its said to us that the "teams" key is the name of a team and the value is the…
-2
votes
1 answer

Enum factory using Java 8 supplier

I am trying to create objects (implement factory pattern) using Java 8 lambda and Supplier interface. public static void main(final String[] args) { FactoryEnum.getEnumByClassName("CLASS_A").getSupplier().execute(); …
Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
-2
votes
2 answers

How do I create a supplier of a class with limitations regarding constructor arguments?

I have a class called Human (accepts name(string) and height(int) in the constructor) and need too create a supplier of this class that will create an object but I want the object's name to let's say be between 5-10 characters, and the height should…
-3
votes
1 answer

Correct way to apply different fucntions based on condition in stream

What would be the correct way to implement this functional logic with streams? Stream through list of items Check if condition 1 passes, if so apply function 1 to the item. Check if condition 2 passes, if so apply function 2 to the item. If both…
ems19
  • 23
  • 6
-3
votes
2 answers

Create new Objects based on a String with Java Stream

i m playing around with Java Streams and I wonder if there is any way to create a code Block like this -> if(givenString.equals("productA")) { return new productA(); } else if(givenString.equals("productB") { return new productB(); }…
user11998955
  • 17
  • 1
  • 5
1 2 3 4
5