Skip to content

Commit cf8c5eb

Browse files
committed
doc map
1 parent 6cc067d commit cf8c5eb

File tree

2 files changed

+37
-3
lines changed
  • core/kotlinx/src/main/kotlin/br/com/mob1st/core/kotlinx/structures
  • features/finances/impl/src/main/kotlin/br/com/mob1st/features/finances/impl/domain/entities

2 files changed

+37
-3
lines changed

Diff for: core/kotlinx/src/main/kotlin/br/com/mob1st/core/kotlinx/structures/BiMap.kt

+37
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,55 @@
11
package br.com.mob1st.core.kotlinx.structures
22

3+
/**
4+
* BI-directional map, allowing searching by direct and reverse keys.
5+
* It's a simple wrapper on top of two maps, one for the left to right and another for the right to left.
6+
* @param L The type of the left key.
7+
* @param R The type of the right key.
8+
* @property leftToRight The map from left to right.
9+
* @property rightToLeft The map from right to left.
10+
*/
311
class BiMap<L, R>(
412
private val leftToRight: MutableMap<L, R> = mutableMapOf(),
513
private val rightToLeft: MutableMap<R, L> = mutableMapOf(),
614
) {
15+
/**
16+
* Gets the right value from the left key.
17+
* @param left The left key or null if not found.
18+
*/
719
fun getLeft(left: L): R? = leftToRight[left]
820

21+
/**
22+
* Gets the right value from the left key.
23+
* @param right The right key or null if not found.
24+
* @return The right value or null if not found.
25+
*/
926
fun getRight(right: R): L? = rightToLeft[right]
1027

28+
/**
29+
* Gets the right value from the left key, throwing an exception if not found.
30+
* @param left The left key.
31+
* @return The right value.
32+
* @throws NoSuchElementException If the left key is not found.
33+
*/
1134
fun getLeftValue(left: L): R = leftToRight.getValue(left)
1235

36+
/**
37+
* Gets the right value from the left key, throwing an exception if not found.
38+
* @param right The right key.
39+
* @return The right value.
40+
* @throws NoSuchElementException If the right key is not found.
41+
*/
1342
fun getRightValue(right: R): L = rightToLeft.getValue(right)
1443
}
1544

45+
/**
46+
* Creates a bi-directional map.
47+
* It uses the giben [pairs] of left and right values and both will be used as keys and values.
48+
* @param L The type of the left key.
49+
* @param R The type of the right key.
50+
* @param pairs The pairs of left and right values.
51+
* @return The bi-directional map.
52+
*/
1653
fun <L, R> biMapOf(vararg pairs: Pair<L, R>): BiMap<L, R> {
1754
val leftToRight = mutableMapOf<L, R>()
1855
val rightToLeft = mutableMapOf<R, L>()

Diff for: features/finances/impl/src/main/kotlin/br/com/mob1st/features/finances/impl/domain/entities/BudgetBuilderAction.kt

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package br.com.mob1st.features.finances.impl.domain.entities
22

3-
import kotlinx.serialization.Serializable
4-
53
/**
64
* Represents the action that the user can take in the category builder.
75
*/
@@ -76,7 +74,6 @@ data object SeasonalExpensesStep : BudgetBuilderAction.Step {
7674
* The fourth step in the category builder.
7775
* It is used to add fixed incomes.
7876
*/
79-
@Serializable
8077
data object FixedIncomesStep : BudgetBuilderAction.Step {
8178
override val minimumRequiredToProceed: Int = 0
8279
override val next: BudgetBuilderAction = BudgetBuilderAction.Complete

0 commit comments

Comments
 (0)