Example usage for java.util Collections emptyList

List of usage examples for java.util Collections emptyList

Introduction

In this page you can find the example usage for java.util Collections emptyList.

Prototype

@SuppressWarnings("unchecked")
public static final <T> List<T> emptyList() 

Source Link

Document

Returns an empty list (immutable).

Usage

From source file:com.shopzilla.api.client.model.CategoryModelAdapter.java

private static List<Category> convertChildren(CategoriesType children) {

    if (children == null || CollectionUtils.isEmpty(children.getCategory())) {
        return Collections.emptyList();
    }// w w w  .jav a2s.c  o m

    List<Category> toReturn = new ArrayList<Category>();
    for (CategoryType child : children.getCategory()) {
        toReturn.add(convertCategory(child));
    }
    return toReturn;
}

From source file:com.spotify.styx.schedule.model.ScheduleDefinition.java

@JsonCreator
public static ScheduleDefinition create(
        @JsonProperty("workflows") @Nullable List<WorkflowConfiguration> workflowConfigurations) {
    if (workflowConfigurations == null) {
        workflowConfigurations = Collections.emptyList();
    }/*from w ww.  j a va  2  s  .  com*/
    return new AutoValue_ScheduleDefinition(workflowConfigurations);
}

From source file:Main.java

/**
 * Helper function that takes an object and returns a list representation
 * of it://www .ja v  a 2s.  c  o m
 *
 * o == null => []
 * o is a list => o
 * else => [o]
 *
 * @param o
 * @return
 */
public static List<Object> toList(final Object o) {
    if (o == null)
        return Collections.emptyList();
    else if (o instanceof List)
        return (List<Object>) o;
    else if (o.getClass().isArray()) {
        final List<Object> l = new ArrayList<Object>();
        Collections.addAll(l, (int[]) o);
        return l;
    } else
        return Collections.singletonList(o);
}

From source file:Main.java

/**
 * General purpose list converter method. Will convert arrays, collections,
 * iterables etc. into lists.//from w  w  w  .j  a  va 2  s  . c o  m
 * 
 * If the argument is a single object (such as a String or a POJO) it will
 * be wrapped in a single-element list.
 * 
 * Null will be converted to the empty list.
 * 
 * @param obj
 *            any object
 * @return a list representation of the object
 */
public static List<?> toList(Object obj) {
    final List<Object> result;
    if (obj == null) {
        result = Collections.emptyList();
    } else if (obj instanceof List) {
        @SuppressWarnings("unchecked")
        List<Object> list = (List<Object>) obj;
        result = list;
    } else if (obj.getClass().isArray()) {
        int length = Array.getLength(obj);
        result = new ArrayList<Object>(length);
        for (int i = 0; i < length; i++) {
            result.add(Array.get(obj, i));
        }
    } else if (obj instanceof Iterable) {
        result = new ArrayList<Object>();
        for (Object item : (Iterable<?>) obj) {
            result.add(item);
        }
    } else if (obj instanceof Iterator) {
        result = new ArrayList<Object>();
        Iterator<?> it = (Iterator<?>) obj;
        while (it.hasNext()) {
            result.add(it.next());
        }
    } else {
        result = new ArrayList<Object>(1);
        result.add(obj);
    }
    return result;
}

From source file:com.skcraft.launcher.builder.BuilderUtils.java

public static List<Compressor> getCompressors(String repoUrl) {
    if (repoUrl.matches("^https?://files.minecraftforge.net/maven/")) {
        return Lists.newArrayList(new Compressor("xz", CompressorStreamFactory.XZ),
                new Compressor("pack", CompressorStreamFactory.PACK200));
    } else {/*w  w  w  .ja  va  2s.  c om*/
        return Collections.emptyList();
    }
}

From source file:Main.java

/**
 * Return a String List representing response from invokeOemRilRequestRaw
 *
 * @param aob byte array response from invokeOemRilRequestRaw
 *///  w  w w  .j a va 2 s .  co m
