DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
DreamVariableTestAPI.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamVariable;
25
26import com.dreamfirestudios.dreamcore.DreamCore;
27import com.dreamfirestudios.dreamcore.DreamPersistentData.PersistentDataTypes;
28
29import java.util.ArrayList;
30import java.util.List;
31
39
47 public static boolean registerVarTest(Class<?> test_class, DreamVariableTest variableLogic, boolean override_if_found){
48 if (DreamCore.DreamCore.DreamVariableTests.containsKey(test_class) && !override_if_found) return false;
49 DreamCore.DreamCore.DreamVariableTests.put(test_class, variableLogic);
50 return true;
51 }
52
57 public static DreamVariableTest returnTestFromType(Class<?> classType){
58 return DreamCore.DreamCore.DreamVariableTests.getOrDefault(classType, null);
59 }
60
64 public static PersistentDataTypes ReturnTypeFromVariableTest(Class<?> classType){
65 var pulseVariableTest = returnTestFromType(classType);
66 return pulseVariableTest == null ? null : pulseVariableTest.PersistentDataType();
67 }
68
76 public static List<String> returnAsAllTypes(String text, boolean addVariableName, boolean isArrayType) {
77 var all_types = new ArrayList<String>();
78 for (var test_key : DreamCore.DreamVariableTests.keySet()) {
79 var test = DreamCore.DreamVariableTests.get(test_key);
80 if (!test.IsType(text)) continue;
81 if (all_types.isEmpty() && addVariableName) all_types.add(text);
82 for (var type : test.ClassTypes()) {
83 if ((type.isArray() && isArrayType) || (!type.isArray() && !isArrayType)) {
84 if (!all_types.contains(type.getSimpleName())) all_types.add(type.getSimpleName());
85 }
86 }
87 }
88 return all_types;
89 }
90}
static final LinkedHashMap< Class<?>, DreamVariableTest > DreamVariableTests
static boolean registerVarTest(Class<?> test_class, DreamVariableTest variableLogic, boolean override_if_found)
Registers a variable test for a class type.
static List< String > returnAsAllTypes(String text, boolean addVariableName, boolean isArrayType)
Produces a list of type names this text could represent, optionally prefixed with the text itself.
static DreamVariableTest returnTestFromType(Class<?> classType)
Looks up a test by class type.
static PersistentDataTypes ReturnTypeFromVariableTest(Class<?> classType)
Returns the persistent data type for a class (or null).
Legacy interface for variable tests (kept for compatibility).