diff --git a/src/main/java/com/pixelgamelibrary/api/scene2d/.gitkeep b/src/main/java/com/pixelgamelibrary/api/scene2d/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/scene2d/.gitkeep @@ -0,0 +1 @@ + diff --git a/src/main/java/com/pixelgamelibrary/api/utils/CollectionUtils.java b/src/main/java/com/pixelgamelibrary/api/utils/CollectionUtils.java index 4536cf3..754b8cd 100644 --- a/src/main/java/com/pixelgamelibrary/api/utils/CollectionUtils.java +++ b/src/main/java/com/pixelgamelibrary/api/utils/CollectionUtils.java @@ -20,10 +20,17 @@ package com.pixelgamelibrary.api.utils; +import com.pixelgamelibrary.api.utils.collections.List; +import com.pixelgamelibrary.api.utils.collections.Map; +import com.pixelgamelibrary.api.utils.collections.Set; + /** * * @author robertvokac */ public interface CollectionUtils { - + <K, V> Map<K, V> objectMap(); + <T> Set<T> objectSet(); + <T> List<T> list(); + } diff --git a/src/main/java/com/pixelgamelibrary/api/utils/collections/EntryImpl.java b/src/main/java/com/pixelgamelibrary/api/utils/collections/EntryImpl.java new file mode 100644 index 0000000..b7695bc --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/collections/EntryImpl.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// <https://www.gnu.org/licenses/> or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.utils.collections; + +import java.util.Map.Entry; + +/** + * + * @author robertvokac + */ +public class EntryImpl<K, V> implements Entry<K, V> { + + private K key; + private V value; + + public EntryImpl(K keyIn, V valueIn) { + this.key = keyIn; + this.value = valueIn; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return value; + } + + @Override + public V setValue(V valueIn) { + this.value = valueIn; + return this.value; + } + + +} diff --git a/src/main/java/com/pixelgamelibrary/api/utils/collections/List.java b/src/main/java/com/pixelgamelibrary/api/utils/collections/List.java new file mode 100644 index 0000000..b9baf08 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/collections/List.java @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: Game library. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// <https://www.gnu.org/licenses/> or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.utils.collections; + +/** + * + * @author robertvokac + * @param <T> item + */ +public interface List<T> extends java.util.List<T> { + +} diff --git a/src/main/java/com/pixelgamelibrary/api/utils/collections/Map.java b/src/main/java/com/pixelgamelibrary/api/utils/collections/Map.java new file mode 100644 index 0000000..ad5b39e --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/collections/Map.java @@ -0,0 +1,30 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: Game library. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// <https://www.gnu.org/licenses/> or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.utils.collections; + +/** + * + * @author robertvokac + * @param <K> key + * @param <V> value + */ +public interface Map<K,V> extends java.util.Map<K,V> { + +} diff --git a/src/main/java/com/pixelgamelibrary/api/utils/collections/PixelCollection.java b/src/main/java/com/pixelgamelibrary/api/utils/collections/PixelCollection.java new file mode 100644 index 0000000..fe708a2 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/collections/PixelCollection.java @@ -0,0 +1,95 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// <https://www.gnu.org/licenses/> or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.utils.collections; + +import java.util.Collection; +import java.util.Iterator; + +/** + * + * @author robertvokac + * @param <T> item + */ +public abstract class PixelCollection<T> implements Collection<T> { + + @Override + public final Object[] toArray() { + Iterator<T> iterator = iterator(); + Object[] array = new Object[size()]; + int i = 0; + while (iterator.hasNext()) { + array[i] = iterator.next(); + i++; + } + return array; + } + + @Override + public final <T> T[] toArray(T[] a) { + Iterator<T> iterator = (Iterator<T>) iterator(); + Object[] array = a; + int i = 0; + while (iterator.hasNext()) { + array[i] = iterator.next(); + i++; + } + return (T[]) array; + } + + @Override + public final boolean containsAll(Collection<?> c) { + Iterator<T> iterator = iterator(); + while (iterator.hasNext()) { + boolean contains = contains(iterator.next()); + if (!contains) { + return false; + } + } + return true; + } + + @Override + public final boolean removeAll(Collection<?> c) { + boolean allKeysRemoved = true; + Iterator<T> iterator = iterator(); + while (iterator.hasNext()) { + boolean removed = remove(iterator.next()); + if (!removed && allKeysRemoved) { + allKeysRemoved = false; + } + } + return allKeysRemoved; + } + + @Override + public boolean addAll(Collection<? extends T> c) { + Iterator<T> iterator = iterator(); + while (iterator.hasNext()) { + add(iterator.next()); + } + return true; + } + + @Override + public boolean retainAll(Collection<?> c) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + +} diff --git a/src/main/java/com/pixelgamelibrary/api/utils/collections/Set.java b/src/main/java/com/pixelgamelibrary/api/utils/collections/Set.java new file mode 100644 index 0000000..0037d72 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/collections/Set.java @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: Game library. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// <https://www.gnu.org/licenses/> or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.utils.collections; + +/** + * + * @author robertvokac + * @param <T> item + */ +public interface Set<T> extends java.util.Set<T> { + +}