Skip to content

Instantly share code, notes, and snippets.

package org.eventroaster.example;
import org.eventroaster.annotation.Event;
import org.eventroaster.EventServiceFactory;
import org.eventroaster.annotation.EventHandler;
import org.eventroaster.EventService;
import org.eventroaster.EventServiceFactory;
@Event
public class EchoEvent {}
@bivas
bivas / FooServiceImpl.java
Created April 11, 2011 09:46
Using Compile-Time AspectJ as @transactional Proxy Provider
package com.example.svc;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service("fooService")
@Transactional
final class FooServiceImpl implements FooService {
/* constractor, fields, etcs. */
@bivas
bivas / JavaCodingStandards.txt
Created May 31, 2011 12:37
Java Coding Standards
= Motivation =
Code conventions are important to programmers for a number of reasons
- 80% of the lifetime cost of a piece of software goes to maintenance.
- Hardly any software is maintained for its whole life by the original author.
- Code conventions improve the software readability, allowing programmers to understand new code more quickly and thoroughly.
= Coding Standards =
@bivas
bivas / CloudFoundryMySqlBootstrap.java
Created August 12, 2011 10:58
Running Play Framework Application in CloudFoundry
package plugins;
import java.util.List;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cloudfoundry.runtime.env.CloudEnvironment;
import org.cloudfoundry.runtime.env.MysqlServiceInfo;
@bivas
bivas / ClassicStrategy.java
Created August 14, 2011 09:39
Strategy pattern as replacement to instanceof if statements
package com.example.strategy;
public interface Strategy<R> {
public R execute(Object input);
}
@bivas
bivas / AbstractFactory.java
Created August 30, 2011 12:39
Factory Pattern
package com.example.factory;
public interface CarFactory {
Car createCar();
}
public FordCarFactory implements CarFactory {
@Override
public Car createCar() {
@bivas
bivas / NotNullCacheEventListener.java
Created September 6, 2011 07:09
EhCache event listener for preventing caching of null values in data store
package com.example.cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.event.CacheEventListener;
final class NotNullCacheEventListener implements CacheEventListener {
public static final CacheEventListener INSTANCE = new NotNullCacheEventListener();
@bivas
bivas / FooBarZoo.java
Created September 7, 2011 10:57
Builder Pattern
public interface Foo {
Collection<Bar> getBars();
Zoo getZoo();
}
public interface Bar {}
public interface Zoo {}
@bivas
bivas / ComplexNumber.java
Created September 11, 2011 15:25
Adapter Pattern
package com.example.adapter;
public interface ComplexNumber {
double real();
double imaginary();
}
@bivas
bivas / DurationPattern.java
Created March 24, 2012 20:26
Human Readable Duration
long now = System.currentTimeMillis();
doSomeLongTask();
long duration = System.currentTimeMillis() - now;