Skip to content

Instantly share code, notes, and snippets.

Avatar

Bill Burcham Bill

View GitHub Profile
@Bill
Bill / RingBufferSequential.java
Last active Jul 13, 2019
A non-thread-safe ring buffer thingie
View RingBufferSequential.java
package com.thoughtpropulsion.reactrode;
import static com.thoughtpropulsion.reactrode.Functional.returning;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import io.vavr.Tuple2;
import io.vavr.control.Option;
@Bill
Bill / scratch_38.java
Created Jun 17, 2019
I don't think the changes to genericize Execution does what we want https://github.com/apache/geode/pull/3715
View scratch_38.java
import java.math.BigInteger;
import java.util.Collections;
import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.FunctionService;
class Scratch {
public static void main(String[] args) {
final Execution<String, String, String> execution = FunctionService.onRegion(null);
View TypeToolsTest.java
import static net.jodah.typetools.TypeResolver.resolveRawArgument;
public class Core {
interface Handler<T> {
void process(T x);
}
void p1(final String s) {}
void p1(final int i) {}
@Bill
Bill / MonoidMenagerie.java
Last active Jun 19, 2019
Monoid Menagerie, or, the uncanny usefulness of four lines of Java
View MonoidMenagerie.java
import java.util.Comparator;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/*
@Bill
Bill / Memoize.java
Last active May 24, 2019
A couple memoization functions for Java Suppliers.
View Memoize.java
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
class Memoize {
private Memoize() {}
/*
Props to AOL Cyclops Memoize for this little trick: using the UNSET reference
value as the sentinel for an uninitialized cache value. This approach allows memoization
@Bill
Bill / EnhancedForLoopOverMapValues.java
Created May 24, 2019
Using JSR 201 enhanced for loop to iterate over Map values
View EnhancedForLoopOverMapValues.java
import java.util.HashMap;
import java.util.Map;
class Scratch {
interface Pool {
void basicDestroy(boolean keepAlive);
}
static class PoolImpl implements Pool {
@Override
public void basicDestroy(final boolean keepAlive) {
@Bill
Bill / DoesOptionalObeyFunctorLaws.java
Last active May 1, 2019
Optional, introduced along with Stream and Function, in Java 8, has a map() method. Does it obey the functor laws, particularly the one pertaining to function composition?
View DoesOptionalObeyFunctorLaws.java
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Scratch {
/*
A method that converts a String to an Integer.
@Bill
Bill / flatMapNulls.java
Created Apr 24, 2019
Use flatMap() to elide nulls in a Stream
View flatMapNulls.java
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Scratch {
public static void main(String[] args) {
final List<String> original =
Stream.of("a", "b", null, "c")
.collect(Collectors.toList());
@Bill
Bill / EnumSetFormat.java
Created Apr 4, 2019
Creates an EnumSet with a couple elements and prints it in String and OutputStream format.
View EnumSetFormat.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.EnumSet;
class Scratch {
enum Fruit {APPLE, ORANGE};
public static void main(String[] args) throws IOException {
final EnumSet<Fruit> fruits = EnumSet.of(Fruit.APPLE, Fruit.ORANGE);
@Bill
Bill / haregionqueue.png
Last active Apr 3, 2019
Geode HARegionQueue Class Diagram