public static List<String> unpackListOfStrings(byte aob[]) {

    if (aob.length == 0) {
        Log.v(TAG, "Length = 0");
        return Collections.emptyList();
    }

    int lines = aob.length / CHARS_PER_LINE;

    String[] display = new String[lines];
    for (int i = 0; i < lines; i++) {
        int offset, byteCount;
        offset = i * CHARS_PER_LINE + 2;
        byteCount = 0;

        if (offset + byteCount >= aob.length) {
            Log.e(TAG, "Unexpected EOF");
            break;
        }

        while (aob[offset + byteCount] != 0 && (byteCount < CHARS_PER_LINE)) {
            byteCount += 1;
            if (offset + byteCount >= aob.length) {
                Log.e(TAG, "Unexpected EOF");
                break;
            }
        }
        display[i] = new String(aob, offset, byteCount).trim();
    }

    int newLength = display.length;
    while (newLength > 0 && TextUtils.isEmpty(display[newLength - 1])) {
        newLength -= 1;
    }

    return Arrays.asList(Arrays.copyOf(display, newLength));
}

From source file:com.spotify.styx.schedule.model.deprecated.ScheduleDefinition.java

@JsonCreator
public static ScheduleDefinition create(
        @JsonProperty("data_endpoints") @Nullable List<WorkflowConfiguration> workflowConfigurations) {
    if (workflowConfigurations == null) {
        workflowConfigurations = Collections.emptyList();
    }//from  www .  j  a  v  a 2 s  . c o  m
    return new AutoValue_ScheduleDefinition(workflowConfigurations);
}

From source file:Main.java

/**
 * Return a String List representing response from invokeOemRilRequestRaw
 *
 * @param aob Byte array response from invokeOemRilRequestRaw
 *///from   ww  w .ja  v a2s . c o m
public static List<String> unpackByteListOfStrings(byte aob[]) {

    if (aob.length == 0) {
        Log.v(TAG, "Length = 0");
        return Collections.emptyList();
    }

    int lines = aob.length / CHARS_PER_LINE;

    String[] display = new String[lines];
    for (int i = 0; i < lines; i++) {
        int offset, byteCount;
        offset = i * CHARS_PER_LINE + 2;
        byteCount = 0;

        if (offset + byteCount >= aob.length) {
            Log.e(TAG, "Unexpected EOF");
            break;
        }

        while (aob[offset + byteCount] != 0 && (byteCount < CHARS_PER_LINE)) {
            byteCount += 1;
            if (offset + byteCount >= aob.length) {
                Log.e(TAG, "Unexpected EOF");
                break;
            }
        }
        display[i] = new String(aob, offset, byteCount).trim();
    }

    int newLength = display.length;
    while (newLength > 0 && TextUtils.isEmpty(display[newLength - 1])) {
        newLength -= 1;
    }

    return Arrays.asList(Arrays.copyOf(display, newLength));
}

From source file:Main.java

/**
 * Wraps a List with the {@code Collections.unmodifiableList}, but only once.
 *
 * <p>Checks the {@link List} passed to ensure that it is not already a {@code Collections.unmodifiableLisy}.
 * If the parameter is a null or empty, then it returns {@code Collections.emptyList}.
 *
 * @param list {@link List} to wrap with {@code Collections.unmodifiableList}
 * @param <V>  Value type//from w  ww . j av a 2  s. c o m
 * @return An unmodifiable List.
 */
public static <V> List<V> unmodifiableList(final List<V> list) {
    if (isNotEmpty(list)) {
        if (!(exampleUnmodifiableList.getClass().equals(list.getClass()))) {
            return Collections.unmodifiableList(list);
        }
        return list;
    }
    return Collections.emptyList();
}

From source file:Main.java

/**
 * Creates new {@link List} from passed {@link Collection} instance
 * /*  w  w  w  .  j  a va  2s  .c o m*/
 * @param collection
 * @return {@link List} translated from collection
 */
public static <T> List<T> translateToList(Collection<T> collection) {

    List<T> list;

    if (valid(collection)) {
        list = new ArrayList<T>(collection);
    } else {
        list = Collections.emptyList();
    }

    return list;
}