Skip to content

Commit

Permalink
Merge pull request #398 from JarvisCraft/1.0.0-rc.11
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft authored Sep 18, 2022
2 parents e783065 + 986f048 commit 30ee5ea
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ jobs:
- uses: actions/checkout@v3.0.2

- name: Set up Java 17
uses: actions/setup-java@v3.4.0
uses: actions/setup-java@v3.5.0
with:
distribution: 'zulu'
java-version: '17'
cache: 'maven'

- name: Initialize CodeQL
uses: github/codeql-action/init@v2.1.15
uses: github/codeql-action/init@v2.1.23
with:
languages: java

- name: Autobuild
uses: github/codeql-action/autobuild@v2.1.15
uses: github/codeql-action/autobuild@v2.1.23

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2.1.15
uses: github/codeql-action/analyze@v2.1.23
4 changes: 2 additions & 2 deletions .github/workflows/deploy-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3.0.2

- name: Set up Java 17 & Deployment credentials
uses: actions/setup-java@v3.4.0
uses: actions/setup-java@v3.5.0
with:
distribution: 'zulu'
java-version: '17'
Expand All @@ -24,7 +24,7 @@ jobs:
gpg-private-key: ${{ secrets.CODE_SIGNING_GPG_PRIVATE_KEY }}
gpg-passphrase: CODE_SIGNING_GPG_KEY_PASSPHRASE

- uses: jactions/maven-version@v1.0.1
- uses: jactions/maven-version@v1.1.0
id: get_version

- name: Deploy release
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3.0.2

- name: Set up Java 17 & Deployment credentials
uses: actions/setup-java@v3.4.0
uses: actions/setup-java@v3.5.0
with:
distribution: 'zulu'
java-version: '17'
Expand All @@ -24,7 +24,7 @@ jobs:
gpg-private-key: ${{ secrets.CODE_SIGNING_GPG_PRIVATE_KEY }}
gpg-passphrase: CODE_SIGNING_GPG_KEY_PASSPHRASE

- uses: jactions/maven-version@v1.0.1
- uses: jactions/maven-version@v1.1.0
id: get_version

- name: Deploy snapshot
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3.0.2

- name: Set up Java 17
uses: actions/setup-java@v3.4.0
uses: actions/setup-java@v3.5.0
with:
distribution: 'zulu'
java-version: '17'
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v3.0.2

- name: Set up Java 17
uses: actions/setup-java@v3.4.0
uses: actions/setup-java@v3.5.0
with:
distribution: 'zulu'
java-version: '17'
Expand Down
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

| Version | Supported |
|---------------| ------------------ |
| [1.0.0-rc.10] | :heavy_check_mark: |
| < 1.0.0-rc.10 | :x: |
| [1.0.0-rc.11] | :heavy_check_mark: |
| < 1.0.0-rc.11 | :x: |

## Reporting a Vulnerability

Expand All @@ -16,4 +16,4 @@ These are checked regularly and are the primary support channel.

<!-- Version links -->

