All Questions
22 questions
1
vote
0
answers
61
views
Do I need declare as volatile the supplier class member in order to preserve thread-safety
I am reading this book "Functional Programming in Java Harnessing the Power Of Java 8 Lambda Expressions" and in chapter 6 (lazy evaluations) there's an example of heavy object creation. ...
0
votes
2
answers
77
views
How to call a function that will create an object of a class if required?
Context:
I've found a bug in a selenium framework I'm working on, in which the Web Browser (at least Chrome) crashes unexpectedly with no notification.
As a patch, I'm reinitializing the WebDriver so ...
1
vote
1
answer
584
views
How to wrap a command inside if-else statements with same condition used in many places
I have a class with many public methods. Each method executes a single task when a single condition is met. The conditions in all methods are exactly the same as seen below:
public class MyClass{
...
2
votes
2
answers
354
views
How to deal with multiple choices based on value (enum) using strategy or functional interfaces?
I am dealing with a case when I have an enum:
public enum CurrencyType {
BTC, ETH
}
A pojo:
public class Challenge {
private final String walletAddress;
private final CurrencyType ...
1
vote
1
answer
101
views
How to implement this in functional programming using Function<T,R> in Java
I have a scenario which in imperative programming would like this
processEvent(Event event) {
if ( isEventOfSpecificType(event) ){ .............................................. 1
Result ...
1
vote
2
answers
1k
views
Creating a parser of Class name + String value to a typed value
I am trying to write a method that can take in a String classname and a String value, and return the value represented as that String.
Example inputs:
parse("java.lang.String", "abc") -> String ...
-2
votes
2
answers
180
views
Holding a Map of functions with differing number of args
I am trying to write a utility class that can take in a String and Class<?> and return back an Object that is really the typed instance of that String.
For example, if I have string "FALSE" ...
4
votes
2
answers
578
views
I am trying to implement the strategy design pattern in the below snippet using Java 8 .Looking for better ways to implement?
I have below service implementation :-
package Java8.controller;
import java.util.function.Function;
public class ServiceImpl implements ITicket {
Function<Integer,Double> ticketCal;
...
4
votes
1
answer
215
views
How to build a custom intermediate operation pipeline in Java for a series of API calls?
I am working on a project which provides a list of operations to be done on an entity, and each operation is an API call to the backend. Let's say the entity is a file, and operations are convert, ...
2
votes
2
answers
286
views
Functional class level arguments in Java 8
I would like to make more of an effort to use Java 8's functional features and shift my thinking towards that paradigm; however, I'm not quite sure how to reconcile this scenario.
For example I ...
0
votes
0
answers
360
views
Trying to use Java lambda expression in a MVC example , don't know if there is more I can do?
The MVC example below comes from Head First Design Patterns book .
This MVC example focus on the observer pattern (between Model & View/Controller)
and the strategy pattern(Controller is Strategy)...
0
votes
2
answers
562
views
How to handle multiple exception raising statements elegantly in Scala
I am building a map structure by extracting 30-40 keys from unstructured text rows from messy csv data. i am extracting using regex on this messy data row , lot of time those values are not there so ...
9
votes
4
answers
3k
views
Functional Programming: How to handle exceptions in Functional Programming or what is its equivalent
Let's say, I've the below code.
public int divide(int dividend, int divisor) {
if( divisor == 0 || (dividend == Integer.MIN_VALUE && divisor == -1))
throw new ...
1
vote
1
answer
162
views
Functional programming interfaces in Java
Where can I look for a list of Java standard libraries for functional design patterns? I've heard java.util package contain all of data structures, but I can't find the equivalents of functional ...
6
votes
3
answers
1k
views
Filtering with truth tables
Imagine a Person class with a boolean flag indicating whether or not the person is employable - set to false by default.
public class Person{
boolean employable = false;
...
}
Now imagine ...