Skip to content

Instantly share code, notes, and snippets.

Future <String> marvel = executor.submit(new Callable <String> () {
public String call() {
return getMarvelHeroWithCharacter(“C”); // totally not making this up
}
});
// other very important stuff of course, non-blocking ftw
System.out.println(marvel.get()); // this bit is blocking if the result isn’t ready yet
CompletableFuture <String> cf =
CompletableFuture.completedFuture("I'm done!");
cf.isDone(); // return true
cf.join(); // return "I'm done"
CompletableFuture <String> marvel = executor.submit(new Callable <String> () {
public String call() {
return getMarvelHeroWithCharacter(“C”);
}
});
// other stuff goes here
marvel.complete(“Mystique”); // sets a “default” value if not yet completed
import static com.google.common.truth.Truth.assertThat;
Set < Foo > foo = ...;
assertThat(foo).isEmpty()
org.truth0.FailureStrategy$ThrowableAssertionError: Not true that is empty
at org.truth0.FailureStrategy.fail(FailureStrategy.java: 33)
...
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.Mockito;
/**
* Test for CannotMockFinalClass.
*/
@RunWith(JUnit4.class)
public class CannotMockFinalClassPositiveCases {
import static strman.Strman.leftPad
leftPad("1", "0", 5)
// result => "00001"
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.iterations(1)
.weightInit(WeightInit.XAVIER)
.activation("relu")
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.learningRate(0.05)
// ... other hyperparameters
.backprop(true)
.build();
public static String randomString(int i)
{
Random ran = new Random(i);
StringBuilder sb = new StringBuilder();
while (true)
{
int k = ran.nextInt(27);
if (k == 0)
break;
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
Date sDt3 = sf.parse(str3);
Date sDt4 = sf.parse(str4);
long ld3 = sDt3.getTime() /1000;
long ld4 = sDt4.getTime() /1000;
System.out.println(ld4-ld3);
}
for (int i = 0; i < 100000; ++i)
{
// Primary loop
for (int c = 0; c < arraySize; ++c)
{
if (data[c] >= 128)
sum += data[c];
}
}