List of usage examples for java.util LinkedList iterator
Iterator<E> iterator();
From source file:fi.smaa.libror.MaximalVectorComputation.java
/** * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007. * /*from w w w.j a v a 2 s.co m*/ * Returns indices of the rows from the original matrix. * * @param mat The matrix of values (each row = 1 vector of input) * * @return Matrix containing rows from the input s.t. none are dominated */ public static int[] computeBESTindices(RealMatrix mat) { LinkedList<Integer> list = matrixToListOfIndices(mat); LinkedList<Integer> results = new LinkedList<Integer>(); while (list.size() > 0) { Iterator<Integer> iter = list.iterator(); Integer b = iter.next(); // Get the first iter.remove(); while (iter.hasNext()) { // Find a max Integer t = iter.next(); if (dominates(mat.getRowVector(b), mat.getRowVector(t))) { iter.remove(); } else if (dominates(mat.getRowVector(t), mat.getRowVector(b))) { iter.remove(); b = t; } } results.add(b); iter = list.iterator(); while (iter.hasNext()) { // Clean up Integer t = iter.next(); if (dominates(mat.getRowVector(b), mat.getRowVector(t))) { iter.remove(); } } } return listOfIntegersToIntArray(results); }
From source file:fi.smaa.libror.MaximalVectorComputation.java
/** * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007. * /*from www. j a v a 2 s .c om*/ * @param mat The matrix of values (each row = 1 vector of input) * * @return Matrix containing rows from the input s.t. none are dominated */ public static RealMatrix computeBEST(RealMatrix mat) { LinkedList<RealVector> list = matrixToListOfRows(mat); LinkedList<RealVector> results = new LinkedList<RealVector>(); while (list.size() > 0) { Iterator<RealVector> iter = list.iterator(); RealVector b = iter.next(); // Get the first iter.remove(); while (iter.hasNext()) { // Find a max RealVector t = iter.next(); if (dominates(b, t)) { iter.remove(); } else if (dominates(t, b)) { iter.remove(); b = t; } } results.add(b); iter = list.iterator(); while (iter.hasNext()) { // Clean up RealVector t = iter.next(); if (dominates(b, t)) { iter.remove(); } } } return listOfRowsToMatrix(results); }
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.// ww w . j ava 2 s . c o m */ 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
/** * 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 ww .j a v a 2 s . c o m*/ */ 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
/** * Normalize a uri containing ../ and ./ paths. * * @param uri The uri path to normalize/*from w ww . j a v a2s. c o m*/ * @return The normalized uri */ public static String normalize(String uri) { if ("".equals(uri)) { return uri; } int leadingSlashes; for (leadingSlashes = 0; leadingSlashes < uri.length() && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) { } boolean isDir = (uri.charAt(uri.length() - 1) == '/'); StringTokenizer st = new StringTokenizer(uri, "/"); LinkedList clean = new LinkedList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if ("..".equals(token)) { if (!clean.isEmpty() && !"..".equals(clean.getLast())) { clean.removeLast(); if (!st.hasMoreTokens()) { isDir = true; } } else { clean.add(".."); } } else if (!".".equals(token) && !"".equals(token)) { clean.add(token); } } StringBuffer sb = new StringBuffer(); while (leadingSlashes-- > 0) { sb.append('/'); } for (Iterator it = clean.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append('/'); } } if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } return sb.toString(); }
From source file:com.github.javarch.persistence.orm.test.DataBaseTestBuilder.java
private T runFor(LinkedList<Resource> scripts) { try {//from ww w.ja v a2s .c o m Iterator<Resource> rs = scripts.iterator(); while (rs.hasNext()) { Resource resource = (Resource) rs.next(); String sql = readNextSqlScript(resource); executeSQL(sql); } return source; } catch (IOException e) { return source; } catch (SQLException e) { return source; } }
From source file:net.sf.j2ep.ConfigParser.java
/** * Will iterate over the server and print out the mappings between servers * and rules.//ww w . j av a 2 s . com * * @param servers The server to debug */ private void debugServers(LinkedList servers) { Iterator itr = servers.iterator(); while (itr.hasNext()) { ServerContainer container = (ServerContainer) itr.next(); log.debug(container + " mapped to --> " + container.getRule()); } }
From source file:br.com.ingenieux.mojo.jbake.SeedMojo.java
private String stripLeadingPath(String name) { LinkedList<String> elements = new LinkedList<>(asList(name.split("/"))); elements.pop();/*from w w w. j a v a 2 s . c o m*/ return join(elements.iterator(), '/'); }
From source file:com.marklogic.contentpump.utilities.FileIterator.java
public FileIterator(FileSplit inSplit, TaskAttemptContext context) { conf = context.getConfiguration();/* w w w . j a v a 2 s . c om*/ fileDirSplits = new LinkedList<FileSplit>(); LinkedList<FileSplit> src = new LinkedList<FileSplit>(); src.add(inSplit); iterator = src.iterator(); PathFilter jobFilter = getInputPathFilter(); List<PathFilter> filters = new ArrayList<PathFilter>(); filters.add(FileAndDirectoryInputFormat.hiddenFileFilter); if (jobFilter != null) { filters.add(jobFilter); } inputFilter = new FileAndDirectoryInputFormat.MultiPathFilter(filters); }
From source file:de.vanita5.twittnuker.util.net.ssl.AbstractCheckSignatureVerifier.java
public static final boolean verify(final String host, final String[] cns, final String[] subjectAlts, final boolean strictWithSubDomains) { // Build the list of names we're going to check. Our DEFAULT and // STRICT implementations of the HostnameVerifier only use the // first CN provided. All other CNs are ignored. // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way). final LinkedList<String> names = new LinkedList<String>(); if (cns != null && cns.length > 0 && cns[0] != null) { names.add(cns[0]);/*www. j a v a 2 s . c o m*/ } if (subjectAlts != null) { for (final String subjectAlt : subjectAlts) { if (subjectAlt != null) { names.add(subjectAlt); } } } if (names.isEmpty()) return false; // StringBuilder for building the error message. final StringBuilder buf = new StringBuilder(); // We're can be case-insensitive when comparing the host we used to // establish the socket to the hostname in the certificate. final String hostName = normaliseIPv6Address(host.trim().toLowerCase(Locale.US)); boolean match = false; for (final Iterator<String> it = names.iterator(); it.hasNext();) { // Don't trim the CN, though! String cn = it.next(); cn = cn.toLowerCase(Locale.US); // Store CN in StringBuilder in case we need to report an error. buf.append(" <"); buf.append(cn); buf.append('>'); if (it.hasNext()) { buf.append(" OR"); } // The CN better have at least two dots if it wants wildcard // action. It also can't be [*.co.uk] or [*.co.jp] or // [*.org.uk], etc... final String parts[] = cn.split("\\."); final boolean doWildcard = parts.length >= 3 && parts[0].endsWith("*") && validCountryWildcard(cn) && !isIPAddress(host); if (doWildcard) { final String firstpart = parts[0]; if (firstpart.length() > 1) { // e.g. server* // e.g. server final String prefix = firstpart.substring(0, firstpart.length() - 1); // skip wildcard part from cn final String suffix = cn.substring(firstpart.length());// skip // wildcard part from host final String hostSuffix = hostName.substring(prefix.length()); match = hostName.startsWith(prefix) && hostSuffix.endsWith(suffix); } else { match = hostName.endsWith(cn.substring(1)); } if (match && strictWithSubDomains) { // If we're in strict mode, then [*.foo.com] is not // allowed to match [a.b.foo.com] match = countDots(hostName) == countDots(cn); } } else { match = hostName.equals(normaliseIPv6Address(cn)); } if (match) { break; } } return match; }