1 package gr.grnet.aquarium.logic.credits.model
4 * The credit distribution type representation.
6 * This dictates how credits are distributed at lower level structure parts, for example
7 * how a University distributes credits to its Departments.
9 * @author Christos KK Loverdos <loverdos@gmail.com>.
11 sealed trait CreditDistributionType {
16 def isFixed = isFixedAny || isFixedEqual
17 def isFixedAny = false
18 def isFixedEqual = false
19 def isOnDemandUnlimited = false
20 def isOnDemandMax = false
25 * @author Christos KK Loverdos <loverdos@gmail.com>.
27 sealed abstract class CreditDistributionTypeSkeleton(_name: String, _value: Int) extends CreditDistributionType {
34 * @author Christos KK Loverdos <loverdos@gmail.com>.
36 case object FixedAnyCreditDistributionType
37 extends CreditDistributionTypeSkeleton(CreditDistributionType.Names.FixedAny, CreditDistributionType.Values.FixedEqual) {
39 override def isFixedAny = true
44 * @author Christos KK Loverdos <loverdos@gmail.com>.
46 case object FixedEqualCreditDistributionType
47 extends CreditDistributionTypeSkeleton(CreditDistributionType.Names.FixedAny, CreditDistributionType.Values.FixedEqual) {
49 override def isFixedEqual = true
54 * @author Christos KK Loverdos <loverdos@gmail.com>.
56 case object OnDemandUnlimitedCreditDistributionType
57 extends CreditDistributionTypeSkeleton(CreditDistributionType.Names.OnDemandUnlimited, CreditDistributionType.Values.OnDemandUnlimited) {
59 override def isOnDemandUnlimited = true
64 * @author Christos KK Loverdos <loverdos@gmail.com>.
66 case object OnDemandMaxCreditDistributionType
67 extends CreditDistributionTypeSkeleton(CreditDistributionType.Names.OnDemandMax, CreditDistributionType.Values.OnDemandMax) {
69 override def isOnDemandMax = true
74 * @author Christos KK Loverdos <loverdos@gmail.com>.
76 case class UnknownCreditDistributionType(reason: Option[String]) extends CreditDistributionTypeSkeleton(CreditDistributionType.Names.Unknown, CreditDistributionType.Values.Unknown) {
77 override def isUnknown = true
80 object CreditDistributionType {
83 * Credits are distributed (pushed) in fixed values and parts can be divided at will.
88 * Credits are distributed (pushed) in fixed values and parts can be divided equally.
93 * Credits are distributed (pulled) on demand.
95 val OnDemandUnlimited = 30
98 * Credits are distributed (pulled) on demand but up to a maximum value.
109 val FixedAny = "FixedAny"
110 val FixedEqual = "FixedEqual"
111 val OnDemandUnlimited = "OnDemandUnlimited"
112 val OnDemandMax = "OnDemandMax"
113 val Unknown = "Unknown"
115 val FixedAny_Lower = FixedAny.toLowerCase
116 val FixedEqual_Lower = FixedEqual.toLowerCase
117 val OnDemandUnlimited_Lower = OnDemandUnlimited.toLowerCase
118 val OnDemandMax_Lower = OnDemandMax.toLowerCase
119 val Unknown_Lower = Unknown.toLowerCase
122 def fromValue(value: Int): CreditDistributionType = {
124 case Values.FixedAny => FixedAnyCreditDistributionType
125 case Values.FixedEqual => FixedEqualCreditDistributionType
126 case Values.OnDemandUnlimited => OnDemandUnlimitedCreditDistributionType
127 case Values.OnDemandMax => OnDemandMaxCreditDistributionType
128 case Values.Unknown => UnknownCreditDistributionType(None)
129 case value => UnknownCreditDistributionType(Some("Bad value %s".format(value)))
133 def fromName(name: String): CreditDistributionType = {
135 case Names.FixedAny => FixedAnyCreditDistributionType
136 case Names.FixedEqual => FixedEqualCreditDistributionType
137 case Names.OnDemandUnlimited => OnDemandUnlimitedCreditDistributionType
138 case Names.OnDemandMax => OnDemandMaxCreditDistributionType
139 case Names.Unknown => UnknownCreditDistributionType(None)
140 case value => UnknownCreditDistributionType(Some("Bad value %s".format(value)))
144 def fromNameIgnoreCase(name: String): CreditDistributionType = {
146 case null => UnknownCreditDistributionType(Some("null name"))
147 case _ => name.toLowerCase match {
148 case Names.FixedAny_Lower => FixedAnyCreditDistributionType
149 case Names.FixedEqual_Lower => FixedEqualCreditDistributionType
150 case Names.OnDemandUnlimited_Lower => OnDemandUnlimitedCreditDistributionType
151 case Names.OnDemandMax_Lower => OnDemandMaxCreditDistributionType
152 case Names.Unknown_Lower => UnknownCreditDistributionType(None)
153 case value => UnknownCreditDistributionType(Some("Bad value %s".format(value)))