New posts
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.primitives.UnsignedBytes;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import java.util.Comparator;
|
||||
|
||||
/** Three Guava features whose implementations have an Unsafe fast path (see output/11): hashing, byte comparison, futures. Needs guava on the class path. */
|
||||
public class GuavaProbe {
|
||||
public static void main(String[] args) throws Exception {
|
||||
byte[] data = "unsafe-migration".getBytes();
|
||||
System.out.println("murmur3_128 = " + Hashing.murmur3_128().hashBytes(data));
|
||||
Comparator<byte[]> cmp = UnsignedBytes.lexicographicalComparator();
|
||||
System.out.println("comparator = " + cmp.getClass().getName());
|
||||
System.out.println("compare = " + Integer.signum(cmp.compare(new byte[] {1, 2, 3}, new byte[] {1, 2, 4})));
|
||||
SettableFuture<String> f = SettableFuture.create();
|
||||
f.set("ok");
|
||||
System.out.println("future = " + f.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user