-
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.
Merge pull request #11 from NightGoat/0.0.8
0.0.8 version
- Loading branch information
Showing
18 changed files
with
415 additions
and
81 deletions.
There are no files selected for viewing
23 changes: 16 additions & 7 deletions
23
KEXtensions/src/main/java/ru/nightgoat/kextensions/BooleanExt.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 |
---|---|---|
@@ -1,25 +1,34 @@ | ||
package ru.nightgoat.kextensions | ||
|
||
fun Boolean?.orTrue(): Boolean = this ?: true | ||
|
||
fun Boolean?.orFalse(): Boolean = this ?: false | ||
|
||
fun Boolean.takeIfTrue() = this.takeIf { it } | ||
|
||
fun Boolean.takeIfFalse() = this.takeIf { !it } | ||
|
||
fun Boolean.doIfTrue(doFun: () -> Unit): Boolean { | ||
fun Boolean.doIfTrue(doFun: (Boolean) -> Unit): Boolean { | ||
if (this) { | ||
doFun.invoke() | ||
doFun(this) | ||
} | ||
return this | ||
} | ||
|
||
fun Boolean.doIfFalse(doFun: () -> Unit): Boolean { | ||
fun Boolean.doIfFalse(doFun: (Boolean) -> Unit): Boolean { | ||
if (!this) { | ||
doFun.invoke() | ||
doFun.invoke(!this) | ||
} | ||
return this | ||
} | ||
|
||
fun Boolean.toBinary() = 1.takeIf { this }.orZero() | ||
/** | ||
* Returns 1 if true or 0 | ||
*/ | ||
fun Boolean.toBinary() = 1.takeIf { this }.orZero() | ||
|
||
/** | ||
* Returns a string represented as the entered characters | ||
* "X" as true, and "" by default | ||
*/ | ||
fun Boolean.toStringBy(trueSymbol: String = "X", falseSymbol: String = ""): String { | ||
return if (this) trueSymbol else falseSymbol | ||
} |
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
12 changes: 11 additions & 1 deletion
12
KEXtensions/src/main/java/ru/nightgoat/kextensions/DateExt.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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
package ru.nightgoat.kextensions | ||
|
||
import ru.nightgoat.kextensions.utils.constants.DateFormats.DATE_FORMAT_dd_mm_yyyy | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
/** | ||
* Sums up milliseconds in dates. | ||
* With that you can write something like this: Date() + Date() | ||
*/ | ||
operator fun Date.plus(other: Date): Date = Date(this.time + other.time) | ||
operator fun Date.minus(other: Date): Date = Date(this.time - other.time) | ||
|
||
fun Date?.orNow() = this ?: Date() | ||
fun Date?.orNow() = this ?: Date() | ||
|
||
/** | ||
* Returns Date in String in entered pattern. By default returns in dd.MM.yyyy | ||
*/ | ||
fun Date.toStringFormatted(pattern: String = DATE_FORMAT_dd_mm_yyyy): String { | ||
return tryOrEmpty { SimpleDateFormat(pattern, Locale.getDefault()).format(this) } | ||
} |
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
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
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
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
Oops, something went wrong.