Created
March 10, 2010 20:44
-
-
Save thesurlydev/328361 to your computer and use it in GitHub Desktop.
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
/* Component */ | |
interface PolyColumn { | |
public void writeToInput(Map<String, String> inputCsvColumns, BondEx bond); | |
} | |
/* Composite */ | |
class CompositePolyColumn implements PolyColumn { | |
private List<PolyColumn> childPolyColumns = new ArrayList<PolyColumn>(); | |
public void add(PolyColumn polyColumn) { | |
childPolyColumns.add(polyColumn); | |
} | |
public void remove(PolyColumn polyColumn) { | |
childPolyColumns.remove(polyColumn); | |
} | |
public void writeToInput(Map<String, String> inputCsvColumns, BondEx bond) { | |
for (PolyColumn polyColumn : childPolyColumns) { | |
polyColumn.writeToInput(inputCsvColumns, bond); | |
} | |
} | |
} | |
/* Leaf */ | |
class Oas implements PolyColumn { | |
public void writeToInput(Map<String, String> inputCsvColumns, BondEx bond) { | |
inputCsvColumns.put(Ply.OAS.getLabel(), Ply.OAS.getDefaultValue()); | |
} | |
} | |
/* Some other Leaf */ | |
class Price implements PolyColumn { | |
public void writeToInput(Map<String, String> inputCsvColumns, BondEx bond) { | |
inputCsvColumns.put(Ply.PRICE.getLabel(), bond.getOfferPrice()); | |
} | |
} | |
/* Client */ | |
public class Client { | |
public static void main(String[] args) { | |
PolyColumn oas = new Oas(); | |
PolyColumn price = new Price(); | |
CompositePolyColumn compositePolyColumn = new CompositePolyColumn(); | |
compositePolyColumn.add(oas); | |
compositePolyColumn.add(price); | |
compositePolyColumn.writeToInput(new HashMap<String, String>); | |
} | |
} | |
/* Helper enum */ | |
public enum Ply { | |
OAS("OAS", ""), | |
PRICE("Price", "30"); | |
private String label; | |
private String defaultValue; | |
Ply(String label, String defaultValue) { | |
this.label = label; | |
this.defaultValue = defaultValue; | |
} | |
public String getLabel() { | |
return label; | |
} | |
public String getDefaultValue() { | |
return defaultValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment