Skip to content

Instantly share code, notes, and snippets.

Bill Burcham Bill

Block or report user

Report or block Bill

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 / 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 / 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 / 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 / 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
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 / 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);
@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 / ConnectableFluxTest.java
Last active Jul 5, 2019
Test Project Reactor ConnectableFlux. State space exploration brought to you by `VirtualTimeSchedulerInaccurate` and changing `new Random(1)` to `new Random()`.
View ConnectableFluxTest.java
package com.thoughtpropulsion.reactrode.rxperiment;
import static com.thoughtpropulsion.reactrode.Functional.returning;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.nanoTime;
import static org.assertj.core.api.Assertions.assertThat;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.Duration;
@Bill
Bill / VirtualTimeSchedulerInaccurate.java
Last active Jul 5, 2019
Project Reactor VirtualTimeScheduler subclass that introduces (controlled) error into schedule times in order to cause changes to task interleaving.
View VirtualTimeSchedulerInaccurate.java
package com.thoughtpropulsion.reactrode;
import static com.thoughtpropulsion.reactrode.Functional.returning;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import reactor.core.Disposable;
You can’t perform that action at this time.