Skip to content

Instantly share code, notes, and snippets.

View krisskross's full-sized avatar

Christofer Sjögren krisskross

View GitHub Profile
@RunWith(JUnitRunner.class)
public class DummyTest {
@Test
@Transactional
public void testTest() {
assertTrue(false);
}
}
@Reliable
@RuleHandler(ExampleRule.class)
public @interface ExampleAnnotation {
}
@Traceable
@RuleHandler(ReliableRule.class)
public @interface Reliable {
}
@Test
@Reliable
public void demoFixtureArguments(FixtureExample one, FixtureExample two, FixtureExample three) {
System.out.println("demonstrateFixtureArguments(" + one + ", " + two + ", " + three + ")");
}
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
@Configuration
public class MysqlXADataSource {
@Property(desc = "User name to use for connection authentication.")
@Size(min = 6, max = 255)
private String user = ""; // default value - hence optional property
public interface Decoder<T> {
public T decode(ByteBuffer buffer);
}
public class TextRowDecoder implements Decoder<byte[][]> {
private static final byte LF = 10;
private final int numFields;
private final byte delimiter;
public TextRowDecoder(int numFields, byte delimiter) {
this.numFields = numFields;
this.delimiter = delimiter;
}
@Override
public byte[][] decode(ByteBuffer buffer) {
public class FileReader implements Iterable<List<T>> {
private static final long CHUNK_SIZE = 4096;
private final Decoder<T> decoder;
private Iterator<File> files;
private FileReader(Decoder<T> decoder, File... files) {
this(decoder, Arrays.asList(files));
}
private FileReader(Decoder<T> decoder, List<File> files) {
this.files = files.iterator();
TextRowDecoder decoder = new TextRowDecoder(4, comma);
FileReader<byte[][]> reader = FileReader.create(decoder, file.listFiles());
for (List<byte[][]> chunk : reader) {
// do something with each chunk
}
public class PeriodEntries<T extends Timestamped> implements Iterable<List<T>> {
private final Iterator<List<T extends Timestamped>> entriesIt;
private final long interval;
private PeriodEntries(Iterable<List<T>> entriesIt, long interval) {
this.entriesIt = entriesIt.iterator();
this.interval = interval;
}
public static <T extends Timestamped> PeriodEntries<T> create(Iterable<List<T>> entriesIt, long interval) {
return new PeriodEntries<T>(entriesIt, interval);
TrueFxDecoder decoder = new TrueFxDecoder();
FileReader<TrueFxData> reader = FileReader.create(decoder, file.listFiles());
long periodLength = TimeUnit.DAYS.toMillis(1);
PeriodEntries<TrueFxData> periods = PeriodEntries.create(reader, periodLength);
for (List<TrueFxData> entries : periods) {
// data for each day
for (TrueFxData entry : entries) {
// process each entry
}