public < T extends AbstractCalculator > T bind ( Class < T > clazz ) { T childCalc = null ; try { childCalc = clazz . newInstance ( ) ; } catch ( Exception e ) { throw new CalculatorException ( e ) ; } if ( childCalc instanceof AbstractCalculator ) { // find last child from root AbstractCalculator < CALC > bParent = this ; while ( bParent != null ) { if ( bParent . childCalculator != null ) bParent = bParent . childCalculator ; else break ; } ( ( AbstractCalculator ) childCalc ) . parentCalculator = bParent ; ( ( AbstractCalculator ) childCalc ) . isBind = true ; bParent . childCalculator = childCalc ; } else { throw new CalculatorException ( "Use calculator which is type of AbstractCalculator" , new IllegalArgumentException ( ) ) ; } return childCalc ; }
Bind another Calculator class functionalities to expression .