This file contains 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.soverby.test; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Semaphore; | |
import java.util.concurrent.locks.ReentrantLock; | |
import java.util.stream.IntStream; | |
public class ThrottledExecutor { |
This file contains 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.soverby.test; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.concurrent.Semaphore; | |
import java.util.concurrent.locks.ReentrantLock; | |
public class AccessPool<T> { |
This file contains 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.soverby.test; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.UUID; | |
import java.util.function.Consumer; | |
import java.util.function.Supplier; | |
import static java.lang.String.format; |
This file contains 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 org.apache.http.client.config.RequestConfig; | |
import org.apache.http.impl.client.CloseableHttpClient; | |
import org.apache.http.impl.client.HttpClientBuilder; | |
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class ClientHttpPoolConfiguration { |
This file contains 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
// Example of a fully imperative approach to writing Java code... | |
public class FullyImperative { | |
// @Inject | |
private final ItemRepository itemRepository; | |
// @Inject | |
private final InventoryLocationRepostitory inventoryLocationRepostitory; | |
// Find the first available InventoryLocation for a given item id. | |
public InventoryLocation itemByFirstAvailable(String itemId) |
This file contains 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
// Somewhere on the road from imperative to functional... | |
public class PartiallyImperative { | |
// @Inject | |
private ItemRepository itemRepository; | |
// @Inject | |
private InventoryLocationRepostitory; | |
// Optionally return inventory location with available inventory for item with the given id | |
public Optional<InventoryLocation> itemByFirstAvailable(String itemId) throws NotFoundException { |
This file contains 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
// And finally a functional example of the find location with non-zero inventory for item example | |
public class Functional { | |
// @Inject | |
private ItemRepository itemRepository; | |
// @Inject | |
private InventoryLocationRepostitory inventoryLocationRepostitory; | |
// Monadic approach, composed behaviors | |
// "The monad represents computations with a sequential structure: a monad defines what it means to chain operations together." |
This file contains 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 OptionalChaining { | |
public static void main(String[] args) { | |
OptionalChaining optionalChaining = new OptionalChaining(); | |
optionalChaining.happyPath(); | |
optionalChaining.nullInput(); | |
optionalChaining.thereBeNullsHereOne(); | |
optionalChaining.thereBeNullsHereTwo(); | |
} | |
// Happy path with a pipeline that doesn't return nulls |
This file contains 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 OptionalChainingComposed { | |
public static void main(String[] args) { | |
OptionalChainingComposed optionalChaining = new OptionalChainingComposed(); | |
optionalChaining.happyPath(); | |
optionalChaining.nullInput(); | |
} | |
public void happyPath() { | |
nonNullPipeline("happyPath") |
This file contains 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.function.BiFunction; | |
import java.util.function.Consumer; | |
import java.util.function.Supplier; | |
public class JavaLambdaSyntax { | |
private Consumer<String> stringConsumer; | |
private Supplier<String> stringSupplier; | |
private BiFunction<String, String, String> stringBiFunction; |
OlderNewer