List of usage examples for java.util ArrayList get
public E get(int index)
From source file:Main.java
public static List<Node> getNodes(Node node, String path) { ArrayList nodeList = new ArrayList(); ArrayList pathList = new ArrayList(); String[] pathArray = path.split("/"); for (int i = 0; i < pathArray.length; i++) { if (pathArray[i].equals("")) continue; pathList.add(pathArray[i]);/*from ww w .j a va 2 s . c om*/ } for (int i = 0; i < pathList.size(); i++) { StringBuffer restPath = new StringBuffer(); for (int k = i + 1; k < pathList.size(); k++) { restPath.append("/").append((String) pathList.get(k)); } for (int j = 0; j < node.getChildNodes().getLength(); j++) { if (!node.getChildNodes().item(j).getNodeName().equals(pathList.get(i))) continue; if (restPath.length() == 0) { nodeList.add(node.getChildNodes().item(j)); } else { nodeList.addAll(getNodes(node.getChildNodes().item(j), restPath.toString())); } } } return nodeList; }
From source file:Main.java
public static Node getSingleChildNode(Node p_node) throws Exception { NodeList l_list = null;//from w ww . j a va 2 s. c o m Node l_node = null; ArrayList<Node> l_a = null; l_list = p_node.getChildNodes(); if (l_list == null) { throw new Exception("XSD001: Unsupported / Invalid Element Type."); } l_a = new ArrayList<Node>(); for (int l_i = 0; l_i < l_list.getLength(); l_i++) { l_node = l_list.item(l_i); if (l_node.getNodeType() == Element.ELEMENT_NODE) { l_a.add(l_node); } } if (l_a.size() == 1) { l_node = l_a.get(0); } else { throw new Exception("XSD003: Unsupported / Invalid Element Type Structure."); } return l_node; }
From source file:com.l2jfree.gameserver.util.GPLLicenseChecker.java
private static List<String> read(File f) throws IOException { ArrayList<String> list = new ArrayList<String>(); LineNumberReader lnr = null;/*from ww w .j av a 2s . co m*/ try { lnr = new LineNumberReader(new FileReader(f)); for (String line; (line = lnr.readLine()) != null;) list.add(line); } finally { IOUtils.closeQuietly(lnr); } int i = 0; for (; i < LICENSE.length; i++) { if (!list.get(i).equals(LICENSE[i])) { MODIFIED.add(f.getPath() + ":" + i); return list; } } if (!startsWithPackageName(list.get(i))) { MODIFIED.add(f.getPath() + ":" + lnr.getLineNumber()); return list; } return null; }
From source file:Main.java
/** * Splits a string into a number of tokens. * The text is split by '?' and '*'.//from ww w . j av a 2 s .c om * Where multiple '*' occur consecutively they are collapsed into a single '*'. * * @param text the text to split * @return the array of tokens, never null */ static String[] splitOnTokens(String text) { // used by wildcardMatch // package level so a unit test may run on this if (text.indexOf('?') == -1 && text.indexOf('*') == -1) { return new String[] { text }; } char[] array = text.toCharArray(); ArrayList<String> list = new ArrayList<String>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (array[i] == '?' || array[i] == '*') { if (buffer.length() != 0) { list.add(buffer.toString()); buffer.setLength(0); } if (array[i] == '?') { list.add("?"); } else if (list.isEmpty() || i > 0 && list.get(list.size() - 1).equals("*") == false) { list.add("*"); } } else { buffer.append(array[i]); } } if (buffer.length() != 0) { list.add(buffer.toString()); } return list.toArray(new String[list.size()]); }
From source file:com.mindcognition.mindraider.export.Atomizer.java
private static void toOneLevel(Feed feed, ConceptTreeNode rootNode, String globalOutlineId, HashMap<String, String> noteUriToGlobalId) { ArrayList<ConceptTreeNode> children = rootNode.getChildren(); if (children != null && children.size() > 0) { for (int i = 0; i < children.size(); i++) { Resource child = children.get(i).getConcept(); ArrayList<ConceptTreeNode> childChildren = children.get(i).children; Entry entry = toAtomEntry(feed, new ConceptResource(child), childChildren, globalOutlineId, noteUriToGlobalId);/* ww w . j a va 2s . c o m*/ feed.addEntry(entry); toOneLevel(feed, children.get(i), globalOutlineId, noteUriToGlobalId); } } }
From source file:jog.my.memory.gcm.ServerUtilities.java
/** * Return a string representation of the arraylist * @param amll arraylist of MyLatLng objects * @return String representation/*from w w w .j a va2 s .co m*/ */ public static String parseLocationString(ArrayList<MyLatLng> amll) { String locationString = ""; Log.d(TAG, "amll:size: " + amll.size()); for (int i = 0; i < amll.size(); i++) { locationString = locationString + "(" + amll.get(i).getLatitude() + ", " + amll.get(i).getLongitude() + ")"; if (i < amll.size() - 1 && locationString.length() < 495) { locationString += ", "; if (locationString.length() > 468) { return locationString; } } } return locationString; }
From source file:ch.unil.genescore.vegas.LinkageDisequilibrium.java
/** Compute rectangular 'cross'-correlation (LD) r values for the two given snp lists( */ static public RealMatrix computeCrossCorrelationMatrix(ArrayList<Snp> geneSnps1, ArrayList<Snp> geneSnps2) { // The correlation matrix for the given set of snps RealMatrix corr = MatrixUtils.createRealMatrix(geneSnps1.size(), geneSnps2.size()); // For each snp pair for (int i = 0; i < geneSnps1.size(); i++) { for (int j = 0; j < geneSnps2.size(); j++) { Snp snp_i = geneSnps1.get(i); Snp snp_j = geneSnps2.get(j); double r = computeCorrelation(snp_i, snp_j); corr.setEntry(i, j, r);/*from w w w .j a va2 s . co m*/ } } return corr; }
From source file:css.variable.converter.CSSVariableConverter.java
private static void loadCSSFiles(File releaseDirectory) { CSSFilter theCSSFilter = new CSSFilter(); DirectoryFilter theDirectoryFilter = new DirectoryFilter(); ArrayList<String> theDirectoryList = new ArrayList<String>(); // We're about to go look for every CSS file in a sub directory theDirectoryList.add(releaseDirectory.getAbsolutePath());// Add the current directory while (!theDirectoryList.isEmpty()) { File currentDirectory = new File(theDirectoryList.get(0)); File[] currentCSSFiles = currentDirectory.listFiles(theCSSFilter); File[] subDirectories = currentDirectory.listFiles(theDirectoryFilter); // Add any css files found to theCSSList if (currentCSSFiles != null) { for (File cssFile : currentCSSFiles) { theCSSList.add(cssFile); }/*from w ww. j a v a 2 s . c o m*/ } // Add any more subdirectories found to the directory list. if (subDirectories != null) { for (File dir : subDirectories) { theDirectoryList.add(dir.getPath()); } } // Remove current directory. theDirectoryList.remove(0); } }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Drop n elements by direction// ww w . j av a 2 s . c om * @param cols * @param n * @param direction Negative direction means drop from tail; Others means drop from head * @return Collection after drop */ public static <T> Collection<T> drop(Collection<T> cols, int n, int direction) { if (cols == null || n < 0) return null; ArrayList<T> result = new ArrayList<T>(); ArrayList<T> colsArr = new ArrayList<T>(cols); int size = colsArr.size(); for (int i = 0; i < size; i++) { if ((i >= n && direction >= 0) || (i < size - n && direction < 0)) result.add(colsArr.get(i)); } return result; }
From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java
/** * @param list/*from w ww. j a va2 s .c om*/ * @param value */ public static <T> void insertToSortedArrayList(ArrayList<T> list, T value) { list.add(value); @SuppressWarnings("unchecked") Comparable<T> cmp = (Comparable<T>) value; for (int i = list.size() - 1; i > 0 && cmp.compareTo(list.get(i - 1)) < 0; i--) Collections.swap(list, i, i - 1); }