Clone OptionalInts too
Dieser Commit ist enthalten in:
Ursprung
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) {
|
||||
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() {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren