/** * Initializes default class loader. It inherits from classloader, which was used to load this * task, therefore build-in classes and resources are loaded automatically. * * <p>Notice: task's classpath has priority over default classpath, therefore we are able to * easily override resources (templates) */ protected void initClassloader() { // NOTICE: we should use the same classloader, which was used to load this task // otherwise we won't be able to cast instances // (that were loaded via different class loaders) // we are introducting workaround, // that tries to add classpath for current task to original class loader // and stores original classpath // after the task is executed, classpath is restored ClassLoader classLoader = getClass().getClassLoader(); if (classLoader instanceof AntClassLoader) { // add defined classpath AntClassLoader antClassLoader = (AntClassLoader) classLoader; antClassLoader.setParentFirst(false); antClassLoader.setProject(getProject()); savedClasspath = antClassLoader.getClasspath(); Path cp = getClasspath(); // add defined classpath to original path cp.add(new Path(getProject(), savedClasspath)); antClassLoader.setClassPath(cp); } else { // create new class loader classLoader = new AntClassLoader(getClass().getClassLoader(), getProject(), getClasspath(), false); } // set this class loader as new class loader for whole thread // ContextClassLoader is used in StringTemplate's PathGroupLoader and other classes Thread.currentThread().setContextClassLoader(classLoader); }
public Path finishCircuit(int dispair, Vertex home, Graphics g) { visited = true; Path bestPath = new Path(); bestPath.cost = 100000000; if (dispair == 0) // Last being visited { Iterator<Edge> it = edges.iterator(); Boolean match = false; // Looks through all this vertex's edges and find the one that goes home while (!match && it.hasNext()) { Edge f = it.next(); if (f.fromVertex.ident == home.ident) { Path p = new Path(); bestPath = p; bestPath.add(f); match = true; } } } else { Iterator<Edge> it = edges.iterator(); // Finds all possible paths through nodes not visited while (it.hasNext()) { Edge e = it.next(); Vertex c = e.fromVertex; if (!c.visited) { e.drawMe(g, Color.black); // Draws edge Path p = c.finishCircuit(dispair - 1, home, g); p.add(e); e.drawMe(g, Color.green); // Un-draws edge if (p.cost < bestPath.cost) // Sets bestPath { bestPath = p; } } } } visited = false; return bestPath; }
private void adding(Road road, Path path) { roadHelper.setPathId(road.getID(), path.getId()); if (!path.contains(road)) { path.add(road); if (entrances.contains(road)) { path.addEntrance(getEntrance(road)); } } }
private void createAPath(Road neighbourRoad, Path path) { if (!path.contains(neighbourRoad)) { path.add(neighbourRoad); added.add(neighbourRoad); } addEntrances(path, neighbourRoad); for (Road road : roadHelper.getConnectedRoads(neighbourRoad.getID())) { if (entrances.contains(road) || added.contains(road)) { continue; } if (end || roadHelper.getConnectedRoads(neighbourRoad.getID()).size() == 1) { return; } if (headRoads.contains(road)) { if (!end) { end = true; if (!path.contains(road)) { path.add(road); } path.setEndOfPath(road); } } else if (!end) { createAPath(road, path); } } if (!end) { for (Road neighbourR : roadHelper.getConnectedRoads(neighbourRoad.getID())) { if (headRoads.contains(neighbourR)) { if (!path.contains(neighbourR)) { path.add(neighbourR); } path.setEndOfPath(neighbourR); end = true; } } } }
private void addEntrances(Path path, Road road) { Entrance entrance; for (Road n : roadHelper.getConnectedRoads(road.getID())) { if (entrances.contains(n)) { roadHelper.setPathId(n.getID(), path.getId()); if (!path.contains(n) && !added.contains(n)) { path.add(n); added.add(n); } entrance = getEntrance(n); if (!path.getEntrances().contains(entrance)) { path.addEntrance(entrance); } } } }
private List<Path> createThisHeadRoadPaths(Road head) { List<Path> paths = new ArrayList<Path>(); List<Road> headRoadEntrances = new ArrayList<Road>(); for (Road neighbourRoad : roadHelper.getConnectedRoads(head.getID())) { if (added.contains(neighbourRoad)) { continue; } else if (entrances.contains(neighbourRoad)) { added.add(neighbourRoad); headRoadEntrances.add(neighbourRoad); continue; } end = false; Path path = new Path(world); path.add(head); added.add(head); path.setHeadOfPath(head); createAPath(neighbourRoad, path); paths.add(path); added.remove(head); } if (!headRoadEntrances.isEmpty() && paths.size() > 0) { List<Road> temp = new ArrayList<Road>(); temp.addAll(paths.get(0)); paths.get(0).clear(); for (Road road : headRoadEntrances) { paths.get(0).add(road); paths.get(0).addEntrance(getEntrance(road)); } paths.get(0).addAll(temp); } return paths; }
/** Answer a new Path whose elements are this Path with <code>s</code> added at the end */ public Path append(Statement s) { Path newPath = new Path(this); newPath.add(s); return newPath; }