Skip to content

Instantly share code, notes, and snippets.

View calaveraInfo's full-sized avatar

František Řezáč calaveraInfo

View GitHub Profile
@calaveraInfo
calaveraInfo / GenericPolymorphicFunctionTest.java
Last active August 22, 2019 20:19
Generic polymorphic function
package cz.cez.trading.algo.core;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class GenericPolymorphicFunctionTest {
@Test
public void testPolymorphicFunction() {
@calaveraInfo
calaveraInfo / Sandbox.java
Created August 23, 2019 11:55
Floating point hell
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
public class Sandbox {
@Test
public void testFloat() {
double raw = 21.05d;
double computed = 21.025d+0.025d;
double rounded = Math.round((21.025d+0.025d) * 1000d) / 1000d;
System.out.println(raw);
@calaveraInfo
calaveraInfo / Index.java
Created November 21, 2019 08:59
Intermittently mutable data concept
public interface Index() {
/*
* @return mutable copy of indexes contained in this instance.
*/
MutableIndex beginMutation();
/*
* Example usage of indexes for data retrieval.
*/
PrimaryKey findBySomeAttributeValue(String value);
@calaveraInfo
calaveraInfo / CovarianceTest.java
Last active November 29, 2019 10:16
Wildcards in "indirect" or "second level" generics.
package x;
/**
* <p>
* Wildcards in "indirect" or "second level" generics.
* <p>
* {@link #list} contains generic items.
* {@link #testWildcard()} and {@link #testGeneric()} wants to work with that items
* and shouldn't care about it's generic type <i>as long as it's the same type through the
* whole method<i>. How to express that correctly (if it's possible at all)?