Created
March 10, 2010 20:30
-
-
Save thesurlydev/328341 to your computer and use it in GitHub Desktop.
This file contains hidden or 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("OAS", bond.getOas()); | |
} | |
} | |
/* Some other Leaf */ | |
class Price implements PolyColumn { | |
public void writeToInput(Map<String, String> inputCsvColumns, BondEx bond) { | |
inputCsvColumns.put("Price", 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>); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment