Skip to content

Commit

Permalink
Removed unused extensions, updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kochetov committed Jul 25, 2023
1 parent 57c79a1 commit 40f19fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 92 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
|__/ \__/ \______/ \___/ |__/|__/|__/ \_______/|__/ \______/ \______/ |_______/
```

[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![MavenCentral](https://img.shields.io/maven-central/v/dev.vladleesi.kutilicious/base?versionPrefix=0.7.1&color=blue&style=flat-square)](https://central.sonatype.com/namespace/dev.vladleesi.kutilicious)
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![MavenCentral](https://img.shields.io/maven-central/v/dev.vladleesi.kutilicious/base?versionPrefix=0.7.2&color=blue&style=flat-square)](https://central.sonatype.com/namespace/dev.vladleesi.kutilicious)

Small Kotlin and Android extensions for a better development experience

Expand All @@ -23,10 +23,10 @@ repositories {
}
dependencies {
implementation 'dev.vladleesi.kutilicious:base:0.7.1'
implementation 'dev.vladleesi.kutilicious:android-preferences:0.7.1'
implementation 'dev.vladleesi.kutilicious:android-view:0.7.1'
implementation 'dev.vladleesi.kutilicious:android-text:0.7.1'
implementation 'dev.vladleesi.kutilicious:base:0.7.2'
implementation 'dev.vladleesi.kutilicious:android-preferences:0.7.2'
implementation 'dev.vladleesi.kutilicious:android-view:0.7.2'
implementation 'dev.vladleesi.kutilicious:android-text:0.7.2'
}
```

