List of usage examples for java.util LinkedList push
public void push(E e)
From source file:Main.java
public static void main(String[] args) { LinkedList<String> linkedList = new LinkedList<String>(); linkedList.push("A"); linkedList.push("B"); linkedList.push("C"); linkedList.push("D"); ArrayList<String> arrayList = new ArrayList<String>(linkedList); for (String s : arrayList) { System.out.println("s = " + s); }//w ww . j a v a 2 s .c om }
From source file:Main.java
public static void main(String[] args) { // create a LinkedList LinkedList<String> list = new LinkedList<String>(); // add some elements list.add("Hello"); list.add("from java2s.com"); list.add("10"); // print the list System.out.println("LinkedList:" + list); // push Element the list list.push("Element"); // print the list System.out.println("LinkedList:" + list); }
From source file:com.semsaas.jsonxml.tools.JsonXpath.java
public static void main(String[] args) { /*/* w w w .j ava2 s. c o m*/ * Process options */ LinkedList<String> files = new LinkedList<String>(); LinkedList<String> expr = new LinkedList<String>(); boolean help = false; String activeOption = null; String error = null; for (int i = 0; i < args.length && error == null && !help; i++) { if (activeOption != null) { if (activeOption.equals("-e")) { expr.push(args[i]); } else if (activeOption.equals("-h")) { help = true; } else { error = "Unknown option " + activeOption; } activeOption = null; } else { if (args[i].startsWith("-")) { activeOption = args[i]; } else { files.push(args[i]); } } } if (error != null) { System.err.println(error); showHelp(); } else if (help) { showHelp(); } else { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); for (String f : files) { System.out.println("*** " + f + " ***"); try { // Create a JSON XML reader XMLReader reader = XMLReaderFactory.createXMLReader("com.semsaas.jsonxml.JsonXMLReader"); // Prepare a reader with the JSON file as input InputStreamReader stringReader = new InputStreamReader(new FileInputStream(f)); SAXSource saxSource = new SAXSource(reader, new InputSource(stringReader)); // Prepare a DOMResult which will hold the DOM of the xjson DOMResult domResult = new DOMResult(); // Run SAX processing through a transformer // (This could be done more simply, but we have here the opportunity to pass our xjson through // an XSLT and get a legacy XML output ;) ) transformer.transform(saxSource, domResult); Node dom = domResult.getNode(); XPathFactory xpathFactory = XPathFactory.newInstance(); for (String x : expr) { try { XPath xpath = xpathFactory.newXPath(); xpath.setNamespaceContext(new NamespaceContext() { public Iterator getPrefixes(String namespaceURI) { return null; } public String getPrefix(String namespaceURI) { return null; } public String getNamespaceURI(String prefix) { if (prefix == null) { return XJSON.XMLNS; } else if ("j".equals(prefix)) { return XJSON.XMLNS; } else { return null; } } }); NodeList nl = (NodeList) xpath.evaluate(x, dom, XPathConstants.NODESET); System.out.println("-- Found " + nl.getLength() + " nodes for xpath '" + x + "' in file '" + f + "'"); for (int i = 0; i < nl.getLength(); i++) { System.out.println(" +(" + i + ")+ "); XMLJsonGenerator handler = new XMLJsonGenerator(); StringWriter buffer = new StringWriter(); handler.setOutputWriter(buffer); SAXResult result = new SAXResult(handler); transformer.transform(new DOMSource(nl.item(i)), result); System.out.println(buffer.toString()); } } catch (XPathExpressionException e) { System.err.println("-- Error evaluating '" + x + "' on file '" + f + "'"); e.printStackTrace(); } catch (TransformerException e) { System.err.println("-- Error evaluating '" + x + "' on file '" + f + "'"); e.printStackTrace(); } } } catch (FileNotFoundException e) { System.err.println("File '" + f + "' was not found"); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } } catch (TransformerConfigurationException e) { e.printStackTrace(); } } }
From source file:Main.java
public static int insertX(int numb, int random) { long result = 0; LinkedList<Integer> stack = new LinkedList<Integer>(); while (numb > 0) { stack.push(numb % 10); numb = numb / 10;/* w ww . jav a 2 s . c o m*/ } while (!stack.isEmpty()) { result = (int) combinedTwoNumber(result, stack.pop()); result = (int) combinedTwoNumber(result, random); } return (int) (result /= 10); }
From source file:com.smallnn.input.FileUtil.java
public static List<File> find(File file, FileFilter filter) { List<File> result = new ArrayList<File>(); LinkedList<File> stack = new LinkedList<File>(); stack.push(file); while (!stack.isEmpty()) { File f = stack.pop();//from w w w .j a va 2 s . c o m if (filter == null || filter.accept(f)) { result.add(f); } if (f.isDirectory() && f.exists()) { stack.addAll(Arrays.asList(f.listFiles())); } } return result; }
From source file:org.alfresco.rest.framework.resource.parameters.where.QueryHelper.java
/** * Walks a query with a callback for each operation * @param query the query//from w w w .ja v a 2 s.c om * @param callback a callback */ public static void walk(Query query, WalkerCallback callback) { CommonTree tree = query.getTree(); if (tree != null) { LinkedList<Tree> stack = new LinkedList<Tree>(); stack.push(tree); callbackTree(tree, callback, false); } }
From source file:org.archive.util.PrefixFinder.java
public static List<String> findKeys(SortedMap<String, ?> map, String input) { LinkedList<String> result = new LinkedList<String>(); map = headMapInclusive(map, input);//from w w w .j a va2s. c o m for (String last = last(map); last != null; last = last(map)) { if (input.startsWith(last)) { result.push(last); map = map.headMap(last); } else { // Find the longest common prefix. int p = StringUtils.indexOfDifference(input, last); if (p <= 0) { return result; } last = input.substring(0, p); map = headMapInclusive(map, last); } } return result; }
From source file:org.archive.util.PrefixFinder.java
/** * Extracts prefixes of a given string from a SortedSet. If an element * of the given set is a prefix of the given string, then that element * is added to the result list./*from w w w .j a v a2s . c o m*/ * * <p>Put another way, for every element in the result list, the following * expression will be true: <tt>string.startsWith(element.getKey())</tt>. * * @param set the sorted set containing potential prefixes * @param input the string whose prefixes to find * @return the list of prefixes */ public static List<String> find(SortedSet<String> set, String input) { LinkedList<String> result = new LinkedList<String>(); set = headSetInclusive(set, input); for (String last = last(set); last != null; last = last(set)) { if (input.startsWith(last)) { result.push(last); set = set.headSet(last); } else { // Find the longest common prefix. int p = StringUtils.indexOfDifference(input, last); if (p <= 0) { return result; } last = input.substring(0, p); set = headSetInclusive(set, last); } } return result; }
From source file:com.bwc.ora.OraUtils.java
public static void setLrpsForAnalysis() { Lrp fovealLrp = lrpCollection.getFovealLrp(); if (fovealLrp == null) { return;/* ww w . j ava 2s . c o m*/ } LrpSettings lrpSettings = ModelsCollection.getInstance().getLrpSettings(); int octWidth = Oct.getInstance().getImageWidth(); int distanceBetweenLrps = lrpSettings.getLrpSeperationDistanceInPixels(); int numberOfLrpTotal = lrpSettings.getNumberOfLrp(); int lrpPosToLeftOfFovea = fovealLrp.getLrpCenterXPosition(); int lrpPosToRightOfFovea = fovealLrp.getLrpCenterXPosition(); LinkedList<Lrp> lrps = new LinkedList<>(); lrps.add(fovealLrp); while (lrps.size() < numberOfLrpTotal) { lrpPosToLeftOfFovea -= distanceBetweenLrps; lrps.push(new Lrp("Left " + ((lrps.size() + 1) / 2), lrpPosToLeftOfFovea, fovealLrp.getLrpCenterYPosition(), lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.PERIPHERAL)); lrpPosToRightOfFovea += distanceBetweenLrps; if (lrps.size() < numberOfLrpTotal) { lrps.add(new Lrp("Right " + (lrps.size() / 2), lrpPosToRightOfFovea, fovealLrp.getLrpCenterYPosition(), lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.PERIPHERAL)); } } boolean illegalPositionLrps = lrps.stream() .anyMatch(lrp -> lrp.getLrpCenterXPosition() - ((lrpSettings.getLrpWidth() - 1) / 2) < 0 || lrp.getLrpCenterXPosition() + ((lrpSettings.getLrpWidth() - 1) / 2) >= octWidth); if (illegalPositionLrps) { throw new IllegalArgumentException("Combination of LRP width, the number of LRPs and LRP " + "separation distance cannot fit within the bounds of the OCT."); } lrpCollection.setLrps(lrps); }
From source file:com.google.jenkins.plugins.storage.AbstractUpload.java
/** * Compute the relative path of the given file inclusion, relative to the * given workspace. If the path is absolute, it returns the root-relative * path instead./*from w w w.ja v a 2s. c o m*/ * * @param include The file whose relative path we are computing * @param workspace The workspace containing the included file. * @return The unix-style relative path of file. * @throws UploadException when the input is malformed */ public static String getRelative(FilePath include, FilePath workspace) throws UploadException { LinkedList<String> segments = new LinkedList<String>(); while (!include.equals(workspace)) { segments.push(include.getName()); include = include.getParent(); if (Strings.isNullOrEmpty(include.getName())) { // When we reach "/" we're done either way. break; } } return Joiner.on("/").join(segments); }