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

public static Element[] getDirectElements(Element parent, String name) {

    NodeList children = parent.getChildNodes();
    List<Element> result = new LinkedList<>();

    for (int i = 0; i < children.getLength(); i++) {

        Node node = children.item(i);
        if (node.getNodeName().equals(name)) {
            result.add((Element) node);
        }/* w  w w .ja v a2 s.  co  m*/
    }

    return result.toArray(new Element[0]);
}

From source file:Main.java

public static String[] parseStringList(String list) {
    //        final Pattern patWs = Pattern.compile("\\s+");
    final Matcher matchWs = Pattern.compile("[^\\s]+").matcher("");
    matchWs.reset(list);/* w w  w  .jav  a  2  s.co m*/

    LinkedList<String> matchList = new LinkedList<String>();
    while (matchWs.find()) {
        matchList.add(matchWs.group());
    }

    String[] retArr = new String[matchList.size()];
    return (String[]) matchList.toArray(retArr);
}

From source file:Main.java

public static int[] parseIntList(String list) {
    if (list == null)
        return null;

    intMatch.reset(list);//from  w  w  w  .j ava2 s  .  co m

    LinkedList<Integer> intList = new LinkedList<Integer>();
    while (intMatch.find()) {
        String val = intMatch.group();
        intList.add(Integer.valueOf(val));
    }

    int[] retArr = new int[intList.size()];
    Iterator<Integer> it = intList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Integer) it.next()).intValue();
    }

    return retArr;
}

From source file:Main.java

public static List<String> getSortedStringList(Collection<String> toSort) {
    List<String> sorted = new LinkedList<String>();
    final PriorityQueue<String> ordered = new PriorityQueue<String>(
            toSort.size() + 1/*In case the toSort is empty*/, new Comparator<String>() {
                @Override//from www  . java2s  . co  m
                public int compare(String lhs, String rhs) {
                    lhs = lhs.replaceAll("[^a-zA-Z0-9]", "");
                    rhs = rhs.replaceAll("[^a-zA-Z0-9]", "");
                    int result = rhs.compareTo(lhs);
                    return result;
                }
            });
    ordered.addAll(toSort);
    int originalSize = ordered.size();
    for (int i = 0; i < originalSize; i++) {
        sorted.add(ordered.poll());
    }
    return sorted;
}

From source file:Main.java

/**
 * @param node/* w  w w  .  j av  a 2  s .c o  m*/
 * @param name
 * @return all children nodes with the given name
 */
public static List<Node> findChildren(Node node, String name) {
    List<Node> ret = new LinkedList<Node>();
    NodeList nl = node.getChildNodes();
    int len = nl.getLength();
    Node child;
    for (int i = 0; i < len; i++) {
        child = nl.item(i);
        if (name.equals(child.getNodeName())) {
            ret.add(child);
        }
    }
    return ret;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static List<ZipEntry> zipEntries(ZipFile zipFile) {
    final List<ZipEntry> result = new LinkedList<ZipEntry>();
    final Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zipFile.entries();
    while (en.hasMoreElements()) {
        result.add(en.nextElement());//from  w ww  .j a va2s  .c o  m
    }
    return result;
}

From source file:Main.java

public static <E> LinkedList<E> createLinkedList(Collection<? extends E> collection) {
    if (collection == null) {
        return new LinkedList<E>();
    }//  ww w  .j  a v a 2s  .com

    return new LinkedList<E>(collection);
}

From source file:Main.java

public static <T> LinkedList<T> newLinkedList(T[] initData) {
    LinkedList<T> ret = new LinkedList<T>();
    for (T t : initData) {
        ret.add(t);//from w  ww .ja  v a  2  s  .c  om
    }
    return ret;
}

From source file:Main.java

public static List<org.jsoup.nodes.Element> findAllElements(String segment, String name, String attrname,
        String attrvalue) {// w ww .  j  a  va 2  s .  c  om
    List<org.jsoup.nodes.Element> ret = new LinkedList<org.jsoup.nodes.Element>();

    Document doc = Jsoup.parse(segment);
    Elements elements = doc.select(name);
    for (int i = 0; i < elements.size(); i++) {
        String value = elements.get(i).attr(attrname);
        if (value != null) {
            if (value.equals(attrvalue)) {
                ret.add(elements.get(i));
            }
        }
    }

    return ret;
}

From source file:Main.java

/**
 * @param node/*from w w w.  jav a2  s  .  c  o m*/
 * @param name
 * @return all children nodes whose names contain <code>like</code>
 */
public static List<Node> findChildrenLike(Node node, String like) {
    List<Node> ret = new LinkedList<Node>();
    NodeList nl = node.getChildNodes();
    int len = nl.getLength();
    Node child;
    for (int i = 0; i < len; i++) {
        child = nl.item(i);
        if (child.getNodeName().indexOf(like) > 0) {
            ret.add(child);
        }
    }
    return ret;
}