Skip to content

Commit

Permalink
dev: Removed ProcessType.java + implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Day-Hawk committed Jul 28, 2023
1 parent 8fa0162 commit 0a3213a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 44 deletions.
22 changes: 0 additions & 22 deletions core/src/main/java/dev/dotspace/common/concurrent/ProcessType.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.dotspace.common.SpaceObjects;
import dev.dotspace.common.annotation.LibraryInformation;
import dev.dotspace.common.concurrent.ProcessType;
import dev.dotspace.common.function.ThrowableConsumer;
import dev.dotspace.common.service.Service;
import org.jetbrains.annotations.NotNull;
Expand All @@ -13,7 +12,6 @@
*/
@LibraryInformation(state = LibraryInformation.State.STABLE, since = "1.0.8")
public final class ResponseService implements Service {
private final @NotNull ProcessType processType;
/**
*
*/
Expand All @@ -24,9 +22,7 @@ public final class ResponseService implements Service {
* @param exceptionConsumer
*/
@LibraryInformation(state = LibraryInformation.State.STABLE, since = "1.0.8")
private ResponseService(@NotNull final ProcessType processType,
@Nullable final ThrowableConsumer<Throwable> exceptionConsumer) {
this.processType = processType;
private ResponseService(@Nullable final ThrowableConsumer<Throwable> exceptionConsumer) {
this.exceptionConsumer = exceptionConsumer;
}

Expand All @@ -38,11 +34,7 @@ private ResponseService(@NotNull final ProcessType processType,
final ThrowableConsumer<Throwable> localConsumer = this.exceptionConsumer;
//Check if local consumer is present
if (localConsumer != null) {
if (this.processType.multiThread()) {
response.ifExceptionallyAsync(localConsumer);
} else {
response.ifExceptionally(localConsumer);
}
}

return response;
Expand All @@ -57,7 +49,7 @@ private ResponseService(@NotNull final ProcessType processType,
*/
@LibraryInformation(state = LibraryInformation.State.STABLE, since = "1.0.8")
public static @NotNull ResponseService simple() {
return new ResponseService(ProcessType.SINGLE, null);
return new ResponseService(null);
}

/**
Expand All @@ -67,8 +59,7 @@ private ResponseService(@NotNull final ProcessType processType,
* @return created instance of service.
*/
@LibraryInformation(state = LibraryInformation.State.STABLE, since = "1.0.8")
public static @NotNull ResponseService handled(@Nullable final ProcessType processType,
@Nullable final ThrowableConsumer<Throwable> exceptionConsumer) {
return new ResponseService(SpaceObjects.throwIfNull(processType), exceptionConsumer);
public static @NotNull ResponseService handled(@Nullable final ThrowableConsumer<Throwable> exceptionConsumer) {
return new ResponseService(exceptionConsumer);
}
}
14 changes: 14 additions & 0 deletions core/src/main/java/dev/dotspace/common/response/mm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.dotspace.common.response;

public class mm {

public static void main(String[] args) {

ResponseService responseService = ResponseService.handled(throwable -> {
System.out.println("Error on " + throwable);
});

responseService.newInstance().completeExceptionally(new NullPointerException("Test"));

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package dev.dotspace.common.test.response;

import dev.dotspace.common.concurrent.ProcessType;
import dev.dotspace.common.response.ResponseConsumer;
import dev.dotspace.common.response.ResponseService;
import dev.dotspace.common.response.State;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -14,12 +11,8 @@ public final class ResponseServiceTest {
@Test
public void testBuilder() {
Assertions.assertDoesNotThrow(ResponseService::simple);
Assertions.assertDoesNotThrow(() -> ResponseService.handled(ProcessType.MULTI, null));
Assertions.assertDoesNotThrow(() -> ResponseService.handled(ProcessType.MULTI, throwable -> {
Assertions.assertDoesNotThrow(() -> ResponseService.handled(null));
Assertions.assertDoesNotThrow(() -> ResponseService.handled(throwable -> {
}));

Assertions.assertThrows(NullPointerException.class, () -> ResponseService.handled(null, null));
}


}

0 comments on commit 0a3213a

Please sign in to comment.