11package ch .jalu .configme .resource ;
22
3+ import ch .jalu .configme .properties .BooleanProperty ;
4+ import ch .jalu .configme .properties .DoubleProperty ;
5+ import ch .jalu .configme .properties .IntegerProperty ;
6+ import ch .jalu .configme .properties .StringProperty ;
7+ import ch .jalu .configme .properties .convertresult .PropertyValue ;
38import org .jetbrains .annotations .NotNull ;
49import org .jetbrains .annotations .Nullable ;
10+
511import java .util .List ;
612import java .util .Set ;
713
@@ -23,6 +29,14 @@ public interface PropertyReader {
2329 */
2430 boolean contains (@ NotNull String path );
2531
32+ /**
33+ * Returns the object at the given path, or null if absent.
34+ *
35+ * @param path the path to retrieve the value for
36+ * @return the value, or null if there is none
37+ */
38+ @ Nullable Object getValue (@ NotNull String path );
39+
2640 /**
2741 * Returns the keys available in the file. Depending on the parameter either all keys are returned,
2842 * or only the keys of the leaf nodes are considered.
@@ -46,47 +60,85 @@ public interface PropertyReader {
4660 *
4761 * @param path the path to retrieve the value for
4862 * @return the value, or null if there is none
63+ * @deprecated Use {@link #getValue}
4964 */
50- @ Nullable Object getObject (@ NotNull String path );
65+ @ Deprecated
66+ default @ Nullable Object getObject (@ NotNull String path ) {
67+ return getValue (path );
68+ }
5169
5270 /**
5371 * Returns the value of the given path as a String if available.
5472 *
5573 * @param path the path to retrieve a String for
5674 * @return the value as a String, or null if not applicable or unavailable
75+ * @deprecated read the value with a {@link StringProperty},
76+ * or call {@link #getValue} and perform your own casts
5777 */
58- @ Nullable String getString (@ NotNull String path );
78+ @ Deprecated
79+ default @ Nullable String getString (@ NotNull String path ) {
80+ StringProperty strProperty = new StringProperty (path , "" );
81+ PropertyValue <String > value = strProperty .determineValue (this );
82+ return value .isValidInResource () ? value .getValue () : null ;
83+ }
5984
6085 /**
6186 * Returns the value of the given path as an integer if available.
6287 *
6388 * @param path the path to retrieve an integer for
6489 * @return the value as integer, or null if not applicable or unavailable
90+ * @deprecated read the value with an {@link IntegerProperty},
91+ * or call {@link #getValue} and perform your own casts
6592 */
66- @ Nullable Integer getInt (@ NotNull String path );
93+ @ Deprecated
94+ default @ Nullable Integer getInt (@ NotNull String path ) {
95+ IntegerProperty intProperty = new IntegerProperty (path , 0 );
96+ PropertyValue <Integer > value = intProperty .determineValue (this );
97+ return value .isValidInResource () ? value .getValue () : null ;
98+ }
6799
68100 /**
69101 * Returns the value of the given path as a double if available.
70102 *
71103 * @param path the path to retrieve a double for
72104 * @return the value as a double, or null if not applicable or unavailable
105+ * @deprecated read the value with an {@link DoubleProperty},
106+ * or call {@link #getValue} and perform your own casts
73107 */
74- @ Nullable Double getDouble (@ NotNull String path );
108+ @ Deprecated
109+ default @ Nullable Double getDouble (@ NotNull String path ) {
110+ DoubleProperty doubleProperty = new DoubleProperty (path , 0 );
111+ PropertyValue <Double > value = doubleProperty .determineValue (this );
112+ return value .isValidInResource () ? value .getValue () : null ;
113+ }
75114
76115 /**
77116 * Returns the value of the given path as a boolean if available.
78117 *
79118 * @param path the path to retrieve a boolean for
80119 * @return the value as a boolean, or null if not applicable or unavailable
120+ * @deprecated read the value with a {@link BooleanProperty},
121+ * or call {@link #getValue} and perform your own casts
81122 */
82- @ Nullable Boolean getBoolean (@ NotNull String path );
123+ @ Deprecated
124+ default @ Nullable Boolean getBoolean (@ NotNull String path ) {
125+ BooleanProperty boolProperty = new BooleanProperty (path , true );
126+ PropertyValue <Boolean > value = boolProperty .determineValue (this );
127+ return value .isValidInResource () ? value .getValue () : null ;
128+ }
83129
84130 /**
85131 * Returns the value of the given path as a list if available.
86132 *
87133 * @param path the path to retrieve a list for
88134 * @return the value as a list, or null if not applicable or unavailable
135+ * @deprecated read the value with a {@link ch.jalu.configme.properties.ListProperty ListProperty},
136+ * or call {@link #getValue} and perform your own casts
89137 */
90- @ Nullable List <?> getList (@ NotNull String path );
138+ @ Deprecated
139+ default @ Nullable List <?> getList (@ NotNull String path ) {
140+ Object value = getValue (path );
141+ return value instanceof List <?> ? (List <?>) value : null ;
142+ }
91143
92144}
0 commit comments