Added part of collections

This commit is contained in:
Robert Vokac 2024-10-12 14:21:21 +02:00
parent 099ac6d87d
commit cd20ac8ea6
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
7 changed files with 247 additions and 1 deletions

View File

@ -0,0 +1 @@

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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> {
}

View File

@ -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> {
}

View File

@ -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
}
}

View File

@ -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> {
}