Skip to content

Instantly share code, notes, and snippets.

@wytrem
wytrem / CallbackToCallable.java
Last active April 23, 2020 14:17
Java: callback (from bungeecord) to callable.
public static <V> Callable<V> createCallable(Consumer<Callback<V>> callbackConsumer) {
return new Callable<V>() {
private final CountDownLatch countDownLatch = new CountDownLatch(1);
private V result;
private Throwable error;
public void callbackDone(V result, Throwable error) {
this.result = result;
this.error = error;
countDownLatch.countDown();
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@wytrem
wytrem / NibbleArray.java
Last active November 3, 2023 04:25
NibbleArray in Java.
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.StringJoiner;
/**
* This class provides a "nibble" array. A nibble is a number stored on less
* than 8 bits.
*
* @author Wytrem (4th August 2016)