From cd20ac8ea6a745ec827cddf66c7de97afc004820 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 12 Oct 2024 14:21:21 +0200 Subject: [PATCH] Added part of collections --- .../com/pixelgamelibrary/api/scene2d/.gitkeep | 1 + .../api/utils/CollectionUtils.java | 9 +- .../api/utils/collections/EntryImpl.java | 55 +++++++++++ .../api/utils/collections/List.java | 29 ++++++ .../api/utils/collections/Map.java | 30 ++++++ .../utils/collections/PixelCollection.java | 95 +++++++++++++++++++ .../api/utils/collections/Set.java | 29 ++++++ 7 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/pixelgamelibrary/api/scene2d/.gitkeep create mode 100644 src/main/java/com/pixelgamelibrary/api/utils/collections/EntryImpl.java create mode 100644 src/main/java/com/pixelgamelibrary/api/utils/collections/List.java create mode 100644 src/main/java/com/pixelgamelibrary/api/utils/collections/Map.java create mode 100644 src/main/java/com/pixelgamelibrary/api/utils/collections/PixelCollection.java create mode 100644 src/main/java/com/pixelgamelibrary/api/utils/collections/Set.java 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 { - + Map objectMap(); + Set objectSet(); + List 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 +// 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 implements Entry { + + 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 +// 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 item + */ +public interface List extends java.util.List { + +} 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 +// 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 key + * @param value + */ +public interface Map extends java.util.Map { + +} 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 +// 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 item + */ +public abstract class PixelCollection implements Collection { + + @Override + public final Object[] toArray() { + Iterator iterator = iterator(); + Object[] array = new Object[size()]; + int i = 0; + while (iterator.hasNext()) { + array[i] = iterator.next(); + i++; + } + return array; + } + + @Override + public final T[] toArray(T[] a) { + Iterator iterator = (Iterator) 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 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 iterator = iterator(); + while (iterator.hasNext()) { + boolean removed = remove(iterator.next()); + if (!removed && allKeysRemoved) { + allKeysRemoved = false; + } + } + return allKeysRemoved; + } + + @Override + public boolean addAll(Collection c) { + Iterator 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 +// 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 item + */ +public interface Set extends java.util.Set { + +}