Skip to content

Commit

Permalink
Replace construction data with metadata + Update license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nahkd123 committed Jun 13, 2024
1 parent 25a5d7a commit b7575b2
Show file tree
Hide file tree
Showing 73 changed files with 727 additions and 69 deletions.
2 changes: 1 addition & 1 deletion HEADER
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/stonks/core/caching/Cached.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
23 changes: 22 additions & 1 deletion core/src/main/java/stonks/core/caching/FutureCache.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* 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.caching;

import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -83,7 +104,7 @@ public CompletableFuture<T> get() {
} catch (Throwable e) {
e.printStackTrace();
}

fetchingTask = null;
}

Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/stonks/core/caching/StonksCache.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* 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.caching;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/stonks/core/dynamic/Dynamic.java
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 core/src/main/java/stonks/core/dynamic/DynamicFactory.java
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);
}
}
77 changes: 77 additions & 0 deletions core/src/main/java/stonks/core/dynamic/DynamicList.java
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);
}
};
}
}
55 changes: 55 additions & 0 deletions core/src/main/java/stonks/core/dynamic/DynamicMap.java
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 core/src/main/java/stonks/core/dynamic/DynamicPrimitive.java
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();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/stonks/core/market/Offer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/stonks/core/market/OfferType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/stonks/core/market/OverviewOffer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 nahkd
* 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
Expand Down
Loading

0 comments on commit b7575b2

Please sign in to comment.