From 3b5c9bc1089f3a95f01fc6a82b0119a8f5c42691 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 12 Oct 2024 14:21:49 +0200 Subject: [PATCH] Added part of collections --- .../libgdx/interfaces/UtilsLibGDXImpl.java | 10 +- .../LibGdxCollectionUtilsImpl.java | 48 +++++++ .../utils/collections/LibGdxListImpl.java | 124 ++++++++++++++++++ .../collections/LibGdxObjectMapImpl.java | 120 +++++++++++++++++ .../collections/LibGdxObjectSetImpl.java | 81 ++++++++++++ 5 files changed, 381 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxCollectionUtilsImpl.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxListImpl.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectMapImpl.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectSetImpl.java diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.java index 47a1c09..41467bd 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.java @@ -33,6 +33,7 @@ import com.pixelgamelibrary.api.interfaces.Utils; import com.pixelgamelibrary.api.interfaces.App; import com.pixelgamelibrary.api.utils.CollectionUtils; import com.pixelgamelibrary.api.utils.ReflectionUtils; +import com.pixelgamelibrary.backend.libgdx.utils.collections.LibGdxCollectionUtilsImpl; /** * @@ -118,10 +119,15 @@ public class UtilsLibGDXImpl implements Utils { public ReflectionUtils reflection() { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody } - + @Override public CollectionUtils collections() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + if(libGdxCollectionUtilsImpl==null){ + libGdxCollectionUtilsImpl = new LibGdxCollectionUtilsImpl(); + } + return libGdxCollectionUtilsImpl; } + + private LibGdxCollectionUtilsImpl libGdxCollectionUtilsImpl = null; } diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxCollectionUtilsImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxCollectionUtilsImpl.java new file mode 100644 index 0000000..d3bc964 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxCollectionUtilsImpl.java @@ -0,0 +1,48 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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.backend.libgdx.utils.collections; + +import com.pixelgamelibrary.api.utils.CollectionUtils; +import com.pixelgamelibrary.api.utils.collections.List; +import com.pixelgamelibrary.api.utils.collections.Map; +import com.pixelgamelibrary.api.utils.collections.Set; + +/** + * + * @author robertvokac + */ +public class LibGdxCollectionUtilsImpl implements CollectionUtils { + + @Override + public Map objectMap() { + return new LibGdxObjectMapImpl<>(); + } + + @Override + public Set objectSet() { + return new LibGdxObjectSetImpl<>(); + } + + @Override + public List list() { + return new LibGdxListImpl<>(); + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxListImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxListImpl.java new file mode 100644 index 0000000..3a319fe --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxListImpl.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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.backend.libgdx.utils.collections; + +import com.badlogic.gdx.utils.Array; +import com.pixelgamelibrary.api.utils.collections.List; +import com.pixelgamelibrary.api.utils.collections.PixelCollection; +import java.util.Collection; +import java.util.Iterator; +import java.util.ListIterator; + +/** + * + * @author robertvokac + */ +public class LibGdxListImpl extends PixelCollection implements List { + private final Array internalArray = new Array<> (); + + @Override + public int size() { + return internalArray.size; + } + + @Override + public boolean isEmpty() { + return internalArray.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return internalArray.contains((T) o, true); + } + + @Override + public Iterator iterator() { + return internalArray.iterator(); + } + + @Override + public boolean add(T e) { + internalArray.add(e); + return true; + } + + @Override + public boolean remove(Object o) { + return internalArray.removeValue((T) o, true); + } + + @Override + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void clear() { + internalArray.clear(); + } + + @Override + public T get(int index) { + return internalArray.get(index); + } + + @Override + public T set(int index, T element) { + internalArray.set(index, element); + return element; + } + + @Override + public void add(int index, T element) { + set(index, element); + } + + @Override + public T remove(int index) { + return internalArray.removeIndex(index); + } + + @Override + public int indexOf(Object o) { + return internalArray.indexOf((T) o, true); + } + + @Override + public int lastIndexOf(Object o) { + return internalArray.lastIndexOf((T) o, true); + } + + @Override + public ListIterator listIterator() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public ListIterator listIterator(int index) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public java.util.List subList(int fromIndex, int toIndex) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectMapImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectMapImpl.java new file mode 100644 index 0000000..5a579e1 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectMapImpl.java @@ -0,0 +1,120 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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.backend.libgdx.utils.collections; + +import com.badlogic.gdx.utils.ObjectMap; +import com.pixelgamelibrary.api.utils.collections.EntryImpl; +import com.pixelgamelibrary.api.utils.collections.List; +import com.pixelgamelibrary.api.utils.collections.Map; +import java.util.Collection; +import java.util.Set; + +/** + * + * @author robertvokac + */ +public class LibGdxObjectMapImpl implements Map { + private final ObjectMap internalMap = new ObjectMap (); + + @Override + public int size() { + return internalMap.size; + } + + @Override + public boolean isEmpty() { + return internalMap.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return internalMap.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return internalMap.containsValue(value, true); + } + + @Override + public V get(Object key) { + return (V) internalMap.get(key); + } + + @Override + public V put(K key, V value) { + Object result = internalMap.put(key, value); + if(result == null) { + return null; + } + return (V) result; + } + + @Override + public V remove(Object key) { + return (V) internalMap.remove(key); + } + + @Override + public void putAll(java.util.Map m) { + ObjectMap om = new ObjectMap<>(); + for(K key: m.keySet()) { + om.put(key, m.get(key)); + } + internalMap.putAll(om); + } + + @Override + public void clear() { + internalMap.clear(); + } + + @Override + public Set keySet() { + var keys = internalMap.keys(); + Set set = new LibGdxObjectSetImpl<>(); + for (Object key : keys) { + set.add((K) key); + } + return set; + } + + @Override + public Collection values() { + List values = new LibGdxListImpl<>(); + for(K key:keySet()) { + values.add(get(key)); + } + return values; + } + + @Override + public Set> entrySet() { + Set> set = new LibGdxObjectSetImpl<>(); + for(Object key:internalMap.keys()) { + K keyK = (K) key; + set.add(new EntryImpl<>(keyK, get(key))); + + } + return set; + } + + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectSetImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectSetImpl.java new file mode 100644 index 0000000..80200ba --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/collections/LibGdxObjectSetImpl.java @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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.backend.libgdx.utils.collections; + +import com.badlogic.gdx.utils.ObjectSet; +import com.pixelgamelibrary.api.utils.collections.PixelCollection; +import com.pixelgamelibrary.api.utils.collections.Set; +import java.util.Collection; +import java.util.Iterator; + +/** + * + * @author robertvokac + */ +public class LibGdxObjectSetImpl extends PixelCollection implements Set { + private final ObjectSet internalSet = new ObjectSet (); + + @Override + public int size() { + return internalSet.size; + } + + @Override + public boolean isEmpty() { + return internalSet.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return internalSet.contains(o); + } + + @Override + public Iterator iterator() { + return internalSet.iterator(); + } + + @Override + public boolean add(T e) { + return internalSet.add(e); + } + + @Override + public boolean remove(Object o) { + return internalSet.remove(o); + } + + @Override + public boolean addAll(Collection c) { + return internalSet.addAll(c); + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void clear() { + internalSet.clear(); + } + + +}