Recommendation.kt 1.2 KB
Newer Older
1
2
package org.craftsrecords.talkadvisor.recommendation

Julien Topçu's avatar
Julien Topçu committed
3
import org.craftsrecords.hexarch.Aggregate
4
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria
5
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
6
import java.util.*
7

Julien Topçu's avatar
Julien Topçu committed
8
@Aggregate
9
class Recommendation(val id: UUID = UUID.randomUUID(), val criteria: Criteria, talks: Set<Talk>) {
Julien Topçu's avatar
Julien Topçu committed
10

11
12
13
14
15
16
17
18
19
20
21
22
    val talks: Set<Talk>

    init {
        checkCriteriaTalkFormatsCorrespondToTheTalksOne(talks)
        this.talks = talks.toSet()
    }

    private fun checkCriteriaTalkFormatsCorrespondToTheTalksOne(talks: Set<Talk>) {
        if (talks.any { !criteria.hasTalkFormat(it.format) }) {
            throw IllegalArgumentException("Criteria talk formats doesn't correspond to the format of the recommended talks")
        }
    }
Julien Topçu's avatar
Julien Topçu committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as Recommendation

        if (id != other.id) return false

        return true
    }

    override fun hashCode(): Int {
        return id.hashCode()
    }

    override fun toString(): String {
40
        return "Recommendation(id=$id, criteria=$criteria, talks=$talks)"
Julien Topçu's avatar
Julien Topçu committed
41
42
    }
}