com.pushtorefresh.storio.internal.InternalQueries Maven / Gradle / Ivy
Show all versions of common Show documentation
package com.pushtorefresh.storio.internal;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableList;
/**
* Util methods for queries.
*
* For internal usage only!
*/
public final class InternalQueries {
private InternalQueries() {
throw new IllegalStateException("No instances please");
}
/**
* Converts array of objects to {@code List}.
*
* @param args array objects that will be converted to list of strings.
* @return non-null, unmodifiable list of strings.
*/
@NonNull
public static List unmodifiableNonNullListOfStrings(@Nullable Object[] args) {
if (args == null || args.length == 0) {
return emptyList();
} else {
final List list = new ArrayList(args.length);
//noinspection ForLoopReplaceableByForEach -> on Android it's faster
for (int i = 0; i < args.length; i++) {
final Object arg = args[i];
list.add(arg != null ? arg.toString() : "null");
}
return unmodifiableList(list);
}
}
/**
* Coverts list of objects to {@code List}.
*
* @param args list of objects that will be converted to list of strings.
* @return non-null, unmodifiable list of strings.
*/
@NonNull
public static List unmodifiableNonNullListOfStrings(@Nullable List> args) {
if (args == null || args.isEmpty()) {
return emptyList();
} else {
final List list = new ArrayList(args.size());
for (Object arg : args) {
list.add(arg != null ? arg.toString() : "null");
}
return unmodifiableList(list);
}
}
/**
* Converts array of objects to {@code List