org.jackstaff.grpc.Original Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grpc-core Show documentation
Show all versions of grpc-core Show documentation
Jackstaff Grpc Core: A java RPC framework , gRPC based and compatible with gRPC
package org.jackstaff.grpc;
import java.util.Optional;
import java.util.function.Consumer;
/**
* @author [email protected]
*/
@FunctionalInterface
public interface Original {
T getOrigin();
static T from(Object source, Class clazz) {
return Optional.ofNullable(source instanceof Original ? ((Original>) source).getOrigin() : source).
filter(clazz::isInstance).map(clazz::cast).orElse(null);
}
static void accept(Object source, Class clazz, Consumer consumer) {
Optional.ofNullable(from(source, clazz)).ifPresent(consumer);
}
}