Skip to content

Commit

Permalink
Added Email & IP Validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Carleslc committed Jul 30, 2017
1 parent 50d85fa commit 3660c9d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Add the following dependencies to your `pom.xml`:
<dependency>
<groupId>com.github.carleslc</groupId>
<artifactId>kotlin-extensions</artifactId>
<version>0.5.1</version>
<version>0.6</version>
</dependency>
</dependencies>
```
Expand All @@ -40,7 +40,7 @@ repositories {
Add the following dependency to your `build.gradle`:
```
dependencies {
compile 'com.github.carleslc:kotlin-extensions:0.5.1'
compile 'com.github.carleslc:kotlin-extensions:0.6'
}
```

Expand All @@ -54,7 +54,7 @@ If you need more powerful extensions and tools check the [optional libraries sec

If you wish, you can use these steps to add the dependency using Maven or Gradle without accessing to the `jitpack.io` remote repository.

Otherwise you will need to add the `kotlin-extensions-0.5.1.jar` from generated `target` folder as external dependency of your project.
Otherwise you will need to add the `kotlin-extensions-0.6.jar` from generated `target` folder as external dependency of your project.

If you need more powerful extensions and tools check the [optional libraries section](https://github.com/Carleslc/kotlin-extensions#optional-libraries).

Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>me.carleslc</groupId>
<artifactId>kotlin-extensions</artifactId>
<version>0.5.1</version>
<version>0.6</version>
<packaging>jar</packaging>

<name>KotlinExtensions</name>
Expand Down Expand Up @@ -74,6 +74,12 @@
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<!-- Apache Commons Validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package me.carleslc.kotlin.extensions.preconditions

import me.carleslc.kotlin.extensions.standard.*
import org.apache.commons.validator.routines.EmailValidator
import org.apache.commons.validator.routines.InetAddressValidator
import java.math.BigDecimal
import java.math.BigInteger

Expand Down Expand Up @@ -79,3 +81,8 @@ inline fun BigInteger.requireNonDefault(): BigInteger = requireNonDefault("canno
fun BigDecimal.requireNonDefault(throwable: Throwable = IllegalArgumentException("cannot be ${defaultBigDecimal()}"), elseBlock: () -> Unit = {}): BigDecimal = require({ this != defaultBigDecimal() }, throwable, { run(elseBlock) })
fun BigDecimal.requireNonDefault(message: String = "cannot be ${defaultBigDecimal()}", elseBlock: () -> Unit = {}): BigDecimal = requireNonDefault(IllegalArgumentException(message), elseBlock)
inline fun BigDecimal.requireNonDefault(): BigDecimal = requireNonDefault("cannot be ${defaultBigDecimal()}")

inline fun String.isValidEmail() = EmailValidator.getInstance().isValid(this)
inline fun String.isValidIP() = InetAddressValidator.getInstance().isValid(this)
inline fun String.isValidIPv4() = InetAddressValidator.getInstance().isValidInet4Address(this)
inline fun String.isValidIPv6() = InetAddressValidator.getInstance().isValidInet6Address(this)
2 changes: 1 addition & 1 deletion src/me/carleslc/kotlin/extensions/time/TimingExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object Durations {
fun from(ago: Long, unit: TimeUnit) = Duration.ofMillis(millis() - unit.toMillis(ago))

/** Duration from [ago] to current [millis()][millis] */
fun fromMillis(millis: Long) = Duration.ofMillis(millis() - millis)
fun fromMillis(ago: Long) = Duration.ofMillis(millis() - ago)

/** Use this method only if [nanos] is extracted from [nanos()][me.carleslc.kotlin.extensions.time.nanos], otherwise resulting duration will be unexpected */
fun fromSystemNanos(nanos: Long): Duration = betweenNanos(nanos, nanos())
Expand Down

0 comments on commit 3660c9d

Please sign in to comment.