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 String[][] tsvToArray(File f, int columns, boolean useFirstLine) throws FileNotFoundException {
    List<String[]> rows = new LinkedList<String[]>();
    Scanner in = new Scanner(f);
    if (!useFirstLine && in.hasNextLine())
        in.nextLine();/*from   www  .ja v  a2  s. co m*/

    while (in.hasNextLine()) {
        String[] tokens = in.nextLine().split("\t");
        if (columns > 0 && tokens.length < columns)
            continue;
        rows.add(tokens);
    }
    in.close();
    return rows.toArray(new String[0][]);
}

From source file:Main.java

private static <T> Collection<T> newCollection(Collection<T> coll) {
    try {/* ww w .j  a v  a  2 s .c o  m*/
        Class cl = coll.getClass();
        Constructor con = cl.getConstructor(new Class[0]);
        return (Collection<T>) con.newInstance(new Object[0]);
    } catch (Exception e) {
        if (coll instanceof List)
            return new LinkedList<T>();
        if (coll instanceof Set)
            return new HashSet<T>();
        throw new RuntimeException("Cannot handle this collection");
    }
}

From source file:Main.java

/**
 * magnify the all fonts in swing.//from   w ww  . jav a  2  s  . co m
 * 
 * @param mag
 *            magnify parameter <br/> mag > 1. : large <br/> mag < 1. :
 *            small
 */
public static void magnifyAllFont(float mag) {
    List history = new LinkedList();
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration it = defaults.keys();
    while (it.hasMoreElements()) {
        Object key = it.nextElement();
        Object a = defaults.get(key);
        if (a instanceof Font) {
            if (history.contains(a))
                continue;
            Font font = (Font) a;
            font = font.deriveFont(font.getSize2D() * mag);
            defaults.put(key, font);
            history.add(font);
        }
    }
}

From source file:Main.java

public static List<Element> findElementsByAttribute(Element node, String tagName, String attrName,
        List<String> attrValues) {
    List<Element> result = new LinkedList<Element>();
    NodeList nodeList = node.getChildNodes();
    if (nodeList == null) {
        return result;
    }/*from   ww  w. j a va 2  s .co  m*/
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Element element = checkIfElement(nodeList.item(i), tagName);
        if (element != null) {
            for (String value : attrValues) {
                if (element.getAttribute(attrName).equals(value)) {
                    result.add(element);
                    break;
                }
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Get all the direct children elements of an element.
 *
 * @param parent/*from ww w.ja v a2s. c o m*/
 *            The parent element.
 *
 * @return A list of Element's.
 */
public static List<Element> getElements(final Element parent) {
    final LinkedList<Element> list = new LinkedList<Element>();

    Node node = parent.getFirstChild();

    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            list.add((Element) node);
        }

        node = node.getNextSibling();
    }

    return list;
}

From source file:Main.java

/**
 * Returns a list of the direct {@link Element} children of the given element.
 *
 * @param parent/*w w w.  jav a2 s.c  o m*/
 *            The {@link Element} to get the children from.
 * @return A {@link LinkedList} of the children {@link Element}s.
 */
public static LinkedList<Element> getDirectChildren(Element parent) {
    LinkedList<Element> list = new LinkedList<>();
    for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child instanceof Element) {
            list.add((Element) child);
        }
    }
    return list;
}

From source file:Main.java

public static List<? extends Node> get_childs(Node parent, String child_name) {
    List<Node> result = new LinkedList<Node>();
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node child = children.item(i);
        if (child.getNodeName().equals(child_name))
            result.add(child);/*from w ww.ja va 2s  .  c o m*/
    }
    return result;
}

From source file:Main.java

public static <T> Queue<T> unicon(Queue<T> queue1, Queue<T> queue2) {
    Queue queue = new LinkedList();
    queue.addAll(queue1);/*from   w  w w .j a v  a  2s. c  o  m*/
    queue.addAll(queue2);
    return queue;
}

From source file:Main.java

/**
 * Returns all fields declared in the class passed as argument or in its super classes annotated with
 * the supplied annotation.//from w w  w. j a va2 s.  co  m
 */
public static List<Field> getAllDeclaredField(Class<?> clazz, Class<? extends Annotation> annotationClass) {
    final List<Field> result = new LinkedList<Field>();
    for (final Field field : clazz.getDeclaredFields()) {
        final Object jakeOption = field.getAnnotation(annotationClass);
        if (jakeOption != null) {
            result.add(field);
        }
    }
    final Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        result.addAll(getAllDeclaredField(superClass, annotationClass));
    }
    return result;
}

From source file:Main.java

/**
 * // ww  w. j a  va  2s.com
 * @param aFile
 * @return
 */
public static String getLastLines(String filename, int number) {
    File aFile = new File(filename);
    StringBuilder contents = new StringBuilder();
    LinkedList<String> ll = new LinkedList<String>();

    try {
        BufferedReader input = new BufferedReader(new FileReader(aFile));
        try {
            String line = null;
            while ((line = input.readLine()) != null) {
                ll.add(line);
            }
        } finally {
            input.close();
        }
    } catch (IOException ex) {
        Log.e(TAG, ex.getMessage());
    }

    if ((ll.size() - number) <= 0) {
        Log.e(TAG, "Requested number of lines exceeds lines of file");
        return "Requested number of lines exceeds lines of file";
    }

    for (int i = (ll.size() - 1); i >= (ll.size() - number); i--) {
        contents.append(ll.get(i - 1));
        contents.append("\n");
    }

    return contents.toString();
}