Skip to content

Instantly share code, notes, and snippets.

View mgenov's full-sized avatar

Miroslav Genov mgenov

View GitHub Profile
@mgenov
mgenov / IterableTranslator.java
Created June 22, 2012 07:47
IterableTranslator.java
protected Collection<Object> createCollection(Type type)
{
// support reusing existing implementations
if (datastore.refresh != null)
{
@SuppressWarnings("unchecked")
Collection<Object> result = (Collection<Object>) datastore.refresh;
datastore.refresh = null;
return result;
}
@mgenov
mgenov / ThreadsSample.java
Created June 12, 2012 14:47
ThredsSample.java
class CountingThread extends Thread {
private final int maxCount;
private final CountingThread terminationThread;
private boolean stopped = false;
public CountingThread(int maxCount, CountingThread terminationThread) {
this.maxCount = maxCount;
this.terminationThread = terminationThread;
}
public class ChangeLoggers {
customer, @Named("CUSTOMER_NAME") String customerName);
public static <T> T create(Class<? extends ChangeLogger> clazz, final CurrentUser currentUser, final ChangeLogBase base) {
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[]{clazz}, new InvocationHandler() {
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
@mgenov
mgenov / ReferenceTest.java
Created March 16, 2012 14:50
ReferenceTest.java
static class Parent {
@Id
Long id;
}
static class Child {
@Id
Long id;
@mgenov
mgenov / PolymorphicTest.java
Created March 16, 2012 14:44
PolymorphicTest.java
static class Person {
@Id
private Long id;
@Embedded(polymorphic = true)
private State state;
}
static class State {
private String value;
@mgenov
mgenov / PolymorphicTest.java
Created March 16, 2012 14:44
PolymorphicTest.java
static class Person {
@Id
private Long id;
@Embedded(polymorphic = true)
private State state;
}
static class State {
private String value;
public interface Child1 extends ValueProxy {
String getValue();
void setValue(String value);
Long getId();
void setId(Long id);
}
@mgenov
mgenov / MockitoBehaviorTest.java
Created January 20, 2012 14:50
MockitoBehaviorTest.java
public class MockitoBehaviorTest {
interface Registry {
void register(Double amount);
}
class PaymentProcessingListener {
private final Registry registry;
@mgenov
mgenov / MessyBehaviorTest.java
Created January 20, 2012 14:38
MessyBehaviorTest.java
public class MessyBehaviorTest {
interface Registry {
void register(Double amount);
}
class PaymentProcessingListener {
private final Registry registry;
@mgenov
mgenov / ConverterRegistration.java
Created August 19, 2011 09:12
Register new type converter in twig.
@Override
protected CombinedConverter createTypeConverter() {
CombinedConverter converter = new CombinedConverter();
converter.append(new PrimitiveConverter());
converter.append(new CollectionConverter(converter));
converter.append(new CityToString());
converter.append(new StringToCity());
converter.append(new StreetToString());