One common task in banking is translating from one form to another. I couldn't find an effectife solution for this problem, but TranslatorPattern offers interesting approach.
I've used similar functionality in Amoeba utility classes:
I've used similar functionality in Amoeba utility classes:
private static interface Amoeba<Value> {
boolean consume(Amoeba<Value> amoeba);
Value produce() throws Exception;
}
private static class AmoebaUtils {
static <Value> boolean populate(Collection<Amoeba<Value>> colony, Amoeba<Value> nominate) {
for (Amoeba<Value> citizen : colony) {
if (citizen.equals(nominate)) {
return citizen.consume(nominate);
}
}
return colony.add(nominate);
}
static <Value> Collection<Value> produce(Set<Amoeba<Value>> colony) throws Exception {
Set<Value> values = new HashSet<Value>();
for (Amoeba<Value> citizen : colony) {
values.add(citizen.produce());
}
return values;
}
}