Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.typho.utils;
- public interface IRType<T> {
- Class<T> getDataType();
- String getName();
- T processRequest(T requestData);
- }
- package net.typho.utils;
- import java.util.function.Function;
- public enum RType implements IRType<Object> {
- STRING(String.class, s -> s + " :)"),
- BOOLEAN(Boolean.class, b -> !((Boolean) b)),
- INTEGER(Integer.class, i -> (int) i + 5);
- private final Class<?> dataType;
- private final Function<Object, Object> processRequest;
- RType(Class<?> dataType, Function<Object, Object> processRequest) {
- this.dataType = dataType;
- this.processRequest = processRequest;
- }
- @Override
- public Class<Object> getDataType() {
- return (Class<Object>) dataType;
- }
- public String getName() {
- return super.toString();
- }
- @Override
- public Object processRequest(Object requestData) {
- return null;
- }
- @Override
- public String toString() {
- return "RType{dataType=" + dataType + ", name=" + getName() + "}";
- }
- }
- package net.typho.datatypes;
- import net.typho.utils.ID;
- import net.typho.utils.IRType;
- import java.io.Serializable;
- import java.util.List;
- public class Request<T> implements Serializable {
- private IRType<T> type;
- private ID id;
- private T data;
- private Request(IRType<T> type, ID id) {
- this.type = type;
- this.id = id;
- }
- public Request(IRType<T> type, ID id, T data) {
- this.type = type;
- this.id = id;
- this.data = data;
- }
- public static <t> Request<t> of(IRType<t> type, List<ID> activeIds, int idLength) {
- return new Request<>(type, new ID(activeIds, idLength));
- }
- public static <H> Request<H> of(IRType<H> type, List<ID> activeIds, int idLength, H data) {
- System.out.println(type);
- return new Request<>(type, new ID(activeIds, idLength), data);
- }
- public static <t> Request<t> of(IRType<t> type, ID id, t data) {
- return new Request<>(type, id, data);
- }
- public IRType<?> getType() {
- return type;
- }
- public void setType(IRType<T> type) {
- this.type = type;
- }
- public ID getId() {
- return id;
- }
- public void setId(ID id) {
- this.id = id;
- }
- public Object getData() {
- return data;
- }
- public void setData(T data) {
- this.data = data;
- }
- @Override
- public String toString() {
- return "Request{type=" + type + ", id=" + id + ", data=" + data + "}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment