List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:com.alibaba.jstorm.ui.utils.UIUtils.java
private static int bfsDepth(List<TreeNode> roots) { LinkedList<TreeNode> queue = Lists.newLinkedList(); for (TreeNode root : roots) { root.setLayer(0);//w ww . ja va 2 s. co m queue.push(root); } int depth = 0; while (!queue.isEmpty()) { TreeNode cur = queue.poll(); if (cur.getLayer() > depth) { depth = cur.getLayer(); } for (TreeNode n : cur.getChildren()) { int newLayer = cur.getLayer() + 1; if (!n.isVisited() || n.getLayer() < newLayer) { if (!n.inCircle(cur)) { //n and cur is not in loop n.setLayer(newLayer); if (!queue.contains(n)) { queue.push(n); } } else if (n.addLoopNode(cur)) { // loop nodes only set layer once. n.setLayer(newLayer); } } } } return depth; }
From source file:com.zimbra.cs.imap.ImapMessage.java
static void serializeStructure(PrintStream ps, MimeMessage root, boolean extensions) throws IOException, MessagingException { LinkedList<LinkedList<MPartInfo>> queue = new LinkedList<LinkedList<MPartInfo>>(); LinkedList<MPartInfo> level = new LinkedList<MPartInfo>(); level.add(Mime.getParts(root).get(0)); queue.add(level);/*from www.j a v a 2 s . c om*/ boolean pop = false; while (!queue.isEmpty()) { level = queue.getLast(); if (level.isEmpty()) { queue.removeLast(); pop = true; continue; } MPartInfo mpi = level.getFirst(); MimePart mp = mpi.getMimePart(); boolean hasChildren = mpi.getChildren() != null && !mpi.getChildren().isEmpty(); // we used to force unset charsets on text/plain parts to US-ASCII, but that always seemed unwise... ContentType ctype = new ContentType(mp.getHeader("Content-Type", null)) .setContentType(mpi.getContentType()); String primary = nATOM(ctype.getPrimaryType()), subtype = nATOM(ctype.getSubType()); if (!pop) ps.write('('); if (primary.equals("\"MULTIPART\"")) { if (!pop) { // 7.4.2: "Multiple parts are indicated by parenthesis nesting. Instead of a body type // as the first element of the parenthesized list, there is a sequence of one // or more nested body structures. The second element of the parenthesized // list is the multipart subtype (mixed, digest, parallel, alternative, etc.)." if (!hasChildren) { ps.print("NIL"); } else { queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren())); continue; } } ps.write(' '); ps.print(subtype); if (extensions) { // 7.4.2: "Extension data follows the multipart subtype. Extension data is never // returned with the BODY fetch, but can be returned with a BODYSTRUCTURE // fetch. Extension data, if present, MUST be in the defined order. The // extension data of a multipart body part are in the following order: // body parameter parenthesized list, body disposition, body language, // body location" ps.write(' '); nparams(ps, ctype); ps.write(' '); ndisposition(ps, mp.getHeader("Content-Disposition", null)); ps.write(' '); nlist(ps, mp.getContentLanguage()); ps.write(' '); nstring(ps, mp.getHeader("Content-Location", null)); } } else { if (!pop) { // 7.4.2: "The basic fields of a non-multipart body part are in the following order: // body type, body subtype, body parameter parenthesized list, body id, body // description, body encoding, body size." String cte = mp.getEncoding(); cte = (cte == null || cte.trim().equals("") ? "7bit" : cte); aSTRING(ps, ctype.getPrimaryType()); ps.write(' '); aSTRING(ps, ctype.getSubType()); ps.write(' '); nparams(ps, ctype); ps.write(' '); nstring(ps, mp.getContentID()); ps.write(' '); nstring2047(ps, mp.getDescription()); ps.write(' '); aSTRING(ps, cte); ps.write(' '); ps.print(Math.max(mp.getSize(), 0)); } boolean rfc822 = primary.equals("\"MESSAGE\"") && subtype.equals("\"RFC822\""); if (rfc822) { // 7.4.2: "A body type of type MESSAGE and subtype RFC822 contains, immediately // after the basic fields, the envelope structure, body structure, and // size in text lines of the encapsulated message." if (!pop) { if (!hasChildren) { ps.print(" NIL NIL"); } else { MimeMessage mm = (MimeMessage) mpi.getChildren().get(0).getMimePart(); ps.write(' '); serializeEnvelope(ps, mm); ps.write(' '); queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren())); continue; } } ps.write(' '); ps.print(getLineCount(mp)); } else if (primary.equals("\"TEXT\"")) { // 7.4.2: "A body type of type TEXT contains, immediately after the basic fields, the // size of the body in text lines. Note that this size is the size in its // content transfer encoding and not the resulting size after any decoding." ps.write(' '); ps.print(getLineCount(mp)); } if (extensions) { // 7.4.2: "Extension data follows the basic fields and the type-specific fields // listed above. Extension data is never returned with the BODY fetch, // but can be returned with a BODYSTRUCTURE fetch. Extension data, if // present, MUST be in the defined order. The extension data of a // non-multipart body part are in the following order: body MD5, body // disposition, body language, body location" ps.write(' '); nstring(ps, mp.getContentMD5()); ps.write(' '); ndisposition(ps, mp.getHeader("Content-Disposition", null)); ps.write(' '); nlist(ps, mp.getContentLanguage()); ps.write(' '); nstring(ps, mp.getHeader("Content-Location", null)); } } ps.write(')'); level.removeFirst(); pop = false; } }
From source file:de._13ducks.cor.game.server.movement.SectorPathfinder.java
/** * Der Start und Zielknoten sind von weit mehr als nur den Knoten ihres Polygons erreichbar. * Dies muss bereits whrend der Basic-Berechnung beachtet werden, das kann die Pfadoptimierung nachtrglich nichtmehr leisten. * Also alle Nodes suchen, die ohne Hinderniss direkt erreichbar sind * @param from alle vollstndig im Mesh liegenden Kanten von hier zu Nachbarknoten suchen * @param basicPolygon Der Polygon, in dem der Node drinliegt. * @return alle direkt erreichbaren Knoten (natrlich sind die des basicPolygons auch dabei) *//*from ww w.java 2s . c o m*/ private static Node[] computeDirectReachable(Node from, FreePolygon basicPolygon) { // Das ist eine modifizierte Breitensuche: LinkedList<FreePolygon> open = new LinkedList<FreePolygon>(); // Queue fr zu untersuchende Polygone LinkedHashSet<FreePolygon> openContains = new LinkedHashSet<FreePolygon>(); // Welche Elemente die open enthlt (schnellerer Test) LinkedHashSet<FreePolygon> closed = new LinkedHashSet<FreePolygon>(); LinkedHashSet<Node> testedNodes = new LinkedHashSet<Node>(); LinkedList<Node> result = new LinkedList<Node>(); open.offer(basicPolygon); // Start-Polygon openContains.add(basicPolygon); while (!open.isEmpty()) { // Diesen hier bearbeiten wir jetzt FreePolygon poly = open.poll(); openContains.remove(poly); closed.add(poly); boolean containsreachableNodes = false; // Alle Nodes dieses Knotens untersuchen for (Node node : poly.getNodes()) { // Schon bekannt? if (result.contains(node)) { // Bekannt und ok containsreachableNodes = true; } else { if (testedNodes.contains(node)) { // Der geht nicht } else { // Testen! FreePolygon currentPoly = basicPolygon; // Testweise Kante zwischen from und node erstellen Edge edge = new Edge(from, node); // Im Folgenden wird untersucht, ob der neue Weg "edge" passierbar ist. // Damit wir beim Dreieckwechsel nicht wieder zurck gehen: Node lastNode = null; boolean routeAllowed = true; // Jetzt so lange weiter laufen, bis wir im Ziel-Polygon sind while (!node.getPolygons().contains(currentPoly)) { // Untersuchen, ob es eine Seite des currentPolygons gibt, die sich mit der alternativRoute schneidet List<Edge> edges = currentPoly.calcEdges(); Edge intersecting = null; SimplePosition intersection = null; for (Edge testedge : edges) { // Gibts da einen Schnitt? intersection = edge.intersectionWithEndsNotAllowed(testedge); if (intersection != null && !intersection.equals(lastNode)) { intersecting = testedge; break; } } // Kandidat fr den nchsten Polygon FreePolygon nextPoly = null; // Kante gefunden if (intersecting != null) { // Von dieser Kante die Enden suchen nextPoly = getOtherPoly(intersecting.getStart(), intersecting.getEnd(), currentPoly); } if (intersecting != null && nextPoly != null) { // Wir haben einen Schnittpunkt und eine Kante gefunden, sind jetzt also in einem neuen Polygon // Extra Node bentigt Node extraNode = intersection.toNode(); extraNode.addPolygon(nextPoly); extraNode.addPolygon(currentPoly); lastNode = extraNode; currentPoly = nextPoly; // Der nchste Schleifendurchlauf wird den nchsten Polygon untersuchen } else { // Es gab leider keinen betretbaren Polygon hier. // Das bedeutet, dass wir die Suche abbrechen knnen, es gibt hier keinen direkten Weg routeAllowed = false; break; } } // Wenn der neue Weg gltig war, einbauen. Sonst weiter mit dem nchsten Knoten if (routeAllowed) { // In die erlaubt-Liste: result.add(node); testedNodes.add(node); containsreachableNodes = true; } else { testedNodes.add(node); } } } } // Nur weiter in die Tiefe gehen, wenn mindestens einer erreichbar war if (containsreachableNodes) { // Alle Nachbarn untersuchen: for (FreePolygon n : poly.getNeighbors()) { // Schon bekannt/bearbeitet? if (!openContains.contains(n) && !closed.contains(n)) { // Nein, also auch zur Bearbeitung vorsehen open.add(n); openContains.add(n); } } } } return result.toArray(new Node[0]); }
From source file:org.opensingular.form.SFormUtil.java
public static String generateUserFriendlyPath(SInstance instance, SInstance parentContext) { LinkedList<String> labels = new LinkedList<>(); SInstance child = null;/*from w w w. j ava 2 s.co m*/ for (SInstance node = instance; node != null && !node.equals(parentContext); child = node, node = node.getParent()) { final String labelNode = node.asAtr().getLabel(); if (node instanceof SIList<?>) { SIList<?> lista = (SIList<?>) node; String labelLista = lista.asAtr().getLabel(); int index = lista.indexOf(child) + 1; labels.add(labelLista + ((index > 0) ? " [" + (index) + ']' : "")); } else { if (StringUtils.isNotBlank(labelNode)) { labels.add(labelNode); } } } Collections.reverse(labels); if (!labels.isEmpty()) { return StringUtils.join(labels, " > "); } return null; }
From source file:cc.kave.commons.model.groum.comparator.Path.java
public Path getTail() { LinkedList<Node> tail = new LinkedList<>(path); if (!tail.isEmpty()) tail.removeFirst();/*from www. j av a 2 s .c o m*/ return new Path(tail); }
From source file:de.science.hack.meshbuilding.AbstractFaceBuilderTask.java
/** * creates two triangle based on the two projections * * @param projections/*www . j a v a2s.c o m*/ * @return */ protected List<Vec3D[]> createTriangles(LinkedList<Line> projections) { List<Vec3D[]> triangles = new ArrayList<>(2); if (!projections.isEmpty()) { Line first = projections.getFirst(); Line last = projections.getLast(); triangles.add(createTriangle(first.getPoint1(), first.getPoint2(), last.getPoint1())); triangles.add(createTriangle(first.getPoint2(), last.getPoint1(), last.getPoint2())); } return triangles; }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java
private static List<FileStatus> recursiveStep(FileSystem fs, List<FileStatus> current) throws IOException { assert fs != null; assert current != null; Set<Path> paths = new HashSet<>(); List<FileStatus> results = new ArrayList<>(); LinkedList<FileStatus> work = new LinkedList<>(current); while (work.isEmpty() == false) { FileStatus next = work.removeFirst(); Path path = next.getPath(); if (paths.contains(path) == false) { paths.add(path);//from w w w . ja v a 2 s . c o m results.add(next); if (next.isDirectory()) { FileStatus[] children; try { children = fs.listStatus(path); } catch (FileNotFoundException e) { children = null; if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Target file is not found: {0}", path), e); //$NON-NLS-1$ } } if (children != null) { Collections.addAll(work, children); } } } } return results; }
From source file:com.asakusafw.directio.tools.DirectIoList.java
@Override public int run(String[] args) throws Exception { LinkedList<String> argList = new LinkedList<>(); Collections.addAll(argList, args); while (argList.isEmpty() == false) { String arg = argList.removeFirst(); if (arg.equals("--")) { //$NON-NLS-1$ break; } else {// w w w . j a v a2s.c om argList.addFirst(arg); break; } } if (argList.size() < 2) { LOG.error(MessageFormat.format("Invalid arguments: {0}", Arrays.toString(args))); System.err.println(MessageFormat.format( "Usage: hadoop {0} -conf <datasource-conf.xml> base-path resource-pattern [resource-pattern [...]]", getClass().getName())); return 1; } String path = argList.removeFirst(); List<FilePattern> patterns = new ArrayList<>(); for (String arg : argList) { patterns.add(FilePattern.compile(arg)); } if (repository == null) { repository = HadoopDataSourceUtil.loadRepository(getConf()); } String basePath = repository.getComponentPath(path); DirectDataSource source = repository.getRelatedDataSource(path); for (FilePattern pattern : patterns) { List<ResourceInfo> list = source.list(basePath, pattern, new Counter()); for (ResourceInfo info : list) { System.out.println(info.getPath()); } } return 0; }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java
private static List<Path> consumeStep(LinkedList<Segment> segments) { assert segments != null; assert segments.isEmpty() == false; assert segments.getFirst().isTraverse() == false; List<Path> results = new ArrayList<>(); Segment current = segments.removeFirst(); for (String segment : resolve(current)) { results.add(new Path(segment)); }/*from w ww .jav a 2 s .c o m*/ while (isGlobRequired(current) && segments.isEmpty() == false && segments.getFirst().isTraverse() == false) { current = segments.removeFirst(); Set<String> suffixCandidates = resolve(current); if (suffixCandidates.size() == 1) { String suffix = suffixCandidates.iterator().next(); for (ListIterator<Path> i = results.listIterator(); i.hasNext();) { Path parent = i.next(); i.set(new Path(parent, suffix)); } } else { List<Path> nextResults = new ArrayList<>(); for (Path parent : results) { for (String suffix : suffixCandidates) { nextResults.add(new Path(parent, suffix)); } } results = nextResults; } } Set<Path> saw = new HashSet<>(); for (Iterator<Path> iter = results.iterator(); iter.hasNext();) { Path path = iter.next(); if (saw.contains(path)) { iter.remove(); } else { saw.add(path); } } return results; }
From source file:org.apache.shindig.gadgets.parse.AbstractParsingTestBase.java
private void assertHtmlEquals(String expected, String serialized) { // Compute the diff of expected vs. serialized, and disregard constructs that we don't // care about, such as whitespace deltas and differently-computed escape sequences. diff_match_patch dmp = new diff_match_patch(); LinkedList<Diff> diffs = dmp.diff_main(expected, serialized); while (!diffs.isEmpty()) { Diff cur = diffs.removeFirst();/*w w w .j ava2s. c o m*/ switch (cur.operation) { case DELETE: if (StringUtils.isBlank(cur.text) || "amp;".equalsIgnoreCase(cur.text)) { continue; } if (diffs.isEmpty()) { // End of the set: assert known failure. assertEquals(expected, serialized); } Diff next = diffs.removeFirst(); if (next.operation != Operation.INSERT) { // Next operation isn't a paired insert: assert known failure. assertEquals(expected, serialized); } if (!equivalentEntities(cur.text, next.text) && !cur.text.equalsIgnoreCase(next.text)) { // Delete/insert pair: fail unless each's text is equivalent // either in terms of case or entity equivalence. assertEquals(expected, serialized); } break; case INSERT: // Assert known failure unless insert is whitespace/blank. if (StringUtils.isBlank(cur.text) || "amp;".equalsIgnoreCase(cur.text)) { continue; } assertEquals(expected, serialized); break; default: // EQUALS: move on. break; } } }