List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
/** * Takes a number of tags of name 'name' that are children of 'root', and * looks for attributes of 'attrib' on them. Converts attributes to an * int and returns in an array.//from w w w. j ava2 s.c om */ public static String[] getElementArrayString(Element root, String name, String attrib) { if (root == null) return null; NodeList nl = root.getChildNodes(); LinkedList<String> elementCache = new LinkedList<String>(); int size = nl.getLength(); for (int i = 0; i < size; i++) { Node node = nl.item(i); if (!(node instanceof Element)) continue; Element ele = (Element) node; if (!ele.getTagName().equals(name)) continue; String valS = ele.getAttribute(attrib); elementCache.addLast(valS); } String[] retArr = new String[elementCache.size()]; Iterator<String> it = elementCache.iterator(); int idx = 0; while (it.hasNext()) { retArr[idx++] = it.next(); } return retArr; }
From source file:Main.java
/** * Returns a list of the direct child {@link Element}s of the given parent * that have the specified tag name./* w w w. j ava 2s .co m*/ * * @param parent The parent element. * @param tagName The tag name to filter. */ public static List<Element> getChildElementsByTagName(Element parent, String tagName) { List<Element> childElementsWithTagName = new LinkedList<Element>(); List<Element> childElements = getChildElements(parent); for (Element child : childElements) { if (child.getTagName().equals(tagName)) childElementsWithTagName.add(child); } return childElementsWithTagName; }
From source file:Main.java
/** * Takes a number of tags of name 'name' that are children of 'root', and * looks for attributes of 'attrib' on them. Converts attributes to an * int and returns in an array.//from www. j ava 2s .c om */ public static int[] getElementArrayInt(Element root, String name, String attrib) { if (root == null) return null; NodeList nl = root.getChildNodes(); LinkedList<Integer> elementCache = new LinkedList<Integer>(); int size = nl.getLength(); for (int i = 0; i < size; i++) { Node node = nl.item(i); if (!(node instanceof Element)) continue; Element ele = (Element) node; if (!ele.getTagName().equals(name)) continue; String valS = ele.getAttribute(attrib); int eleVal = 0; try { eleVal = Integer.parseInt(valS); } catch (Exception e) { } elementCache.addLast(new Integer(eleVal)); } int[] retArr = new int[elementCache.size()]; Iterator<Integer> it = elementCache.iterator(); int idx = 0; while (it.hasNext()) { retArr[idx++] = it.next().intValue(); } return retArr; }
From source file:Main.java
/** * Given an XML element, this method returns nested elements which are direct * children of the given element - but only those that have the element-name "childrenName" (the second parameter). * @param element/*from ww w.ja v a 2s. co m*/ * @param childrenName * @return */ public static List<Element> getChildElements(Element element, String childrenName) { List<Element> ret = new LinkedList<Element>(); NodeList nodeList = element.getChildNodes(); for (int index = 0; index < nodeList.getLength(); ++index) { Node node = nodeList.item(index); if (node instanceof Element) { Element elementOfNode = (Element) node; if (elementOfNode.getTagName().equals(childrenName)) { ret.add(elementOfNode); } } } return ret; }
From source file:Main.java
/** * <strong>WARNING:</strong> very low efficiency (O(N*N)) * @return A list containing the elements of source that are also in filter, using <code>equivalence</code> to distinguish different elements. *//*from w w w.j a va 2 s . co m*/ public static <T> List<T> intersection(Iterable<? extends T> source, Iterable<? extends T> filter, Equivalence<? super T> equivalence) { final List<T> result = new LinkedList<T>(); if (source != null && filter != null) { sourceLoop: for (T sourceElement : source) { for (T filterElement : filter) { if (equivalence.equivalent(sourceElement, filterElement)) { result.add(sourceElement); continue sourceLoop; } } } } return result; }
From source file:Main.java
public final static <T> Queue<T> unicon(Queue<T> queue1, Queue<T> queue2) { Queue queue = new LinkedList(); queue.addAll(queue1);// w ww. j a v a 2s.c om queue.addAll(queue2); return queue; }
From source file:Main.java
static public List<Element> elements(Node context, String expression) { try {//from w w w. j a v a 2 s . c om NodeList nodeList = (NodeList) xpath.evaluate(expression, context, XPathConstants.NODESET); List<Element> result = new LinkedList<Element>(); for (int i = 0, len = nodeList.getLength(); i < len; i++) { result.add((Element) nodeList.item(i)); } return result; } catch (XPathExpressionException ex) { ex.printStackTrace(); throw new RuntimeException("invalid xpath expresion used"); } }
From source file:Main.java
/** * Reqursion search in node for elements with paramantrs * @param node//from w ww. jav a 2 s . c o m * @param tagName * @param attrName * @param attrValue * @return */ public static List<Element> findAllElementsByAttribute(Node node, String tagName, String attrName, String attrValue) { List<Element> result = new LinkedList<Element>(); findAllElementsByAttribute(node, tagName, attrName, attrValue, result); return result; }
From source file:Main.java
public static List<Element> getChildElementsByTagName(Element element, String name) { List<Element> elements = new LinkedList<Element>(); NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) node; if (e.getTagName().equals(name)) { elements.add(e);/*ww w . j a va 2 s . c o m*/ } } } return elements; }
From source file:Main.java
public static Map<String, List<String>> classify(List<Map<String, Object>> result, String key, String key2) { Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> values = null; for (Map<String, Object> record : result) { String mapKey = String.valueOf(record.get(key)); String mapkey2 = String.valueOf(record.get(key2)); if (!map.containsKey(mapKey)) { values = new LinkedList<String>(); values.add(mapkey2);/* w w w.ja v a 2s. co m*/ } else { map.get(mapKey).add(mapkey2); } map.put(mapKey, values); } return map; }