mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-22 08:12:05 +01:00
Clone OptionalInts too
This commit is contained in:
parent
8c20d19339
commit
446a1c8326
@ -4,6 +4,7 @@
|
||||
package com.comphenix.protocol.reflect.cloning;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/**
|
||||
* A cloner that can clone Java Optional objects
|
||||
@ -18,13 +19,22 @@ public class JavaOptionalCloner implements Cloner {
|
||||
|
||||
@Override
|
||||
public boolean canClone(Object source) {
|
||||
return source instanceof Optional;
|
||||
return source instanceof Optional || source instanceof OptionalInt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone(Object source) {
|
||||
Optional<?> optional = (Optional<?>) source;
|
||||
return optional.map(o -> wrapped.clone(o));
|
||||
if (source instanceof Optional) {
|
||||
Optional<?> optional = (Optional<?>) source;
|
||||
return optional.map(o -> wrapped.clone(o));
|
||||
} else if (source instanceof OptionalInt) {
|
||||
// why Java felt the need to make each optional class distinct is beyond me
|
||||
// like why couldn't they have given us at least a common interface or something
|
||||
OptionalInt optional = (OptionalInt) source;
|
||||
return optional.isPresent() ? OptionalInt.of(optional.getAsInt()) : OptionalInt.empty();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Cloner getWrapped() {
|
||||
|
Loading…
Reference in New Issue
Block a user