Added part of collections
This commit is contained in:
parent
dbc5d5558b
commit
3b5c9bc108
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
// <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.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 <K, V> Map<K, V> objectMap() {
|
||||
return new LibGdxObjectMapImpl<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Set<T> objectSet() {
|
||||
return new LibGdxObjectSetImpl<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> list() {
|
||||
return new LibGdxListImpl<>();
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
// <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.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<T> extends PixelCollection<T> implements List<T> {
|
||||
private final Array<T> 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<T> 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<? extends T> 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<T> listIterator() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<T> listIterator(int index) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<T> subList(int fromIndex, int toIndex) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
// <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.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<K,V> implements Map<K,V> {
|
||||
private final ObjectMap internalMap = new ObjectMap<K,V> ();
|
||||
|
||||
@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<? extends K, ? extends V> m) {
|
||||
ObjectMap<K,V> 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<K> keySet() {
|
||||
var keys = internalMap.keys();
|
||||
Set<K> set = new LibGdxObjectSetImpl<>();
|
||||
for (Object key : keys) {
|
||||
set.add((K) key);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
List<V> values = new LibGdxListImpl<>();
|
||||
for(K key:keySet()) {
|
||||
values.add(get(key));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
Set<Entry<K,V>> set = new LibGdxObjectSetImpl<>();
|
||||
for(Object key:internalMap.keys()) {
|
||||
K keyK = (K) key;
|
||||
set.add(new EntryImpl<>(keyK, get(key)));
|
||||
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
// <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.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<T> extends PixelCollection<T> implements Set<T> {
|
||||
private final ObjectSet internalSet = new ObjectSet<T> ();
|
||||
|
||||
@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<T> 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<? extends T> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user