This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Avro) -> Size 43 Bytes | |
{"tradeId": 454442738626075203, "customerId": 1924973958993118808, "qty": 100, "tradeType": "Buy", "symbol": "GOOGL", "exchange": "NYSE"} | |
(Avro) -> Size 43 Bytes | |
{"tradeId": 1984810212692753661, "customerId": -7397692262047989958, "qty": 100, "tradeType": "Sell", "symbol": "AAPL", "exchange": "NYSE"} | |
(chronicle) -> Size 35 Bytes | |
CVCNX©ãá¶NYSEBuyGOOGLd | |
(chronicle) -> Size 35 Bytes | |
ý|Z_v:?ùVNYSESellAAPLd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object[][] data = new Object[][]{ | |
{new Random().nextLong(), new Random().nextLong(), "NYSE", "Buy", "GOOGL", 100}, | |
{new Random().nextLong(), new Random().nextLong(), "NYSE", "Sell", "AAPL", 100}, | |
}; | |
process("Avro", Arrays.stream(data), AvroTradeRecordBuilder::newTrade, AvroTradeRecordBuilder::toBytes, AvroTradeRecordBuilder::fromBytes); | |
process("chronicle", Arrays.stream(data), ChronicleTradeRecordBuilder::newTrade, ChronicleTradeRecordBuilder::toBytes, ChronicleTradeRecordBuilder::fromBytes); | |
process("sbe", Arrays.stream(data), SBETradeRecordBuilder::newTrade, SBETradeRecordBuilder::toBytes, SBETradeRecordBuilder::fromBytes); | |
process("csv", Arrays.stream(data), CSVTradeRecordBuilder::newTrade, CSVTradeRecordBuilder::toBytes, CSVTradeRecordBuilder::fromBytes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long tradeId , customerId; | |
int qty; | |
TradeType tradeType; | |
String symbol,exchange; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List functions = asList( | |
SerCode.f((Integer x) -> x * x), | |
SerCode.f((String x) -> x.toUpperCase()), | |
SerCode.p((String x) -> x.length() > 5) | |
); | |
byte[] code = saveFunction(functions); | |
ObjectInputStream fStream = codeStream(code); | |
List rFunctions = (List) fStream.readObject(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
public interface SerFunction<T, R> extends Function<T, R>, Serializable { | |
} | |
@FunctionalInterface | |
public interface SerPredicate<T> extends Predicate<T>, Serializable { | |
} | |
.... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test() | |
public void save_function_works() throws Exception { | |
// Addtional casting allow to mark as serilized | |
Function<String, String> upper = (Function<String, String> & Serializable) x -> x.toUpperCase(); | |
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
ObjectOutputStream os = new ObjectOutputStream(bos)) { | |
os.writeObject(upper); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void save_function() throws Exception { | |
Function<String, String> upper = x -> x.toUpperCase(); | |
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
ObjectOutputStream os = new ObjectOutputStream(bos)) { | |
os.writeObject(upper); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void square_number() { | |
Function<Integer, Integer> sqr = x -> x * x; | |
assertEquals(4, sqr.apply(2)); | |
assertEquals(9, sqr.apply(3)); | |
assertEquals(16, sqr.apply(4)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RingBuffer<T> { | |
public RingBuffer(int size) { | |
this.capacity = Bits.powOf2(size); | |
this.mask = capacity - 1; | |
buffer = new Object[this.capacity]; | |
} | |
private int offset(int index) {return index & mask; | |
//return index % capacity; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void restoreDisk() { | |
RaidDisk disk1 = new RaidDisk(2); | |
disk1.set(0, MoreInts.toByte("01101101")); | |
disk1.set(1, MoreInts.toByte("00101101")); | |
RaidDisk disk2 = new RaidDisk(1); | |
disk2.set(0, MoreInts.toByte("11010100")); | |
RaidDisk raidDisk = disk1.xor(disk2); // This xor allow to keep data for both disk in RaidDisk |