Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
1.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
sokomishalov committed Dec 2, 2019
1 parent 2d452f5 commit 723c3b7
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 142 deletions.
73 changes: 16 additions & 57 deletions commons-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>ru.sokomishalov.commons</groupId>
<artifactId>commons-parent</artifactId>
<version>1.0.24</version>
<version>1.0.25</version>
</parent>

<artifactId>commons-core</artifactId>
<version>1.0.24</version>
<version>1.0.25</version>

<properties>
<kotlin.version>1.3.61</kotlin.version>
Expand All @@ -27,12 +27,12 @@
<slf4j.version>1.7.29</slf4j.version>
<logback.version>1.2.3</logback.version>
<easy-random.version>4.1.0</easy-random.version>
<classgraph.version>4.8.57</classgraph.version>
<jsoup.version>1.12.1</jsoup.version>
</properties>


<dependencies>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
Expand All @@ -43,11 +43,6 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-common</artifactId>
<version>${kotlinx.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
Expand Down Expand Up @@ -79,22 +74,7 @@
<artifactId>reactor-netty</artifactId>
<version>${reactor-netty.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-extra</artifactId>
<version>${reactor-addons.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-adapter</artifactId>
<version>${reactor.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand All @@ -115,65 +95,44 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>${classgraph.version}</version>
</dependency>
<!-- OPTIONAL DEPS -->

<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-random-core</artifactId>
<version>${easy-random.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
<optional>true</optional>
</dependency>

<!-- TEST DEPS -->

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("unused", "NOTHING_TO_INLINE")
@file:Suppress("unused")

package ru.sokomishalov.commons.core.collections

Expand All @@ -22,14 +22,6 @@ package ru.sokomishalov.commons.core.collections
* @author sokomishalov
*/

inline fun <K, V> Map<out K, V>?.isNullOrEmpty(): Boolean {
return this == null || isEmpty()
}

inline fun <K, V> Map<out K, V>?.isNotNullOrEmpty(): Boolean {
return (this == null || isEmpty()).not()
}

infix fun <K, V> Map<K, V>.containsEntryFrom(other: Map<K, V>): Boolean {
return this.entries.intersect(other.entries).isNullOrEmpty().not()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ package ru.sokomishalov.commons.core.common
/**
* @author sokomishalov
*/
fun Any?.unit() {}
fun Any?.unit(): Unit = Unit

fun Any?.void(): Void? = null
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package ru.sokomishalov.commons.core.log

import io.github.classgraph.ClassGraph
import org.slf4j.Logger
import java.util.concurrent.ConcurrentHashMap

Expand All @@ -26,16 +25,6 @@ object CustomLoggerFactory {

private val loggersMap: MutableMap<String, Logger> = ConcurrentHashMap()

init {
ClassGraph()
.enableClassInfo()
.disableJarScanning()
.scan()
.getClassesImplementing(Loggable::class.java.name)
.names
.forEach { loggersMap[it] = loggerFor(it) }
}

fun <T : Loggable> getLogger(clazz: Class<T>): Logger {
val logger = loggersMap[clazz.name]
return when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package ru.sokomishalov.commons.core.random

import org.apache.commons.lang3.RandomStringUtils.random
import org.jeasy.random.EasyRandom
import org.jeasy.random.EasyRandomParameters
import java.nio.charset.StandardCharsets.UTF_8
Expand Down Expand Up @@ -45,10 +44,4 @@ inline fun <reified T> randomPojoSequence(params: EasyRandomParameters = EASY_RA
while (true) {
yield(randomPojo(params))
}
}

fun randomString(
length: Int = 20,
useLetters: Boolean = true,
useDigits: Boolean = false
): String = random(length, useLetters, useDigits)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2019-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("unused")

package ru.sokomishalov.commons.core.random

import org.apache.commons.lang3.RandomStringUtils.random

/**
* @author sokomishalov
*/

fun randomString(
length: Int = 20,
useLetters: Boolean = true,
useDigits: Boolean = false
): String = random(length, useLetters, useDigits)
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUM
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategy
import com.fasterxml.jackson.databind.PropertyNamingStrategy.LOWER_CAMEL_CASE
import com.fasterxml.jackson.databind.PropertyNamingStrategy.SNAKE_CASE
import com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS
import com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.datatype.guava.GuavaModule
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule

Expand All @@ -38,18 +36,14 @@ import com.fasterxml.jackson.module.kotlin.registerKotlinModule
*/
val OBJECT_MAPPER: ObjectMapper = buildComplexObjectMapper()

val SNAKE_CASE_OBJECT_MAPPER: ObjectMapper = buildComplexObjectMapper(namingStrategy = SNAKE_CASE)

val YAML_OBJECT_MAPPER: ObjectMapper = buildComplexObjectMapper(YAMLFactory())

fun buildComplexObjectMapper(
factory: JsonFactory? = null,
namingStrategy: PropertyNamingStrategy = LOWER_CAMEL_CASE
): ObjectMapper {
return ObjectMapper(factory)
.registerKotlinModule()
.registerModule(JavaTimeModule())
.registerModule(GuavaModule())
.registerModule(Jdk8Module())
.enable(
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE,
ACCEPT_SINGLE_VALUE_AS_ARRAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,76 @@ inline fun CharSequence?.isNotNullOrBlank(): Boolean {
returns(true) implies (this@isNotNullOrBlank != null)
}
return (this == null || this.isBlank()).not()
}


// https://stackoverflow.com/a/1248627/5843129
fun String.convertGlobToRegex(): Regex {
val sb = StringBuilder(length)
var inGroup = 0
var inClass = 0
var firstIndexInClass = -1
val arr = toCharArray()
var i = 0
while (i < arr.size) {
when (val ch = arr[i]) {
'\\' -> if (++i >= arr.size) {
sb.append('\\')
} else {
val next = arr[i]
when (next) {
',' -> {
}
'Q', 'E' -> {
// extra escape needed
sb.append('\\')
sb.append('\\')
}
else -> sb.append('\\')
}// escape not needed
sb.append(next)
}
'*' -> if (inClass == 0)
sb.append(".*")
else
sb.append('*')
'?' -> if (inClass == 0)
sb.append('.')
else
sb.append('?')
'[' -> {
inClass++
firstIndexInClass = i + 1
sb.append('[')
}
']' -> {
inClass--
sb.append(']')
}
'.', '(', ')', '+', '|', '^', '$', '@', '%' -> {
if (inClass == 0 || firstIndexInClass == i && ch == '^')
sb.append('\\')
sb.append(ch)
}
'!' -> if (firstIndexInClass == i)
sb.append('^')
else
sb.append('!')
'{' -> {
inGroup++
sb.append('(')
}
'}' -> {
inGroup--
sb.append(')')
}
',' -> if (inGroup > 0)
sb.append('|')
else
sb.append(',')
else -> sb.append(ch)
}
i++
}
return sb.toString().toRegex()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("unused")

package ru.sokomishalov.commons.core.url

import org.apache.commons.lang3.SystemUtils.getHostName
import ru.sokomishalov.commons.core.consts.EMPTY
import java.net.InetAddress
import java.lang.System.getenv
import java.net.InetAddress.getLocalHost

/**
* @author sokomishalov
*/
val HOSTNAME: String
get() = getHostName()
?: runCatching { InetAddress.getLocalHost().hostAddress }.getOrNull()
?: EMPTY

val HOSTNAME: String by lazy {
getenv("HOSTNAME")
?: getenv("COMPUTERNAME")
?: runCatching { getLocalHost().hostAddress }.getOrNull()
?: EMPTY
}
Loading

0 comments on commit 723c3b7

Please sign in to comment.