@Override public PersistentAbsQuantity add( final PersistentAbsQuantity summand1, final PersistentAbsQuantity summand2) throws model.NotComputableException, PersistenceException { final PersistentAbsUnitType arg1Type = summand1.accept(new FetchUnitTypeVisitor()); final PersistentAbsUnitType arg2Type = summand2.accept(new FetchUnitTypeVisitor()); if (!arg1Type.equals(arg2Type)) { throw new NotComputableException(ExceptionConstants.NC_QUANTITY_UNITTYPES); } final QuantitySearchList arg1Parts = summand1.accept(new FetchQuantityPartsVisitor()); final QuantitySearchList arg2Parts = summand2.accept(new FetchQuantityPartsVisitor()); PersistentAbsQuantity newQuantity = CompoundQuantity.createCompoundQuantity(); try { ((PersistentCompoundQuantity) newQuantity).getParts().add(arg1Parts); ((PersistentCompoundQuantity) newQuantity).getParts().add(arg2Parts); } catch (final UserException e) { // TODO Auto-generated catch block e.printStackTrace(); } newQuantity = getThis().concludeQuantity(newQuantity); replaceInQuantityList(summand1, summand2, newQuantity, false); return newQuantity; // final PersistentAddition addi = Addition.createAddition(); // addi.setArg1(summand1); // addi.setArg2(summand2); // addi.calculate(); // return addi.getResultt(); }
protected PersistentCompoundQuantity doInvertSign(final PersistentCompoundQuantity q) throws PersistenceException { final PersistentCompoundQuantity cp = CompoundQuantity.createCompoundQuantity(); final Iterator<PersistentQuantity> i = q.getParts().iterator(); while (i.hasNext()) { final PersistentQuantity current = i.next(); final PersistentQuantity invertedQuantity = this.doInvertSign(current); cp.getParts().add(invertedQuantity); } getThis().getQuantities().add(cp); return cp; }
@Override public QuantitySearchList handleCompoundQuantity( final PersistentCompoundQuantity compoundQuantity) throws PersistenceException { final QuantitySearchList ret = new QuantitySearchList(); final Iterator<PersistentQuantity> i = compoundQuantity.getParts().iterator(); while (i.hasNext()) { final PersistentQuantity curQuantity = i.next(); ret.add(curQuantity); } return ret; }
@Override public PersistentAbsUnitType handleCompoundQuantity( final PersistentCompoundQuantity compoundQuantity) throws PersistenceException { return compoundQuantity.getParts().iterator().next().getUnit().getType(); }