1 package net.mograsim.logic.model.snippets;
3 import java.util.function.BiFunction;
5 import com.google.gson.Gson;
6 import com.google.gson.JsonElement;
8 public interface SnippetDefinintion<C, P, S>
10 public Class<P> getParamClass();
12 public S create(C context, P params);
14 public default S create(C context, JsonElement params)
16 Class<P> paramClass = getParamClass();
17 if (paramClass.equals(Void.class))
20 throw new IllegalArgumentException("Params given where none were expected");
21 return create(context, (P) null);
23 return create(context, new Gson().fromJson(params, getParamClass()));
26 public static <C, P, S> SnippetDefinintion<C, P, S> create(Class<P> paramClass, BiFunction<C, P, S> supplier)
28 return new SnippetDefinintion<>()
31 public Class<P> getParamClass()
37 public S create(C context, P params)
39 return supplier.apply(context, params);