Expand All @@ -38,32 +38,30 @@ dependencies {
- `ifTrue(block: Boolean.() -> Unit)`: Executes the specified block of code if the Boolean value is true.
- `ifFalse(block: Boolean?.() -> Unit)`: Executes the specified block of code if the Boolean value is false.
- `nullOrFalse()`: Checks if the Boolean value is null or false.
- `orFalse()`: Returns the Boolean value if it is not null, or false if it is null.
- `orFalse()`: Wraps a nullable type and returns the Boolean value if it is not null, or false if it is null.
### Integer Extensions
- `orZero()`: Returns the integer value if it is not null, or zero if it is null.
- `orZero()`: Wraps a nullable type and returns the integer value if it is not null, or zero if it is null.
- `takePositiveOrNull()`: Returns the positive integer value if it is greater than zero, or null if it is not.
- `isZero()`: Checks if the integer value is zero.
- `isNotZero()`: Checks if the integer value is not zero.
- `divideToPercent(divideTo: Int)`: Divides the integer value by the specified divisor and returns the result as a percentage. Returns 0 if the divisor is 0.
### Float Extensions
- `orZero()`: Returns the float value if it is not null, or zero if it is null.
- `orZero()`: Wraps a nullable type and returns the float value if it is not null, or zero if it is null.
- `isZero()`: Checks if the float value is zero.
- `isNotZero()`: Checks if the float value is not zero.
### Double Extensions
- `orZero()`: Returns the double value if it is not null, or zero if it is null.
- `orZero()`: Wraps a nullable type and returns the double value if it is not null, or zero if it is null.
- `isZero()`: Checks if the double value is zero.
- `isNotZero()`: Checks if the double value is not zero.
### BigDecimal Extensions
- `orZero()`: Returns the BigDecimal value if it is not null, or BigDecimal.ZERO if it is null.
- `orZero()`: Wraps a nullable type and returns the BigDecimal value if it is not null, or BigDecimal.ZERO if it is null.
- `isZero()`: Checks if the BigDecimal value is zero.
- `isNotZero()`: Checks if the BigDecimal value is not zero.
- `same(value: BigDecimal?)`: Checks if two BigDecimal values are equal.
### String Extensions
- `isNullOrEmptyAfterTrim()`: Implements deprecated logic from PojoUtils.isNull(). Checks if the string is null or the trimmed string is empty.
- `isNotNullOrEmptyAfterTrim()`: Implements deprecated logic from PojoUtils.isNotNull(). Checks if the string is not null and the trimmed string is not empty.
- `firstLetterUpperCase()`: Converts the first letter of the string to uppercase.
- `addMissingPrefix(prefix: String, ignoreCase: Boolean = false)`: Adds a prefix to the string if it doesn't already start with it.
- `isNotNullOrEmpty()`: Checks if the string is not null and not empty.
- `isNotNullOrEmpty()`: Checks if the string is not null and not empty and returns a non-null boolean.
##### String as URL
- `isUrl()`: Checks if the string is a valid URL.
- `isUrlWithCustomScheme()`: Checks if the string is a URL with a custom scheme.
Expand Down
8 changes: 4 additions & 4 deletions base/src/main/java/dev/vladleesi/base/NumberExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package dev.vladleesi.base
import java.math.BigDecimal

/**
* Returns the integer value if it is not null, or zero if it is null.
* Wraps a nullable type and returns the integer value if it is not null, or zero if it is null.
*
* @return The integer value if not null, zero if null.
*/
Expand Down Expand Up @@ -46,7 +46,7 @@ fun Int.divideToPercent(divideTo: Int): Int {
}

/**
* Returns the float value if it is not null, or zero if it is null.
* Wraps a nullable type and returns the float value if it is not null, or zero if it is null.
*
* @return The float value if not null, zero if null.
*/
Expand All @@ -67,7 +67,7 @@ fun Float?.isZero(): Boolean = this != null && this == 0.0F
fun Float?.isNotZero(): Boolean = !isZero()

/**
* Returns the double value if it is not null, or zero if it is null.
* Wraps a nullable type and returns the double value if it is not null, or zero if it is null.
*
* @return The double value if not null, zero if null.
*/
Expand All @@ -88,7 +88,7 @@ fun Double?.isZero(): Boolean = this != null && this == 0.0
fun Double?.isNotZero(): Boolean = !isZero()

/**
* Returns the BigDecimal value if it is not null, or BigDecimal.ZERO if it is null.
* Wraps a nullable type and returns the BigDecimal value if it is not null, or BigDecimal.ZERO if it is null.
*
* @return The BigDecimal value if not null, BigDecimal.ZERO if null.
*/
Expand Down
18 changes: 0 additions & 18 deletions base/src/main/java/dev/vladleesi/base/StringExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ private const val URL_REGEX =
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*" +
"[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$"

/**
* Implements deprecated logic from PojoUtils.isNull()
* @param string to check
* @return true if string is null or trimmed string is empty
*/
fun String?.isNullOrEmptyAfterTrim(): Boolean {
return this == null || this.trim().isEmpty()
}

/**
* Implements deprecated logic from PojoUtils.isNotNull()
* @param string to check
* @return true if string is not null and trimmed string is not empty
*/
fun String?.isNotNullOrEmptyAfterTrim(): Boolean {
return !this.isNullOrEmptyAfterTrim()
}

/**
* Converts the first letter of the string to uppercase.
*
Expand Down
56 changes: 0 additions & 56 deletions base/src/test/java/dev/vladleesi/base/StringExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,6 @@ import org.junit.Test
*/
class StringExtensionsTest {

@Test
fun `isNullOrEmptyAfterTrim should return true for null string`() {
val string: String? = null
val result = string.isNullOrEmptyAfterTrim()
assertTrue(result)
}

@Test
fun `isNullOrEmptyAfterTrim should return true for empty string`() {
val string = ""
val result = string.isNullOrEmptyAfterTrim()
assertTrue(result)
}

@Test
fun `isNullOrEmptyAfterTrim should return true for string with only whitespaces`() {
val string = " "
val result = string.isNullOrEmptyAfterTrim()
assertTrue(result)
}

@Test
fun `isNullOrEmptyAfterTrim should return false for non-empty string`() {
val string = "Hello, World!"
val result = string.isNullOrEmptyAfterTrim()
assertFalse(result)
}

@Test
fun `isNotNullOrEmptyAfterTrim should return false for null string`() {
val string: String? = null
val result = string.isNotNullOrEmptyAfterTrim()
assertFalse(result)
}

@Test
fun `isNotNullOrEmptyAfterTrim should return false for empty string`() {
val string = ""
val result = string.isNotNullOrEmptyAfterTrim()
assertFalse(result)
}

@Test
fun `isNotNullOrEmptyAfterTrim should return false for string with only whitespaces`() {
val string = " "
val result = string.isNotNullOrEmptyAfterTrim()
assertFalse(result)
}

@Test
fun `isNotNullOrEmptyAfterTrim should return true for non-empty string`() {
val string = "Hello, World!"
val result = string.isNotNullOrEmptyAfterTrim()
assertTrue(result)
}

@Test
fun `firstLetterUpperCase should capitalize the first letter of a string`() {
val string = "hello, world!"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kotlin.code.style=official
android.nonTransitiveRClass=true

publication.groupId=dev.vladleesi.kutilicious
publication.version=0.7.1
publication.version=0.7.2

pom.url=https://github.com/vladleesi/kutilicious
pom.name=kutilicious
Expand Down

0 comments on commit 40f19fc

Please sign in to comment.