Skip to content

Instantly share code, notes, and snippets.

View theboreddev's full-sized avatar
💭
💻

The Bored Dev theboreddev

💭
💻
View GitHub Profile
package com.theboreddev.springbootapp
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.util.UriComponentsBuilder
@RestController
@RequestMapping("/api/customers")
@theboreddev
theboreddev / Processor.java
Created July 1, 2020 06:21
interface interface
public interface Processor {
Integer process(List<Integer> input) throws InterruptedException;
}
private static final NavigableMap<Integer, String> ROMAN_NUMERALS = new TreeMap<>() {
{
put(1, "I");
put(4, "IV");
put(5, "V");
put(9, "IX");
put(10, "X");
put(50, "L");
put(100, "C");
put(500, "D");
@theboreddev
theboreddev / FakeSocialMediaServiceTest.java
Created June 16, 2020 20:37
FakeSocialMediaServiceTest
import org.junit.Test;
import java.time.LocalTime;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Lists.emptyList;
CompletableFuture<Void> chain = new CompletableFuture<>();
chain.thenComposeAsync(nil -> createUser())
.thenAcceptAsync(logNewUserId())
.thenComposeAsync(nil ->
registerAddress()
.thenAcceptBothAsync(registerPaymentDetails(), (address, paymentDetailsSuccess) -> {
System.out.println("Registered address was : " + address);
System.out.println("Registered payment details success : " + paymentDetailsSuccess);
})
CompletableFuture<String> subTask = new CompletableFuture<>();
CompletableFuture<Result> chain = CompletableFuture.runAsync(() -> System.out.println("Start"))
.thenCombine(subTask, (nil, text) -> {
if (text == null || text.isEmpty())
throw new IllegalArgumentException("Text cannot be null or empty!");
return Result.COMPLETED;
})
.completeOnTimeout(Result.TIMEOUT, 500, TimeUnit.MILLISECONDS)
.exceptionally(exception -> Result.FAILED);
package com.theboreddev.examples.forkjoin;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveTask;
public class ForkJoinExample {
public static void main(String[] args) {
final Collection<Employee> employees = List.of(
new Employee("Karen Smith", 51200.0, 29, Employee.Sex.FEMALE),
new Employee("John Smith", 24000.0, 32, Employee.Sex.MALE),
new Employee("Anthony Jackson", 44000.0, 33, Employee.Sex.MALE),
new Employee("Alyson Palmer", 34320.0, 36, Employee.Sex.FEMALE),
new Employee("Jessica Sanders", 64320.0, 34, Employee.Sex.FEMALE)
);
final Map<Employee.Sex, List<Employee>> employeesBySex = employees.stream()
.collect(groupingBy(Employee::getSex));
final Map<Employee.Sex, Set<Employee>> employeesBySex = employees.stream()
.collect(groupingBy(Employee::getSex, toSet()));