-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace construction data with metadata + Update license headers
- Loading branch information
Showing
73 changed files
with
727 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2023-2024 nahkd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package stonks.core.dynamic; | ||
|
||
/** | ||
* <p> | ||
* A {@link Dynamic} is an interface that proxies the underlying dynamic object | ||
* structure, such as JSON or NBT. | ||
* </p> | ||
*/ | ||
public interface Dynamic { | ||
public DynamicFactory getFactory(); | ||
} |
66 changes: 66 additions & 0 deletions
66
core/src/main/java/stonks/core/dynamic/DynamicFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2023-2024 nahkd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package stonks.core.dynamic; | ||
|
||
public interface DynamicFactory { | ||
public DynamicPrimitive createPrimitive(Number value); | ||
|
||
public DynamicPrimitive createPrimitive(String value); | ||
|
||
public DynamicPrimitive createPrimitive(boolean value); | ||
|
||
public DynamicMap createMap(); | ||
|
||
public DynamicList createList(); | ||
|
||
/** | ||
* <p> | ||
* Deep clone (a.k.a recursive clone) the dynamic. The cloned dynamic will have | ||
* its factory bounds to this factory. | ||
* </p> | ||
* | ||
* @param another A dynamic. | ||
* @return A cloned dynamic. | ||
*/ | ||
default Dynamic cloneDynamic(Dynamic another) { | ||
if (another instanceof DynamicPrimitive prim) { | ||
if (prim.isString()) return createPrimitive(prim.asString()); | ||
if (prim.isNumber()) return createPrimitive(prim.asNumber()); | ||
if (prim.isBoolean()) return createPrimitive(prim.asBoolean()); | ||
throw new IllegalArgumentException("Unknown primitive type for " + prim); | ||
} | ||
|
||
if (another instanceof DynamicMap map) { | ||
var out = createMap(); | ||
map.forEach(entry -> map.put(entry.getKey(), cloneDynamic(entry.getValue()))); | ||
return out; | ||
} | ||
|
||
if (another instanceof DynamicList list) { | ||
var out = createList(); | ||
list.forEach(val -> out.add(val)); | ||
return out; | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown type for " + another); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2023-2024 nahkd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package stonks.core.dynamic; | ||
|
||
import java.util.Iterator; | ||
|
||
public interface DynamicList extends Dynamic, Iterable<Dynamic> { | ||
public int size(); | ||
|
||
public Dynamic get(int at); | ||
|
||
public void add(int insertAt, Dynamic value); | ||
|
||
default void add(Dynamic value) { | ||
add(size(), value); | ||
} | ||
|
||
public void remove(int at); | ||
|
||
default boolean remove(Dynamic value) { | ||
for (int i = 0; i < size(); i++) { | ||
if (get(i) == value) { | ||
remove(i); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
default void clear() { | ||
for (int i = size() - 1; i >= 0; i--) remove(i); | ||
} | ||
|
||
@Override | ||
default Iterator<Dynamic> iterator() { | ||
return new Iterator<>() { | ||
int index = 0; | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return index < size(); | ||
} | ||
|
||
@Override | ||
public Dynamic next() { | ||
return get(index++); | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
if (index > size() || index == 0) throw new ArrayIndexOutOfBoundsException(); | ||
index--; | ||
DynamicList.this.remove(index); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2023-2024 nahkd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package stonks.core.dynamic; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
|
||
public interface DynamicMap extends Dynamic, Iterable<Map.Entry<String, ? extends Dynamic>> { | ||
public Set<String> keys(); | ||
|
||
public Dynamic getOrNull(String key); | ||
|
||
public Dynamic put(String key, Dynamic value); | ||
|
||
public boolean remove(String key); | ||
|
||
default void clear() { | ||
for (String key : keys()) remove(key); | ||
} | ||
|
||
@Override | ||
default Iterator<Entry<String, ? extends Dynamic>> iterator() { | ||
return keys().stream().<Map.Entry<String, ? extends Dynamic>>map(k -> Map.entry(k, getOrNull(k))).iterator(); | ||
} | ||
|
||
default Collection<Map.Entry<String, ? extends Dynamic>> entries() { | ||
var out = new ArrayList<Map.Entry<String, ? extends Dynamic>>(); | ||
var iter = iterator(); | ||
while (iter.hasNext()) out.add(iter.next()); | ||
return out; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/stonks/core/dynamic/DynamicPrimitive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2023-2024 nahkd | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package stonks.core.dynamic; | ||
|
||
public interface DynamicPrimitive extends Dynamic { | ||
public String asString(); | ||
|
||
public boolean isString(); | ||
|
||
public Number asNumber(); | ||
|
||
public boolean isNumber(); | ||
|
||
public boolean asBoolean(); | ||
|
||
public boolean isBoolean(); | ||
} |
2 changes: 1 addition & 1 deletion
2
core/src/main/java/stonks/core/exec/InstantOfferExecuteResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.