Models { public static Specification clone(Specification specification) { Application<Task, Dependency> iApplication = clone(specification.getApplication()); Architecture<Resource, Link> iArchitecture = clone(specification.getArchitecture()); Mappings<Task, Resource> iMappings = new Mappings<Task, Resource>(); Routings<Task, Resource, Link> iRoutings = new Routings<Task, Resource, Link>(); for (Mapping<Task, Resource> m : specification.getMappings()) { iMappings.add(m); } Routings<Task, Resource, Link> sRoutings = specification.getRoutings(); for (Task c : filterCommunications(specification.getApplication())) { Architecture<Resource, Link> sRouting = sRoutings.get(c); iRoutings.set(c, sRouting); } Specification clone = new Specification(iApplication, iArchitecture, iMappings, iRoutings); return clone; }  static Iterable<Task> filterCommunications(final Iterable<Task> iterable); static Iterable<Task> filterProcesses(final Iterable<Task> iterable); static boolean isProcess(Task task); static boolean isCommunication(Task task); static List<DirectedLink> getOutLinks(Architecture<Resource, Link> architecture, Resource r0); static List<DirectedLink> getInLinks(Architecture<Resource, Link> architecture, Resource r0); static List<DirectedLink> getLinks(Architecture<Resource, Link> architecture); static List<DirectedLink> getLinks(Architecture<Resource, Link> architecture, Link link); static Map<String, Element> getElementsMap(Specification specification); static Set<Element> getElements(Specification specification); static Iterable<E> filterType(final Iterable<E> iterable, final String... types); static Specification copy(Specification specification); static Routings<Task, Resource, Link> copyRoutings(Application<Task, Dependency> sApplication,
			Routings<Task, Resource, Link> sRoutings, Application<Task, Dependency> iApplication,
			Architecture<Resource, Link> iArchitecture); static Mappings<Task, Resource> copyMappings(Mappings<Task, Resource> sMappings,
			Architecture<Resource, Link> iArchitecture, Application<Task, Dependency> iApplication); static Application<Task, Dependency> copy(Application<Task, Dependency> sApplication); static Architecture<Resource, Link> copy(Architecture<Resource, Link> sArchitecture); @SuppressWarnings("unchecked") static E copy(Element element); @SuppressWarnings("unchecked") static M copy(Mapping<?, ?> mapping); static void setAttributes(IAttributes e, Attributes attributes); static Specification clone(Specification specification); static Application<T, D> clone(Application<T, D> sApplication); static Architecture<R, L> clone(Architecture<R, L> sArchitecture); static void filterByResources(Specification specification, Collection<Resource> resources); static void filter(Specification specification, Collection<Function<Task, Dependency>> functions); static void filterByFunctionName(Specification specification, Collection<String> functions); static void filterByFunctionName(Specification specification, String... functions);  }
@Test public void cloneApplication() { Application<Task, Dependency> app = new Application<Task, Dependency>(); Task task1 = new Task("t1"); Task task2 = new Task("t2"); Dependency dependency = new Dependency("d"); app.addVertex(task1); app.addVertex(task2); app.addEdge(dependency, task1, task2); Application<Task, Dependency> app2 = Models.clone(app); Assert.assertEquals(2, app2.getVertexCount()); Assert.assertTrue(app2.containsVertex(task1)); Assert.assertTrue(app2.getVertex(task1) == task1); Assert.assertTrue(app2.containsVertex(task2)); Assert.assertTrue(app2.isNeighbor(task1, task2)); Assert.assertTrue(app2.getSuccessors(task1).iterator().hasNext()); Assert.assertTrue(app2.getOutEdges(task1).iterator().hasNext()); Assert.assertTrue(app2.getOutEdges(task1).iterator().next() == dependency); }