com.github.tommyettinger.ds.interop.ConversionToJDK Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdkgdxds_interop Show documentation
Show all versions of jdkgdxds_interop Show documentation
Inter-operate between libGDX and jdkgdxds.
The newest version!
/*
* Copyright (c) 2023 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.tommyettinger.ds.interop;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ArrayMap;
import com.badlogic.gdx.utils.BooleanArray;
import com.badlogic.gdx.utils.ByteArray;
import com.badlogic.gdx.utils.CharArray;
import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.LongArray;
import com.badlogic.gdx.utils.LongMap;
import com.badlogic.gdx.utils.LongQueue;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.OrderedSet;
import com.badlogic.gdx.utils.Queue;
import com.badlogic.gdx.utils.ShortArray;
import com.github.tommyettinger.ds.*;
import com.github.tommyettinger.ds.support.sort.FloatComparator;
import com.github.tommyettinger.ds.support.sort.IntComparator;
import com.github.tommyettinger.ds.support.sort.LongComparator;
import java.util.Comparator;
import java.util.Iterator;
/**
* Converts libGDX data structures to the JDK-interface-compatible data structures in jdkgdxds. This is arguably
* misleadingly-named, because not all the interfaces used by jdkgdxds are present in the JDK, and this isn't always
* a perfect fit. If you primarily use jdkgdxds data structures, then most of the APIs should be very similar to JDK
* data structures, when they aren't identical. There are all sorts of extensions jdkgdxds does, such as for the ordered
* data structures.
*/
public class ConversionToJDK {
/**
* Can be used to convert from a libGDX Array to a jdkgdxds ObjectList of the same element type.
* @param from an Array from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectList of type T holding the items of {@code from}
*/
public static ObjectList toObjectList(Array from) {
ObjectList list = new ObjectList<>(from.size);
for(T t : from)
list.add(t);
return list;
}
/**
* Can be used to convert from a libGDX Array to a jdkgdxds ObjectBag of the same element type.
* @param from an Array from libGDX; may be ordered or unordered
* @param the element type for {@code from} and the result
* @return a new ObjectBag of type T holding the items of {@code from}
*/
public static ObjectBag toObjectBag(Array from) {
ObjectBag bag = new ObjectBag<>(from.size);
for(T t : from)
bag.add(t);
return bag;
}
/**
* Can be used to convert from a libGDX Queue to a jdkgdxds ObjectList of the same element type.
* @param from a Queue from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectList of type T holding the items of {@code from}
*/
public static ObjectList toObjectList(Queue from) {
ObjectList list = new ObjectList<>(from.size);
for(T t : from)
list.add(t);
return list;
}
/**
* Can be used to convert from a libGDX Queue to a jdkgdxds ObjectBag of the same element type.
* @param from a Queue from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectBag of type T holding the items of {@code from}
*/
public static ObjectBag toObjectBag(Queue from) {
ObjectBag Bag = new ObjectBag<>(from.size);
for(T t : from)
Bag.add(t);
return Bag;
}
/**
* Can be used to convert from a libGDX ObjectSet or OrderedSet to a jdkgdxds ObjectList of the same element type.
* @param from an ObjectSet or OrderedSet from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectList of type T holding the unique items of {@code from}
*/
public static ObjectList toObjectList(com.badlogic.gdx.utils.ObjectSet from) {
ObjectList list = new ObjectList<>(from.size);
for(T t : from)
list.add(t);
return list;
}
/**
* Can be used to convert from a libGDX IntArray to a jdkgdxds IntList.
* @param from a libGDX IntArray
* @return a new IntList holding the items of {@code from}
*/
public static IntList toIntList(IntArray from){
return new IntList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX IntArray to a jdkgdxds IntBag.
* @param from a libGDX IntArray, which may be ordered or unordered
* @return a new IntBag holding the items of {@code from}
*/
public static IntBag toIntBag(IntArray from){
return new IntBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntSet}
* to a new jdkgdxds {@link IntList}.
* @param from a libGDX IntSet
* @return a new jdkgdxds IntList holding the items in {@code from}
*/
public static IntList toIntList(com.badlogic.gdx.utils.IntSet from) {
IntList set = new IntList(from.size);
com.badlogic.gdx.utils.IntSet.IntSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntSet}
* to a new jdkgdxds {@link IntBag}.
* @param from a libGDX IntSet
* @return a new jdkgdxds IntBag holding the items in {@code from}
*/
public static IntBag toIntBag(com.badlogic.gdx.utils.IntSet from) {
IntBag set = new IntBag(from.size);
com.badlogic.gdx.utils.IntSet.IntSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX LongArray to a jdkgdxds LongList.
* @param from a libGDX LongArray
* @return a new LongList holding the items of {@code from}
*/
public static LongList toLongList(LongArray from){
return new LongList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX LongArray to a jdkgdxds LongBag.
* @param from a libGDX LongArray
* @return a new LongBag holding the items of {@code from}
*/
public static LongBag toLongBag(LongArray from){
return new LongBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX LongQueue to a jdkgdxds LongList.
* @param from a libGDX LongQueue
* @return a new LongList holding the items of {@code from}
*/
public static LongList toLongList(LongQueue from){
LongList list = new LongList(from.size);
for (int i = 0; i < from.size; i++) {
list.add(from.get(i));
}
return list;
}
/**
* Can be used to convert from a libGDX LongQueue to a jdkgdxds LongBag.
* @param from a libGDX LongQueue
* @return a new LongBag holding the items of {@code from}
*/
public static LongBag toLongBag(LongQueue from){
LongBag list = new LongBag(from.size);
for (int i = 0; i < from.size; i++) {
list.add(from.get(i));
}
return list;
}
/**
* Can be used to convert from a libGDX FloatArray to a jdkgdxds FloatList.
* @param from a libGDX FloatArray
* @return a new FloatList holding the items of {@code from}
*/
public static FloatList toFloatList(FloatArray from){
return new FloatList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX ByteArray to a jdkgdxds ByteList.
* @param from a libGDX ByteArray
* @return a new ByteList holding the items of {@code from}
*/
public static ByteList toByteList(ByteArray from){
return new ByteList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX CharArray to a jdkgdxds CharList.
* @param from a libGDX CharArray
* @return a new CharList holding the items of {@code from}
*/
public static CharList toCharList(CharArray from){
return new CharList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX ShortArray to a jdkgdxds ShortList.
* @param from a libGDX ShortArray
* @return a new ShortList holding the items of {@code from}
*/
public static ShortList toShortList(ShortArray from){
return new ShortList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX BooleanArray to a jdkgdxds BooleanList.
* @param from a libGDX BooleanArray
* @return a new BooleanList holding the items of {@code from}
*/
public static BooleanList toBooleanList(BooleanArray from){
return new BooleanList(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX FloatArray to a jdkgdxds FloatBag.
* @param from a libGDX FloatArray
* @return a new FloatBag holding the items of {@code from}
*/
public static FloatBag toFloatBag(FloatArray from){
return new FloatBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX ByteArray to a jdkgdxds ByteBag.
* @param from a libGDX ByteArray
* @return a new ByteBag holding the items of {@code from}
*/
public static ByteBag toByteBag(ByteArray from){
return new ByteBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX CharArray to a jdkgdxds CharBag.
* @param from a libGDX CharArray
* @return a new CharBag holding the items of {@code from}
*/
public static CharBag toCharBag(CharArray from){
return new CharBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX ShortArray to a jdkgdxds ShortBag.
* @param from a libGDX ShortArray
* @return a new ShortBag holding the items of {@code from}
*/
public static ShortBag toShortBag(ShortArray from){
return new ShortBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX BooleanArray to a jdkgdxds BooleanBag.
* @param from a libGDX BooleanArray
* @return a new BooleanBag holding the items of {@code from}
*/
public static BooleanBag toBooleanBag(BooleanArray from){
return new BooleanBag(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.Array}
* to a new jdkgdxds {@link ObjectSet}. This will not necessarily maintain the order of the
* items in the Array.
* @param from a libGDX Array
* @return a new jdkgdxds ObjectSet holding the unique items in {@code from}
*/
public static ObjectSet toObjectSet(com.badlogic.gdx.utils.Array from) {
ObjectSet set = new ObjectSet<>(from.size);
for (T t : from) {
set.add(t);
}
return set;
}
/**
* Can be used to convert from a libGDX {@link Queue}
* to a new jdkgdxds {@link ObjectSet}. This will not necessarily maintain the order of the
* items in the Queue.
* @param from a libGDX Queue
* @return a new jdkgdxds ObjectSet holding the unique items in {@code from}
*/
public static ObjectSet toObjectSet(Queue from) {
ObjectSet set = new ObjectSet<>(from.size);
for (T t : from) {
set.add(t);
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectSet}
* to a new jdkgdxds {@link ObjectSet}.
* @param from a libGDX ObjectSet or OrderedSet
* @return a new jdkgdxds ObjectSet holding the unique items in {@code from}
*/
public static ObjectSet toObjectSet(com.badlogic.gdx.utils.ObjectSet from) {
ObjectSet set = new ObjectSet<>(from.size);
com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.Array}
* to a new jdkgdxds {@link ObjectOrderedSet}. This will maintain the order of the
* items in the Array.
* @param from a libGDX Array
* @return a new jdkgdxds ObjectOrderedSet holding the unique items in {@code from}
*/
public static ObjectOrderedSet toObjectOrderedSet(com.badlogic.gdx.utils.Array from) {
ObjectOrderedSet set = new ObjectOrderedSet<>(from.size);
for (T t : from) {
set.add(t);
}
return set;
}
/**
* Can be used to convert from a libGDX {@link Queue}
* to a new jdkgdxds {@link ObjectOrderedSet}. This will maintain the order of the
* items in the Queue.
* @param from a libGDX Queue
* @return a new jdkgdxds ObjectOrderedSet holding the unique items in {@code from}
*/
public static ObjectOrderedSet toObjectOrderedSet(Queue from) {
ObjectOrderedSet set = new ObjectOrderedSet<>(from.size);
for (T t : from) {
set.add(t);
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectSet} or
* {@link com.badlogic.gdx.utils.OrderedSet} to a new jdkgdxds {@link ObjectOrderedSet}.
* @param from a libGDX ObjectSet or OrderedSet
* @return a new jdkgdxds ObjectOrderedSet holding the unique items in {@code from}
*/
public static ObjectOrderedSet toObjectOrderedSet(com.badlogic.gdx.utils.ObjectSet from) {
ObjectOrderedSet set = new ObjectOrderedSet<>(from.size);
com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.Array}
* to a new jdkgdxds {@link CaseInsensitiveSet}. This will not necessarily maintain the order of the
* items in the Array.
* @param from a libGDX Array
* @return a new jdkgdxds CaseInsensitiveSet holding the unique items (case-insensitive) in {@code from}
*/
public static CaseInsensitiveSet toCaseInsensitiveSet(com.badlogic.gdx.utils.Array from) {
CaseInsensitiveSet set = new CaseInsensitiveSet(from.size);
for (T t : from) {
set.add(t);
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectSet} or
* {@link com.badlogic.gdx.utils.OrderedSet} to a new jdkgdxds {@link CaseInsensitiveSet}.
* @param from a libGDX ObjectSet or OrderedSet
* @return a new jdkgdxds CaseInsensitiveSet holding the unique items (case-insensitive) in {@code from}
*/
public static CaseInsensitiveSet toCaseInsensitiveSet(com.badlogic.gdx.utils.ObjectSet from) {
CaseInsensitiveSet set = new CaseInsensitiveSet(from.size);
com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.Array}
* to a new jdkgdxds {@link CaseInsensitiveSet}. This will maintain the order of the
* items in the Array.
* @param from a libGDX Array
* @return a new jdkgdxds CaseInsensitiveSet holding the unique items (case-insensitive) in {@code from}
*/
public static CaseInsensitiveOrderedSet toCaseInsensitiveOrderedSet(com.badlogic.gdx.utils.Array from) {
CaseInsensitiveOrderedSet set = new CaseInsensitiveOrderedSet(from.size);
for (T t : from) {
set.add(t);
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectSet} or
* {@link com.badlogic.gdx.utils.OrderedSet} to a new jdkgdxds {@link ObjectOrderedSet}.
* If from is an OrderedSet, this will maintain its order.
* @param from a libGDX ObjectSet or OrderedSet
* @return a new jdkgdxds ObjectOrderedSet holding the unique items (case-insensitive) in {@code from}
*/
public static CaseInsensitiveOrderedSet toCaseInsensitiveOrderedSet(com.badlogic.gdx.utils.ObjectSet from) {
CaseInsensitiveOrderedSet set = new CaseInsensitiveOrderedSet(from.size);
com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntSet}
* to a new jdkgdxds {@link IntSet}.
* @param from a libGDX IntSet
* @return a new jdkgdxds IntSet holding the unique items in {@code from}
*/
public static IntSet toIntSet(com.badlogic.gdx.utils.IntSet from) {
IntSet set = new IntSet(from.size);
com.badlogic.gdx.utils.IntSet.IntSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntArray}
* to a new jdkgdxds {@link IntSet}.
* @param from a libGDX IntArray
* @return a new jdkgdxds IntSet holding the unique items in {@code from}
*/
public static IntSet toIntSet(com.badlogic.gdx.utils.IntArray from) {
return new IntSet(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntSet}
* to a new jdkgdxds {@link IntOrderedSet}. Because a libGDX IntSet is not
* meaningfully ordered, the initial order of the IntOrderedSet this returns is
* probably not going to match the insertion order for the IntSet. You can sort
* an {@link IntOrderedSet} with {@link IntOrderedSet#sort()}.
* @param from a libGDX IntSet
* @return a new jdkgdxds IntSet holding the unique items in {@code from}
*/
public static IntOrderedSet toIntOrderedSet(com.badlogic.gdx.utils.IntSet from) {
IntOrderedSet set = new IntOrderedSet(from.size);
com.badlogic.gdx.utils.IntSet.IntSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntArray}
* to a new jdkgdxds {@link IntOrderedSet}. This will maintain the order of the
* items in the IntArray.
* @param from a libGDX IntArray
* @return a new jdkgdxds IntOrderedSet holding the unique items in {@code from}
*/
public static IntOrderedSet toIntOrderedSet(com.badlogic.gdx.utils.IntArray from) {
return new IntOrderedSet(from.items, 0, from.size);
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectSet}
* (or more typically, a libGDX {@link OrderedSet}) to a new jdkgdxds {@link NumberedSet}.
* This will maintain the order in an OrderedSet argument, and because it returns a
* NumberedSet, the order can be looked up bidirectionally with
* {@link NumberedSet#indexOf(Object)}. If given an ordinary ObjectSet, it will not maintain
* any kind of order with the given set.
* @param from a libGDX ObjectSet or OrderedSet
* @return a new jdkgdxds NumberedSet holding the unique items in {@code from}
*/
public static NumberedSet toNumberedSet(com.badlogic.gdx.utils.ObjectSet from) {
NumberedSet set = new NumberedSet<>(from.size);
com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator it = from.iterator();
while (it.hasNext) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.Array} to a new
* jdkgdxds {@link NumberedSet}, keeping only unique items in the Array. This will
* maintain the order in the Array argument, and because it returns a NumberedSet, the order
* can be looked up bidirectionally with {@link NumberedSet#indexOf(Object)}.
* @param from a libGDX Array
* @return a new jdkgdxds NumberedSet holding the unique items in {@code from}
*/
public static NumberedSet toNumberedSet(Array from) {
NumberedSet set = new NumberedSet<>(from.size);
Array.ArrayIterator it = from.iterator();
while (it.hasNext()) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX {@link Queue} to a new
* jdkgdxds {@link NumberedSet}, keeping only unique items in the Queue. This will
* maintain the order in the Queue argument, and because it returns a NumberedSet, the order
* can be looked up bidirectionally with {@link NumberedSet#indexOf(Object)}.
* @param from a libGDX Queue
* @return a new jdkgdxds NumberedSet holding the unique items in {@code from}
*/
public static NumberedSet toNumberedSet(Queue from) {
NumberedSet set = new NumberedSet<>(from.size);
Iterator it = from.iterator();
while (it.hasNext()) {
set.add(it.next());
}
return set;
}
/**
* Can be used to convert from a libGDX ObjectMap (or OrderedMap) to a new jdkgdxds
* {@link ObjectObjectMap}.
* @param from a libGDX ObjectMap (or OrderedMap)
* @param the type of keys; the same in {@code from} and the returned ObjectObjectMap
* @param the type of values; the same in {@code from} and the returned ObjectObjectMap
* @return a new ObjectObjectMap holding all the key-value pairs in {@code from}
*/
public static ObjectObjectMap toObjectObjectMap(ObjectMap from){
ObjectObjectMap map = new ObjectObjectMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX ObjectMap (or OrderedMap) to a new jdkgdxds
* {@link ObjectObjectOrderedMap}. If {@code from} is an OrderedMap, then this will maintain
* its order in the returned ObjectObjectOrderedMap.
* @param from a libGDX ObjectMap (or OrderedMap)
* @param the type of keys; the same in {@code from} and the returned ObjectObjectOrderedMap
* @param the type of values; the same in {@code from} and the returned ObjectObjectOrderedMap
* @return a new ObjectObjectOrderedMap holding all the key-value pairs in {@code from}
*/
public static ObjectObjectOrderedMap toObjectObjectOrderedMap(ObjectMap from){
ObjectObjectOrderedMap map = new ObjectObjectOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX ArrayMap to a new jdkgdxds {@link ObjectObjectMap}.
* @param from a libGDX ArrayMap
* @param the type of keys; the same in {@code from} and the returned ObjectObjectMap
* @param the type of values; the same in {@code from} and the returned ObjectObjectMap
* @return a new ObjectObjectMap holding all the key-value pairs in {@code from}
*/
public static ObjectObjectMap toObjectObjectMap(ArrayMap from){
ObjectObjectMap map = new ObjectObjectMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX ArrayMap to a new jdkgdxds
* {@link ObjectObjectOrderedMap}. This will maintain the ArrayMap's order in the
* returned ObjectObjectOrderedMap.
* @param from a libGDX ArrayMap
* @param the type of keys; the same in {@code from} and the returned ObjectObjectOrderedMap
* @param the type of values; the same in {@code from} and the returned ObjectObjectOrderedMap
* @return a new ObjectObjectOrderedMap holding all the key-value pairs in {@code from}
*/
public static ObjectObjectOrderedMap toObjectObjectOrderedMap(ArrayMap from){
ObjectObjectOrderedMap map = new ObjectObjectOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX ObjectMap (or OrderedMap) to a new jdkgdxds
* {@link CaseInsensitiveMap}.
* @param from a libGDX ObjectMap (or OrderedMap)
* @param the type of keys; must extend CharSequence, so this could be String, StringBuilder, etc.
* @param the type of values; the same in {@code from} and the returned CaseInsensitiveMap
* @return a new CaseInsensitiveMap holding all the key-value pairs in {@code from}
*/
public static CaseInsensitiveMap toCaseInsensitiveMap(ObjectMap from){
CaseInsensitiveMap map = new CaseInsensitiveMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX ObjectMap (or OrderedMap) to a new jdkgdxds
* {@link CaseInsensitiveOrderedMap}. If {@code from} is an OrderedMap, then this will maintain
* its order in the returned CaseInsensitiveOrderedMap.
* @param from a libGDX ObjectMap (or OrderedMap)
* @param the type of keys; must extend CharSequence, so this could be String, StringBuilder, etc.
* @param the type of values; the same in {@code from} and the returned CaseInsensitiveOrderedMap
* @return a new CaseInsensitiveOrderedMap holding all the key-value pairs in {@code from}
*/
public static CaseInsensitiveOrderedMap toCaseInsensitiveOrderedMap(ObjectMap from){
CaseInsensitiveOrderedMap map = new CaseInsensitiveOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectIntMap} to a
* jdkgdxds ObjectIntMap.
* @param from a libGDX ObjectIntMap
* @param the type of keys; the same in {@code from} and the returned ObjectIntMap
* @return a new jdkgdxds ObjectIntMap holding all the key-value pairs in {@code from}
*/
public static ObjectIntMap toObjectIntMap(com.badlogic.gdx.utils.ObjectIntMap from){
ObjectIntMap map = new ObjectIntMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectIntMap} to a
* jdkgdxds ObjectIntOrderedMap. Because the given libGDX ObjectIntMap does not maintain order,
* the initial ordering of the returned ObjectIntOrderedMap is undefined, but it can be sorted
* with {@link ObjectIntOrderedMap#sort()} or {@link ObjectIntOrderedMap#sortByValue(IntComparator)}.
* @param from a libGDX ObjectIntMap
* @param the type of keys; the same in {@code from} and the returned ObjectIntOrderedMap
* @return a new jdkgdxds ObjectIntOrderedMap holding all the key-value pairs in {@code from}
*/
public static ObjectIntOrderedMap toObjectIntOrderedMap(com.badlogic.gdx.utils.ObjectIntMap from){
ObjectIntOrderedMap map = new ObjectIntOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectLongMap} to a
* jdkgdxds ObjectLongMap.
* @param from a libGDX ObjectLongMap
* @param the type of keys; the same in {@code from} and the returned ObjectLongMap
* @return a new jdkgdxds ObjectLongMap holding all the key-value pairs in {@code from}
*/
public static ObjectLongMap toObjectLongMap(com.badlogic.gdx.utils.ObjectLongMap from){
ObjectLongMap map = new ObjectLongMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectLongMap} to a
* jdkgdxds ObjectLongOrderedMap. Because the given libGDX ObjectLongMap does not maintain order,
* the initial ordering of the returned ObjectLongOrderedMap is undefined, but it can be sorted
* with {@link ObjectLongOrderedMap#sort()} or {@link ObjectLongOrderedMap#sortByValue(LongComparator)}.
* @param from a libGDX ObjectLongMap
* @param the type of keys; the same in {@code from} and the returned ObjectLongOrderedMap
* @return a new jdkgdxds ObjectLongOrderedMap holding all the key-value pairs in {@code from}
*/
public static ObjectLongOrderedMap toObjectLongOrderedMap(com.badlogic.gdx.utils.ObjectLongMap from){
ObjectLongOrderedMap map = new ObjectLongOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectFloatMap} to a
* jdkgdxds ObjectFloatMap.
* @param from a libGDX ObjectFloatMap
* @param the type of keys; the same in {@code from} and the returned ObjectFloatMap
* @return a new jdkgdxds ObjectFloatMap holding all the key-value pairs in {@code from}
*/
public static ObjectFloatMap toObjectFloatMap(com.badlogic.gdx.utils.ObjectFloatMap from){
ObjectFloatMap map = new ObjectFloatMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.ObjectFloatMap} to a
* jdkgdxds ObjectFloatOrderedMap. Because the given libGDX ObjectFloatMap does not maintain order,
* the initial ordering of the returned ObjectFloatOrderedMap is undefined, but it can be sorted
* with {@link ObjectFloatOrderedMap#sort()} or {@link ObjectFloatOrderedMap#sortByValue(FloatComparator)}.
* @param from a libGDX ObjectFloatMap
* @param the type of keys; the same in {@code from} and the returned ObjectFloatOrderedMap
* @return a new jdkgdxds ObjectFloatOrderedMap holding all the key-value pairs in {@code from}
*/
public static ObjectFloatOrderedMap toObjectFloatOrderedMap(com.badlogic.gdx.utils.ObjectFloatMap from){
ObjectFloatOrderedMap map = new ObjectFloatOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntMap} to a
* jdkgdxds IntObjectMap.
* @param from a libGDX IntMap
* @param the type of values; the same in {@code from} and the returned IntObjectMap
* @return a new jdkgdxds IntObjectMap holding all the key-value pairs in {@code from}
*/
public static IntObjectMap toIntObjectMap(com.badlogic.gdx.utils.IntMap from){
IntObjectMap map = new IntObjectMap<>(from.size);
IntMap.Keys it = from.keys();
while (it.hasNext){
int k = it.next();
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntMap} to a
* jdkgdxds IntObjectOrderedMap. Because the given libGDX IntMap does not maintain order,
* the initial ordering of the returned IntObjectOrderedMap is undefined, but it can be sorted
* with {@link IntObjectOrderedMap#sort()} or {@link IntObjectOrderedMap#sortByValue(Comparator)}.
* @param from a libGDX IntMap
* @param the type of values; the same in {@code from} and the returned IntObjectOrderedMap
* @return a new jdkgdxds IntObjectOrderedMap holding all the key-value pairs in {@code from}
*/
public static IntObjectOrderedMap toIntObjectOrderedMap(com.badlogic.gdx.utils.IntMap from){
IntObjectOrderedMap map = new IntObjectOrderedMap<>(from.size);
IntMap.Keys it = from.keys();
while (it.hasNext){
int k = it.next();
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntIntMap} to a
* jdkgdxds IntIntMap.
* @param from a libGDX IntIntMap
* @return a new jdkgdxds IntIntMap holding all the key-value pairs in {@code from}
*/
public static IntIntMap toIntIntMap(com.badlogic.gdx.utils.IntIntMap from){
IntIntMap map = new IntIntMap(from.size);
com.badlogic.gdx.utils.IntIntMap.Keys it = from.keys();
while (it.hasNext){
int k = it.next();
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntIntMap} to a
* jdkgdxds IntIntOrderedMap. Because the given libGDX IntIntMap does not maintain order,
* the initial ordering of the returned IntIntOrderedMap is undefined, but it can be sorted
* with {@link IntIntOrderedMap#sort()} or {@link IntIntOrderedMap#sortByValue(IntComparator)}.
* @param from a libGDX IntIntMap
* @return a new jdkgdxds IntIntOrderedMap holding all the key-value pairs in {@code from}
*/
public static IntIntOrderedMap toIntIntOrderedMap(com.badlogic.gdx.utils.IntIntMap from){
IntIntOrderedMap map = new IntIntOrderedMap(from.size);
com.badlogic.gdx.utils.IntIntMap.Keys it = from.keys();
while (it.hasNext){
int k = it.next();
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntFloatMap} to a
* jdkgdxds IntFloatMap.
* @param from a libGDX IntFloatMap
* @return a new jdkgdxds IntFloatMap holding all the key-value pairs in {@code from}
*/
public static IntFloatMap toIntFloatMap(com.badlogic.gdx.utils.IntFloatMap from){
IntFloatMap map = new IntFloatMap(from.size);
com.badlogic.gdx.utils.IntFloatMap.Keys it = from.keys();
while (it.hasNext){
int k = it.next();
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.IntFloatMap} to a
* jdkgdxds IntFloatOrderedMap. Because the given libGDX IntFloatMap does not maintain order,
* the initial ordering of the returned IntFloatOrderedMap is undefined, but it can be sorted
* with {@link IntFloatOrderedMap#sort()} or {@link IntFloatOrderedMap#sortByValue(FloatComparator)}.
* @param from a libGDX IntFloatMap
* @return a new jdkgdxds IntFloatOrderedMap holding all the key-value pairs in {@code from}
*/
public static IntFloatOrderedMap toIntFloatOrderedMap(com.badlogic.gdx.utils.IntFloatMap from){
IntFloatOrderedMap map = new IntFloatOrderedMap(from.size);
com.badlogic.gdx.utils.IntFloatMap.Keys it = from.keys();
while (it.hasNext){
int k = it.next();
map.put(k, from.get(k, 0));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.LongMap} to a
* jdkgdxds LongObjectMap.
* @param from a libGDX LongMap
* @param the type of values; the same in {@code from} and the returned LongObjectMap
* @return a new jdkgdxds LongObjectMap holding all the key-value pairs in {@code from}
*/
public static LongObjectMap toLongObjectMap(com.badlogic.gdx.utils.LongMap from){
LongObjectMap map = new LongObjectMap<>(from.size);
LongMap.Keys it = from.keys();
while (it.hasNext){
long k = it.next();
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX {@link com.badlogic.gdx.utils.LongMap} to a
* jdkgdxds LongObjectOrderedMap. Because the given libGDX LongMap does not maintain order,
* the initial ordering of the returned LongObjectOrderedMap is undefined, but it can be sorted
* with {@link LongObjectOrderedMap#sort()} or {@link LongObjectOrderedMap#sortByValue(Comparator)}.
* @param from a libGDX LongMap
* @param the type of values; the same in {@code from} and the returned LongObjectOrderedMap
* @return a new jdkgdxds LongObjectOrderedMap holding all the key-value pairs in {@code from}
*/
public static LongObjectOrderedMap toLongObjectOrderedMap(com.badlogic.gdx.utils.LongMap from){
LongObjectOrderedMap map = new LongObjectOrderedMap<>(from.size);
LongMap.Keys it = from.keys();
while (it.hasNext){
long k = it.next();
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX IdentityMap, ObjectMap, or OrderedMap to a new
* jdkgdxds {@link IdentityObjectMap}.
* @param from a libGDX IdentityMap, ObjectMap, or OrderedMap
* @param the type of keys; the same in {@code from} and the returned IdentityObjectMap
* @param the type of values; the same in {@code from} and the returned IdentityObjectMap
* @return a new IdentityObjectMap holding all the key-value pairs in {@code from}
*/
public static IdentityObjectMap toIdentityObjectMap(ObjectMap from){
IdentityObjectMap map = new IdentityObjectMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX IdentityMap, ObjectMap, or OrderedMap to a new jdkgdxds
* {@link IdentityObjectOrderedMap}. If {@code from} is an OrderedMap, then this will maintain
* its order in the returned IdentityObjectOrderedMap.
* @param from a libGDX IdentityMap, ObjectMap, or OrderedMap
* @param the type of keys; the same in {@code from} and the returned IdentityObjectOrderedMap
* @param the type of values; the same in {@code from} and the returned IdentityObjectOrderedMap
* @return a new IdentityObjectOrderedMap holding all the key-value pairs in {@code from}
*/
public static IdentityObjectOrderedMap toIdentityObjectOrderedMap(ObjectMap from){
IdentityObjectOrderedMap map = new IdentityObjectOrderedMap<>(from.size);
for(K k : from.keys()) {
map.put(k, from.get(k));
}
return map;
}
/**
* Can be used to convert from a libGDX Array to a jdkgdxds ObjectDeque of the same element type.
* @param from an Array from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectDeque of type T holding the items of {@code from}
*/
public static ObjectDeque toObjectDeque(Array from) {
ObjectDeque deque = new ObjectDeque<>(from.size);
for(T t : from)
deque.add(t);
return deque;
}
/**
* Can be used to convert from a libGDX Queue to a jdkgdxds ObjectDeque of the same element type.
* @param from a Queue from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectDeque of type T holding the items of {@code from}
*/
public static ObjectDeque toObjectDeque(Queue from) {
ObjectDeque deque = new ObjectDeque<>(from.size);
for(T t : from)
deque.add(t);
return deque;
}
/**
* Can be used to convert from a libGDX ObjectSet or OrderedSet to a jdkgdxds ObjectDeque of the same element type.
* @param from an ObjectSet or OrderedSet from libGDX
* @param the element type for {@code from} and the result
* @return a new ObjectDeque of type T holding the unique items of {@code from}
*/
public static ObjectDeque toObjectDeque(com.badlogic.gdx.utils.ObjectSet from) {
ObjectDeque deque = new ObjectDeque<>(from.size);
for(T t : from)
deque.add(t);
return deque;
}
/**
* Can be used to convert from a libGDX LongQueue to a jdkgdxds LongDeque.
* @param from a libGDX LongQueue
* @return a new LongDeque holding the items of {@code from}
*/
public static LongDeque toLongDeque(LongQueue from){
LongDeque deque = new LongDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
/**
* Can be used to convert from a libGDX LongArray to a jdkgdxds LongDeque.
* @param from a libGDX LongArray
* @return a new LongDeque holding the items of {@code from}
*/
public static LongDeque toLongDeque(LongArray from){
LongDeque deque = new LongDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
/**
* Can be used to convert from a libGDX IntArray to a jdkgdxds IntDeque.
* @param from a libGDX IntArray
* @return a new IntDeque holding the items of {@code from}
*/
public static IntDeque toIntDeque(IntArray from){
IntDeque deque = new IntDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
/**
* Can be used to convert from a libGDX IntSet to a jdkgdxds IntDeque.
* @param from a libGDX IntSet
* @return a new IntDeque holding the items of {@code from}
*/
public static IntDeque toIntDeque(com.badlogic.gdx.utils.IntSet from){
IntDeque deque = new IntDeque(from.size);
com.badlogic.gdx.utils.IntSet.IntSetIterator it = from.iterator();
while (it.hasNext) {
deque.add(it.next());
}
return deque;
}
/**
* Can be used to convert from a libGDX ByteArray to a jdkgdxds ByteDeque.
* @param from a libGDX ByteArray
* @return a new ByteDeque holding the items of {@code from}
*/
public static ByteDeque toByteDeque(ByteArray from){
ByteDeque deque = new ByteDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
/**
* Can be used to convert from a libGDX ShortArray to a jdkgdxds ShortDeque.
* @param from a libGDX ShortArray
* @return a new ShortDeque holding the items of {@code from}
*/
public static ShortDeque toShortDeque(ShortArray from){
ShortDeque deque = new ShortDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
/**
* Can be used to convert from a libGDX CharArray to a jdkgdxds CharDeque.
* @param from a libGDX CharArray
* @return a new CharDeque holding the items of {@code from}
*/
public static CharDeque toCharDeque(CharArray from){
CharDeque deque = new CharDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
/**
* Can be used to convert from a libGDX FloatArray to a jdkgdxds FloatDeque.
* @param from a libGDX FloatArray
* @return a new FloatDeque holding the items of {@code from}
*/
public static FloatDeque toFloatDeque(FloatArray from){
FloatDeque deque = new FloatDeque(from.size);
for (int i = 0; i < from.size; i++) {
deque.add(from.get(i));
}
return deque;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy