Example usage for java.util List get

List of usage examples for java.util List get

Introduction

In this page you can find the example usage for java.util List get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:Main.java

public static <T> T first(List<T> list) {
    return isNullOrEmpty(list) ? null : list.get(0);
}

From source file:Main.java

public static SpannableString backgroundColor(SpannableString sequence, List<String> color) {
    int hex = Color.parseColor(color.get(0));

    sequence.setSpan(new BackgroundColorSpan(hex), 0, sequence.length(), 0);
    return sequence;
}

From source file:Main.java

public static int getOne(int data, int index) {
    List<Integer> list = getList(data);
    return list.get(index);
}

From source file:Main.java

public static <T> T random(List<T> list, Random random) {
    return list.get(random.nextInt(list.size()));
}

From source file:Main.java

/**
 * Return the first item of <code>l</code> if it's the only one, otherwise <code>null</code>.
 * //from   ww w  .  j av  a2  s .  co m
 * @param <T> type of list.
 * @param l the list.
 * @return the first item of <code>l</code> or <code>null</code>.
 */
public static <T> T getSole(List<T> l) {
    return l.size() == 1 ? l.get(0) : null;
}

From source file:com.ning.metrics.action.hdfs.data.RowFactory.java

/**
 * Return the right row associated with some data.
 * <p/>//from  w  w w  .  java2  s .  c o m
 * The decoding from Hadoop was done in the RowSerializers. This utility class simply maps the right Row representation
 * given the decoded datatype.
 *
 * @param rowSchema      schema associated with the row
 * @param data           decoded Data
 * @param <T>            decoded column types
 * @param <Serializable> serialization
 * @return a row instance with associated schema and data
 * @see com.ning.metrics.action.hdfs.data.parser.RowSerializer
 */
public static <T extends Comparable, Serializable> Row getRow(RowSchema rowSchema, List<T> data) {
    if (data.get(0) instanceof DataItem) {
        return new RowThrift(rowSchema, (List<DataItem>) data);
    } else if (data.get(0) instanceof JsonNode) {
        return new RowSmile(rowSchema, (List<JsonNodeComparable>) data);
    } else {
        return new RowText(rowSchema, (List<String>) data);
    }
}

From source file:Main.java

public static <T> T last(List<T> list) {
    return list != null && !list.isEmpty() ? list.get(list.size() - 1) : null;
}

From source file:de.tudarmstadt.lt.utilities.ListUtils.java

public static <T> T getLastElement(final List<T> values) {
    return values.get(values.size() - 1);
}

From source file:Main.java

public static String getMaxId(List<String> ids) {
    String oozieId = ids.get(0);
    int maxInt = Integer.valueOf(oozieId.split("-")[0]);
    for (int i = 1; i < ids.size(); i++) {
        String currentId = ids.get(i);
        int currInt = Integer.valueOf(currentId.split("-")[0]);
        if (currInt > maxInt) {
            oozieId = currentId;// w  ww.  j a  va 2 s. c  o m
        }
    }
    return oozieId;
}

From source file:Main.java

public static <E> E sample(List<E> l, Random r) {
    int i = r.nextInt(l.size());
    return l.get(i);
}