[1.0.0-rc.10]: https://mvnrepository.com/artifact/ru.progrm-jarvis/padla/1.0.0-rc.10
[1.0.0-rc.11]: https://mvnrepository.com/artifact/ru.progrm-jarvis/padla/1.0.0-rc.11
2 changes: 1 addition & 1 deletion java-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>ru.progrm-jarvis</groupId>
<artifactId>padla-parent</artifactId>
<version>1.0.0-rc.10</version>
<version>1.0.0-rc.11</version>
<relativePath>../padla-parent</relativePath>
</parent>
<artifactId>java-commons</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ public interface Result<T, E> extends Supplier<T> {
* @see #from(Optional) alternative with default (i.e. null) error
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") // convertion from optional itself
static <T, E> @NotNull Result<T, E> from(final @NonNull Optional<? extends T> optional,
final @NonNull Supplier<? extends E> errorSupplier) {
static <T, E> @NotNull Result<T, E> from(
final @NonNull Optional<? extends T> optional,
final @NonNull Supplier<? extends E> errorSupplier
) {
return optional.<Result<T, E>>map(Result::success).orElseGet(() -> error(errorSupplier.get()));
}

Expand Down Expand Up @@ -401,17 +403,25 @@ default <X extends Throwable> T orElseSneakyThrow(
* Gets the value of this result if this is a {@link #isSuccess() successful}
* otherwise returning default value.
*
* @param defaultValue default value to be returned if this is an {@link #isError()} error value}
* @param defaultValue default value to be returned if this is an {@link #isError() error value}
* @return successful value if this a {@link #isSuccess() successful result} or {@code defaultValue} otherwise
*/
T orDefault(T defaultValue);

/**
* Gets the value of this result if this is a {@link #isSuccess() successful}
* otherwise returning {@code null}.
*
* @return successful value if this a {@link #isSuccess() successful result} or {@code null} otherwise
*/
@Nullable T orNull();

/**
* Gets the value of this result if this is a {@link #isSuccess() successful}
* otherwise returning the value got by using the specified supplier.
*
* @param defaultValueSupplier supplier of the default value
* to be returned if this is an {@link #isError()} error value}
* to be returned if this is an {@link #isError() error value}
* @return successful value if this a {@link #isSuccess() successful result} or got default otherwise
*/
T orGetDefault(@NonNull Supplier<? extends T> defaultValueSupplier);
Expand All @@ -421,7 +431,7 @@ default <X extends Throwable> T orElseSneakyThrow(
* otherwise returning the value computed by applying the given function to the {@link #unwrapError() error value}.
*
* @param defaultValueFactory factory used for creation of the default value
* to be returned if this is an {@link #isError()} error value}
* to be returned if this is an {@link #isError() error value}
* @return successful value if this a {@link #isSuccess() successful result} or the computed default otherwise
*/
T orComputeDefault(@NonNull Function<? super E, ? extends T> defaultValueFactory);
Expand Down Expand Up @@ -488,6 +498,45 @@ default <X extends Throwable> E errorOrElseSneakyThrow(
return errorOrElseThrow(exceptionFactory);
}

/**
* Gets the error of this result if this is an {@link #isError() error}
* otherwise returning default value.
*
* @param defaultError default value to be returned if this is an {@link #isSuccess() successful result}
* @return error value if this an {@link #isError() error result} or {@code defaultError} otherwise
*/
E errorOrDefault(E defaultError);

/**
* Gets the error of this result if this is an {@link #isError() error}
* otherwise returning {@code null}.
*
* @return error value if this an {@link #isError() error result} or {@code null} otherwise
*/
@Nullable E errorOrNull();

/**
* Gets the value of this result if this is an {@link #isError() error}
* otherwise returning the value got by using the specified supplier.
*
* @param defaultErrorSupplier supplier of the default error
* to be returned if this is a {@link #isSuccess() successful value}
* @return error value if this an {@link #isError() error result} or got default otherwise
*/
E errorOrGetDefault(@NonNull Supplier<? extends E> defaultErrorSupplier);

/**
* Gets the value of this result if this is a {@link #isSuccess() successful}
* otherwise returning the value computed by applying the given function to the {@link #unwrapError() error value}.
*
* @param defaultErrorFactory factory used for creation of the default error
* to be returned if this is a {@link #isSuccess() successful value}
* @return successful value if this an {@link #isError() error result} or the computed default otherwise
*/
E errorOrComputeDefault(@NonNull Function<? super T, ? extends E> defaultErrorFactory);

/* ********************************************** Handling methods ********************************************** */

/**
* Invokes the given function if this result is a {@link #isSuccess() successful result}.
*
Expand Down Expand Up @@ -727,6 +776,11 @@ public T orDefault(final T defaultValue) {
return value;
}

@Override
public @Nullable T orNull() {
return value;
}

@Override
public T orGetDefault(final @NonNull Supplier<? extends T> defaultValueSupplier) {
return value;
Expand Down Expand Up @@ -754,6 +808,26 @@ public <X extends Throwable> E errorOrElseThrow(
throw exceptionSupplier.apply(value);
}

@Override
public E errorOrDefault(final E defaultError) {
return defaultError;
}

@Override
public @Nullable E errorOrNull() {
return null;
}

@Override
public E errorOrGetDefault(@NonNull final Supplier<? extends E> defaultErrorSupplier) {
return defaultErrorSupplier.get();
}

@Override
public E errorOrComputeDefault(@NonNull final Function<? super T, ? extends E> defaultErrorFactory) {
return defaultErrorFactory.apply(value);
}

@Override
public void ifSuccess(final @NonNull Consumer<? super T> successConsumer) {
successConsumer.accept(value);
Expand Down Expand Up @@ -928,6 +1002,11 @@ public T orDefault(final T defaultValue) {
return defaultValue;
}

@Override
public @Nullable T orNull() {
return null;
}

@Override
public T orGetDefault(final @NonNull Supplier<? extends T> defaultValueSupplier) {
return defaultValueSupplier.get();
Expand Down Expand Up @@ -955,6 +1034,26 @@ public <X extends Throwable> E errorOrElseThrow(
return error;
}

@Override
public E errorOrDefault(final E defaultError) {
return error;
}

@Override
public @Nullable E errorOrNull() {
return error;
}

@Override
public E errorOrGetDefault(@NonNull final Supplier<? extends E> defaultErrorSupplier) {
return error;
}

@Override
public E errorOrComputeDefault(@NonNull final Function<? super T, ? extends E> defaultErrorFactory) {
return error;
}

@Override
public void ifSuccess(final @NonNull Consumer<? super T> successConsumer) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ru.progrm_jarvis.javacommons.util;

import lombok.NonNull;
import lombok.experimental.UtilityClass;
import lombok.val;
import lombok.var;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Array;
import java.util.function.Function;
import java.util.function.IntFunction;

/**
* Utilities for working with arrays.
*/
@UtilityClass
public class ArrayUtils {

/**
* Maps the given array by-element using the provided function.
*
* @param source source array
* @param mappingFunction function used to map elements
* @param arrayFactory function used to create a new array by its length
* @return created array
* @param <T> the type of source elements
* @param <R> the type of target elements
*/
public static <T, R> R @NotNull [] map(
final T @NonNull [] source,
final @NonNull Function<? super T, ? extends R> mappingFunction,
final @NonNull IntFunction<? extends R @NotNull []> arrayFactory
) {
final int length;
val target = arrayFactory.apply(length = source.length);
for (var i = 0; i < length; i++) target[i] = mappingFunction.apply(source[i]);

return target;
}
/**
* Maps the given array by-element using the provided function.
*
* @param source source array
* @param mappingFunction function used to map elements
* @param typeHint pseudo-array of the same type as the target array
* @return created array
* @param <T> the type of source elements
* @param <R> the type of target elements
*/
public static <T, R> R @NotNull [] map(
final T @NonNull [] source,
final @NonNull Function<? super T, ? extends R> mappingFunction,
@TypeHints.TypeHint
final @NonNull R... typeHint
) {
final int length;
@SuppressWarnings("unchecked")
val target = (R[]) Array.newInstance(TypeHints.resolve(typeHint), length = source.length);
for (var i = 0; i < length; i++) target[i] = mappingFunction.apply(source[i]);

return target;
}
}
2 changes: 1 addition & 1 deletion java-commons/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module ru.progrm_jarvis.javacommons {
// optional dependencies
requires org.objectweb.asm;
requires javassist;
requires org.javassist;

requires static lombok;
requires static org.jetbrains.annotations;
Expand Down
8 changes: 4 additions & 4 deletions padla-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>ru.progrm-jarvis</groupId>
<artifactId>padla</artifactId>
<version>1.0.0-rc.10</version>
<version>1.0.0-rc.11</version>
</parent>
<artifactId>padla-bom</artifactId>
<packaging>pom</packaging>
Expand All @@ -20,17 +20,17 @@
<dependency>
<groupId>ru.progrm-jarvis</groupId>
<artifactId>java-commons</artifactId>
<version>1.0.0-rc.10</version>
<version>1.0.0-rc.11</version>
</dependency>
<dependency>
<groupId>ru.progrm-jarvis</groupId>
<artifactId>reflector</artifactId>
<version>1.0.0-rc.10</version>
<version>1.0.0-rc.11</version>
</dependency>
<dependency>
<groupId>ru.progrm-jarvis</groupId>
<artifactId>ultimate-messenger</artifactId>
<version>1.0.0-rc.10</version>
<version>1.0.0-rc.11</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Loading

0 comments on commit 30ee5ea

Please sign in to comment.