You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
830 B
51 lines
830 B
10 years ago
|
package mightypork.gamecore.util.objects;
|
||
10 years ago
|
|
||
10 years ago
|
|
||
10 years ago
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
10 years ago
|
|
||
10 years ago
|
import mightypork.gamecore.logging.Log;
|
||
10 years ago
|
|
||
10 years ago
|
|
||
|
/**
|
||
|
* Object utils class
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
|
public class ObjectUtils {
|
||
10 years ago
|
|
||
10 years ago
|
public static Object fallback(Object... options)
|
||
|
{
|
||
10 years ago
|
for (final Object o : options) {
|
||
10 years ago
|
if (o != null) return o;
|
||
|
}
|
||
|
return null; // error
|
||
|
}
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
public static <T> String arrayToString(T[] arr)
|
||
10 years ago
|
{
|
||
10 years ago
|
final StringBuilder sb = new StringBuilder();
|
||
10 years ago
|
|
||
10 years ago
|
sb.append('[');
|
||
10 years ago
|
final boolean first = true;
|
||
10 years ago
|
for (final T o : arr) {
|
||
10 years ago
|
if (!first) sb.append(',');
|
||
10 years ago
|
sb.append(Log.str(o));
|
||
10 years ago
|
}
|
||
|
sb.append(']');
|
||
10 years ago
|
|
||
10 years ago
|
return sb.toString();
|
||
|
}
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
public static <T> List<T> arrayToList(T[] objs)
|
||
10 years ago
|
{
|
||
10 years ago
|
final ArrayList<T> list = new ArrayList<>();
|
||
10 years ago
|
for (final T o : objs) {
|
||
10 years ago
|
list.add(o);
|
||
|
}
|
||
|
return list;
|
||
|
}
|
||
|
}
|