From 54ada1d1af2f8f1ebb1b190ec7a78412eaee7d52 Mon Sep 17 00:00:00 2001 From: Georgios Gousios Date: Wed, 23 Nov 2011 16:08:20 +0200 Subject: [PATCH] Dead code elimination --- .../logic/accounting/AccountingEvent.scala | 11 ++- .../accounting/agreements/AgreementRegistry.scala | 53 -------------- .../accounting/agreements/DefaultAgreement.scala | 50 ------------- .../accounting/policies/DefaultRatePolicy.scala | 45 ------------ .../accounting/policies/ScalableRatePolicy.scala | 74 -------------------- .../gr/grnet/aquarium/logic/test/BillingTest.scala | 17 +---- 6 files changed, 7 insertions(+), 243 deletions(-) delete mode 100644 logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/AgreementRegistry.scala delete mode 100644 logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/DefaultAgreement.scala delete mode 100644 logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/DefaultRatePolicy.scala delete mode 100644 logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/ScalableRatePolicy.scala diff --git a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/AccountingEvent.scala b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/AccountingEvent.scala index 925f24a..fc2107b 100644 --- a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/AccountingEvent.scala +++ b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/AccountingEvent.scala @@ -35,9 +35,7 @@ package gr.grnet.aquarium.logic.accounting -import agreements.AgreementRegistry import gr.grnet.aquarium.model.{Entity, DB} -import policies.DefaultRatePolicy import java.util.Date @@ -68,11 +66,11 @@ class AccountingEvent(et: AccountingEventType.Value, start: Date, } def policy(): List[Policy] = { - val agr = AgreementRegistry.getAgreement(entity().agreement) match { + /*val agr = AgreementRegistry.getAgreement(entity().agreement) match { case Some(x) => x case None => throw new Exception("No agreement with id:" + entity().agreement) - } + }*/ /*agr.policy(et, when) match { case Some(x) => x @@ -83,11 +81,12 @@ class AccountingEvent(et: AccountingEventType.Value, start: Date, } def getRate(): Float = { - val agreement = AgreementRegistry.getAgreement(entity.agreement) + /*val agreement = AgreementRegistry.getAgreement(entity.agreement) agreement match { case Some(x) => x.pricelist.get(et).getOrElse(0) case None => 0 - } + }*/ + 0F } } diff --git a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/AgreementRegistry.scala b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/AgreementRegistry.scala deleted file mode 100644 index 6de7d06..0000000 --- a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/AgreementRegistry.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2011 GRNET S.A. All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and - * documentation are those of the authors and should not be - * interpreted as representing official policies, either expressed - * or implied, of GRNET S.A. - */ - -package gr.grnet.aquarium.logic.accounting.agreements - -import gr.grnet.aquarium.logic.accounting.Agreement - -object AgreementRegistry { - - var agreements = Map[Long, Agreement] ( - DefaultAgreement.id -> DefaultAgreement - ) - - def getAgreement(agrId : Long) : Option[Agreement] = { - agreements.get(agrId) - } - - def addAgreement[A <: Agreement](agr : A) = { - agreements = agreements ++ Map(agr.id -> agr) - } -} \ No newline at end of file diff --git a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/DefaultAgreement.scala b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/DefaultAgreement.scala deleted file mode 100644 index f7e01e3..0000000 --- a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/agreements/DefaultAgreement.scala +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 GRNET S.A. All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and - * documentation are those of the authors and should not be - * interpreted as representing official policies, either expressed - * or implied, of GRNET S.A. - */ - -package gr.grnet.aquarium.logic.accounting.agreements - -import gr.grnet.aquarium.logic.accounting.{AccountingEventType, Agreement} - -object DefaultAgreement extends Agreement { - - override val id = 1L - - override val pricelist = Map ( - AccountingEventType.DiskSpace -> 0.00002F, - AccountingEventType.NetDataDown -> 0.0001F, - AccountingEventType.NetDataUp -> 0.0001F, - AccountingEventType.VMTime -> 0.001F - ) -} \ No newline at end of file diff --git a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/DefaultRatePolicy.scala b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/DefaultRatePolicy.scala deleted file mode 100644 index 6f76d1e..0000000 --- a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/DefaultRatePolicy.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2011 GRNET S.A. All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and - * documentation are those of the authors and should not be - * interpreted as representing official policies, either expressed - * or implied, of GRNET S.A. - */ - -package gr.grnet.aquarium.logic.accounting.policies - -import gr.grnet.aquarium.logic.accounting.{AccountingEvent, AccountingEntryType, Policy} - -class DefaultRatePolicy(et: AccountingEntryType.Value) extends Policy(et) { - - def calculateAmount(evt: AccountingEvent) : Float = { - evt.value() * evt.getRate() - } -} \ No newline at end of file diff --git a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/ScalableRatePolicy.scala b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/ScalableRatePolicy.scala deleted file mode 100644 index d17046d..0000000 --- a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/policies/ScalableRatePolicy.scala +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2011 GRNET S.A. All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and - * documentation are those of the authors and should not be - * interpreted as representing official policies, either expressed - * or implied, of GRNET S.A. - */ - -package gr.grnet.aquarium.logic.accounting.policies - -import gr.grnet.aquarium.logic.accounting.{AccountingEventType, AccountingEvent, Policy, AccountingEntryType} - -class ScalableRatePolicy(et: AccountingEntryType.Value) extends Policy(et) { - - def calculateAmount(evt: AccountingEvent) : Float = { - evt.kind() match { - case AccountingEventType.VMTime => - if (evt.value() <= 25) - evt.value() * evt.getRate() * 1 - else if (evt.value() > 25 && evt.value() < 50) - evt.value() * evt.getRate() * 1.2F - else - evt.value() * evt.getRate() * 2 - case AccountingEventType.DiskSpace => - if (evt.value() <= 100) - evt.value() * evt.getRate() * 1 - else if (evt.value() > 150 && evt.value() < 200) - evt.value() * evt.getRate() * 1.2F - else - evt.value() * evt.getRate() * 2 - case AccountingEventType.NetDataUp => - if (evt.value() <= 1000) - evt.value() * evt.getRate() * 1 - else if (evt.value() > 1500 && evt.value() < 2000) - evt.value() * evt.getRate() * 1.2F - else - evt.value() * evt.getRate() * 2 - case AccountingEventType.NetDataDown => - if (evt.value() <= 500) - evt.value() * evt.getRate() * 1 - else if (evt.value() > 1000 && evt.value() < 1500) - evt.value() * evt.getRate() * 1.2F - else - evt.value() * evt.getRate() * 2 - } - } -} \ No newline at end of file diff --git a/logic/src/test/scala/gr/grnet/aquarium/logic/test/BillingTest.scala b/logic/src/test/scala/gr/grnet/aquarium/logic/test/BillingTest.scala index ea2a416..b51c712 100644 --- a/logic/src/test/scala/gr/grnet/aquarium/logic/test/BillingTest.scala +++ b/logic/src/test/scala/gr/grnet/aquarium/logic/test/BillingTest.scala @@ -36,13 +36,10 @@ package gr.grnet.aquarium.logic.test import org.junit._ -import org.junit.Assert._ import gr.grnet.aquarium.logic.Bills import gr.grnet.aquarium.model.{User} -import gr.grnet.aquarium.logic.accounting.policies.DefaultRatePolicy -import gr.grnet.aquarium.logic.accounting.{Agreement, AccountingEvent, AccountingEntryType, AccountingEventType} -import gr.grnet.aquarium.logic.accounting.agreements.AgreementRegistry -import java.util.Date +import gr.grnet.aquarium.logic.accounting.{Agreement, AccountingEventType} + import gr.grnet.aquarium.util.FixtureLoader class BillingTest @@ -70,16 +67,6 @@ class BillingTest @Test def testOverallAccountingRules() = { - TestAgreement.addPolicy(AccountingEventType.VMTime, - new DefaultRatePolicy(AccountingEntryType.VMTIME_CHARGE), new Date(2)) - TestAgreement.addPolicy(AccountingEventType.DiskSpace, - new DefaultRatePolicy(AccountingEntryType.STORAGE_CHARGE), new Date(2)) - TestAgreement.addPolicy(AccountingEventType.NetDataDown, - new DefaultRatePolicy(AccountingEntryType.NET_CHARGE), new Date(2)) - TestAgreement.addPolicy(AccountingEventType.NetDataUp, - new DefaultRatePolicy(AccountingEntryType.NET_CHARGE), new Date(2)) - - AgreementRegistry.addAgreement(TestAgreement) val u = new User u.agreement = TestAgreement.id -- 1.7.10.4