This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(desktop): create class BookCopyImpl that implement BookCopy, Gen…
…eralSchoolSupplyImpl that implement GeneralSchoolSupply and AbstractSchoolSupply, abstract class for both
- Loading branch information
1 parent
efc5326
commit f800158
Showing
3 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...in/com/intelligentbackpack/desktopdomain/entities/implementations/AbstractSchoolSupply.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.intelligentbackpack.desktopdomain.entities.implementations | ||
|
||
import com.intelligentbackpack.desktopdomain.entities.MutableSchoolSupply | ||
import com.intelligentbackpack.desktopdomain.entities.SchoolSupply | ||
import com.intelligentbackpack.desktopdomain.entities.SchoolSupplyType | ||
import com.intelligentbackpack.desktopdomain.entities.Subject | ||
import com.intelligentbackpack.desktopdomain.exception.ReplaceException | ||
import com.intelligentbackpack.desktopdomain.policies.ReplacePolicy | ||
import kotlin.jvm.Throws | ||
|
||
/** | ||
* Abstract implementation of a school supply. | ||
* | ||
* @property type The type of the school supply. | ||
* @property rfidCode The RFID code of the school supply. | ||
* @property subjects The subjects of the school supply. | ||
* @property replacedBy The school supplies that replace this one. | ||
* @property replace The school supplies that this one replaces. | ||
*/ | ||
abstract class AbstractSchoolSupply<T : SchoolSupply> : MutableSchoolSupply<T> { | ||
|
||
/** | ||
* The type of the school supply. | ||
* @param type The type of the school supply. | ||
* @param rfidCode The RFID code of the school supply. | ||
* @param subjects The subjects of the school supply. | ||
* @param replacedBy The school supplies that replace this one. | ||
* @param replace The school supplies that this one replaces. | ||
* @return The school supply with the given type. | ||
*/ | ||
protected abstract fun copy( | ||
type: SchoolSupplyType = this.type, | ||
rfidCode: String = this.rfidCode, | ||
subjects: Set<Subject> = this.subjects, | ||
replacedBy: Set<T> = this.replacedBy, | ||
replace: Set<T> = this.replace, | ||
): MutableSchoolSupply<T> | ||
|
||
/** | ||
* Add the given school supply to the list of school supplies that replace this one. | ||
* @param schoolSupply The school supply to add. | ||
* @return The school supply with the given school supply added to the list of school supplies that replace this one. | ||
* @throws ReplaceException If the school supply that replace doesn't respect the [ReplacePolicy]. | ||
*/ | ||
@Throws(ReplaceException::class) | ||
override fun addReplacedBy(schoolSupply: T): MutableSchoolSupply<T> { | ||
if (ReplacePolicy.isValid(setOf(schoolSupply), setOf(this))) | ||
return this.copy(replacedBy = replacedBy + schoolSupply) | ||
else | ||
throw ReplaceException() | ||
} | ||
|
||
/** | ||
* Add the given school supply to the list of school supplies that this one replaces. | ||
* @param schoolSupply The school supply to add. | ||
* @return The school supply with the given school supply added to the list of school supplies that this one replaces. | ||
* @throws ReplaceException If the school supply to replace doesn't respect the [ReplacePolicy]. | ||
*/ | ||
@Throws(ReplaceException::class) | ||
override fun addReplace(schoolSupply: T): MutableSchoolSupply<T> { | ||
if (ReplacePolicy.isValid(setOf(this), setOf(schoolSupply))) | ||
return this.copy(replace = replace + schoolSupply) | ||
else | ||
throw ReplaceException() | ||
} | ||
|
||
override fun addSubjects(subjects: Set<Subject>) = | ||
this.copy(subjects = this.subjects + subjects) | ||
} |
71 changes: 71 additions & 0 deletions
71
...ain/kotlin/com/intelligentbackpack/desktopdomain/entities/implementations/BookCopyImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.intelligentbackpack.desktopdomain.entities.implementations | ||
|
||
import com.intelligentbackpack.desktopdomain.entities.BookCopy | ||
import com.intelligentbackpack.desktopdomain.entities.SchoolSupplyType | ||
import com.intelligentbackpack.desktopdomain.entities.SchoolSupplyTypes | ||
import com.intelligentbackpack.desktopdomain.entities.Subject | ||
|
||
/** | ||
* Implementation of a book copy. | ||
* | ||
* @property rfidCode The RFID code of the book copy. | ||
* @property subjects The subjects of the book copy. | ||
* @property isbn The ISBN of the book copy. | ||
* @property title The title of the book copy. | ||
* @property authors The authors of the book copy. | ||
* @property replacedBy The book copies that replace this one. | ||
* @property replace The book copies that this one replaces. | ||
* @property type is automatically set to [SchoolSupplyTypes.BOOK]. | ||
*/ | ||
internal data class BookCopyImpl( | ||
override val rfidCode: String, | ||
) : AbstractSchoolSupply<BookCopy>(), BookCopy { | ||
|
||
override lateinit var subjects: Set<Subject> | ||
private set | ||
override lateinit var isbn: String | ||
private set | ||
override lateinit var title: String | ||
private set | ||
override lateinit var authors: List<String> | ||
private set | ||
override var replacedBy: Set<BookCopy> = setOf() | ||
private set | ||
override var replace: Set<BookCopy> = setOf() | ||
private set | ||
|
||
constructor( | ||
rfidCode: String, | ||
subjects: Set<Subject>, | ||
isbn: String, | ||
title: String, | ||
authors: List<String>, | ||
replacedBy: Set<BookCopy>, | ||
replace: Set<BookCopy> | ||
) : this(rfidCode) { | ||
this.subjects = subjects | ||
this.isbn = isbn | ||
this.title = title | ||
this.authors = authors | ||
this.replacedBy = replacedBy | ||
this.replace = replace | ||
} | ||
|
||
override val type: SchoolSupplyType = SchoolSupplyTypes.BOOK | ||
override fun copy( | ||
type: SchoolSupplyType, | ||
rfidCode: String, | ||
subjects: Set<Subject>, | ||
replacedBy: Set<BookCopy>, | ||
replace: Set<BookCopy> | ||
): BookCopy = | ||
BookCopyImpl( | ||
rfidCode = rfidCode, | ||
subjects = subjects, | ||
isbn = isbn, | ||
title = title, | ||
authors = authors, | ||
replacedBy = replacedBy, | ||
replace = replace | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
...com/intelligentbackpack/desktopdomain/entities/implementations/GeneralSchoolSupplyImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.intelligentbackpack.desktopdomain.entities.implementations | ||
|
||
import com.intelligentbackpack.desktopdomain.entities.GeneralSchoolSupply | ||
import com.intelligentbackpack.desktopdomain.entities.SchoolSupplyType | ||
import com.intelligentbackpack.desktopdomain.entities.Subject | ||
|
||
/** | ||
* Implementation of a general school supply. | ||
* | ||
* @property type The type of the school supply. | ||
* @property rfidCode The RFID code of the school supply. | ||
* @property description The description of the school supply. | ||
* @property subjects The subjects of the school supply. | ||
* @property replacedBy The school supplies that replace this one. | ||
* @property replace The school supplies that this one replaces. | ||
*/ | ||
internal data class GeneralSchoolSupplyImpl( | ||
override val rfidCode: String | ||
) : AbstractSchoolSupply<GeneralSchoolSupply>(), GeneralSchoolSupply { | ||
|
||
constructor( | ||
type: SchoolSupplyType, | ||
rfidCode: String, | ||
description: String, | ||
subjects: Set<Subject>, | ||
replacedBy: Set<GeneralSchoolSupply>, | ||
replace: Set<GeneralSchoolSupply> | ||
) : this(rfidCode) { | ||
this.type = type | ||
this.description = description | ||
this.subjects = subjects | ||
this.replacedBy = replacedBy | ||
this.replace = replace | ||
} | ||
|
||
override lateinit var type: SchoolSupplyType | ||
private set | ||
override lateinit var description: String | ||
private set | ||
override lateinit var subjects: Set<Subject> | ||
private set | ||
override var replacedBy: Set<GeneralSchoolSupply> = setOf() | ||
private set | ||
override var replace: Set<GeneralSchoolSupply> = setOf() | ||
private set | ||
|
||
override fun copy( | ||
type: SchoolSupplyType, | ||
rfidCode: String, | ||
subjects: Set<Subject>, | ||
replacedBy: Set<GeneralSchoolSupply>, | ||
replace: Set<GeneralSchoolSupply> | ||
): GeneralSchoolSupply = GeneralSchoolSupplyImpl( | ||
type = type, | ||
rfidCode = rfidCode, | ||
description = description, | ||
subjects = subjects, | ||
replacedBy = replacedBy, | ||
replace = replace | ||
) | ||
} |