-
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.
Replace a lot of Optional.of with ofNullable
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
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
25 changes: 25 additions & 0 deletions
25
src/main/java/dev/andante/codex/mixin/DataResultErrorMixin.java
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,25 @@ | ||
package dev.andante.codex.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(targets = { "com.mojang.serialization.DataResult$Error" }) | ||
public class DataResultErrorMixin<R> { | ||
@Redirect(method = "error", at = @At(value = "INVOKE", target = "Ljava/util/Optional;of(Ljava/lang/Object;)Ljava/util/Optional;"), remap = false) | ||
private Optional<R> onErrorOf(R value) { | ||
return Optional.ofNullable(value); | ||
} | ||
|
||
@Redirect(method = "flatMap(Ljava/util/function/Function;)Lcom/mojang/serialization/DataResult$Error;", at = @At(value = "INVOKE", target = "Ljava/util/Optional;of(Ljava/lang/Object;)Ljava/util/Optional;"), remap = false) | ||
private Optional<R> onFlatMapOf(R value) { | ||
return Optional.ofNullable(value); | ||
} | ||
|
||
@Redirect(method = "setPartial(Ljava/lang/Object;)Lcom/mojang/serialization/DataResult$Error;", at = @At(value = "INVOKE", target = "Ljava/util/Optional;of(Ljava/lang/Object;)Ljava/util/Optional;"), remap = false) | ||
private Optional<R> onSetPartialOf(R value) { | ||
return Optional.ofNullable(value); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/dev/andante/codex/mixin/DataResultSuccessMixin.java
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,25 @@ | ||
package dev.andante.codex.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(targets = { "com.mojang.serialization.DataResult$Success" }) | ||
public class DataResultSuccessMixin<R> { | ||
@Redirect(method = "result", at = @At(value = "INVOKE", target = "Ljava/util/Optional;of(Ljava/lang/Object;)Ljava/util/Optional;"), remap = false) | ||
private Optional<R> onResultOf(R value) { | ||
return Optional.ofNullable(value); | ||
} | ||
|
||
@Redirect(method = "resultOrPartial()Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Ljava/util/Optional;of(Ljava/lang/Object;)Ljava/util/Optional;"), remap = false) | ||
private Optional<R> onResultOrPartialOf(R value) { | ||
return Optional.ofNullable(value); | ||
} | ||
|
||
@Redirect(method = "resultOrPartial(Ljava/util/function/Consumer;)Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Ljava/util/Optional;of(Ljava/lang/Object;)Ljava/util/Optional;"), remap = false) | ||
private Optional<R> onResultOrPartialConsumerOf(R value) { | ||
return Optional.ofNullable(value); | ||
} | ||
} |
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