You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor ObjectConverter, creating Utils, bitwise optimizations, preparation for variable deserialization and abolishment of scope runtime temporary inharitance, other refactorings,
@@ -277,10 +276,82 @@ public <V extends ValT> V get(KeyT variableKey, V defaultValue)
277
276
{
278
277
Vobj = (V) variables().get(variableKey);
279
278
if (obj == null)
280
-
return(V) defaultValue;
279
+
returndefaultValue;
281
280
returnobjinstanceofNULL ? null : obj;
282
281
}
283
282
283
+
/**
284
+
* @param pathToValue | Array with variables creating path to required value, nested in multiple sub-scopes.
285
+
*
286
+
* @return Value of variable at given path. If no path is given (length is 0) then this {@link GenericScope} will be returned.<br>
287
+
* If 1 path argument is given then this behaves similarly to {@link GenericScope#get(Object)}.<br>
288
+
* if 2+ path arguments are given then it will search the sub-scopes and return first match value. For example:<br>
289
+
* Consider this scope tree:<br>
290
+
* <pre>
291
+
* <code>
292
+
* {
293
+
* 125: {
294
+
* "hello": {
295
+
* "value" true
296
+
* }
297
+
* }
298
+
* }
299
+
* </code>
300
+
* </pre>
301
+
* Then to get value of "value" you can do <code>scope.get(125, "hello", "value")</code>!<br>
302
+
* If there is no other variable called "value" in the scope tree then you can also simplify it to <code>scope.get("value")</code>, but make sure that there is no equally-named variable!<br>
303
+
* Note: Make sure that you are not calling {@link GenericScope#get(Object, Object)} by accident when you are using inline vargas array (unspecified count of arguments)!
* @param defaultValue | Class that you want the obtained object to be converted into! Exact conversion algorithm can differ based on its implementations.
338
+
*
339
+
* @return Value of variable with name given converted to object of cls or defaultValue if there is no such a one!
340
+
*
341
+
* @throws Exception | If converting to object of cls failed from some reason! This can differ from implementation to implementation! By default it uses {@link GenericScope#toObject(cls)}
342
+
*
343
+
* @since 1.3.7
344
+
*/
345
+
public <VextendsValT> Vget(KeyTvariableKey, Class<V> cls, VdefaultValue) throwsException
346
+
{
347
+
Vobj = get(variableKey, defaultValue);
348
+
if (obj != null && obj.getClass() == cls)
349
+
returnobj;
350
+
if (objinstanceofGenericScope)
351
+
return ((GenericScope<?, ?>) obj).toObject(cls);
352
+
returnobj;
353
+
}
354
+
284
355
/**
285
356
* @param variableKey | Variables name to search for.
286
357
*
@@ -312,7 +383,7 @@ public boolean containsIndependentValue(ValT value)
312
383
* @param valueIndex | Index of independent value. Also can be negative, in this case u will get elements from back!
313
384
* {@link IndexOutOfBoundsException} will be thrown if index is too big!
314
385
*
315
-
* @return Independent value with valueIndex.
386
+
* @return Independent value with valueIndex of this {@link GenericScope}!
316
387
*
317
388
* @since 1.2.0
318
389
*/
@@ -323,6 +394,26 @@ public <V extends ValT> V get(int valueIndex)
323
394
returnobjinstanceofNULL ? null : obj;
324
395
}
325
396
397
+
/**
398
+
* @param valueIndex | Index of independent value. Also can be negative, in this case u will get elements from back!
399
+
* @param cls | Class that you want the obtained object to be converted into! Exact conversion algorithm can differ based on its implementations.
400
+
*
401
+
* @return Independent value with valueIndex of this converted to object of cls!
402
+
*
403
+
* @throws Exception | If converting to object of cls failed from some reason! This can differ from implementation to implementation!
404
+
*
405
+
* @since 1.3.7
406
+
*/
407
+
public <VextendsValT> Vget(intvalueIndex, Class<V> cls) throwsException
408
+
{
409
+
Vobj = get(valueIndex);
410
+
if (obj != null && obj.getClass() == cls)
411
+
returnobj;
412
+
if (objinstanceofGenericScope)
413
+
return ((GenericScope<?, ?>) obj).toObject(cls);
414
+
returnobj;
415
+
}
416
+
326
417
/**
327
418
* @param value | Independent value to add into array of values.
* @param scopesPath | Array with variables creating path to required scope.
477
+
* @param pathToScope | Array with variables creating path to required scope.
387
478
*
388
-
* @return Sub-scope stored by variable with required name (last element) in inserted path or null if there is no such a one in inserted path. If there is more than one result, the first one found will be returned!
389
-
* This search will also includes sub-scopes of scope but variables from lower ones are prioritize!<br>
479
+
* @return Sub-scope stored by variable with required name (last element of pathToScope) or null if there is no such a one in inserted path. If there is more than one result, the first one found will be returned!
480
+
* This search will also includes sub-scopes stored by variables of this scope while variables from lower ones are prioritize!<br>
390
481
* If this function is called with no arguments then self will be returned!
391
482
* Note: Remember that this search includes variables only, no values! <br>
392
483
* Note: Also remember that this function will work only when this scope generically allows to store other scopes inside (when ValT is base class of {@link GenericScope})
393
484
*
394
485
* @since 1.2.0
395
486
*/
396
487
@SuppressWarnings("unchecked")
397
-
public <K, V> GenericScope<K, V> getGenericScope(K... scopesPath)
488
+
public <K, V> GenericScope<K, V> getGenericScope(K... pathToScope)
LogProvider.instance.logErr("Variable with name \"" + scopesPath[0] + "\" does exists! However its value is not instance of scope, use \"get\" function instead if possible!", null);
418
-
}
419
-
catch (ClassCastExceptione)
420
-
{}
490
+
Objectobj = get((KeyT[]) pathToScope);
491
+
if (objinstanceofGenericScope)
492
+
return (GenericScope<K, V>) obj;
493
+
494
+
if (containsVariable((KeyT) pathToScope[0]))
495
+
LogProvider.instance.logErr("Variable with name \"" + pathToScope[0] + "\" does exists! However its value is not instance of scope, use \"get\" function instead if possible!", null);
421
496
returnnull;
422
497
}
423
498
@@ -657,7 +732,7 @@ public GenericScope<KeyT, ValT> inheritParent()
* @param absoluteParent | If true, absolute parent of this scope will be returned (parent of parent of parent...)!
727
-
*
728
-
* @return The parent scope of this scope or null if this scope has no parent such as default one in file.
801
+
* @param depth | Positive number representing how many times will this method call itself... <br> For example 0 or less = this, 1 = parent, 2 = parentOfParent (parent.getParent()) and so on...
802
+
* If you want to get the root parent (the one that has no parent), simply put a big number as depth. 99 should be enough!
803
+
*
804
+
* @return The parent scope based on depth or null if this scope has no parent which means its already root (default one in file).
805
+
* If depth was bigger than 1, null will be never returned, last not null parent will be returned instead!<br>
0 commit comments