@@ -31,79 +31,103 @@ public class JOption<T> {
3131 protected Writer <T > writer ;
3232 protected Reader <T > reader ;
3333
34- public JOption (@ NotNull String path , @ NotNull Reader <T > reader , @ NotNull Supplier < T > defaultValue , @ Nullable String ... description ) {
35- this (path , reader , defaultValue . get () , description );
34+ public JOption (@ NotNull String path , @ NotNull Reader <T > reader , @ NotNull T defaultValue , @ Nullable String ... description ) {
35+ this (path , JYML :: set , reader , defaultValue , description );
3636 }
3737
38- public JOption (@ NotNull String path , @ NotNull Reader <T > reader , @ NotNull T defaultValue , @ Nullable String ... description ) {
39- this (path , null , reader , defaultValue , description );
38+ public JOption (@ NotNull String path , @ NotNull Reader <T > reader , @ NotNull Supplier < T > defaultValue , @ Nullable String ... description ) {
39+ this (path , JYML :: set , reader , defaultValue . get () , description );
4040 }
4141
42- public JOption (@ NotNull String path , @ Nullable Writer <T > writer , @ NotNull Reader <T > reader , @ NotNull T defaultValue , @ Nullable String ... description ) {
42+ public JOption (@ NotNull String path , @ NotNull Writer <T > writer , @ NotNull Reader <T > reader , @ NotNull T defaultValue , @ Nullable String ... description ) {
4343 this .path = path ;
4444 this .description = description == null ? new String [0 ] : description ;
45+ this .writer = writer ;
4546 this .reader = reader ;
4647 this .defaultValue = defaultValue ;
4748 }
4849
4950 @ NotNull
50- public static <T > JOption <T > create (@ NotNull ConfigKey <T > key , @ NotNull T defaultValue , @ Nullable String ... description ) {
51- return new JOption <>(key .getPath (), key .getWriter (), key .getReader (), defaultValue , description );
51+ public static <T > JOption <T > create (@ NotNull String path ,
52+ @ NotNull Writer <T > writer ,
53+ @ NotNull Reader <T > reader ,
54+ @ NotNull T defaultValue ,
55+ @ Nullable String ... description ) {
56+ return new JOption <>(path , writer , reader , defaultValue , description );
57+ }
58+
59+ @ NotNull
60+ public static <T > JOption <T > create (@ NotNull String path ,
61+ @ NotNull Writer <T > writer ,
62+ @ NotNull Reader <T > reader ,
63+ @ NotNull Supplier <T > defaultValue ,
64+ @ Nullable String ... description ) {
65+ return create (path , writer , reader , defaultValue .get (), description );
66+ }
67+
68+ @ NotNull
69+ public static <T > JOption <T > create (@ NotNull String path , @ NotNull Reader <T > reader , @ NotNull T defaultValue , @ Nullable String ... description ) {
70+ return create (path , JYML ::set , reader , defaultValue , description );
71+ }
72+
73+ @ NotNull
74+ public static <T > JOption <T > create (@ NotNull String path , @ NotNull Reader <T > reader , @ NotNull Supplier <T > defaultValue , @ Nullable String ... description ) {
75+ return create (path , JYML ::set , reader , defaultValue , description );
5276 }
5377
5478 @ NotNull
5579 public static JOption <Boolean > create (@ NotNull String path , boolean defaultValue , @ Nullable String ... description ) {
56- return new JOption <> (path , READER_BOOLEAN , defaultValue , description );
80+ return create (path , READER_BOOLEAN , defaultValue , description );
5781 }
5882
5983 @ NotNull
6084 public static JOption <Integer > create (@ NotNull String path , int defaultValue , @ Nullable String ... description ) {
61- return new JOption <> (path , READER_INT , defaultValue , description );
85+ return create (path , READER_INT , defaultValue , description );
6286 }
6387
6488 @ NotNull
6589 public static JOption <Double > create (@ NotNull String path , double defaultValue , @ Nullable String ... description ) {
66- return new JOption <> (path , READER_DOUBLE , defaultValue , description );
90+ return create (path , READER_DOUBLE , defaultValue , description );
6791 }
6892
6993 @ NotNull
7094 public static JOption <Long > create (@ NotNull String path , long defaultValue , @ Nullable String ... description ) {
71- return new JOption <> (path , READER_LONG , defaultValue , description );
95+ return create (path , READER_LONG , defaultValue , description );
7296 }
7397
7498 @ NotNull
7599 public static JOption <String > create (@ NotNull String path , @ NotNull String defaultValue , @ Nullable String ... description ) {
76- return new JOption <> (path , READER_STRING , defaultValue , description );
100+ return create (path , READER_STRING , defaultValue , description );
77101 }
78102
79103 @ NotNull
80104 public static JOption <List <String >> create (@ NotNull String path , @ NotNull List <String > defaultValue , @ Nullable String ... description ) {
81- return new JOption <> (path , READER_LIST_STRING , defaultValue , description );
105+ return create (path , READER_LIST_STRING , defaultValue , description );
82106 }
83107
84108 @ NotNull
85109 public static JOption <Set <String >> create (@ NotNull String path , @ NotNull Set <String > defaultValue , @ Nullable String ... description ) {
86- return new JOption <> (path , READER_SET_STRING , defaultValue , description );
110+ return create (path , READER_SET_STRING , defaultValue , description );
87111 }
88112
89113 @ NotNull
90114 public static JOption <ItemStack > create (@ NotNull String path , @ NotNull ItemStack defaultValue , @ Nullable String ... description ) {
91- return new JOption <> (path , READER_ITEM , defaultValue , description ).setWriter (JYML ::setItem );
115+ return create (path , READER_ITEM , defaultValue , description ).setWriter (JYML ::setItem );
92116 }
93117
94118 @ NotNull
95119 public static JOption <UniSound > create (@ NotNull String path , @ NotNull UniSound defaultValue , @ Nullable String ... description ) {
96- return new JOption <> (path , (cfg , path1 , def ) -> UniSound .read (cfg , path1 ), defaultValue , description ).setWriter ((cfg , path2 , us ) -> us .write (cfg , path2 ));
120+ return create (path , (cfg , path1 , def ) -> UniSound .read (cfg , path1 ), defaultValue , description ).setWriter ((cfg , path2 , us ) -> us .write (cfg , path2 ));
97121 }
98122
99123 @ NotNull
100124 public static JOption <UniParticle > create (@ NotNull String path , @ NotNull UniParticle defaultValue , @ Nullable String ... description ) {
101- return new JOption <> (path , (cfg , path1 , def ) -> UniParticle .read (cfg , path1 ), defaultValue , description ).setWriter ((cfg , path2 , us ) -> us .write (cfg , path2 ));
125+ return create (path , (cfg , path1 , def ) -> UniParticle .read (cfg , path1 ), defaultValue , description ).setWriter ((cfg , path2 , us ) -> us .write (cfg , path2 ));
102126 }
103127
104128 @ NotNull
105129 public static <E extends Enum <E >> JOption <E > create (@ NotNull String path , @ NotNull Class <E > clazz , @ NotNull E defaultValue , @ Nullable String ... description ) {
106- return new JOption <> (path , ((cfg , path1 , def ) -> cfg .getEnum (path1 , clazz , defaultValue )), defaultValue , description )
130+ return create (path , ((cfg , path1 , def ) -> cfg .getEnum (path1 , clazz , defaultValue )), defaultValue , description )
107131 .setWriter ((cfg , path1 , type ) -> cfg .set (path1 , type .name ()));
108132 }
109133
@@ -116,7 +140,7 @@ public static <V> JOption<Set<V>> forSet(@NotNull String path, @NotNull Function
116140 @ NotNull
117141 public static <V > JOption <Set <V >> forSet (@ NotNull String path , @ NotNull Function <String , V > valFun ,
118142 @ NotNull Set <V > defaultValue , @ Nullable String ... description ) {
119- return new JOption <> (path ,
143+ return create (path ,
120144 (cfg , path1 , def ) -> cfg .getStringSet (path1 ).stream ().map (valFun ).filter (Objects ::nonNull ).collect (Collectors .toCollection (HashSet ::new )),
121145 defaultValue ,
122146 description );
@@ -160,7 +184,7 @@ public static <K, V, M extends Map<K, V>> JOption<M> forMap(@NotNull String path
160184 @ NotNull TriFunction <JYML , String , String , V > valFun ,
161185 @ NotNull Supplier <M > mapSupplier ,
162186 @ NotNull M defaultValue , @ Nullable String ... description ) {
163- return new JOption <> (path ,
187+ return create (path ,
164188 (cfg , path1 , def ) -> {
165189 M map = mapSupplier .get ();
166190 for (String id : cfg .getSection (path1 )) {
@@ -228,6 +252,7 @@ public Reader<T> getReader() {
228252 }
229253
230254 @ NotNull
255+ @ Deprecated
231256 public JOption <T > mapReader (@ NotNull UnaryOperator <T > operator ) {
232257 if (this .reader == null ) return this ;
233258
0 commit comments