@Override public PersistentQuantityManager getThis() throws PersistenceException { if (this.This == null) { final PersistentQuantityManager result = new QuantityManagerProxi(this.getId()); result.getTheObject(); return result; } return this.This; }
/** * testet die Division mit der gleichen Einheit . * * @throws PersistenceException * @throws NotComputableException */ @Test public void testBasicCalculation_Same_Unit_div() throws PersistenceException, NotComputableException { final PersistentQuantity two = quanMan.createQuantity(meter, Fraction.parse("2")); final PersistentQuantity eight = quanMan.createQuantity(squareMeter, Fraction.parse("8")); final PersistentQuantity fiveMeter = quanMan.createQuantity(meter, Fraction.parse("5")); final PersistentQuantity twoSeconds = quanMan.createQuantity(second, Fraction.parse("2")); /* * Test 16m^2 / 8m = 2m (simple) */ final PersistentQuantity test1_act = (PersistentQuantity) quanMan.div(eight, two); final PersistentQuantity test1_exp = quanMan.createQuantity(meter, Fraction.parse("4")); assertEquals(test1_exp.getUnit(), test1_act.getUnit()); assertEquals(test1_exp.getAmount(), test1_act.getAmount()); /* * Test 5m / 2s = 5/2 m/s */ final PersistentQuantity test2_act = (PersistentQuantity) quanMan.div(fiveMeter, twoSeconds); final PersistentQuantity test2_exp = quanMan.createQuantity(meterPerSecond, Fraction.parse("5/2")); assertEquals(test2_exp.getUnit(), test2_act.getUnit()); assertEquals(test2_exp.getAmount(), test2_act.getAmount()); }
/** * testet die Multiplikation mit der gleichen Einheit . * * @throws PersistenceException * @throws NotComputableException */ @Test public void testBasicCalculation_Same_Unit_mul() throws PersistenceException, NotComputableException { final PersistentQuantity two = quanMan.createQuantity(meter, Fraction.parse("2")); final PersistentQuantity eight = quanMan.createQuantity(meter, Fraction.parse("8")); /* * Test 1: 2m * 8m = 16m^2 (simple) */ final PersistentQuantity test1_act = (PersistentQuantity) quanMan.mul(two, eight); final PersistentQuantity test1_exp = quanMan.createQuantity(squareMeter, Fraction.parse("16")); assertEquals(test1_exp.getUnit(), test1_act.getUnit()); assertEquals(test1_exp.getAmount(), test1_act.getAmount()); }
protected void setThis(final PersistentQuantityManager newValue) throws PersistenceException { if (newValue == null) throw new PersistenceException("Null values not allowed!", 0); if (newValue.equals(this)) { this.This = null; return; } if (newValue.equals(this.This)) return; final long objectId = newValue.getId(); final long classId = newValue.getClassId(); this.This = (PersistentQuantityManager) PersistentProxi.createProxi(objectId, classId); if (!this.isDelayed$Persistence()) { newValue.store(); ConnectionHandler.getTheConnectionHandler() .theQuantityManagerFacade .ThisSet(this.getId(), newValue); } }
/** * testet die Addition mit der gleichen Einheit. * * @throws PersistenceException * @throws NotComputableException */ @Test public void testBasicCalculation_Same_Unit_add() throws PersistenceException, NotComputableException { final PersistentQuantity two = quanMan.createQuantity(meter, Fraction.parse("2")); final PersistentQuantity minusOne = quanMan.createQuantity(meter, Fraction.parse("-1")); final PersistentQuantity eight = quanMan.createQuantity(meter, Fraction.parse("8")); /* * Test 1: -1 +2 = 1 */ final PersistentQuantity test1_act = (PersistentQuantity) quanMan.add(minusOne, two); final PersistentQuantity test1_exp = quanMan.createQuantity(meter, Fraction.parse("1")); assertEquals(test1_exp.getUnit(), test1_act.getUnit()); assertEquals(test1_exp.getAmount(), test1_act.getAmount()); /* * Test 2: 8 + -1 = 7 */ final PersistentQuantity test2_act = (PersistentQuantity) quanMan.add(eight, minusOne); final PersistentQuantity test2_exp = quanMan.createQuantity(meter, Fraction.parse("7")); assertEquals(test1_exp.getUnit(), test1_act.getUnit()); assertEquals(test1_exp.getAmount(), test1_act.getAmount()); }