List of usage examples for java.util LinkedList LinkedList
public LinkedList()
From source file:Main.java
/** * Build a list of bean from the provided iterable * @param source any kind of iterable//from w ww. jav a 2 s. co m * @return a {@link Serializable} {@link List} containing the same element set */ public static <Bean> List<Bean> asList(Iterable<Bean> source) { if (source instanceof List && source instanceof Serializable) { return (List<Bean>) source; } else if (source == null) { return Collections.emptyList(); } else { List<Bean> returned = new LinkedList<Bean>(); for (Bean b : source) { returned.add(b); } return returned; } }
From source file:Main.java
public static List<Node> getTextAndElementChildren(Node node) { List<Node> result = new LinkedList<Node>(); NodeList children = node.getChildNodes(); if (children == null) { return result; }/*from w w w. j av a 2 s . c o m*/ for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (Node.ELEMENT_NODE == child.getNodeType() || Node.TEXT_NODE == child.getNodeType()) { result.add(child); } } return result; }
From source file:Main.java
public static Collection<File> listFiles(File directory, String suffix) { final String _suffix = "." + suffix; FileFilter filter = new FileFilter() { @Override//from w ww . ja v a 2 s .com public boolean accept(File file) { if (file.isDirectory()) return true; String name = file.getName(); int endLen = _suffix.length(); if (name.regionMatches(true, name.length() - endLen, _suffix, 0, endLen)) { return true; } return false; } }; if (!directory.isDirectory()) { throw new IllegalArgumentException("Parameter 'directory' is not a directory"); } if (filter == null) { throw new NullPointerException("Parameter 'fileFilter' is null"); } Collection<File> files = new LinkedList<File>(); innerListFiles(files, directory, filter); return files; }
From source file:Main.java
static String[] tokenize(String listString, String delimiters) { char[] delimiterChars = delimiters.toCharArray(); char[] listChars = listString.toCharArray(); int i = 0;// www .jav a 2 s . co m List<String> stringList = new LinkedList<String>(); StringBuffer buffer = new StringBuffer(); while (i < listChars.length) { char c = listChars[i]; boolean advance = false; for (char d : delimiterChars) { if (c == d) { stringList.add(buffer.toString()); buffer = new StringBuffer(); advance = true; break; } } if (!advance) { if (c == '\\') { if (i < listChars.length - 1) { char next = listChars[i + 1]; //if one of next chars is delimiter chars, //then advance to next char for (char d : delimiterChars) { if (d == next) { i++; c = next; break; } } } } buffer.append(c); } i++; } //add last buffer to String stringList.add(buffer.toString()); String[] pairings = stringList.toArray(EMPTY_STRING); //StringUtils.tokenizeToStringArray(listString, delimiters); return pairings; }
From source file:Main.java
/** * Given any of the known collection types, this method will return an instance of the collection. * @param collectionType the type of the collection * @return the collection instance// w w w . j a va 2s.c o m */ public static Collection<?> getCollection(Class<?> collectionType) { if (HashSet.class.equals(collectionType)) { return new HashSet<Object>(); } else if (TreeSet.class.equals(collectionType)) { return new TreeSet<Object>(); } else if (CopyOnWriteArraySet.class.equals(collectionType)) { return new CopyOnWriteArraySet<Object>(); } else if (LinkedHashSet.class.equals(collectionType)) { return new LinkedHashSet<Object>(); } else if (ArrayList.class.equals(collectionType)) { return new ArrayList<Object>(); } else if (LinkedList.class.equals(collectionType)) { return new LinkedList<Object>(); } else if (Vector.class.equals(collectionType)) { return new Vector<Object>(); } else if (Stack.class.equals(collectionType)) { return new Stack<Object>(); } else if (PriorityQueue.class.equals(collectionType)) { return new PriorityQueue<Object>(); } else if (PriorityBlockingQueue.class.equals(collectionType)) { return new PriorityBlockingQueue<Object>(); } else if (ArrayDeque.class.equals(collectionType)) { return new ArrayDeque<Object>(); } else if (ConcurrentLinkedQueue.class.equals(collectionType)) { return new ConcurrentLinkedQueue<Object>(); } else if (LinkedBlockingQueue.class.equals(collectionType)) { return new LinkedBlockingQueue<Object>(); } else if (LinkedBlockingDeque.class.equals(collectionType)) { return new LinkedBlockingDeque<Object>(); } else if (List.class.equals(collectionType)) { return new LinkedList<Object>(); } else if (Set.class.equals(collectionType)) { return new HashSet<Object>(); } else if (Queue.class.equals(collectionType)) { return new PriorityQueue<Object>(); } else if (Deque.class.equals(collectionType)) { return new ArrayDeque<Object>(); } else if (Collection.class.equals(collectionType)) { return new LinkedList<Object>(); } throw new IllegalArgumentException("Unsupported collection type: " + collectionType); }
From source file:Main.java
public static <T> Collection<T> reverse(final Collection<T> collection) { final LinkedList<T> newCollection = new LinkedList<>(); final Iterator<T> i = collection.iterator(); while (i.hasNext()) { newCollection.addFirst(i.next()); }//from w w w.j a va 2s . c om return newCollection; }
From source file:Main.java
public static List<Element> getChildElementsByName(Element root, String tagName) { List<Element> tags = new LinkedList<Element>(); NodeList nl = root.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i);/*from w ww . j av a 2s . co m*/ if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } if (tagName.equals(child.getNodeName())) { tags.add((Element) child); } } return tags; }
From source file:cn.vlabs.duckling.vwb.service.ddl.NameValuePairUtil.java
public static List<NameValuePair> assemble(String... params) { List<NameValuePair> paramsList = new LinkedList<NameValuePair>(); if (params != null && params.length > 0) { assert params.length % 2 == 0 : "Params's length must be even number"; for (int i = 0; i < params.length / 2; i++) { paramsList.add(new BasicNameValuePair(params[i * 2], params[i * 2 + 1])); }//from w w w. ja va 2 s .c o m } return paramsList; }
From source file:coolmapplugin.util.CMCyCommunicationUtil.java
private static List<Long> iterRowAndMatchNodeName(String jsonStringRows, Set<String> nodeNames) { LinkedList<Long> matchedNodeSUIDs = new LinkedList<>(); try {//from w ww . ja v a 2 s . c om JSONArray jsonRows = new JSONArray(jsonStringRows); for (int i = 0; i < jsonRows.length(); ++i) { JSONObject jsonRow = jsonRows.getJSONObject(i); String nodeName = jsonRow.getString("name"); if (nodeNames.contains(nodeName)) { matchedNodeSUIDs.add(jsonRow.getLong("SUID")); } } } catch (JSONException e) { return null; } return matchedNodeSUIDs; }
From source file:Main.java
public static <T> List<T> asList(Enumeration<T> e) { List<T> l = new LinkedList<T>(); while (e.hasMoreElements()) { l.add(e.nextElement());/*www . j a v a2 s.co m*/ } return l; }