Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

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

Prototype

public LinkedList() 

Source Link

Document

Constructs an empty list.

Usage

From source file:Main.java

/**
 * Transform the source collection using the mapping function to convert the elements to the output type. The result
 * is written to a list./*w  w w.  j  av  a  2s .c  o m*/
 *
 * @param <T>
 *            the source type type
 * @param <R>
 *            the result type
 * @param source
 *            the source
 * @param mapping
 *            the mapping used for the value transformation
 * @return the list
 */
public static <T, R> List<R> transformToList(Collection<T> source, Function<T, R> mapping) {
    Objects.requireNonNull(mapping, "Mapping functions is required!");
    if (isEmpty(source)) {
        return new LinkedList<>();
    }
    List<R> result = new LinkedList<>();
    for (T item : source) {
        result.add(mapping.apply(item));
    }
    return result;
}

From source file:Main.java

/**
 * Returns all the components (and their children) associated to the given container.
 *
 * @param container Container/*from   w  w w . j ava  2 s  . c o  m*/
 * @return {@code Component} list
 * @since 0.3.0
 */
public static List<Component> getAllComponents(Container container) {
    List<Component> out = new LinkedList<Component>();
    for (Component comp : container.getComponents()) {
        out.add(comp);
        if (comp instanceof Container)
            out.addAll(getAllComponents((Container) comp));
    }

    return out;
}

From source file:com.intropro.prairie.utils.FileUtils.java

public static List<String> readLineInDirectory(File file) throws IOException {
    List<String> result = new LinkedList<>();
    for (String child : file.list()) {
        File childFile = new File(file, child);
        if (childFile.isDirectory()) {
            result.addAll(readLineInDirectory(childFile));
        } else {//  www  .  jav  a 2  s  .c om
            result.addAll(IOUtils.readLines(new FileInputStream(childFile)));
        }
    }
    return result;
}

From source file:Main.java

public static <T> List<T> list(T... source) {
    List<T> r = new LinkedList<T>();
    for (int i = 0; i < source.length; i++) {
        r.add(source[i]);/*from w  w  w .  j a  va 2 s .c o  m*/
    }
    return r;
}

From source file:Main.java

public static <T> LinkedList<T> createLinkedList(Iterable<? extends T> c) {
    LinkedList<T> list = new LinkedList<T>();

    iterableToCollection(c, list);//from  w  w  w . java2s  . c  o  m

    return list;
}

From source file:Main.java

public static int deepHashCode(Object obj) {
    Set visited = new HashSet();
    LinkedList<Object> stack = new LinkedList<Object>();
    stack.addFirst(obj);/*from  w  w  w .  j a v a2  s . c o  m*/
    int hash = 0;

    while (!stack.isEmpty()) {
        obj = stack.removeFirst();
        if (obj == null || visited.contains(obj)) {
            continue;
        }

        visited.add(obj);

        if (obj.getClass().isArray()) {
            int len = Array.getLength(obj);
            for (int i = 0; i < len; i++) {
                stack.addFirst(Array.get(obj, i));
            }
            continue;
        }

        if (obj instanceof Collection) {
            stack.addAll(0, (Collection) obj);
            continue;
        }

        if (obj instanceof Map) {
            stack.addAll(0, ((Map) obj).keySet());
            stack.addAll(0, ((Map) obj).values());
            continue;
        }

        if (hasCustomHashCode(obj.getClass())) {
            hash += obj.hashCode();
            continue;
        }

        Collection<Field> fields = getDeepDeclaredFields(obj.getClass());
        for (Field field : fields) {
            try {
                stack.addFirst(field.get(obj));
            } catch (Exception ignored) {
            }
        }
    }
    return hash;
}

From source file:Main.java

/**
 * @param csv/*from  w  ww .java2 s  . co m*/
 * @return List of the comma separated tokens of the trimmed input or empty list.
 */
public static List<String> explode(String csv) {
    final List<String> tokens = Arrays.asList(csv.trim().split("\\s*,\\s*"));
    final List<String> result = new LinkedList<>();
    for (String token : tokens) {
        if (token != null && !(token = token.trim()).isEmpty()) {
            result.add(token);
        }
    }
    return result;
}

From source file:Main.java

public static List<Node> getByName(Node node, String name) {
    List<Node> result = new LinkedList<Node>();
    getByName(node, name, result);/*from   w  w w  .  j a  v  a2 s.c o  m*/
    return result;
}

From source file:Main.java

public static List<Element> getChildElements(String tagName, Element element) {
    LinkedList<Element> result = new LinkedList<>();
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);// ww w  . jav  a  2s.  com
        if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(tagName)) {
            result.add((Element) n);
        }
    }
    return result;
}

From source file:Main.java

/**
 * Returns the last element of list. If the given list is empty, the
 * returned value will be null./*from w ww .ja v a2s. co m*/
 *
 * @param <T> Class type
 * @param collection List of elements
 * @return Last element of list
 */
public static <T> T getLastElement(Collection<T> collection) {
    LinkedList<T> elements = collection == null ? new LinkedList<>() : new LinkedList<>(collection);
    return elements.isEmpty() ? null : elements.getLast();
}