Added part of collections
This commit is contained in:
parent
099ac6d87d
commit
cd20ac8ea6
1
src/main/java/com/pixelgamelibrary/api/scene2d/.gitkeep
Normal file
1
src/main/java/com/pixelgamelibrary/api/scene2d/.gitkeep
Normal file
@ -0,0 +1 @@
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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> {
|
||||
|
||||
}
|
@ -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> {
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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> {
|
||||
|
||||
}
|
Reference in New Issue
Block a user