/
SchemaDomain.scala
68 lines (58 loc) · 1.61 KB
/
SchemaDomain.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright © 2021 - 2022 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/
package dsp.schema.domain
import Cardinality._
/**
* Represents a cardinality value object.
*/
sealed trait Cardinality { self =>
/**
* The string representation of the cardinality
*/
val value: String
/**
* Checks whether a cardinality is stricter than another one.
*
* @param that the cardinality to be compared against
* @return `true` if the present cardinality is stricter than `that`, `false` otherwise
*/
def isStricterThan(that: Cardinality): Boolean =
if (self == that) {
false
} else {
self match {
case MustHaveOne => true
case MustHaveSome => that == MayHaveMany
case MayHaveOne => that == MayHaveMany
case MayHaveMany => false
}
}
}
object Cardinality {
/**
* The cardinality of a property that must have one value.
*/
final case object MustHaveOne extends Cardinality {
override val value: String = "1"
}
/**
* The cardinality of a property that must have at least one value.
*/
final case object MustHaveSome extends Cardinality {
override val value: String = "1-n"
}
/**
* The cardinality of a property that may have one value.
*/
final case object MayHaveOne extends Cardinality {
override val value: String = "0-1"
}
/**
* The cardinality of a property that may have one or more values.
*/
final case object MayHaveMany extends Cardinality {
override val value: String = "0-n"
}
}