The_Typholorian

java discord pastebin

Dec 19th, 2023
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | Source Code | 0 0
  1. package net.typho.utils;
  2.  
  3. public interface IRType<T> {
  4.     Class<T> getDataType();
  5.  
  6.     String getName();
  7.  
  8.     T processRequest(T requestData);
  9. }
  10.  
  11. package net.typho.utils;
  12.  
  13. import java.util.function.Function;
  14.  
  15. public enum RType implements IRType<Object> {
  16.     STRING(String.class, s -> s + " :)"),
  17.     BOOLEAN(Boolean.class, b -> !((Boolean) b)),
  18.     INTEGER(Integer.class, i -> (int) i + 5);
  19.  
  20.     private final Class<?> dataType;
  21.     private final Function<Object, Object> processRequest;
  22.  
  23.     RType(Class<?> dataType, Function<Object, Object> processRequest) {
  24.         this.dataType = dataType;
  25.         this.processRequest = processRequest;
  26.     }
  27.  
  28.     @Override
  29.     public Class<Object> getDataType() {
  30.         return (Class<Object>) dataType;
  31.     }
  32.  
  33.     public String getName() {
  34.         return super.toString();
  35.     }
  36.  
  37.     @Override
  38.     public Object processRequest(Object requestData) {
  39.         return null;
  40.     }
  41.  
  42.     @Override
  43.     public String toString() {
  44.         return "RType{dataType=" + dataType + ", name=" + getName() + "}";
  45.     }
  46. }
  47.  
  48. package net.typho.datatypes;
  49.  
  50. import net.typho.utils.ID;
  51. import net.typho.utils.IRType;
  52.  
  53. import java.io.Serializable;
  54. import java.util.List;
  55.  
  56. public class Request<T> implements Serializable {
  57.     private IRType<T> type;
  58.     private ID id;
  59.     private T data;
  60.  
  61.     private Request(IRType<T> type, ID id) {
  62.         this.type = type;
  63.         this.id = id;
  64.     }
  65.  
  66.     public Request(IRType<T> type, ID id, T data) {
  67.         this.type = type;
  68.         this.id = id;
  69.         this.data = data;
  70.     }
  71.  
  72.     public static <t> Request<t> of(IRType<t> type, List<ID> activeIds, int idLength) {
  73.         return new Request<>(type, new ID(activeIds, idLength));
  74.     }
  75.  
  76.     public static <H> Request<H> of(IRType<H> type, List<ID> activeIds, int idLength, H data) {
  77.         System.out.println(type);
  78.         return new Request<>(type, new ID(activeIds, idLength), data);
  79.     }
  80.  
  81.     public static <t> Request<t> of(IRType<t> type, ID id, t data) {
  82.         return new Request<>(type, id, data);
  83.     }
  84.  
  85.     public IRType<?> getType() {
  86.         return type;
  87.     }
  88.  
  89.     public void setType(IRType<T> type) {
  90.         this.type = type;
  91.     }
  92.  
  93.     public ID getId() {
  94.         return id;
  95.     }
  96.  
  97.     public void setId(ID id) {
  98.         this.id = id;
  99.     }
  100.  
  101.     public Object getData() {
  102.         return data;
  103.     }
  104.  
  105.     public void setData(T data) {
  106.         this.data = data;
  107.     }
  108.  
  109.     @Override
  110.     public String toString() {
  111.         return "Request{type=" + type + ", id=" + id + ", data=" + data + "}";
  112.     }
  113. }
Tags: Java
Advertisement
Add Comment
Please, Sign In to add comment