ContractBuilderFactory { public static IContractBuilder getContractBuilder( Ticker ticker ) { if( ticker instanceof StockTicker ) { return new StockContractBuilder(); } else if( ticker instanceof CurrencyTicker ) { return new CurrencyContractBuilder(); } else if( ticker instanceof FuturesTicker ) { return new FuturesContractBuilder(); } else if( ticker instanceof ComboTicker ) { return new ComboContractBuilder(); } else if( ticker instanceof IndexTicker ) { return new IndexContractBuilder(); } else if( ticker instanceof CFDTicker ) { return new CFDContractBuilder(); } else if( ticker instanceof OptionTicker ) { return new OptionContractBuilder(); } else { throw new IllegalStateException( "Unsupported ticker type: " + ticker.getClass() ); } }  static IContractBuilder getContractBuilder( Ticker ticker );  }
@Test public void testGetContractBuilder() { Ticker stockTicker = new StockTicker("ABC"); Ticker currencyTicker = new CurrencyTicker(); Ticker futurTicker = new FuturesTicker(); Ticker optionsTicker = new OptionTicker("QQQ"); Ticker combTicker = new ComboTicker(futurTicker, stockTicker); Ticker indexTicker = new IndexTicker(); Ticker cfdTicker = new CFDTicker("XYZ"); assertTrue( ContractBuilderFactory.getContractBuilder(stockTicker) instanceof StockContractBuilder ); assertTrue( ContractBuilderFactory.getContractBuilder(currencyTicker) instanceof CurrencyContractBuilder ); assertTrue( ContractBuilderFactory.getContractBuilder(futurTicker) instanceof FuturesContractBuilder ); assertTrue( ContractBuilderFactory.getContractBuilder(combTicker) instanceof ComboContractBuilder ); assertTrue( ContractBuilderFactory.getContractBuilder(indexTicker) instanceof IndexContractBuilder ); assertTrue( ContractBuilderFactory.getContractBuilder(cfdTicker) instanceof CFDContractBuilder ); assertTrue( ContractBuilderFactory.getContractBuilder(optionsTicker) instanceof OptionContractBuilder ); }