This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
adriantodt
committed
Aug 25, 2019
1 parent
ed2dfed
commit cc15236
Showing
19 changed files
with
233 additions
and
220 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ package pw.aru.psi.exported | |
/** | ||
* Psi Version | ||
*/ | ||
const val psi_version = "1.5" | ||
const val psi_version = "1.6" |
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/pw/aru/utils/extensions/lang/Collections.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") | ||
@file:JvmName("LangExt") | ||
@file:JvmMultifileClass | ||
|
||
package pw.aru.utils.extensions.lang | ||
|
||
fun <E> List<E>.bestSplit(minSize: Int, maxSize: Int): List<List<E>> { | ||
return when { | ||
size < maxSize -> listOf(this) | ||
else -> chunked((minSize..maxSize).minBy { it - size % it } ?: (minSize + maxSize) / 2) | ||
} | ||
} | ||
|
||
fun <T> Iterable<Iterable<T>>.roundRobinFlatten(): List<T> { | ||
val result = ArrayList<T>() | ||
val iterators = mapTo(ArrayList(), Iterable<T>::iterator) | ||
|
||
while (iterators.isNotEmpty()) { | ||
val i = iterators.iterator() | ||
while (i.hasNext()) { | ||
val ii = i.next() | ||
if (ii.hasNext()) { | ||
result.add(ii.next()) | ||
} else { | ||
i.remove() | ||
} | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
inline fun <K, V> Map<K, V>.ifContains(k: K, function: (V) -> Unit) { | ||
if (containsKey(k)) function(get(k)!!) | ||
} | ||
|
||
inline fun <E> List<E>.randomOrNull(): E? = if (isEmpty()) null else random() | ||
|
||
inline fun <E> Array<E>.randomOrNull(): E? = if (isEmpty()) null else random() | ||
|
||
inline fun <E> randomOf(vararg objects: E): E = objects.random() |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/pw/aru/utils/extensions/lang/Conditions.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") | ||
@file:JvmName("LangExt") | ||
@file:JvmMultifileClass | ||
|
||
package pw.aru.utils.extensions.lang | ||
|
||
inline fun anyOf(vararg cases: Boolean) = cases.any { it } | ||
|
||
inline fun allOf(vararg cases: Boolean) = cases.all { it } | ||
|
||
inline fun noneOf(vararg cases: Boolean) = cases.none { it } |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/pw/aru/utils/extensions/lang/Environiment.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package pw.aru.utils.extensions.lang | ||
|
||
import kotlin.properties.ReadOnlyProperty | ||
import kotlin.reflect.KProperty | ||
|
||
object Environiment : ReadOnlyProperty<Any?, String> { | ||
private val env by lazy { System.getenv() } | ||
|
||
override fun getValue(thisRef: Any?, property: KProperty<*>): String { | ||
return env.get(property.name) ?: throw IllegalStateException("No environment property ${property.name}") | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") | ||
@file:JvmName("LangExt") | ||
@file:JvmMultifileClass | ||
|
||
package pw.aru.utils.extensions.lang | ||
|
||
inline fun <T, U> T.applyOn(thisObj: U, block: U.() -> Unit): T { | ||
thisObj.block() | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") | ||
@file:JvmName("LangExt") | ||
@file:JvmMultifileClass | ||
|
||
package pw.aru.utils.extensions.lang | ||
|
||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.CompletionStage | ||
import java.util.concurrent.Future | ||
import kotlin.reflect.KProperty | ||
|
||
@JvmName("futureValue") | ||
fun <V> Future<V>.value(): V = get() | ||
|
||
@JvmName("completionValue") | ||
fun <V> CompletionStage<V>.value(): V = stageToFuture().join() | ||
|
||
@JvmName("futureCompletionValue") | ||
fun <V, T> T.value(): V where T : Future<V>, T : CompletionStage<V> = get() | ||
|
||
@JvmName("futureGetValue") | ||
operator fun <V> Future<V>.getValue(r: Any?, p: KProperty<*>): V = get() | ||
|
||
@JvmName("completionGetValue") | ||
operator fun <V> CompletionStage<V>.getValue(r: Any?, p: KProperty<*>): V = stageToFuture().join() | ||
|
||
@JvmName("futureCompletionGetValue") | ||
operator fun <V, T> T.getValue(r: Any?, p: KProperty<*>): V where T : Future<V>, T : CompletionStage<V> = get() | ||
|
||
private fun <T> CompletionStage<T>.stageToFuture(): CompletableFuture<T> { | ||
return if (this is CompletableFuture<*>) { | ||
this as CompletableFuture<T> | ||
} else { | ||
toCompletableFuture() | ||
} | ||
} | ||
|
||
fun <T> Array<CompletionStage<T>>.awaitAll(): CompletionStage<Void> { | ||
return CompletableFuture.allOf( | ||
*map { it.stageToFuture() } | ||
.toTypedArray() | ||
) | ||
} | ||
|
||
fun <T> Collection<CompletionStage<T>>.awaitAll(): CompletionStage<Void> { | ||
return CompletableFuture.allOf( | ||
*map { it.stageToFuture() } | ||
.toTypedArray() | ||
) | ||
} |
23 changes: 13 additions & 10 deletions
23
src/main/kotlin/pw/aru/utils/extensions/lang/JavaHttpClient.kt
100755 → 100644
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,20 +1,23 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") | ||
@file:JvmName("LangExt") | ||
@file:JvmMultifileClass | ||
|
||
package pw.aru.utils.extensions.lang | ||
|
||
import java.net.http.HttpClient | ||
import java.net.http.HttpRequest | ||
import java.net.http.HttpResponse | ||
import java.net.http.HttpResponse.BodyHandler | ||
import java.util.concurrent.CompletableFuture | ||
import java.net.http.HttpRequest.newBuilder as requestBuilder | ||
|
||
private typealias RequestBuilder = HttpRequest.Builder.() -> Unit | ||
private typealias CompletableResponse<T> = CompletableFuture<HttpResponse<T>> | ||
|
||
fun <T> HttpClient.send( | ||
bodyHandler: HttpResponse.BodyHandler<T>, | ||
block: HttpRequest.Builder.() -> Unit | ||
): HttpResponse<T> { | ||
return send(HttpRequest.newBuilder().also(block).build(), bodyHandler) | ||
inline fun <T> HttpClient.send(bodyHandler: BodyHandler<T>, block: RequestBuilder): HttpResponse<T> { | ||
return send(requestBuilder().also(block).build(), bodyHandler) | ||
} | ||
|
||
fun <T> HttpClient.sendAsync( | ||
bodyHandler: HttpResponse.BodyHandler<T>, | ||
block: HttpRequest.Builder.() -> Unit | ||
): CompletableFuture<HttpResponse<T>> { | ||
return sendAsync(HttpRequest.newBuilder().also(block).build(), bodyHandler) | ||
inline fun <T> HttpClient.sendAsync(bodyHandler: BodyHandler<T>, block: RequestBuilder): CompletableResponse<T> { | ||
return sendAsync(requestBuilder().also(block).build(), bodyHandler) | ||
} |
Oops, something went wrong.