Skip to content

Instantly share code, notes, and snippets.

Avatar

Trisha Gee trishagee

View GitHub Profile
View Page99.java
List.of(manager1, manager2).stream()
.flatMap(m ->
Stream.concat(m.getEmployeeList().stream(), Stream.of(m)))
.distinct()
.mapToInt(Employee::getYearlySalary)
.sum();
View tutorial-reactive-spring-1-c-initial-rest-controller
@RestController
class RestController(val priceService: PriceService) {
fun prices(@PathVariable symbol: String): Flux<StockPrice> {
}
}
@trishagee
trishagee / tutorial-reactive-spring-1-a-kotlin-app
Created Oct 21, 2019
Default Spring Boot Kotlin application
View tutorial-reactive-spring-1-a-kotlin-app
package com.mechanitis.demo.stockservice
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class StockServiceApplication
fun main(args: Array<String>) {
runApplication<StockServiceApplication>(*args)
@trishagee
trishagee / CityAndPhone.java
Last active Jan 4, 2017
Refactoring to pipelines, Java
View CityAndPhone.java
public static class CityAndPhone {
private String city;
private String phone;
public CityAndPhone(String city, String phone) {
this.city = city;
this.phone = phone;
}
View Exercise32_Oracle.java
static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream stream = IntStream.range(0, LIST_SIZE);
if (parallel) {
stream = stream.parallel(); // Convert the stream to a parallel one
}
stream.forEach(i -> {
View Exercise32_4.java
static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Supplier<Stream<String>> streamSupplier = () -> wordList.stream();
Stream<String> stream = streamSupplier.get();
if (true == parallel) {
stream = stream.parallel();
}
View Exercise32_3.java
public static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream range = range(0, LIST_SIZE * LIST_SIZE);
if (parallel) {
range.parallel();
}
View Exercise32_2.java
public static int[][] computeLevenshteinAugustin(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Stream<String> wordStream = wordList.stream();
if (parallel) {
wordStream.parallel();
}
wordStream.forEach(word -> {
int wordIndex = wordList.indexOf(word);
View Exercise32_1.java
public static int[][] computeLevenshteinHector(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Stream<String> wordStream = wordList.stream();
if (parallel) {
wordStream.parallel();
}
distances = wordStream.map(word -> IntStream.range(0, LIST_SIZE)
.map(i -> lesson3b.Levenshtein.lev(word, wordList.get(i)))
View BadLambdas.java
package com.mechanitis.talks.stayingahead;
import com.mongodb.DBCollection;
import org.mongojack.JacksonDBCollection;
import org.mongojack.WriteResult;
import javax.ws.rs.core.Response;
import java.net.URI;
public class BadLambdas {