This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis.clients.jedis.Jedis; | |
import java.util.List; | |
import java.util.Random; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class RedisQueueConsumer { | |
public static void main(String[] args) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis.clients.jedis.Jedis; | |
import java.util.Scanner; | |
public class RedisQueueProducer { | |
public static void main(String[] args) { | |
Jedis jedis = new Jedis("localhost"); | |
Scanner scanIn = new Scanner(System.in); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.TimeoutException; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
public class CompletableFutureTimeoutUnEfficientWay { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.samples; | |
import java.util.*; | |
import java.util.function.BinaryOperator; | |
import java.util.function.Function; | |
import java.util.stream.Collectors; | |
import static java.util.stream.Collectors.*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Worker w1 = new Worker ("w1", 181, 81); | |
Worker w2 = new Worker ("w2", 182, 82); | |
Worker w3 = new Worker ("w3", 183, 83); | |
Worker w4 = null; | |
Worker w5 = new Worker ("w5", 185, 85); | |
List<Optional<Worker>> workerList = new ArrayList<> (); | |
workerList.add (Optional.ofNullable (w1)); | |
workerList.add (Optional.ofNullable (w2)); | |
workerList.add (Optional.ofNullable (w3)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.samples.optional; | |
import com.company.samples.way10.Worker; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Optional; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Predicate<T>-- T in ,boolean out | |
Predicate<Man> richManMatcher = m->m.getCashAmount () > 1000000; | |
if (richManMatcher.test (someMan)) { | |
marryWithRichMan (someMan); | |
} | |
Function<T,R> -- Tin, R out | |
Function<Worker,Integer> salaryIncreaser = w->w.getSalary () + 500; | |
for (Worker worker: workers){ | |
worker.setSalary (salaryIncreaser.apply(worker)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StateManager stateManager = new StateManager(); | |
stateManager.addNewStateListener( | |
(oldState, newState) -> System.out.println("State changed") | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StateManager { | |
public void addNewStateListener(StateChangeListener listener) { //blahh } | |
} |
NewerOlder