Questions tagged [supplier]

70 questions
0
votes
1 answer

Still getting "stream has already been operated upon or closed" error

I'm reading lines from a txt file trying to get two lines at once (current and next). I use Supplier, but still get the error. Stream lines = Files.lines(Paths.get(fileName)); Supplier> streamSupplier = () ->…
0
votes
3 answers

Java Supplier<> get origins information

I Use the Supplier in my code to call restTemplate and make the custom Message when have exception.. But, im my message, i need get information by my requestCall, But when i cast the request the java thow error ... My code: public void execute()…
0
votes
1 answer

Correct use of Java 8 supplier consumer

I'm still strugling with Suppliers and Consumers for Java 8, I have this: final Set roles = new HashSet<>(); user.getRoleGroups().forEach(rg -> rg.getRoles().forEach(r -> roles.add(r.getName()))); To get a Set from role names that are…
Leandro Diniz
  • 63
  • 1
  • 1
  • 4
0
votes
1 answer

How to find the percentage of a single product of a supplier's total revenue?

There are multiple suppliers and each has sold multiple products. How would I find the percentage of the revenue of one of their products against that supplier's total sales in SQL? Here is an example of data I have to work…
0
votes
0 answers

Make java supplier return a value using side effect

I have a java suppler that returns a Student pojo like so: @Bean public Supplier studentSupplier() { return () -> new Student(); } Now I want to make this supplier returns a Student pojo after an entry is created using…
java_doctor_101
  • 3,287
  • 4
  • 46
  • 78
0
votes
1 answer

Supplier INT returning the value that I enter + Predicate that tells if the number I enter is prime or not

I have the next task: Write a Supplier of type that returns a number read by screen with a block lambda expression Write a Predicate that tells us if the entered number is a prime with a block expression that has a for loop. Apply it to the…
Clavillo
  • 1
  • 2
0
votes
1 answer

System.out.println doesn't work on a supplied Stream?

I'm still new to Java, and especially new to Suppliers, but I can't figure out why I can't get any output from the following code: final BufferedReader brLines = new BufferedReader(new InputStreamReader(csvFile)); final…
kn0wmad1c
  • 110
  • 10
0
votes
0 answers

Cast Supplier to Supplier java

I have an Interface IParent, an abstract class implementing it AbstractChild and a class extending the abstract class ConcreteChild. One other class Foo requires an instance of a Supplier. My problem is that I have an instance of a…
Kostas Thanasis
  • 368
  • 4
  • 11
0
votes
2 answers

How can I read a character from an InputStream and return it in a Supplier (Java)

So I have a method I need to implement. It gets an InputStream and returns a Supplier like this: public Supplier buildPipe(InputStream input) Now I want to read a character from the InputStream (probably with the read()-method) and return…
Sir0
  • 3
  • 3
0
votes
3 answers

Supplier interface for constructor reference

the following code Supplier newString = String::new; System.out.println(newString.get()); // prints an empty string (nothing) to the console and then a newline character and for the definition of Supplier get method T get() the get method…
user1169587
  • 1,104
  • 2
  • 17
  • 34
0
votes
1 answer

How can we create an instance for Supplier as it is an Interface?

I am trying to understand Supplier interface. I understand that it can return an object if we invoke its get() method. However, in the following example: public class SupplierExample { public static void main(String[] args) { …
Sukh
  • 424
  • 5
  • 16
0
votes
3 answers

Java - How to read a file twice using buffer reader or use stream twice

How to read file twice eihher using buffer reader or using stream twice ??? That I need manipulate large amounts of data in the code, so the performance needs to be considered. Sample code 1 below, gives exception "stream closed" - Url url =…
user10386436
0
votes
3 answers

JAVA-STREAM : re-use double a DoubleStream

I need a trick to solve this problem i'm using Java 1.8 And I retrieved a an object from a method that returns a DoubleStream object. So, the problem is I could not reuse the stream after it has been consumed. Here is the first version of the code…
Rodik
  • 271
  • 2
  • 19
0
votes
0 answers

The constructed object of type xxx is incompatible with the descriptor's return type: T

I am trying to build a Collector class that will summarize my results into a TreeMap. I am having trouble using a generic type for the accumulator/results. The problem occurs in the definition of my supplier method. My class currently looks like…
Ben
  • 31
  • 3
0
votes
3 answers

How to define a BiFunction using a Supplier as Fallback to produce some objects?

What's wrong with this code? I need to create a factory method which is dependend on a BiFunction to fulfil it's job . The compiler told me: The method apply(Class, Supplier) in the type BiFunction,Supplier,T> is not applicable…
motte
  • 51
  • 3