From 5d61f33fc68e73d035c023df81eb79b12b02b7f9 Mon Sep 17 00:00:00 2001 From: Dimitris Anyfadakis Date: Sun, 7 Jan 2024 13:15:27 +0100 Subject: [PATCH] Reformat Code Style --- .github/workflows/maven.yml | 66 +- README.md | 74 +- .../0.1/JavaFXSmartGraph-0.1.pom | 12 +- .../JavaFXSmartGraph/maven-metadata.xml | 18 +- .../PlantUML/1.2023.7/PlantUML-1.2023.7.pom | 12 +- libs/PlantUML/PlantUML/maven-metadata.xml | 18 +- pom.xml | 226 ++-- src/main/java/controller/Controller.java | 170 +-- .../java/controller/ControllerFactory.java | 15 +- src/main/java/controller/ControllerType.java | 48 +- .../java/controller/DiagramController.java | 138 ++- .../java/manager/ClassDiagramManager.java | 272 +++-- src/main/java/manager/DiagramManager.java | 171 +-- .../java/manager/DiagramManagerFactory.java | 17 +- src/main/java/manager/DiagramType.java | 52 +- .../java/manager/PackageDiagramManager.java | 253 ++-- src/main/java/manager/SourceProject.java | 48 +- src/main/java/model/diagram/ClassDiagram.java | 183 +-- .../diagram/GraphClassDiagramConverter.java | 52 +- .../diagram/GraphPackageDiagramConverter.java | 54 +- .../java/model/diagram/PackageDiagram.java | 172 +-- .../java/model/diagram/ShadowCleaner.java | 103 +- .../ClassDiagramArrangementManager.java | 182 +-- .../DiagramArrangementManagerInterface.java | 39 +- .../PackageDiagramArrangementManager.java | 184 +-- .../AdvancedFruchtermanReingold.java | 86 +- .../algorithms/AdvancedSpring.java | 90 +- .../algorithms/FruchtermanReingold.java | 92 +- .../arrangement/algorithms/KamadaKawai.java | 102 +- .../algorithms/LayoutAlgorithm.java | 24 +- .../algorithms/LayoutAlgorithmFactory.java | 11 +- .../algorithms/LayoutAlgorithmType.java | 40 +- .../arrangement/algorithms/Spring.java | 96 +- .../arrangement/algorithms/Sugiyama.java | 156 +-- .../arrangement/geometry/DiagramGeometry.java | 102 +- .../ClassifierVertexSerializer.java | 147 +-- .../exportation/CoordinatesUpdater.java | 123 +- .../diagram/exportation/DiagramExporter.java | 17 +- .../GraphMLClassDiagramExporter.java | 51 +- .../diagram/exportation/GraphMLFile.java | 88 +- .../GraphMLPackageDiagramExporter.java | 63 +- .../JavaFXClassDiagramExporter.java | 60 +- .../JavaFXPackageDiagramExporter.java | 58 +- .../exportation/PackageVertexSerializer.java | 189 +-- .../PlantUMLClassDiagramImageExporter.java | 185 +-- .../PlantUMLClassDiagramTextExporter.java | 100 +- .../PlantUMLPackageDiagramImageExporter.java | 232 ++-- .../PlantUMLPackageDiagramTextExporter.java | 131 +- .../graphml/GraphMLClassifierVertex.java | 143 ++- .../graphml/GraphMLClassifierVertexArc.java | 99 +- .../diagram/graphml/GraphMLPackageVertex.java | 62 +- .../graphml/GraphMLPackageVertexArc.java | 65 +- .../model/diagram/graphml/GraphMLSyntax.java | 279 +++-- .../diagram/graphml/GraphMLSyntaxIds.java | 40 +- .../javafx/ClassifierVertexDeserializer.java | 152 +-- .../javafx/JavaFXClassDiagramLoader.java | 96 +- .../javafx/JavaFXClassVisualization.java | 175 +-- .../javafx/JavaFXPackageDiagramLoader.java | 93 +- .../javafx/JavaFXPackageVisualization.java | 189 +-- .../diagram/javafx/JavaFXVisualization.java | 23 +- .../javafx/PackageVertexDeserializer.java | 156 +-- .../plantuml/PlantUMLClassifierVertex.java | 159 ++- .../plantuml/PlantUMLClassifierVertexArc.java | 69 +- .../plantuml/PlantUMLPackageVertex.java | 29 +- .../plantuml/PlantUMLPackageVertexArc.java | 72 +- src/main/java/model/graph/Arc.java | 6 +- src/main/java/model/graph/ArcType.java | 80 +- .../java/model/graph/ClassifierVertex.java | 191 +-- src/main/java/model/graph/ModifierType.java | 54 +- src/main/java/model/graph/PackageVertex.java | 220 ++-- .../java/model/graph/VertexCoordinate.java | 17 +- src/main/java/model/graph/VertexType.java | 54 +- src/main/java/parser/FileVisitor.java | 650 +++++----- .../java/parser/IRelationshipIdentifier.java | 35 +- src/main/java/parser/Interpreter.java | 329 ++--- src/main/java/parser/PackageNodeCleaner.java | 78 +- src/main/java/parser/ProjectParser.java | 125 +- .../java/parser/RelationshipIdentifier.java | 380 +++--- src/main/java/parser/factory/Parser.java | 45 +- src/main/java/parser/factory/ParserType.java | 7 +- .../parser/factory/ProjectParserFactory.java | 17 +- src/main/java/parser/tree/LeafNode.java | 46 +- .../java/parser/tree/LeafNodeBuilder.java | 65 +- src/main/java/parser/tree/ModifierType.java | 54 +- src/main/java/parser/tree/NodeType.java | 21 +- src/main/java/parser/tree/PackageNode.java | 183 +-- .../java/parser/tree/RelationshipType.java | 23 +- src/main/java/view/AboutPageController.java | 51 +- src/main/java/view/AppStarter.java | 10 +- src/main/java/view/AppStarterHelper.java | 59 +- src/main/java/view/DiagramCreation.java | 245 ++-- .../java/view/DiagramCreationController.java | 141 ++- src/main/java/view/DiagramVisualization.java | 219 ++-- .../view/DiagramVisualizationController.java | 374 +++--- .../java/view/FileAndDirectoryUtility.java | 152 +-- src/main/java/view/MenuUtility.java | 191 +-- src/main/java/view/PopupWindow.java | 42 +- src/main/java/view/ProjectLoadController.java | 218 ++-- src/main/java/view/ProjectTreeView.java | 269 ++-- src/main/java/view/TreeViewResizer.java | 141 ++- .../resources/assets/UserDocumentation.html | 262 ---- src/main/resources/fxml/AboutPageView.fxml | 38 +- .../resources/fxml/DiagramCreationView.fxml | 116 +- .../fxml/DiagramVisualizationView.fxml | 154 +-- src/main/resources/fxml/ProjectLoadView.fxml | 93 +- .../resources/styles/smartgraph.properties | 28 +- .../java/manager/ClassDiagramManagerTest.java | 501 ++++---- .../manager/PackageDiagramManagerTest.java | 88 +- .../model/GraphClassDiagramConverterTest.java | 86 +- .../GraphPackageDiagramConverterTest.java | 81 +- src/test/java/model/ShadowCleanerTest.java | 242 ++-- .../GraphMLClassDiagramExporterTest.java | 96 +- .../JavaFXClassDiagramExporterTest.java | 270 ++-- .../JavaFXPackageDiagramExporterTest.java | 767 +++++++----- ...PlantUMLClassDiagramImageExporterTest.java | 110 +- .../PlantUMLClassDiagramTextExporterTest.java | 105 +- .../graphml/GraphMLPackageVertexArcTest.java | 92 +- .../graphml/GraphMLPackageVertexTest.java | 81 +- .../GraphMLSinkPackageVertexArcTest.java | 136 ++- .../graphml/GraphMLSinkPackageVertexTest.java | 196 +-- .../javafx/JavaFXClassDiagramLoaderTest.java | 127 +- .../JavaFXPackageDiagramLoaderTest.java | 152 +-- .../PlantUMLClassifierVertexArcTest.java | 75 +- .../PlantUMLClassifierVertexTest.java | 219 ++-- .../PlantUMLPackageVertexArcTest.java | 97 +- .../plantuml/PlantUMLPackageVertexTest.java | 95 +- src/test/java/parser/FileVisitorTest.java | 516 ++++---- src/test/java/parser/InterpreterTest.java | 229 ++-- .../java/parser/PackageNodeCleanerTest.java | 230 ++-- src/test/java/parser/ProjectParserTest.java | 1083 +++++++++-------- src/test/java/utils/PathConstructor.java | 24 +- .../src/bicycleBody/Bicycle.java | 238 ++-- .../src/bicycleBreaks/BrakeFactory.java | 49 +- .../src/bicycleBreaks/DuperBrakes.java | 62 +- .../src/bicycleBreaks/IBrakes.java | 51 +- .../src/bicycleBreaks/NiceBrakes.java | 81 +- .../src/bicyclePedal/IPedal.java | 52 +- .../src/bicyclePedal/PedalFactory.java | 50 +- .../src/bicyclePedal/SimplePedal.java | 76 +- .../src/bicyclePedal/ZuperPedal.java | 61 +- .../BicycleSimpleApplication.java | 188 +-- .../BicycleRaceV01/src/race/IRace.java | 42 +- .../src/race/RaceTypeFactory.java | 32 +- .../src/race/RaceWithStages.java | 304 ++--- .../BookstoreAdvancedV01/bin/gui/cart.fxml | 72 +- .../BookstoreAdvancedV01/bin/gui/gui.fxml | 60 +- .../src/bookstore/Book.java | 149 ++- .../src/bookstore/CD.java | 78 +- .../src/bookstore/Item.java | 114 +- .../src/bookstore/ItemFactory.java | 128 +- .../src/bookstore/ItemManager.java | 141 ++- .../src/bookstore/ShoppingCart.java | 210 ++-- .../src/gui/AdvancedBookstoreApplication.java | 186 +-- .../src/gui/CartController.java | 94 +- .../src/gui/CartViewer.java | 91 +- .../BookstoreAdvancedV01/src/gui/Gui.java | 107 +- .../src/gui/GuiEventHandler.java | 127 +- .../src/gui/ShopItem.java | 93 +- .../BookstoreAdvancedV01/src/gui/cart.fxml | 72 +- .../BookstoreAdvancedV01/src/gui/gui.fxml | 60 +- .../src/controller/LatexEditorController.java | 49 +- .../controller/commands/AddLatexCommand.java | 26 +- .../ChangeVersionsStrategyCommand.java | 29 +- .../src/controller/commands/Command.java | 5 +- .../controller/commands/CommandFactory.java | 92 +- .../controller/commands/CreateCommand.java | 37 +- .../DisableVersionsManagementCommand.java | 33 +- .../src/controller/commands/EditCommand.java | 29 +- .../EnableVersionsManagementCommand.java | 28 +- .../src/controller/commands/LoadCommand.java | 51 +- .../RollbackToPreviousVersionCommand.java | 27 +- .../src/controller/commands/SaveCommand.java | 30 +- .../LatexEditor/src/model/Document.java | 133 +- .../src/model/DocumentManager.java | 219 ++-- .../src/model/VersionsManager.java | 298 +++-- .../strategies/StableVersionsStrategy.java | 182 +-- .../model/strategies/VersionsStrategy.java | 17 +- .../strategies/VersionsStrategyFactory.java | 28 +- .../strategies/VolatileVersionsStrategy.java | 95 +- .../LatexEditor/src/view/ChooseTemplate.java | 273 +++-- .../LatexEditor/src/view/LatexEditorView.java | 250 ++-- .../LatexEditor/src/view/MainWindow.java | 662 +++++----- .../LatexEditor/src/view/OpeningWindow.java | 163 +-- .../resources/ParserTesting/EnumSample.java | 3 +- .../ParserTesting/ExtensionClass.java | 3 +- .../ParserTesting/ImplementingClass.java | 3 +- .../ParserTesting/InnerClassSample.java | 10 +- .../ParserTesting/ObjectCreationSample.java | 21 +- .../ParserTesting/TestingInterface.java | 3 +- .../ParserTesting/TestingInterface2.java | 3 +- .../ChangeLog.md | 18 +- .../RestaurantWeeklyEvaluationV03/pom.xml | 44 +- .../src/main/java/app/ApplicationMainGUI.java | 164 +-- .../src/main/java/app/DishTableView.java | 126 +- .../src/main/java/app/EmpTableView.java | 157 +-- .../src/main/java/app/simpleTryUserMain.java | 53 +- .../src/main/java/controller/IMainEngine.java | 88 +- .../src/main/java/controller/MainEngine.java | 241 ++-- .../java/controller/MainEngineFactory.java | 45 +- .../main/java/load/AbstractRecordLoader.java | 183 +-- .../src/main/java/load/DishLoader.java | 92 +- .../src/main/java/load/EmployeeLoader.java | 94 +- .../src/main/java/load/FullDataLoader.java | 204 ++-- .../main/java/load/FullDataLoaderFactory.java | 87 +- .../src/main/java/load/IFullDataLoader.java | 38 +- .../src/main/java/load/OrderLoader.java | 92 +- .../src/main/java/model/Chef.java | 51 +- .../src/main/java/model/ChefDeCuisine.java | 74 +- .../src/main/java/model/Dish.java | 215 ++-- .../src/main/java/model/Employee.java | 185 +-- .../src/main/java/model/EmployeeFactory.java | 73 +- .../src/main/java/model/OrderItem.java | 159 +-- .../src/main/java/model/SousChef.java | 66 +- .../src/main/java/model/WeeklyStats.java | 126 +- .../main/java/reporting/IReportGenerator.java | 49 +- .../reporting/ReportGeneratorForFiles.java | 170 +-- .../reporting/ReportGeneratorForHTML.java | 266 ++-- .../main/java/reporting/ReporterFactory.java | 56 +- .../src/main/resources/output/Dishes.html | 29 - .../src/main/resources/output/Emps.html | 20 - .../TimelineToPhasesV01/showMeTheTL.html | 57 - .../src/analysis/AnalyserFactory.java | 46 +- .../src/analysis/IAnalyser.java | 47 +- .../src/analysis/NaiveAnalyser.java | 152 +-- .../src/analysis/Phase.java | 254 ++-- .../src/application/ClientApplication.java | 98 +- .../src/commons/TimeLine.java | 81 +- .../src/commons/ValuePair.java | 46 +- .../src/engine/EngineFactory.java | 36 +- .../src/engine/IEngine.java | 101 +- .../src/engine/MainEngine.java | 214 ++-- .../src/parsing/IParser.java | 32 +- .../src/parsing/ParserFactory.java | 56 +- .../src/parsing/SimpleTextParser.java | 118 +- .../visual/AbstractRasterBasedVisualizer.java | 115 +- .../src/visual/ConsoleVisualizer.java | 78 +- .../src/visual/HtmlVisualizer.java | 129 +- .../src/visual/IVisualizer.java | 29 +- .../src/visual/VisualizerFactory.java | 52 +- .../src/controller/LatexEditorController.java | 49 +- .../controller/commands/AddLatexCommand.java | 26 +- .../ChangeVersionsStrategyCommand.java | 29 +- .../src/controller/commands/Command.java | 5 +- .../controller/commands/CommandFactory.java | 92 +- .../controller/commands/CreateCommand.java | 37 +- .../DisableVersionsManagementCommand.java | 33 +- .../src/controller/commands/EditCommand.java | 29 +- .../EnableVersionsManagementCommand.java | 28 +- .../src/controller/commands/LoadCommand.java | 51 +- .../RollbackToPreviousVersionCommand.java | 27 +- .../src/controller/commands/SaveCommand.java | 30 +- .../LatexEditor/src/model/Document.java | 133 +- .../src/model/DocumentManager.java | 219 ++-- .../src/model/VersionsManager.java | 298 +++-- .../strategies/StableVersionsStrategy.java | 182 +-- .../model/strategies/VersionsStrategy.java | 17 +- .../strategies/VersionsStrategyFactory.java | 28 +- .../strategies/VolatileVersionsStrategy.java | 95 +- .../LatexEditor/src/view/ChooseTemplate.java | 273 +++-- .../LatexEditor/src/view/LatexEditorView.java | 250 ++-- .../LatexEditor/src/view/MainWindow.java | 662 +++++----- .../LatexEditor/src/view/OpeningWindow.java | 163 +-- 262 files changed, 17068 insertions(+), 14468 deletions(-) delete mode 100644 src/main/resources/assets/UserDocumentation.html delete mode 100644 src/test/resources/RestaurantWeeklyEvaluationV03/src/main/resources/output/Dishes.html delete mode 100644 src/test/resources/RestaurantWeeklyEvaluationV03/src/main/resources/output/Emps.html delete mode 100644 src/test/resources/TimelineToPhasesV01/showMeTheTL.html diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ac0d87a..708c4d2 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,36 +27,36 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - - name: Set Up - run: ./mvnw install:install-file -Dfile=${{ github.workspace }}/libs/JavaFXSmartGraph/JavaFXSmartGraph/0.1/JavaFXSmartGraph-0.1.jar -DgroupId=JavaFXSmartGraph -DartifactId=JavaFXSmartGraph -Dversion=0.1 -Dpackaging=jar - - run: ./mvnw install:install-file -Dfile=${{ github.workspace }}/libs/PlantUML/PlantUML/1.2023.7/PlantUML-1.2023.7.jar -DgroupId=PlantUML -DartifactId=PlantUML -Dversion=1.2023.7 -Dpackaging=jar - - - name: Build with Maven - run: ./mvnw -B package --file pom.xml --update-snapshots verify -DskipTests - - - name: Test - run: ./mvnw --batch-mode -Dmaven.test.failure.ignore=true test - - - name: Report - uses: dorny/test-reporter@v1 - if: always() - with: - name: Maven Tests - path: target/surefire-reports/*.xml - reporter: java-junit - fail-on-error: true - - - name: Upload artifact - uses: actions/upload-artifact@v1 - if: always() - with: - name: surefire-reports - path: /home/runner/work + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Set Up + run: ./mvnw install:install-file -Dfile=${{ github.workspace }}/libs/JavaFXSmartGraph/JavaFXSmartGraph/0.1/JavaFXSmartGraph-0.1.jar -DgroupId=JavaFXSmartGraph -DartifactId=JavaFXSmartGraph -Dversion=0.1 -Dpackaging=jar + - run: ./mvnw install:install-file -Dfile=${{ github.workspace }}/libs/PlantUML/PlantUML/1.2023.7/PlantUML-1.2023.7.jar -DgroupId=PlantUML -DartifactId=PlantUML -Dversion=1.2023.7 -Dpackaging=jar + + - name: Build with Maven + run: ./mvnw -B package --file pom.xml --update-snapshots verify -DskipTests + + - name: Test + run: ./mvnw --batch-mode -Dmaven.test.failure.ignore=true test + + - name: Report + uses: dorny/test-reporter@v1 + if: always() + with: + name: Maven Tests + path: target/surefire-reports/*.xml + reporter: java-junit + fail-on-error: true + + - name: Upload artifact + uses: actions/upload-artifact@v1 + if: always() + with: + name: surefire-reports + path: /home/runner/work diff --git a/README.md b/README.md index f0fb96c..861dff6 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,14 @@ # Table of Contents + > - [About](#about) -> * [Motivation](#motivation) + > +* [Motivation](#motivation) > * [Features](#features) > - [Getting Started](#getting-started) -> * [Requirements](#requirements) + > +* [Requirements](#requirements) > * [Installation](#installation) > * [Usage](#usage) >* [Contributing / Reporting issues](#contributing--reporting-issues) @@ -37,55 +40,64 @@ ### Motivation -The purpose of this project is to develop an independent software tool that produces UML diagrams by reverse engineering Java object-oriented source code. +The purpose of this project is to develop an independent software tool that produces UML diagrams by reverse engineering Java object-oriented source code. ### Features -* Visualize class && package UML diagrams - * Choose the classes/packages that will be included in the diagram - * Create different diagrams from the same project +* Visualize class && package UML diagrams + * Choose the classes/packages that will be included in the diagram + * Create different diagrams from the same project * Export a diagram to: - * GraphML in order to visualize it using yEd - * Image - * text file that can you can later load + * GraphML in order to visualize it using yEd + * Image + * text file that can you can later load ## Getting Started ### Requirements 1. Clone the repository + ```bash git clone https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer.git ``` 2. Import project into: - * [Eclipse][importEclipse-url] - * [Intellij IDEA][importIntellij-url] + +* [Eclipse][importEclipse-url] +* [Intellij IDEA][importIntellij-url] ### Installation 1. Run + ```bash ./mvnw compile ``` + to build the project. -2. +2. + * In Eclipse: Project -> Build * In Intellij IDEA : Build -> Project ### Usage 1. Run + ```bash ./mvnw package ``` + to create the jar **ObjectOrientedArchitectureDiagrammer-0.0.1-SNAPSHOT-jar-with-dependencies.jar** 2. Run + ```bash java -jar ObjectOrientedArchitectureDiagrammer\target\ObjectOrientedArchitectureDiagrammer-0.0.1-SNAPSHOT-jar-with-dependencies.jar ``` + to execute the jar Check the [User Documentation][userDocumentation-url] regarding more about the usage of the tool @@ -93,6 +105,7 @@ Check the [User Documentation][userDocumentation-url] regarding more about the u ### Tests To run the tests simply run + ```bash ./mvnw test ``` @@ -111,17 +124,23 @@ If you want to contribute to the development of our tool, please fork the repo a 1. Fork the Project. 2. Create your Feature Branch. + ```bash git checkout -b feature/NewFeature ``` + 3. Commit your Changes. + ```bash git commit -m 'Add some NewFeature' ``` + 4. Push to the Branch. + ```bash git push origin feature/NewFeature ``` + 5. Open a Pull Request. ### Issues @@ -129,6 +148,7 @@ If you want to contribute to the development of our tool, please fork the repo a Create a new [Issue][issues-url] to report any issues ## Roadmap + - [X] Fix crashes with underscores, files/folders starting with '.', etc - [ ] Build a visualization library that supports: - [ ] A layout algorithm that uses bend minimization @@ -136,14 +156,15 @@ Create a new [Issue][issues-url] to report any issues - [ ] Editable canvas in order to move & delete UML components and entities - [ ] Editable edges that can split when clicked to help the user avoid edge/box overlapping - [ ] Support [PlantUML][plantuml-url] - - [X] Use PlantUML’s language to define the diagram - - [X] Export the image of the diagram - - [ ] Visualize the diagram within the tool's canvas + - [X] Use PlantUML’s language to define the diagram + - [X] Export the image of the diagram + - [ ] Visualize the diagram within the tool's canvas - [ ] Deprecate jdt parser after heavy usage of javaparser, or, extend the jdt parser to support: - - [ ] Creation of new() objects via local variables (and the resulting dependencies) - - [ ] Enums - + - [ ] Creation of new() objects via local variables (and the resulting dependencies) + - [ ] Enums + ## Authors + v0.2: Dimitris Anyfantakis added a new java parser; Bill Dodis added the PlanUML extension as part of his Diploma Thesis in Univ. Ioannina.
v0.1: Dimitris Anyfantakis has developed the first version of the tool as part of his Diploma Thesis in Univ. Ioannina; Panos Vassiliadis acted solely as code reviewer and co-designer. @@ -154,20 +175,37 @@ See [License][license-url] for more information regarding the license ## Acknowledgments [workflow-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/actions/workflows/maven.yml/badge.svg + [contributors-shield]: https://img.shields.io/github/contributors/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [contributors-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/graphs/contributors + [commits-shield]: https://img.shields.io/github/last-commit/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [commits-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/commit/main + [forks-shield]: https://img.shields.io/github/forks/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [forks-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/network/members + [stars-shield]: https://img.shields.io/github/stars/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [stars-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/stargazers + [issues-shield]: https://img.shields.io/github/issues/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [issues-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/issues/ + [license-shield]: https://img.shields.io/github/license/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [license-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/blob/main/LICENSE + [userDocumentation-url]: https://drive.google.com/file/d/17h9-hPtQ7GXwKxacQCjEKP51aE3G2JdZ/view?usp=sharing + [demo-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer + [importEclipse-url]: https://www.baeldung.com/maven-import-eclipse + [importIntellij-url]: https://www.jetbrains.com/idea/guide/tutorials/working-with-maven/importing-a-project/ + [plantuml-url]: https://plantuml.com/ \ No newline at end of file diff --git a/libs/JavaFXSmartGraph/JavaFXSmartGraph/0.1/JavaFXSmartGraph-0.1.pom b/libs/JavaFXSmartGraph/JavaFXSmartGraph/0.1/JavaFXSmartGraph-0.1.pom index cad458b..90e371d 100644 --- a/libs/JavaFXSmartGraph/JavaFXSmartGraph/0.1/JavaFXSmartGraph-0.1.pom +++ b/libs/JavaFXSmartGraph/JavaFXSmartGraph/0.1/JavaFXSmartGraph-0.1.pom @@ -1,9 +1,9 @@ - 4.0.0 - JavaFXSmartGraph - JavaFXSmartGraph - 0.1 - POM was created from install:install-file + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 + JavaFXSmartGraph + JavaFXSmartGraph + 0.1 + POM was created from install:install-file diff --git a/libs/JavaFXSmartGraph/JavaFXSmartGraph/maven-metadata.xml b/libs/JavaFXSmartGraph/JavaFXSmartGraph/maven-metadata.xml index db63bb2..93bd666 100644 --- a/libs/JavaFXSmartGraph/JavaFXSmartGraph/maven-metadata.xml +++ b/libs/JavaFXSmartGraph/JavaFXSmartGraph/maven-metadata.xml @@ -1,12 +1,12 @@ - JavaFXSmartGraph - JavaFXSmartGraph - - 0.1 - - 0.1 - - 20221010180439 - + JavaFXSmartGraph + JavaFXSmartGraph + + 0.1 + + 0.1 + + 20221010180439 + diff --git a/libs/PlantUML/PlantUML/1.2023.7/PlantUML-1.2023.7.pom b/libs/PlantUML/PlantUML/1.2023.7/PlantUML-1.2023.7.pom index 324c53e..c1ece49 100644 --- a/libs/PlantUML/PlantUML/1.2023.7/PlantUML-1.2023.7.pom +++ b/libs/PlantUML/PlantUML/1.2023.7/PlantUML-1.2023.7.pom @@ -1,9 +1,9 @@ - 4.0.0 - PlantUML - PlantUML - 1.2023.7 - POM was created from install:install-file + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 + PlantUML + PlantUML + 1.2023.7 + POM was created from install:install-file diff --git a/libs/PlantUML/PlantUML/maven-metadata.xml b/libs/PlantUML/PlantUML/maven-metadata.xml index 8802e43..df06c94 100644 --- a/libs/PlantUML/PlantUML/maven-metadata.xml +++ b/libs/PlantUML/PlantUML/maven-metadata.xml @@ -1,12 +1,12 @@ - PlantUML - PlantUML - - 1.2023.7 - - 1.2023.7 - - 20230518044318 - + PlantUML + PlantUML + + 1.2023.7 + + 1.2023.7 + + 20230518044318 + diff --git a/pom.xml b/pom.xml index 17f0937..bde2e0b 100644 --- a/pom.xml +++ b/pom.xml @@ -50,51 +50,51 @@ test - org.junit.jupiter - junit-jupiter - 5.9.2 - test - - - org.junit.platform - junit-platform-suite-engine - 1.8.1 - - - net.sf.jung - jung-algorithms - 2.1.1 - - - net.sf.jung - jung-graph-impl - 2.1.1 - - - net.sf.jung - jung-visualization - 2.1.1 - - - org.openjfx - javafx-controls - 18.0.1 - - - org.openjfx - javafx-fxml - 18.0.1 - - - org.openjfx - javafx-web - 18.0.1 - - - com.sirolf2009 - fxgraph - 0.0.3 - + org.junit.jupiter + junit-jupiter + 5.9.2 + test + + + org.junit.platform + junit-platform-suite-engine + 1.8.1 + + + net.sf.jung + jung-algorithms + 2.1.1 + + + net.sf.jung + jung-graph-impl + 2.1.1 + + + net.sf.jung + jung-visualization + 2.1.1 + + + org.openjfx + javafx-controls + 18.0.1 + + + org.openjfx + javafx-fxml + 18.0.1 + + + org.openjfx + javafx-web + 18.0.1 + + + com.sirolf2009 + fxgraph + 0.0.3 + JavaFXSmartGraph JavaFXSmartGraph @@ -132,73 +132,73 @@ - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - **/*Test.java - - - - - org.junit.jupiter - junit-jupiter-engine - 5.10.0 - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - package - - single - - - - - - view/AppStarter - - - - - jar-with-dependencies - - - - - - - maven-compiler-plugin - 3.8.0 - - 17 - - - - org.openjfx - javafx-maven-plugin - 0.0.8 - - MainApp - - - + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + **/*Test.java + + + + + org.junit.jupiter + junit-jupiter-engine + 5.10.0 + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + + view/AppStarter + + + + + jar-with-dependencies + + + + + + + maven-compiler-plugin + 3.8.0 + + 17 + + + + org.openjfx + javafx-maven-plugin + 0.0.8 + + MainApp + + + diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index 87c9bc6..a53747e 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -7,88 +7,92 @@ import java.nio.file.Path; import java.util.List; -public interface Controller { - - /** - * This method creates the tree of the project by calling the DiagramManager's createTree method. - * - * @param sourcePackagePath the project's source package path - * @return the SourceProject created - */ - SourceProject createTree(Path sourcePackagePath); - - /** - * This method converts the created tree to a diagram, by creating the corresponding DiagramManager - * based on the type of the graph, i.e. package or class and then calling the createDiagram method - * of the DiagramManager. - * - * @param chosenFileNames the names of the files selected by the designer to be included in the diagram - */ - void convertTreeToDiagram(List chosenFileNames); - - /** - * This method arranges the diagram by calling the DiagramManager's arrangeDiagram method. - */ - void arrangeDiagram(); - - // TODO JavaDoc - SmartGraphPanel applyLayout(); - - // TODO JavaDoc - SmartGraphPanel applySpecificLayout(String choice); - - /** - * This method exports the diagram to a GraphML file by calling the DiagramManager's exportDiagramToGraphML method. - * - * @param graphMLSavePath the selected path by the designer where the diagram will be saved - * @return the created File in which the diagram was saved - */ - File exportDiagramToGraphML(Path graphMLSavePath); - - /** - * This method saves the diagram to a text file by calling the DiagramManager's saveDiagram method. - * - * @param graphSavePath the selected path by the designer where the diagram will be saved - * @return the created File in which the diagram was saved - */ - File saveDiagram(Path graphSavePath); - - /** - * This method loads a diagram from a text file by calling the DiagramManager's loadDiagram method. - * - * @param graphSavePath the file's path where the diagram is saved - */ - void loadDiagram(Path graphSavePath); - - /** - * This method creates the JavaFX graphView by calling the DiagramManager's visualizeJavaFXGraph method. - * - * @return the created graphView {@link SmartGraphPanel} - */ - SmartGraphPanel visualizeJavaFXGraph(); - - /** - * This method creates the loaded Diagram's JavaFX graphView by calling the DiagramManager's visualizeLoadedJavaFXGraph method. - * - * @return the created graphView - */ - SmartGraphPanel visualizeLoadedJavaFXGraph(); - - /** - * This method exports the diagram as an image with the help of PlantUML by calling the DiagramManager's - * exportPlantUMLDiagram method. - * - * @param graphSavePath the selected path by the designer where the diagram's image will be saved - * @return the created PlantUML diagram - */ - File exportPlantUMLDiagram(Path graphSavePath); - - /** - * This method saves the PlantUML code to a text file by calling the DiagramManager's exportPlantUMLText method. - * - * @param textSavePath the selected path by the designer where the text file will be saved - * @return the created PlantUML text file - */ - File exportPlantUMLText(Path textSavePath); +public interface Controller +{ + + /** + * This method creates the tree of the project by calling the DiagramManager's createTree method. + * + * @param sourcePackagePath the project's source package path + * @return the SourceProject created + */ + SourceProject createTree(Path sourcePackagePath); + + /** + * This method converts the created tree to a diagram, by creating the corresponding DiagramManager + * based on the type of the graph, i.e. package or class and then calling the createDiagram + * method of the DiagramManager. + * + * @param chosenFileNames the names of the files selected by the designer to be included in the diagram + */ + void convertTreeToDiagram(List chosenFileNames); + + /** + * This method arranges the diagram by calling the DiagramManager's arrangeDiagram method. + */ + void arrangeDiagram(); + + // TODO JavaDoc + SmartGraphPanel applyLayout(); + + // TODO JavaDoc + SmartGraphPanel applySpecificLayout(String choice); + + /** + * This method exports the diagram to a GraphML file by calling + * the DiagramManager's exportDiagramToGraphML method. + * + * @param graphMLSavePath the selected path by the designer where the diagram will be saved + * @return the created File in which the diagram was saved + */ + File exportDiagramToGraphML(Path graphMLSavePath); + + /** + * This method saves the diagram to a text file by calling the DiagramManager's saveDiagram method. + * + * @param graphSavePath the selected path by the designer where the diagram will be saved + * @return the created File in which the diagram was saved + */ + File saveDiagram(Path graphSavePath); + + /** + * This method loads a diagram from a text file by calling the DiagramManager's loadDiagram method. + * + * @param graphSavePath the file's path where the diagram is saved + */ + void loadDiagram(Path graphSavePath); + + /** + * This method creates the JavaFX graphView by calling the DiagramManager's visualizeJavaFXGraph method. + * + * @return the created graphView {@link SmartGraphPanel} + */ + SmartGraphPanel visualizeJavaFXGraph(); + + /** + * This method creates the loaded Diagram's JavaFX graphView by calling + * the DiagramManager's visualizeLoadedJavaFXGraph method. + * + * @return the created graphView + */ + SmartGraphPanel visualizeLoadedJavaFXGraph(); + + /** + * This method exports the diagram as an image with the help of PlantUML by calling + * the DiagramManager's exportPlantUMLDiagram method. + * + * @param graphSavePath the selected path by the designer where the diagram's image will be saved + * @return the created PlantUML diagram + */ + File exportPlantUMLDiagram(Path graphSavePath); + + /** + * This method saves the PlantUML code to a text file by calling + * the DiagramManager's exportPlantUMLText method. + * + * @param textSavePath the selected path by the designer where the text file will be saved + * @return the created PlantUML text file + */ + File exportPlantUMLText(Path textSavePath); } diff --git a/src/main/java/controller/ControllerFactory.java b/src/main/java/controller/ControllerFactory.java index 74f2e0b..a3328b6 100644 --- a/src/main/java/controller/ControllerFactory.java +++ b/src/main/java/controller/ControllerFactory.java @@ -1,11 +1,14 @@ package controller; -public class ControllerFactory { +public class ControllerFactory +{ - public static Controller createController(String controllerType, String diagramType) { - return switch (ControllerType.get(controllerType)) { - case UML -> new DiagramController(diagramType); - }; - } + public static Controller createController(String controllerType, String diagramType) + { + return switch (ControllerType.get(controllerType)) + { + case UML -> new DiagramController(diagramType); + }; + } } diff --git a/src/main/java/controller/ControllerType.java b/src/main/java/controller/ControllerType.java index af21026..3a8891e 100644 --- a/src/main/java/controller/ControllerType.java +++ b/src/main/java/controller/ControllerType.java @@ -4,26 +4,32 @@ import java.util.HashMap; import java.util.Map; -public enum ControllerType { - UML; - - public static final Map CONTROLLER_TYPE; - - static { - Map map = new HashMap<>(); - for (ControllerType controllerType: ControllerType.values()) { - map.put(controllerType.toString().toLowerCase(), controllerType); - } - CONTROLLER_TYPE = Collections.unmodifiableMap(map); - } - - public static ControllerType get(String controllerType) { - return CONTROLLER_TYPE.get(controllerType.toLowerCase()); - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } +public enum ControllerType +{ + UML; + + public static final Map CONTROLLER_TYPE; + + static + { + Map map = new HashMap<>(); + for (ControllerType controllerType : ControllerType.values()) + { + map.put(controllerType.toString().toLowerCase(), controllerType); + } + CONTROLLER_TYPE = Collections.unmodifiableMap(map); + } + + public static ControllerType get(String controllerType) + { + return CONTROLLER_TYPE.get(controllerType.toLowerCase()); + } + + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/controller/DiagramController.java b/src/main/java/controller/DiagramController.java index bf96d91..2c5d7af 100644 --- a/src/main/java/controller/DiagramController.java +++ b/src/main/java/controller/DiagramController.java @@ -3,67 +3,93 @@ import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel; import manager.DiagramManager; import manager.DiagramManagerFactory; -import manager.DiagramType; import manager.SourceProject; import java.io.File; import java.nio.file.Path; import java.util.List; -public class DiagramController implements Controller { - - private static DiagramManager diagramManager; - - public DiagramController(String diagramType) { - diagramManager = DiagramManagerFactory.createDiagramManager(diagramType); - } - - public SourceProject createTree(Path sourcePackagePath) { - return diagramManager.createSourceProject(sourcePackagePath); - } - - public void convertTreeToDiagram(List chosenClassesNames) { - diagramManager.convertTreeToDiagram(chosenClassesNames); - } - - public void arrangeDiagram(){ - diagramManager.arrangeDiagram(); - } - - public SmartGraphPanel applyLayout(){ - return diagramManager.applyLayout(); - } - - public SmartGraphPanel applySpecificLayout(String choice){ - return diagramManager.applySpecificLayout(choice); - } - - public File exportDiagramToGraphML(Path graphMLSavePath) { - return diagramManager.exportDiagramToGraphML(graphMLSavePath); - } - - public File exportPlantUMLDiagram(Path plantUMLSavePath) { - return diagramManager.exportPlantUMLImage(plantUMLSavePath); - } - - public File exportPlantUMLText(Path textSavePath) { - return diagramManager.exportPlantUMLText(textSavePath); - } - - public SmartGraphPanel visualizeJavaFXGraph() { - return diagramManager.visualizeJavaFXGraph(); - } - - public SmartGraphPanel visualizeLoadedJavaFXGraph(){ - return diagramManager.visualizeLoadedJavaFXGraph(); - } - - public File saveDiagram(Path graphSavePath) { - return diagramManager.saveDiagram(graphSavePath); - } - - public void loadDiagram(Path graphSavePath) { - diagramManager.loadDiagram(graphSavePath); - } +public class DiagramController implements Controller +{ + + private final DiagramManager diagramManager; + + + public DiagramController(String diagramType) + { + diagramManager = DiagramManagerFactory.createDiagramManager(diagramType); + } + + @Override + public SourceProject createTree(Path sourcePackagePath) + { + return diagramManager.createSourceProject(sourcePackagePath); + } + + @Override + public void convertTreeToDiagram(List chosenClassesNames) + { + diagramManager.convertTreeToDiagram(chosenClassesNames); + } + + @Override + public void arrangeDiagram() + { + diagramManager.arrangeDiagram(); + } + + @Override + public SmartGraphPanel applyLayout() + { + return diagramManager.applyLayout(); + } + + @Override + public SmartGraphPanel applySpecificLayout(String choice) + { + return diagramManager.applySpecificLayout(choice); + } + + @Override + public File exportDiagramToGraphML(Path graphMLSavePath) + { + return diagramManager.exportDiagramToGraphML(graphMLSavePath); + } + + @Override + public File exportPlantUMLDiagram(Path plantUMLSavePath) + { + return diagramManager.exportPlantUMLImage(plantUMLSavePath); + } + + @Override + public File exportPlantUMLText(Path textSavePath) + { + return diagramManager.exportPlantUMLText(textSavePath); + } + + @Override + public SmartGraphPanel visualizeJavaFXGraph() + { + return diagramManager.visualizeJavaFXGraph(); + } + + @Override + public SmartGraphPanel visualizeLoadedJavaFXGraph() + { + return diagramManager.visualizeLoadedJavaFXGraph(); + } + + @Override + public File saveDiagram(Path graphSavePath) + { + return diagramManager.saveDiagram(graphSavePath); + } + + @Override + public void loadDiagram(Path graphSavePath) + { + diagramManager.loadDiagram(graphSavePath); + } } diff --git a/src/main/java/manager/ClassDiagramManager.java b/src/main/java/manager/ClassDiagramManager.java index ce840be..83d6548 100644 --- a/src/main/java/manager/ClassDiagramManager.java +++ b/src/main/java/manager/ClassDiagramManager.java @@ -23,121 +23,161 @@ import java.util.Collection; import java.util.List; -public class ClassDiagramManager implements DiagramManager { - - private static ClassDiagram classDiagram; - private static DiagramArrangementManagerInterface classDiagramArrangement; - private static Collection> vertexCollection; - private static SmartGraphPanel graphView; - - public ClassDiagramManager() { - classDiagram = new ClassDiagram(); - } - - @Override - public SourceProject createSourceProject(Path sourcePackagePath) { - SourceProject sourceProject = new SourceProject(); - sourceProject.createClassGraph(sourcePackagePath, classDiagram); - return sourceProject; - } - - @Override - public void convertTreeToDiagram(List chosenFilesNames) { - classDiagram.createNewDiagram(chosenFilesNames); - ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagram); - classDiagram.setDiagram(shadowCleaner.shadowWeakRelationships()); - } - - @Override - public void arrangeDiagram(){ - classDiagramArrangement = new ClassDiagramArrangementManager(classDiagram); - DiagramGeometry diagramGeometry = classDiagramArrangement.arrangeDiagram(); - classDiagram.setDiagramGeometry(diagramGeometry); - } - - @Override - public SmartGraphPanel visualizeJavaFXGraph() { - JavaFXVisualization javaFXVisualization = new JavaFXClassVisualization(classDiagram); - graphView = javaFXVisualization.createGraphView(); - vertexCollection = javaFXVisualization.getVertexCollection(); - return graphView; - } - - @Override - public SmartGraphPanel visualizeLoadedJavaFXGraph() { - JavaFXVisualization javaFXVisualization = new JavaFXClassVisualization(classDiagram); - javaFXVisualization.createGraphView(); - graphView = javaFXVisualization.getLoadedGraph(); - vertexCollection = javaFXVisualization.getVertexCollection(); - return graphView; - } - - @Override - public File exportDiagramToGraphML(Path graphMLSavePath) { - classDiagram.setGraphMLDiagramGeometry(classDiagramArrangement.arrangeGraphMLDiagram()); - DiagramExporter diagramExporter = new GraphMLClassDiagramExporter(classDiagram); - return diagramExporter.exportDiagram(graphMLSavePath); - } - - @Override - public File exportPlantUMLImage(Path plantUMLSavePath) { - DiagramExporter diagramExporter = new PlantUMLClassDiagramImageExporter(classDiagram); - return diagramExporter.exportDiagram(plantUMLSavePath); - } - - @Override - public File exportPlantUMLText(Path textSavePath) { - DiagramExporter diagramExporter = new PlantUMLClassDiagramTextExporter(classDiagram); - return diagramExporter.exportDiagram(textSavePath); - } - - @Override - public File saveDiagram(Path graphSavePath) { - CoordinatesUpdater coordinatesUpdater = new CoordinatesUpdater(classDiagram); - coordinatesUpdater.updateClassCoordinates(vertexCollection, graphView); - DiagramExporter diagramExporter = new JavaFXClassDiagramExporter(classDiagram); - return diagramExporter.exportDiagram(graphSavePath); - } - - @Override - public void loadDiagram(Path graphSavePath) { - JavaFXClassDiagramLoader javaFXClassDiagramLoader = new JavaFXClassDiagramLoader(graphSavePath); - classDiagram = new ClassDiagram(); - classDiagram.createDiagram(javaFXClassDiagramLoader.loadDiagram()); - ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagram); - classDiagram.setDiagram(shadowCleaner.shadowWeakRelationships()); - } - - public ClassDiagram getClassDiagram() { - return classDiagram; - } - - public SmartGraphPanel applyLayout() { - DiagramGeometry nodesGeometry = classDiagram.getDiagramGeometry(); - for(Vertex vertex : vertexCollection) { - if (!nodesGeometry.containsKey(vertex.element())) { - continue; - } - - Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); - graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); - } - - return graphView; - } - - public SmartGraphPanel applySpecificLayout(String choice){ - DiagramGeometry nodesGeometry = classDiagramArrangement.applyNewLayout(choice); - for(Vertex vertex : vertexCollection) { - if (!nodesGeometry.containsKey(vertex.element())) { - continue; - } - - Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); - graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); - } - - return graphView; - } +public class ClassDiagramManager implements DiagramManager +{ + + private ClassDiagram classDiagram; + private DiagramArrangementManagerInterface classDiagramArrangement; + private Collection> vertexCollection; + private SmartGraphPanel graphView; + + + public ClassDiagramManager() + { + classDiagram = new ClassDiagram(); + } + + + @Override + public SourceProject createSourceProject(Path sourcePackagePath) + { + SourceProject sourceProject = new SourceProject(); + sourceProject.createClassGraph(sourcePackagePath, classDiagram); + return sourceProject; + } + + + @Override + public void convertTreeToDiagram(List chosenFilesNames) + { + classDiagram.createNewDiagram(chosenFilesNames); + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagram); + classDiagram.setDiagram(shadowCleaner.shadowWeakRelationships()); + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + classDiagramArrangement = new ClassDiagramArrangementManager(classDiagram); + DiagramGeometry diagramGeometry = classDiagramArrangement.arrangeDiagram(); + classDiagram.setDiagramGeometry(diagramGeometry); + return diagramGeometry; + } + + + @Override + public SmartGraphPanel visualizeJavaFXGraph() + { + JavaFXVisualization javaFXVisualization = new JavaFXClassVisualization(classDiagram); + graphView = javaFXVisualization.createGraphView(); + vertexCollection = javaFXVisualization.getVertexCollection(); + return graphView; + } + + + @Override + public SmartGraphPanel visualizeLoadedJavaFXGraph() + { + JavaFXVisualization javaFXVisualization = new JavaFXClassVisualization(classDiagram); + javaFXVisualization.createGraphView(); + + graphView = javaFXVisualization.getLoadedGraph(); + vertexCollection = javaFXVisualization.getVertexCollection(); + return graphView; + } + + + @Override + public File exportDiagramToGraphML(Path graphMLSavePath) + { + classDiagram.setGraphMLDiagramGeometry(classDiagramArrangement.arrangeGraphMLDiagram()); + DiagramExporter diagramExporter = new GraphMLClassDiagramExporter(classDiagram); + return diagramExporter.exportDiagram(graphMLSavePath); + } + + + @Override + public File exportPlantUMLImage(Path plantUMLSavePath) + { + DiagramExporter diagramExporter = new PlantUMLClassDiagramImageExporter(classDiagram); + return diagramExporter.exportDiagram(plantUMLSavePath); + } + + + @Override + public File exportPlantUMLText(Path textSavePath) + { + DiagramExporter diagramExporter = new PlantUMLClassDiagramTextExporter(classDiagram); + return diagramExporter.exportDiagram(textSavePath); + } + + + @Override + public File saveDiagram(Path graphSavePath) + { + CoordinatesUpdater coordinatesUpdater = new CoordinatesUpdater(classDiagram); + coordinatesUpdater.updateClassCoordinates(vertexCollection, graphView); + + DiagramExporter diagramExporter = new JavaFXClassDiagramExporter(classDiagram); + return diagramExporter.exportDiagram(graphSavePath); + } + + + @Override + public void loadDiagram(Path graphSavePath) + { + JavaFXClassDiagramLoader javaFXClassDiagramLoader = new JavaFXClassDiagramLoader(graphSavePath); + + classDiagram = new ClassDiagram(); + classDiagram.createDiagram(javaFXClassDiagramLoader.loadDiagram()); + + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagram); + classDiagram.setDiagram(shadowCleaner.shadowWeakRelationships()); + } + + + public ClassDiagram getClassDiagram() + { + return classDiagram; + } + + @Override + public SmartGraphPanel applyLayout() + { + DiagramGeometry nodesGeometry = classDiagram.getDiagramGeometry(); + for (Vertex vertex : vertexCollection) + { + if (!nodesGeometry.containsKey(vertex.element())) + { + continue; + } + + Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); + graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); + } + + return graphView; + } + + @Override + public SmartGraphPanel applySpecificLayout(String choice) + { + DiagramGeometry nodesGeometry = classDiagramArrangement.applyNewLayout(choice); + for (Vertex vertex : vertexCollection) + { + if (!nodesGeometry.containsKey(vertex.element())) + { + continue; + } + + Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); + graphView.setVertexPosition(vertex, + coordinates.getValue0(), + coordinates.getValue1()); + } + + return graphView; + } } diff --git a/src/main/java/manager/DiagramManager.java b/src/main/java/manager/DiagramManager.java index ead8dfb..acd3fb7 100644 --- a/src/main/java/manager/DiagramManager.java +++ b/src/main/java/manager/DiagramManager.java @@ -1,93 +1,98 @@ package manager; import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel; +import model.diagram.arrangement.geometry.DiagramGeometry; import java.io.File; import java.nio.file.Path; import java.util.List; -public interface DiagramManager { - - /** - * This method creates the tree of the project by parsing the project's source package that the designer has loaded. - * - * @param sourcePackagePath the project's source package path - * @return the {@link SourceProject} created, representing the model of the tree - */ - SourceProject createSourceProject(Path sourcePackagePath); - - /** - * This method converts the tree created by the Parser to a Diagram, based on the files(classes or packages) selected - * by the designer. The type of the Diagram depends on the type of files the designer has chosen and the Controller - * is responsible for creating the corresponding GraphDiagramManager that implements the createDiagram method. - * - * @param chosenFilesNames the names of the files selected by the designer - */ - void convertTreeToDiagram(List chosenFilesNames); - - /** - * This method arranges the createdDiagram's node geometry by creating a Jung Graph and then applying the SpringLayout - * algorithm, implemented by the Jung library. - */ - void arrangeDiagram(); - - /** - * This method exports the created diagram to a file, to the path selected by the designer, in GraphMLFormat, by - * converting the nodes and edges to GraphML syntax. - * - * @param graphMLSavePath the selected path by the designer where the diagram will be saved - * @return the created File in which the diagram was saved - */ - File exportDiagramToGraphML(Path graphMLSavePath); - - /** - * This method saves the created JavaFX diagram to a text file, to the path selected by the designer, by implementing - * a Map that stores the diagrams' nodes as keys and a Map of their edges and the relationship type as their values. - * - * @param graphSavePath the selected path by the designer where the diagram will be saved - * @return the created File in which the diagram was saved - */ - File saveDiagram(Path graphSavePath); - - /** - * This method loads a JavaFX diagram from a file, selected by the designer, by creating an object of the class - * Diagram and populating the createdDiagram Collection with the contents of the file. The createdDiagram is a Map - * as described in the method above. - * - * @param graphSavePath the file's path where the diagram is saved - */ - void loadDiagram(Path graphSavePath); - - /** - * This method creates the JavaFX graphView that will be rendered by view in the JavaFX Pane. - * - * @return the created graphView {@link SmartGraphPanel} - */ - SmartGraphPanel visualizeJavaFXGraph(); - - /** - * This method is responsible for exporting the diagram to a PlantUML image diagram. - * - * @param plantUMLSavePath the selected path by the designer where the exported diagram will be saved - * @return the exported file - */ - File exportPlantUMLImage(Path plantUMLSavePath); - - /** - * This method is responsible for exporting the diagram to a PlantUML text file. - * - * @param textSavePath the selected path by the designer where the exported diagram will be saved - * @return the exported file - */ - File exportPlantUMLText(Path textSavePath); - - // TODO JavaDoc - SmartGraphPanel applyLayout(); - - // TODO JavaDoc - SmartGraphPanel applySpecificLayout(String choice); - - // TODO JavaDoc - SmartGraphPanel visualizeLoadedJavaFXGraph(); +public interface DiagramManager +{ + + /** + * This method creates the tree of the project by parsing the project's source package that the designer has loaded. + * + * @param sourcePackagePath the project's source package path + * @return the {@link SourceProject} created, representing the model of the tree + */ + SourceProject createSourceProject(Path sourcePackagePath); + + /** + * This method converts the tree created by the Parser to a Diagram, + * based on the files(classes or packages) selected by the designer. + * The type of the Diagram depends on the type of files the designer has chosen + * and the Controller is responsible for creating the corresponding GraphDiagramManager + * that implements the createDiagram method. + * + * @param chosenFilesNames the names of the files selected by the designer + */ + void convertTreeToDiagram(List chosenFilesNames); + + /** + * This method arranges the createdDiagram's node geometry by creating a Jung Graph + * and then applying the SpringLayout algorithm, implemented by the Jung library. + */ + DiagramGeometry arrangeDiagram(); + + /** + * This method exports the created diagram to a file, to the path selected by the designer, + * in GraphMLFormat, by converting the nodes and edges to GraphML syntax. + * + * @param graphMLSavePath the selected path by the designer where the diagram will be saved + * @return the created File in which the diagram was saved + */ + File exportDiagramToGraphML(Path graphMLSavePath); + + /** + * This method saves the created JavaFX diagram to a text file, to the path selected by the designer, + * by implementing a Map that stores the diagrams' nodes as keys and a Map of their edges and the relationship type as their values. + * + * @param graphSavePath the selected path by the designer where the diagram will be saved + * @return the created File in which the diagram was saved + */ + File saveDiagram(Path graphSavePath); + + /** + * This method loads a JavaFX diagram from a file, selected by the designer, + * by creating an object of the class Diagram and populating the createdDiagram Collection + * with the contents of the file. + * The createdDiagram is a Map as described in the method above. + * + * @param graphSavePath the file's path where the diagram is saved + */ + void loadDiagram(Path graphSavePath); + + /** + * This method creates the JavaFX graphView that will be rendered by view in the JavaFX Pane. + * + * @return the created graphView {@link SmartGraphPanel} + */ + SmartGraphPanel visualizeJavaFXGraph(); + + /** + * This method is responsible for exporting the diagram to a PlantUML image diagram. + * + * @param plantUMLSavePath the selected path by the designer where the exported diagram will be saved + * @return the exported file + */ + File exportPlantUMLImage(Path plantUMLSavePath); + + /** + * This method is responsible for exporting the diagram to a PlantUML text file. + * + * @param textSavePath the selected path by the designer where the exported diagram will be saved + * @return the exported file + */ + File exportPlantUMLText(Path textSavePath); + + // TODO JavaDoc + SmartGraphPanel applyLayout(); + + // TODO JavaDoc + SmartGraphPanel applySpecificLayout(String choice); + + // TODO JavaDoc + SmartGraphPanel visualizeLoadedJavaFXGraph(); } diff --git a/src/main/java/manager/DiagramManagerFactory.java b/src/main/java/manager/DiagramManagerFactory.java index cf7dd24..cdb9e2d 100644 --- a/src/main/java/manager/DiagramManagerFactory.java +++ b/src/main/java/manager/DiagramManagerFactory.java @@ -1,12 +1,15 @@ package manager; -public class DiagramManagerFactory { +public class DiagramManagerFactory +{ - public static DiagramManager createDiagramManager(String diagramType) { - return switch (DiagramType.get(diagramType)) { - case CLASS -> new ClassDiagramManager(); - case PACKAGE -> new PackageDiagramManager(); - }; - } + public static DiagramManager createDiagramManager(String diagramType) + { + return switch (DiagramType.get(diagramType)) + { + case CLASS -> new ClassDiagramManager(); + case PACKAGE -> new PackageDiagramManager(); + }; + } } diff --git a/src/main/java/manager/DiagramType.java b/src/main/java/manager/DiagramType.java index 471e97b..c788254 100644 --- a/src/main/java/manager/DiagramType.java +++ b/src/main/java/manager/DiagramType.java @@ -4,28 +4,34 @@ import java.util.HashMap; import java.util.Map; -public enum DiagramType { - CLASS, - PACKAGE; - - public static final Map DIAGRAM_TYPE; - - static { - Map map = new HashMap<>(); - for (DiagramType diagramType: DiagramType.values()) { - map.put(diagramType.toString().toLowerCase(), diagramType); - } - - DIAGRAM_TYPE = Collections.unmodifiableMap(map); - } - - public static DiagramType get(String diagramType) { - return DIAGRAM_TYPE.get(diagramType.toLowerCase().trim()); - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } +public enum DiagramType +{ + CLASS, + PACKAGE; + + public static final Map DIAGRAM_TYPE; + + static + { + Map map = new HashMap<>(); + for (DiagramType diagramType : DiagramType.values()) + { + map.put(diagramType.toString().toLowerCase(), diagramType); + } + + DIAGRAM_TYPE = Collections.unmodifiableMap(map); + } + + public static DiagramType get(String diagramType) + { + return DIAGRAM_TYPE.get(diagramType.toLowerCase().trim()); + } + + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/manager/PackageDiagramManager.java b/src/main/java/manager/PackageDiagramManager.java index d44aed4..f615aa1 100644 --- a/src/main/java/manager/PackageDiagramManager.java +++ b/src/main/java/manager/PackageDiagramManager.java @@ -25,120 +25,157 @@ import java.util.logging.Level; import java.util.logging.Logger; -public class PackageDiagramManager implements DiagramManager { - - private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - - private static PackageDiagram packageDiagram; - private static DiagramArrangementManagerInterface packageDiagramArrangement; - private static Collection> vertexCollection; - private static SmartGraphPanel graphView; - - public PackageDiagramManager() { - packageDiagram = new PackageDiagram(); - } - - @Override - public SourceProject createSourceProject(Path sourcePackagePath) { - SourceProject sourceProject = new SourceProject(); - sourceProject.createPackageGraph(sourcePackagePath, packageDiagram); - return sourceProject; - } - - @Override - public void convertTreeToDiagram(List chosenFilesNames) { - packageDiagram.createNewDiagram(chosenFilesNames); - } - - @Override - public void arrangeDiagram() { - packageDiagramArrangement = new PackageDiagramArrangementManager(packageDiagram); - DiagramGeometry diagramGeometry = packageDiagramArrangement.arrangeDiagram(); - packageDiagram.setDiagramGeometry(diagramGeometry); - } - - @Override - public SmartGraphPanel visualizeJavaFXGraph() { - JavaFXVisualization javaFXPackageVisualization = new JavaFXPackageVisualization(packageDiagram); - graphView = javaFXPackageVisualization.createGraphView(); - vertexCollection = javaFXPackageVisualization.getVertexCollection(); - return graphView; - } - - @Override - public SmartGraphPanel visualizeLoadedJavaFXGraph() { - JavaFXVisualization javaFXPackageVisualization = new JavaFXPackageVisualization(packageDiagram); - javaFXPackageVisualization.createGraphView(); - graphView = javaFXPackageVisualization.getLoadedGraph(); - vertexCollection = javaFXPackageVisualization.getVertexCollection(); - return graphView; - } - - @Override - public File exportDiagramToGraphML(Path graphMLSavePath) { - packageDiagram.setGraphMLDiagramGeometry(packageDiagramArrangement.arrangeGraphMLDiagram()); - DiagramExporter diagramExporter = new GraphMLPackageDiagramExporter(packageDiagram); - return diagramExporter.exportDiagram(graphMLSavePath); - } - - @Override - public File exportPlantUMLImage(Path plantUMLSavePath) { - DiagramExporter diagramExporter = new PlantUMLPackageDiagramImageExporter(packageDiagram); - return diagramExporter.exportDiagram(plantUMLSavePath); - } - - @Override - public File exportPlantUMLText(Path textSavePath) { - DiagramExporter diagramExporter = new PlantUMLPackageDiagramTextExporter(packageDiagram); - return diagramExporter.exportDiagram(textSavePath); - } - - @Override - public File saveDiagram(Path graphSavePath) { - CoordinatesUpdater coordinatesUpdater = new CoordinatesUpdater(packageDiagram); - coordinatesUpdater.updatePackageCoordinates(vertexCollection, graphView); - DiagramExporter diagramExporter = new JavaFXPackageDiagramExporter(packageDiagram); - return diagramExporter.exportDiagram(graphSavePath); - } - - @Override - public void loadDiagram(Path graphSavePath) throws JsonParseException { - JavaFXPackageDiagramLoader javaFXPackageDiagramLoader = new JavaFXPackageDiagramLoader(graphSavePath); - packageDiagram = new PackageDiagram(); - packageDiagram.createDiagram(javaFXPackageDiagramLoader.loadDiagram()); - } - - public PackageDiagram getPackageDiagram() { - return packageDiagram; - } - - public SmartGraphPanel applyLayout() { - DiagramGeometry nodesGeometry = packageDiagram.getDiagramGeometry(); - for(Vertex vertex : vertexCollection) { - if (!nodesGeometry.containsKey(vertex.element())) { +public class PackageDiagramManager implements DiagramManager +{ + + private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + + private PackageDiagram packageDiagram; + private DiagramArrangementManagerInterface packageDiagramArrangement; + private Collection> vertexCollection; + private SmartGraphPanel graphView; + + + public PackageDiagramManager() + { + packageDiagram = new PackageDiagram(); + } + + + @Override + public SourceProject createSourceProject(Path sourcePackagePath) + { + SourceProject sourceProject = new SourceProject(); + sourceProject.createPackageGraph(sourcePackagePath, packageDiagram); + return sourceProject; + } + + + @Override + public void convertTreeToDiagram(List chosenFilesNames) + { + packageDiagram.createNewDiagram(chosenFilesNames); + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + packageDiagramArrangement = new PackageDiagramArrangementManager(packageDiagram); + DiagramGeometry diagramGeometry = packageDiagramArrangement.arrangeDiagram(); + packageDiagram.setDiagramGeometry(diagramGeometry); + return diagramGeometry; + } + + + @Override + public SmartGraphPanel visualizeJavaFXGraph() + { + JavaFXVisualization javaFXPackageVisualization = new JavaFXPackageVisualization(packageDiagram); + graphView = javaFXPackageVisualization.createGraphView(); + vertexCollection = javaFXPackageVisualization.getVertexCollection(); + return graphView; + } + + + @Override + public SmartGraphPanel visualizeLoadedJavaFXGraph() + { + JavaFXVisualization javaFXPackageVisualization = new JavaFXPackageVisualization(packageDiagram); + javaFXPackageVisualization.createGraphView(); + + graphView = javaFXPackageVisualization.getLoadedGraph(); + vertexCollection = javaFXPackageVisualization.getVertexCollection(); + return graphView; + } + + + @Override + public File exportDiagramToGraphML(Path graphMLSavePath) + { + packageDiagram.setGraphMLDiagramGeometry(packageDiagramArrangement.arrangeGraphMLDiagram()); + DiagramExporter diagramExporter = new GraphMLPackageDiagramExporter(packageDiagram); + return diagramExporter.exportDiagram(graphMLSavePath); + } + + + @Override + public File exportPlantUMLImage(Path plantUMLSavePath) + { + DiagramExporter diagramExporter = new PlantUMLPackageDiagramImageExporter(packageDiagram); + return diagramExporter.exportDiagram(plantUMLSavePath); + } + + + @Override + public File exportPlantUMLText(Path textSavePath) + { + DiagramExporter diagramExporter = new PlantUMLPackageDiagramTextExporter(packageDiagram); + return diagramExporter.exportDiagram(textSavePath); + } + + + @Override + public File saveDiagram(Path graphSavePath) + { + CoordinatesUpdater coordinatesUpdater = new CoordinatesUpdater(packageDiagram); + coordinatesUpdater.updatePackageCoordinates(vertexCollection, graphView); + + DiagramExporter diagramExporter = new JavaFXPackageDiagramExporter(packageDiagram); + return diagramExporter.exportDiagram(graphSavePath); + } + + + @Override + public void loadDiagram(Path graphSavePath) throws JsonParseException + { + JavaFXPackageDiagramLoader javaFXPackageDiagramLoader = new JavaFXPackageDiagramLoader(graphSavePath); + + packageDiagram = new PackageDiagram(); + packageDiagram.createDiagram(javaFXPackageDiagramLoader.loadDiagram()); + } + + + public PackageDiagram getPackageDiagram() + { + return packageDiagram; + } + + @Override + public SmartGraphPanel applyLayout() + { + DiagramGeometry nodesGeometry = packageDiagram.getDiagramGeometry(); + for (Vertex vertex : vertexCollection) + { + if (!nodesGeometry.containsKey(vertex.element())) + { logger.log(Level.INFO, vertex.element()); - continue; + continue; } - Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); - graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); + Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); + graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); } - return graphView; - } - - public SmartGraphPanel applySpecificLayout(String choice){ - DiagramGeometry nodesGeometry = packageDiagramArrangement.applyNewLayout(choice); - for(Vertex vertex : vertexCollection) { - if (!nodesGeometry.containsKey(vertex.element())) { - continue; - } + return graphView; + } + + @Override + public SmartGraphPanel applySpecificLayout(String choice) + { + DiagramGeometry nodesGeometry = packageDiagramArrangement.applyNewLayout(choice); + for (Vertex vertex : vertexCollection) + { + if (!nodesGeometry.containsKey(vertex.element())) + { + continue; + } - Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); - graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); - } + Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element()); + graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1()); + } - return graphView; - } + return graphView; + } } diff --git a/src/main/java/manager/SourceProject.java b/src/main/java/manager/SourceProject.java index e476a00..94edec1 100644 --- a/src/main/java/manager/SourceProject.java +++ b/src/main/java/manager/SourceProject.java @@ -6,24 +6,34 @@ import java.nio.file.Path; -public class SourceProject { - - private final Interpreter interpreter = new Interpreter(); - - public void createClassGraph(Path sourcePackagePath, ClassDiagram classDiagram) { - interpreter.parseProject(sourcePackagePath); - interpreter.convertTreeToGraph(); - classDiagram.setSinkVertices(interpreter.getSinkVertices()); - } - - public void createPackageGraph(Path sourcePackagePath, PackageDiagram packageDiagram) { - interpreter.parseProject(sourcePackagePath); - interpreter.convertTreeToGraph(); - packageDiagram.setVertices(interpreter.getVertices()); - } - - public Interpreter getInterpreter() { - return interpreter; - } +public class SourceProject +{ + + private final Interpreter interpreter = new Interpreter(); + + + public void createClassGraph(Path sourcePackagePath, + ClassDiagram classDiagram) + { + interpreter.parseProject(sourcePackagePath); + interpreter.convertTreeToGraph(); + classDiagram.setSinkVertices(interpreter.getSinkVertices()); + } + + + public void createPackageGraph(Path sourcePackagePath, + PackageDiagram packageDiagram) + { + interpreter.parseProject(sourcePackagePath); + interpreter.convertTreeToGraph(); + packageDiagram.setVertices(interpreter.getVertices()); + } + + // Only used for testing. + // TODO remove it completely. + protected Interpreter getInterpreter() + { + return interpreter; + } } \ No newline at end of file diff --git a/src/main/java/model/diagram/ClassDiagram.java b/src/main/java/model/diagram/ClassDiagram.java index c4c9226..c51870c 100644 --- a/src/main/java/model/diagram/ClassDiagram.java +++ b/src/main/java/model/diagram/ClassDiagram.java @@ -13,81 +13,112 @@ import java.util.Optional; import java.util.Set; -public class ClassDiagram { - - private final Map graphNodes; - private static Map>> diagram; - private static Map sinkVertices; - private static Map> diagramGeometryGraphML; - private static DiagramGeometry diagramGeometry; - - public ClassDiagram() { - this.graphNodes = new HashMap<>(); - } - - public void createNewDiagram(List chosenFilesNames) { - createGraphNodes(chosenFilesNames); - createDiagram(graphNodes.keySet()); - } - - public void createDiagram(Set sinkVertices) { - GraphClassDiagramConverter classDiagramConverter = new GraphClassDiagramConverter(sinkVertices); - diagram = classDiagramConverter.convertGraphToClassDiagram(); - } - - private void createGraphNodes(List chosenFileNames) { - int nodeId = 0; - for (ClassifierVertex classifierVertex : getChosenNodes(chosenFileNames)) { - graphNodes.put(classifierVertex, nodeId); - nodeId++; - } - } - - private List getChosenNodes(List chosenClassesNames) { - List chosenClasses = new ArrayList<>(); - for (String chosenClass: chosenClassesNames) { - Optional optionalSinkVertex = sinkVertices.values() - .stream() - .filter(sinkVertex -> sinkVertex.getName().equals(chosenClass)) - .findFirst(); - if (optionalSinkVertex.isEmpty()) { - continue; - } - chosenClasses.add(optionalSinkVertex.get()); - } - return chosenClasses; - } - - public void setSinkVertices(Map sinkVertices) { - ClassDiagram.sinkVertices = sinkVertices; - } - - public void setDiagram(Map>> diagram) { - ClassDiagram.diagram = diagram; - } - - public void setGraphMLDiagramGeometry(Map> diagramGeometryGraphML) { - ClassDiagram.diagramGeometryGraphML = diagramGeometryGraphML; - } - - public void setDiagramGeometry(DiagramGeometry diagramGeometry) { - ClassDiagram.diagramGeometry = diagramGeometry; - } - - public Map>> getDiagram() { - return diagram; - } - - public Map getGraphNodes() { - return graphNodes; - } - - public Map> getGraphMLDiagramGeometry() { - return diagramGeometryGraphML; - } - - public DiagramGeometry getDiagramGeometry() { - return diagramGeometry; - } +public class ClassDiagram +{ + + private final Map graphNodes; + private Map>> diagram; + private Map sinkVertices; + private Map> diagramGeometryGraphML; + private DiagramGeometry diagramGeometry; + + + public ClassDiagram() + { + this.graphNodes = new HashMap<>(); + } + + + public void createNewDiagram(List chosenFilesNames) + { + createGraphNodes(chosenFilesNames); + createDiagram(graphNodes.keySet()); + } + + + public void createDiagram(Set sinkVertices) + { + GraphClassDiagramConverter classDiagramConverter = new GraphClassDiagramConverter(sinkVertices); + diagram = classDiagramConverter.convertGraphToClassDiagram(); + } + + + private void createGraphNodes(List chosenFileNames) + { + int nodeId = 0; + for (ClassifierVertex classifierVertex : getChosenNodes(chosenFileNames)) + { + graphNodes.put(classifierVertex, nodeId); + nodeId++; + } + } + + + private List getChosenNodes(List chosenClassesNames) + { + List chosenClasses = new ArrayList<>(); + for (String chosenClass : chosenClassesNames) + { + Optional optionalSinkVertex = sinkVertices + .values() + .stream() + .filter(sinkVertex -> sinkVertex.getName().equals(chosenClass)) + .findFirst(); + if (optionalSinkVertex.isEmpty()) + { + continue; + } + chosenClasses.add(optionalSinkVertex.get()); + } + return chosenClasses; + } + + + public void setSinkVertices(Map sinkVertices) + { + this.sinkVertices = sinkVertices; + } + + + public void setDiagram(Map>> diagram) + { + this.diagram = diagram; + } + + + public void setGraphMLDiagramGeometry(Map> diagramGeometryGraphML) + { + this.diagramGeometryGraphML = diagramGeometryGraphML; + } + + + public void setDiagramGeometry(DiagramGeometry diagramGeometry) + { + this.diagramGeometry = diagramGeometry; + } + + + public Map>> getDiagram() + { + return diagram; + } + + + public Map getGraphNodes() + { + return graphNodes; + } + + + public Map> getGraphMLDiagramGeometry() + { + return diagramGeometryGraphML; + } + + + public DiagramGeometry getDiagramGeometry() + { + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/GraphClassDiagramConverter.java b/src/main/java/model/diagram/GraphClassDiagramConverter.java index 9527311..1afe767 100644 --- a/src/main/java/model/diagram/GraphClassDiagramConverter.java +++ b/src/main/java/model/diagram/GraphClassDiagramConverter.java @@ -8,27 +8,35 @@ import java.util.Map; import java.util.Set; -public class GraphClassDiagramConverter { - - private final Map>> adjacencyList; - private final Set sinkVertices; - - public GraphClassDiagramConverter(Set sinkVertices) { - this.sinkVertices = sinkVertices; - adjacencyList = new HashMap<>(); - } - - public Map>> convertGraphToClassDiagram() { - for (ClassifierVertex classifierVertex : sinkVertices) { - adjacencyList.put(classifierVertex, new HashSet<>()); - for (Arc arc: classifierVertex.getArcs()) { - if (!sinkVertices.contains(arc.targetVertex())) { - continue; - } - adjacencyList.get(arc.sourceVertex()).add(arc); - } - } - return adjacencyList; - } +public class GraphClassDiagramConverter +{ + + private final Map>> adjacencyList; + private final Set sinkVertices; + + + public GraphClassDiagramConverter(Set sinkVertices) + { + this.sinkVertices = sinkVertices; + adjacencyList = new HashMap<>(); + } + + + public Map>> convertGraphToClassDiagram() + { + for (ClassifierVertex classifierVertex : sinkVertices) + { + adjacencyList.put(classifierVertex, new HashSet<>()); + for (Arc arc : classifierVertex.getArcs()) + { + if (!sinkVertices.contains(arc.targetVertex())) + { + continue; + } + adjacencyList.get(arc.sourceVertex()).add(arc); + } + } + return adjacencyList; + } } diff --git a/src/main/java/model/diagram/GraphPackageDiagramConverter.java b/src/main/java/model/diagram/GraphPackageDiagramConverter.java index 7479498..1ae36db 100644 --- a/src/main/java/model/diagram/GraphPackageDiagramConverter.java +++ b/src/main/java/model/diagram/GraphPackageDiagramConverter.java @@ -8,28 +8,36 @@ import java.util.Map; import java.util.Set; -public class GraphPackageDiagramConverter { - - private final Map>> adjacencyList; - private final Set vertices; - - public GraphPackageDiagramConverter(Set vertices) { - this.vertices = vertices; - adjacencyList = new HashMap<>(); - } - - public Map>> convertGraphToPackageDiagram() { - for (PackageVertex vertex: vertices) { - adjacencyList.put(vertex, new HashSet<>()); - for (Arc arc: vertex.getArcs()) { - if (!vertices.contains(arc.targetVertex())) { - continue; - } - adjacencyList.get(arc.sourceVertex()).add(arc); - } - } - - return adjacencyList; - } +public class GraphPackageDiagramConverter +{ + + private final Map>> adjacencyList; + private final Set vertices; + + + public GraphPackageDiagramConverter(Set vertices) + { + this.vertices = vertices; + adjacencyList = new HashMap<>(); + } + + + public Map>> convertGraphToPackageDiagram() + { + for (PackageVertex vertex : vertices) + { + adjacencyList.put(vertex, new HashSet<>()); + for (Arc arc : vertex.getArcs()) + { + if (!vertices.contains(arc.targetVertex())) + { + continue; + } + adjacencyList.get(arc.sourceVertex()).add(arc); + } + } + + return adjacencyList; + } } diff --git a/src/main/java/model/diagram/PackageDiagram.java b/src/main/java/model/diagram/PackageDiagram.java index 6f854dd..7743dcc 100644 --- a/src/main/java/model/diagram/PackageDiagram.java +++ b/src/main/java/model/diagram/PackageDiagram.java @@ -8,77 +8,105 @@ import java.nio.file.Path; import java.util.*; -public class PackageDiagram { - - private final Map graphNodes; - private static Map>> diagram; - private static Map vertices; - private static Map> diagramGeometryGraphML; - private static DiagramGeometry diagramGeometry; - - public PackageDiagram() { - this.graphNodes = new HashMap<>(); - } - - public void createNewDiagram(List chosenFileNames) { - createGraphNodes(chosenFileNames); - createDiagram(graphNodes.keySet()); - } - - public void createDiagram(Set vertices) { - GraphPackageDiagramConverter packageDiagramConverter = new GraphPackageDiagramConverter(vertices); - diagram = packageDiagramConverter.convertGraphToPackageDiagram(); - } - - private void createGraphNodes(List chosenFileNames) { - int nodeId = 0; - for (PackageVertex vertex: getChosenNodes(chosenFileNames)) { - graphNodes.put(vertex, nodeId); - nodeId++; - } - } - - public List getChosenNodes(List chosenPackagesNames) { - List chosenPackages = new ArrayList<>(); - for (String chosenPackage: chosenPackagesNames) { - Optional vertex = vertices.values() - .stream() - .filter(vertex1 -> vertex1.getName().equals(chosenPackage)) - .findFirst(); - if (vertex.isEmpty()) { - continue; - } - chosenPackages.add(vertex.get()); - } - return chosenPackages; - } - - public void setVertices(Map vertices) { - PackageDiagram.vertices = vertices; - } - - public void setGraphMLDiagramGeometry(Map> diagramGeometryGraphML) { - PackageDiagram.diagramGeometryGraphML = diagramGeometryGraphML; - } - - public void setDiagramGeometry(DiagramGeometry diagramGeometry) { - PackageDiagram.diagramGeometry = diagramGeometry; - } - - public Map getGraphNodes() { - return graphNodes; - } - - public Map>> getDiagram() { - return diagram; - } - - public Map> getGraphMLDiagramGeometry() { - return diagramGeometryGraphML; - } - - public DiagramGeometry getDiagramGeometry() { - return diagramGeometry; - } +public class PackageDiagram +{ + + private final Map graphNodes; + private Map>> diagram; + private Map vertices; + private Map> diagramGeometryGraphML; + private DiagramGeometry diagramGeometry; + + + public PackageDiagram() + { + this.graphNodes = new HashMap<>(); + } + + + public void createNewDiagram(List chosenFileNames) + { + createGraphNodes(chosenFileNames); + createDiagram(graphNodes.keySet()); + } + + + public void createDiagram(Set vertices) + { + GraphPackageDiagramConverter packageDiagramConverter = new GraphPackageDiagramConverter(vertices); + diagram = packageDiagramConverter.convertGraphToPackageDiagram(); + } + + + private void createGraphNodes(List chosenFileNames) + { + int nodeId = 0; + for (PackageVertex vertex : getChosenNodes(chosenFileNames)) + { + graphNodes.put(vertex, nodeId); + nodeId++; + } + } + + + public List getChosenNodes(List chosenPackagesNames) + { + List chosenPackages = new ArrayList<>(); + for (String chosenPackage : chosenPackagesNames) + { + Optional vertex = vertices.values() + .stream() + .filter(vertex1 -> vertex1.getName().equals(chosenPackage)) + .findFirst(); + if (vertex.isEmpty()) + { + continue; + } + chosenPackages.add(vertex.get()); + } + return chosenPackages; + } + + + public void setVertices(Map vertices) + { + this.vertices = vertices; + } + + + public void setGraphMLDiagramGeometry(Map> diagramGeometryGraphML) + { + this.diagramGeometryGraphML = diagramGeometryGraphML; + } + + + public void setDiagramGeometry(DiagramGeometry diagramGeometry) + { + this.diagramGeometry = diagramGeometry; + } + + + public Map getGraphNodes() + { + return graphNodes; + } + + + public Map>> getDiagram() + { + return diagram; + } + + + public Map> getGraphMLDiagramGeometry() + { + return diagramGeometryGraphML; + } + + + public DiagramGeometry getDiagramGeometry() + { + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/ShadowCleaner.java b/src/main/java/model/diagram/ShadowCleaner.java index cebd1f1..8982418 100644 --- a/src/main/java/model/diagram/ShadowCleaner.java +++ b/src/main/java/model/diagram/ShadowCleaner.java @@ -6,59 +6,74 @@ import java.util.*; -public class ShadowCleaner { +public class ShadowCleaner +{ - // TODO Replace with the new ArcType Map - private static final List strongerToWeakerArcTypes = List.of(ArcType.EXTENSION, - ArcType.IMPLEMENTATION, - ArcType.AGGREGATION, - ArcType.ASSOCIATION); + // TODO Replace with the new ArcType Map. + private static final List strongerToWeakerArcTypes = List.of(ArcType.EXTENSION, + ArcType.IMPLEMENTATION, + ArcType.AGGREGATION, + ArcType.ASSOCIATION); - private final ClassDiagram classDiagram; + private final ClassDiagram classDiagram; - public ShadowCleaner(ClassDiagram diagram) { - this.classDiagram = diagram; - } - public Map>> shadowWeakRelationships() { - for (Set> arcs: classDiagram.getDiagram().values()) { - Map>> shadowedArcs = new HashMap<>(); - for (Arc arc: arcs) { - shadowedArcs.computeIfAbsent(arc.targetVertex(), - sinkVertex -> new ArrayList<>()).add(arc); - } + public ShadowCleaner(ClassDiagram diagram) + { + this.classDiagram = diagram; + } - for (Map.Entry>> arc: shadowedArcs.entrySet()) { - if (!(arc.getValue().size() > 1)) { - continue; - } - for (ArcType arcType: strongerToWeakerArcTypes) { - if (!doesStrongerRelationshipExist(arc.getValue(), arcType)) { - continue; - } + + public Map>> shadowWeakRelationships() + { + for (Set> arcs : classDiagram.getDiagram().values()) + { + Map>> shadowedArcs = new HashMap<>(); + for (Arc arc : arcs) + { + shadowedArcs.computeIfAbsent(arc.targetVertex(), + sinkVertex -> new ArrayList<>()).add(arc); + } + + for (Map.Entry>> arc : shadowedArcs.entrySet()) + { + if (!(arc.getValue().size() > 1)) + { + continue; + } + for (ArcType arcType : strongerToWeakerArcTypes) + { + if (!doesStrongerRelationshipExist(arc.getValue(), arcType)) + { + continue; + } removeWeakerRelationships(arcs, arc.getKey(), arcType); break; } - } - } + } + } + + return classDiagram.getDiagram(); + } + - return classDiagram.getDiagram(); - } + private boolean doesStrongerRelationshipExist(List> arc, + ArcType arcType) + { + Optional> inheritanceArc = arc + .stream() + .filter(sinkVertexArc -> sinkVertexArc.arcType().equals(arcType)) + .findFirst(); + return inheritanceArc.isPresent(); + } - private boolean doesStrongerRelationshipExist(List> arc, - ArcType arcType) { - Optional> inheritanceArc = arc - .stream() - .filter(sinkVertexArc -> sinkVertexArc.arcType().equals(arcType)) - .findFirst(); - return inheritanceArc.isPresent(); - } - private void removeWeakerRelationships(Set> arcs, - ClassifierVertex classifierVertex, - ArcType arcType) { - arcs.removeIf(arc -> - arc.targetVertex().equals(classifierVertex) && - !arc.arcType().equals(arcType)); - } + private void removeWeakerRelationships(Set> arcs, + ClassifierVertex classifierVertex, + ArcType arcType) + { + arcs.removeIf(arc -> + arc.targetVertex().equals(classifierVertex) && + !arc.arcType().equals(arcType)); + } } diff --git a/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java b/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java index dffd5c9..764c130 100644 --- a/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java +++ b/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java @@ -21,86 +21,106 @@ import java.util.Map; import java.util.Set; -public class ClassDiagramArrangementManager implements DiagramArrangementManagerInterface{ - - public static final LayoutAlgorithmType LAYOUT_ALGORITHM_TYPE = LayoutAlgorithmType.SUGIYAMA; - public static final int WIDTH = 1500; - public static final int HEIGHT = 1000; - private final ClassDiagram classDiagram; - private final Graph graph; - - public ClassDiagramArrangementManager(ClassDiagram classDiagram) { - this.classDiagram = classDiagram; - this.graph = createGraphWithStrings(); - } - - @Override - public Map> arrangeGraphMLDiagram() { - Map> nodesGeometryGraphML = new HashMap<>(); - Graph graph = createGraph(); - AbstractLayout layout = new SpringLayout<>(graph); - layout.setSize(new Dimension(WIDTH, HEIGHT)); - for (Integer i : classDiagram.getGraphNodes().values()) { - nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i))); - } - - return nodesGeometryGraphML; - } - - @Override - public DiagramGeometry arrangeDiagram() { - LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(LAYOUT_ALGORITHM_TYPE); - layoutAlgorithm.setGraph(graph); - return layoutAlgorithm.arrangeDiagram(); - } - - @Override - public DiagramGeometry applyNewLayout(String algorithmType){ - LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.valueOf(algorithmType.toUpperCase()); - LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType); - layout.setGraph(graph); - return layout.arrangeDiagram(); - } - - private Graph createGraph(){ - Graph graph = new SparseGraph<>(); - for (Integer nodeId: classDiagram.getGraphNodes().values()) { - graph.addVertex(nodeId); - } - - List> arcs = new ArrayList<>(); - for (Set> arcSet: classDiagram.getDiagram().values()) { - arcs.addAll(arcSet); - } - - for (Arc arc: arcs) { - graph.addEdge(classDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + classDiagram.getGraphNodes().get(arc.targetVertex()), - classDiagram.getGraphNodes().get(arc.sourceVertex()), - classDiagram.getGraphNodes().get(arc.targetVertex()), - EdgeType.DIRECTED); - } - - return graph; - } - - private Graph createGraphWithStrings(){ - Graph graph = new SparseGraph<>(); - for (ClassifierVertex vertex: classDiagram.getGraphNodes().keySet()) { - graph.addVertex(vertex.getName()); - } - - List> arcs = new ArrayList<>(); - for (Set> arcSet: classDiagram.getDiagram().values()) { - arcs.addAll(arcSet); - } - - for (Arc arc: arcs) { - graph.addEdge(arc.sourceVertex().getName() + " " + arc.targetVertex().getName(), - arc.sourceVertex().getName(), - arc.targetVertex().getName(), EdgeType.DIRECTED); - } - - return graph; - } +public class ClassDiagramArrangementManager implements DiagramArrangementManagerInterface +{ + + public static final LayoutAlgorithmType LAYOUT_ALGORITHM_TYPE = LayoutAlgorithmType.SUGIYAMA; + public static final int WIDTH = 1500; + public static final int HEIGHT = 1000; + private final ClassDiagram classDiagram; + private final Graph graph; + + + public ClassDiagramArrangementManager(ClassDiagram classDiagram) + { + this.classDiagram = classDiagram; + graph = createGraphWithStrings(); + } + + + @Override + public Map> arrangeGraphMLDiagram() + { + Map> nodesGeometryGraphML = new HashMap<>(); + Graph graph = createGraph(); + AbstractLayout layout = new SpringLayout<>(graph); + layout.setSize(new Dimension(WIDTH, HEIGHT)); + for (Integer i : classDiagram.getGraphNodes().values()) + { + nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i))); + } + + return nodesGeometryGraphML; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(LAYOUT_ALGORITHM_TYPE); + layoutAlgorithm.setGraph(graph); + return layoutAlgorithm.arrangeDiagram(); + } + + + @Override + public DiagramGeometry applyNewLayout(String algorithmType) + { + LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.get(algorithmType); + LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType); + layout.setGraph(graph); + return layout.arrangeDiagram(); + } + + + private Graph createGraph() + { + Graph graph = new SparseGraph<>(); + for (Integer nodeId : classDiagram.getGraphNodes().values()) + { + graph.addVertex(nodeId); + } + + List> arcs = new ArrayList<>(); + for (Set> arcSet : classDiagram.getDiagram().values()) + { + arcs.addAll(arcSet); + } + + for (Arc arc : arcs) + { + graph.addEdge(classDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + classDiagram.getGraphNodes().get(arc.targetVertex()), + classDiagram.getGraphNodes().get(arc.sourceVertex()), + classDiagram.getGraphNodes().get(arc.targetVertex()), + EdgeType.DIRECTED); + } + + return graph; + } + + + private Graph createGraphWithStrings() + { + Graph graph = new SparseGraph<>(); + for (ClassifierVertex vertex : classDiagram.getGraphNodes().keySet()) + { + graph.addVertex(vertex.getName()); + } + + List> arcs = new ArrayList<>(); + for (Set> arcSet : classDiagram.getDiagram().values()) + { + arcs.addAll(arcSet); + } + + for (Arc arc : arcs) + { + graph.addEdge(arc.sourceVertex().getName() + " " + arc.targetVertex().getName(), + arc.sourceVertex().getName(), + arc.targetVertex().getName(), EdgeType.DIRECTED); + } + + return graph; + } } \ No newline at end of file diff --git a/src/main/java/model/diagram/arrangement/DiagramArrangementManagerInterface.java b/src/main/java/model/diagram/arrangement/DiagramArrangementManagerInterface.java index 0ffefa1..f085df5 100644 --- a/src/main/java/model/diagram/arrangement/DiagramArrangementManagerInterface.java +++ b/src/main/java/model/diagram/arrangement/DiagramArrangementManagerInterface.java @@ -6,25 +6,24 @@ import java.util.Map; -public interface DiagramArrangementManagerInterface { - - /** - * This method is responsible for the arrangement of the graph by creating a graph of the Jung library - * and using the SpringLayout algorithm. - * - * @return a Map with the nodes' id as key and geometry(x,y) as value - */ - Map> arrangeGraphMLDiagram(); - - /** - * This method is responsible for the arrangement of the graph by creating a graph of the Jung library - * and using different layout algorithms. - * - * @return a {@link DiagramGeometry} object which represents the diagram's geometry - */ - DiagramGeometry arrangeDiagram(); - - // TODO JavaDoc - DiagramGeometry applyNewLayout(String choice); +public interface DiagramArrangementManagerInterface +{ + + /** + * This method is responsible for the arrangement of the graph by creating a graph of the Jung library and using the SpringLayout algorithm. + * + * @return a Map with the nodes' id as key and geometry(x,y) as value + */ + Map> arrangeGraphMLDiagram(); + + /** + * This method is responsible for the arrangement of the graph by creating a graph of the Jung library and using different layout algorithms. + * + * @return a {@link DiagramGeometry} object which represents the diagram's geometry + */ + DiagramGeometry arrangeDiagram(); + + // TODO JavaDoc + DiagramGeometry applyNewLayout(String choice); } diff --git a/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java b/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java index fb0ab66..c67a414 100644 --- a/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java +++ b/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java @@ -21,87 +21,107 @@ import java.util.Map; import java.util.Set; -public class PackageDiagramArrangementManager implements DiagramArrangementManagerInterface { - - public static final LayoutAlgorithmType LAYOUT_ALGORITHM_TYPE = LayoutAlgorithmType.SUGIYAMA; - public static final int WIDTH = 1500; - public static final int HEIGHT = 1000; - private final Graph graph; - private final PackageDiagram packageDiagram; - - public PackageDiagramArrangementManager(PackageDiagram packageDiagram) { - this.packageDiagram = packageDiagram; - this.graph = populatePackageGraphWithStrings(); - } - - @Override - public Map> arrangeGraphMLDiagram() { - Map> nodesGeometryGraphML = new HashMap<>(); - Graph graph = populatePackageGraph(); - AbstractLayout layout = new SpringLayout<>(graph); - layout.setSize(new Dimension(WIDTH, HEIGHT)); - for (Integer i : packageDiagram.getGraphNodes().values()) { - nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i))); - } - - return nodesGeometryGraphML; - } - - @Override - public DiagramGeometry arrangeDiagram() { - LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(LAYOUT_ALGORITHM_TYPE); - layoutAlgorithm.setGraph(graph); - return layoutAlgorithm.arrangeDiagram(); - } - - @Override - public DiagramGeometry applyNewLayout(String algorithmType){ - LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.valueOf(algorithmType.toUpperCase()); - LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType); - layout.setGraph(graph); - return layout.arrangeDiagram(); - } - - private Graph populatePackageGraph() { - Graph graph = new SparseGraph<>(); - for (Integer i : packageDiagram.getGraphNodes().values()) { - graph.addVertex(i); - } - - List> arcs = new ArrayList<>(); - for (Set> arcSet: packageDiagram.getDiagram().values()) { - arcs.addAll(arcSet); - } - - for (Arc arc: arcs) { - graph.addEdge(packageDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + packageDiagram.getGraphNodes().get(arc.targetVertex()), - packageDiagram.getGraphNodes().get(arc.sourceVertex()), - packageDiagram.getGraphNodes().get(arc.targetVertex()), EdgeType.DIRECTED); - } - - return graph; - } - - private Graph populatePackageGraphWithStrings(){ - Graph graph = new SparseGraph<>(); - for (PackageVertex vertex: packageDiagram.getGraphNodes().keySet()) { - graph.addVertex(vertex.getName()); - } - - List> arcs = new ArrayList<>(); - for (Set> arcSet: packageDiagram.getDiagram().values()) { - arcs.addAll(arcSet); - } - - for (Arc arc: arcs) { - graph.addEdge(String.join(" ", - arc.sourceVertex().getName(), - arc.targetVertex().getName()), - arc.sourceVertex().getName(), - arc.targetVertex().getName(), EdgeType.DIRECTED); - } - - return graph; - } +public class PackageDiagramArrangementManager implements DiagramArrangementManagerInterface +{ + + public static final LayoutAlgorithmType LAYOUT_ALGORITHM_TYPE = LayoutAlgorithmType.SUGIYAMA; + public static final int WIDTH = 1500; + public static final int HEIGHT = 1000; + private final Graph graph; + private final PackageDiagram packageDiagram; + + + public PackageDiagramArrangementManager(PackageDiagram packageDiagram) + { + this.packageDiagram = packageDiagram; + graph = populatePackageGraphWithStrings(); + } + + + @Override + public Map> arrangeGraphMLDiagram() + { + Map> nodesGeometryGraphML = new HashMap<>(); + Graph graph = populatePackageGraph(); + AbstractLayout layout = new SpringLayout<>(graph); + layout.setSize(new Dimension(WIDTH, HEIGHT)); + for (Integer i : packageDiagram.getGraphNodes().values()) + { + nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i))); + } + + return nodesGeometryGraphML; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(LAYOUT_ALGORITHM_TYPE); + layoutAlgorithm.setGraph(graph); + return layoutAlgorithm.arrangeDiagram(); + } + + + @Override + public DiagramGeometry applyNewLayout(String algorithmType) + { + LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.get(algorithmType); + LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType); + layout.setGraph(graph); + return layout.arrangeDiagram(); + } + + + private Graph populatePackageGraph() + { + Graph graph = new SparseGraph<>(); + for (Integer i : packageDiagram.getGraphNodes().values()) + { + graph.addVertex(i); + } + + List> arcs = new ArrayList<>(); + for (Set> arcSet : packageDiagram.getDiagram().values()) + { + arcs.addAll(arcSet); + } + + for (Arc arc : arcs) + { + graph.addEdge(packageDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + packageDiagram.getGraphNodes().get(arc.targetVertex()), + packageDiagram.getGraphNodes().get(arc.sourceVertex()), + packageDiagram.getGraphNodes().get(arc.targetVertex()), EdgeType.DIRECTED); + } + + return graph; + } + + + private Graph populatePackageGraphWithStrings() + { + Graph graph = new SparseGraph<>(); + for (PackageVertex vertex : packageDiagram.getGraphNodes().keySet()) + { + graph.addVertex(vertex.getName()); + } + + List> arcs = new ArrayList<>(); + for (Set> arcSet : packageDiagram.getDiagram().values()) + { + arcs.addAll(arcSet); + } + + for (Arc arc : arcs) + { + graph.addEdge(String.join(" ", + arc.sourceVertex().getName(), + arc.targetVertex().getName()), + arc.sourceVertex().getName(), + arc.targetVertex().getName(), EdgeType.DIRECTED); + } + + return graph; + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java b/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java index b6184ea..fb2599c 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java +++ b/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java @@ -7,45 +7,55 @@ import model.diagram.arrangement.geometry.DiagramGeometry; import model.diagram.arrangement.geometry.GeometryNode; -public class AdvancedFruchtermanReingold implements LayoutAlgorithm{ - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; +public class AdvancedFruchtermanReingold implements LayoutAlgorithm +{ + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; - private Graph graph; + private Graph graph; - @Override - public void setGraph(Graph graph) { - this.graph = graph; - } - @Override - public DiagramGeometry arrangeDiagram() { - double maxXdistance = 0.0; - double maxYdistance = 0.0; - DiagramGeometry diagramGeometry = new DiagramGeometry(); - AbstractLayout layout = new FRLayout2<>(graph); - @SuppressWarnings("unused") - VisualizationViewer vv = new VisualizationViewer(layout); - // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); - for (String vertex : graph.getVertices()) { - GeometryNode geometryNode = new GeometryNode(vertex); - double x = layout.getX(vertex); - double y = layout.getY(vertex); - if (x < MIN_X_WINDOW_VALUE) { - double difference = MIN_X_WINDOW_VALUE - x; - if (difference > maxXdistance) { - maxXdistance = difference; - } - } - if (y < MIN_Y_WINDOW_VALUE) { - double difference = MIN_Y_WINDOW_VALUE - y; - if (difference > maxYdistance) { - maxYdistance = difference; - } - } - diagramGeometry.addGeometry(geometryNode, x, y); - } - diagramGeometry.correctPositions(maxXdistance, maxYdistance); - return diagramGeometry; - } + @Override + public void setGraph(Graph graph) + { + this.graph = graph; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + double maxXdistance = 0.0; + double maxYdistance = 0.0; + DiagramGeometry diagramGeometry = new DiagramGeometry(); + AbstractLayout layout = new FRLayout2<>(graph); + @SuppressWarnings("unused") + VisualizationViewer vv = new VisualizationViewer<>(layout); + // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); + for (String vertex : graph.getVertices()) + { + GeometryNode geometryNode = new GeometryNode(vertex); + double x = layout.getX(vertex); + double y = layout.getY(vertex); + if (x < MIN_X_WINDOW_VALUE) + { + double difference = MIN_X_WINDOW_VALUE - x; + if (difference > maxXdistance) + { + maxXdistance = difference; + } + } + if (y < MIN_Y_WINDOW_VALUE) + { + double difference = MIN_Y_WINDOW_VALUE - y; + if (difference > maxYdistance) + { + maxYdistance = difference; + } + } + diagramGeometry.addGeometry(geometryNode, x, y); + } + diagramGeometry.correctPositions(maxXdistance, maxYdistance); + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java b/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java index 99fe725..5d137b8 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java +++ b/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java @@ -6,47 +6,57 @@ import model.diagram.arrangement.geometry.DiagramGeometry; import model.diagram.arrangement.geometry.GeometryNode; -public class AdvancedSpring implements LayoutAlgorithm{ - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; +public class AdvancedSpring implements LayoutAlgorithm +{ + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; - private Graph graph; + private Graph graph; - @Override - public void setGraph(Graph graph) { - this.graph = graph; - } - @Override - public DiagramGeometry arrangeDiagram() { - double maxXdistance = 0.0; - double maxYdistance = 0.0; - DiagramGeometry diagramGeometry = new DiagramGeometry(); - SpringLayout2 layout = new SpringLayout2<>(graph); - layout.setForceMultiplier(0.1); - layout.setRepulsionRange(500); - @SuppressWarnings("unused") - VisualizationViewer vv = new VisualizationViewer(layout); - // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); - for (String vertex : graph.getVertices()) { - GeometryNode geometryNode = new GeometryNode(vertex); - double x = layout.getX(vertex); - double y = layout.getY(vertex); - if (x < MIN_X_WINDOW_VALUE) { - double difference = MIN_X_WINDOW_VALUE - x; - if (difference > maxXdistance) { - maxXdistance = difference; - } - } - if (y < MIN_Y_WINDOW_VALUE) { - double difference = MIN_Y_WINDOW_VALUE - y; - if (difference > maxYdistance) { - maxYdistance = difference; - } - } - diagramGeometry.addGeometry(geometryNode, x, y); - } - diagramGeometry.correctPositions(maxXdistance, maxYdistance); - return diagramGeometry; - } + @Override + public void setGraph(Graph graph) + { + this.graph = graph; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + double maxXdistance = 0.0; + double maxYdistance = 0.0; + DiagramGeometry diagramGeometry = new DiagramGeometry(); + SpringLayout2 layout = new SpringLayout2<>(graph); + layout.setForceMultiplier(0.1); + layout.setRepulsionRange(500); + @SuppressWarnings("unused") + VisualizationViewer vv = new VisualizationViewer<>(layout); + // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); + for (String vertex : graph.getVertices()) + { + GeometryNode geometryNode = new GeometryNode(vertex); + double x = layout.getX(vertex); + double y = layout.getY(vertex); + if (x < MIN_X_WINDOW_VALUE) + { + double difference = MIN_X_WINDOW_VALUE - x; + if (difference > maxXdistance) + { + maxXdistance = difference; + } + } + if (y < MIN_Y_WINDOW_VALUE) + { + double difference = MIN_Y_WINDOW_VALUE - y; + if (difference > maxYdistance) + { + maxYdistance = difference; + } + } + diagramGeometry.addGeometry(geometryNode, x, y); + } + diagramGeometry.correctPositions(maxXdistance, maxYdistance); + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java b/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java index 2dc93be..8609f17 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java +++ b/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java @@ -7,46 +7,56 @@ import model.diagram.arrangement.geometry.DiagramGeometry; import model.diagram.arrangement.geometry.GeometryNode; -public class FruchtermanReingold implements LayoutAlgorithm{ - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; - - private Graph graph; - - @Override - public void setGraph(Graph graph) { - this.graph = graph; - } - - @Override - public DiagramGeometry arrangeDiagram() { - double maxXdistance = 0.0; - double maxYdistance = 0.0; - DiagramGeometry diagramGeometry = new DiagramGeometry(); - AbstractLayout layout = new FRLayout<>(graph); - @SuppressWarnings("unused") - VisualizationViewer vv = new VisualizationViewer(layout); - // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); - for (String vertex : graph.getVertices()) { - GeometryNode geometryNode = new GeometryNode(vertex); - double x = layout.getX(vertex); - double y = layout.getY(vertex); - if (x < MIN_X_WINDOW_VALUE) { - double difference = MIN_X_WINDOW_VALUE - x; - if (difference > maxXdistance) { - maxXdistance = difference; - } - } - if (y < MIN_Y_WINDOW_VALUE) { - double difference = MIN_Y_WINDOW_VALUE - y; - if (difference > maxYdistance) { - maxYdistance = difference; - } - } - diagramGeometry.addGeometry(geometryNode, x, y); - } - diagramGeometry.correctPositions(maxXdistance, maxYdistance); - return diagramGeometry; - } +public class FruchtermanReingold implements LayoutAlgorithm +{ + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; + + private Graph graph; + + + @Override + public void setGraph(Graph graph) + { + this.graph = graph; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + double maxXdistance = 0.0; + double maxYdistance = 0.0; + DiagramGeometry diagramGeometry = new DiagramGeometry(); + AbstractLayout layout = new FRLayout<>(graph); + @SuppressWarnings("unused") + VisualizationViewer vv = new VisualizationViewer<>(layout); + // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); + for (String vertex : graph.getVertices()) + { + GeometryNode geometryNode = new GeometryNode(vertex); + double x = layout.getX(vertex); + double y = layout.getY(vertex); + if (x < MIN_X_WINDOW_VALUE) + { + double difference = MIN_X_WINDOW_VALUE - x; + if (difference > maxXdistance) + { + maxXdistance = difference; + } + } + if (y < MIN_Y_WINDOW_VALUE) + { + double difference = MIN_Y_WINDOW_VALUE - y; + if (difference > maxYdistance) + { + maxYdistance = difference; + } + } + diagramGeometry.addGeometry(geometryNode, x, y); + } + diagramGeometry.correctPositions(maxXdistance, maxYdistance); + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java b/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java index 36311ab..f1a5f13 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java +++ b/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java @@ -8,51 +8,61 @@ import java.awt.*; -public class KamadaKawai implements LayoutAlgorithm{ - - private final static int GRAPH_X_SIZE = 1200; - private final static int GRAPH_Y_SIZE = 725; - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; - - private Graph graph; - - @Override - public void setGraph(Graph graph) { - this.graph = graph; - } - - @Override - public DiagramGeometry arrangeDiagram() { - double maxXdistance = 0.0; - double maxYdistance = 0.0; - DiagramGeometry diagramGeometry = new DiagramGeometry(); - KKLayout layout = new KKLayout<>(graph); - layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); - layout.setLengthFactor(1.5); - @SuppressWarnings("unused") - VisualizationViewer vv = new VisualizationViewer(layout); - // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); - for (String vertex : graph.getVertices()) { - GeometryNode geometryNode = new GeometryNode(vertex); - double x = layout.getX(vertex); - double y = layout.getY(vertex); - if (x < MIN_X_WINDOW_VALUE) { - double difference = MIN_X_WINDOW_VALUE - x; - if (difference > maxXdistance) { - maxXdistance = difference; - } - } - if (y < MIN_Y_WINDOW_VALUE) { - double difference = MIN_Y_WINDOW_VALUE - y; - if (difference > maxYdistance) { - maxYdistance = difference; - } - } - diagramGeometry.addGeometry(geometryNode, x, y); - } - diagramGeometry.correctPositions(maxXdistance, maxYdistance); - return diagramGeometry; - } +public class KamadaKawai implements LayoutAlgorithm +{ + + private final static int GRAPH_X_SIZE = 1200; + private final static int GRAPH_Y_SIZE = 725; + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; + + private Graph graph; + + + @Override + public void setGraph(Graph graph) + { + this.graph = graph; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + double maxXdistance = 0.0; + double maxYdistance = 0.0; + DiagramGeometry diagramGeometry = new DiagramGeometry(); + KKLayout layout = new KKLayout<>(graph); + layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); + layout.setLengthFactor(1.5); + @SuppressWarnings("unused") + VisualizationViewer vv = new VisualizationViewer<>(layout); + // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); + for (String vertex : graph.getVertices()) + { + GeometryNode geometryNode = new GeometryNode(vertex); + double x = layout.getX(vertex); + double y = layout.getY(vertex); + if (x < MIN_X_WINDOW_VALUE) + { + double difference = MIN_X_WINDOW_VALUE - x; + if (difference > maxXdistance) + { + maxXdistance = difference; + } + } + if (y < MIN_Y_WINDOW_VALUE) + { + double difference = MIN_Y_WINDOW_VALUE - y; + if (difference > maxYdistance) + { + maxYdistance = difference; + } + } + diagramGeometry.addGeometry(geometryNode, x, y); + } + diagramGeometry.correctPositions(maxXdistance, maxYdistance); + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java index fe0edb3..1e3d71e 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java +++ b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java @@ -3,16 +3,18 @@ import edu.uci.ics.jung.graph.Graph; import model.diagram.arrangement.geometry.DiagramGeometry; -public interface LayoutAlgorithm { - // TODO Update JavaDoc - /** - * This method is responsible for the arrangement of the graph by creating a graph of the Jung library - * and using this graph's coordinates in our front end. - * - * @return a {@link DiagramGeometry} object which represents the diagram's geometry - */ - DiagramGeometry arrangeDiagram(); +public interface LayoutAlgorithm +{ + // TODO Update JavaDoc - // TODO JavaDoc - void setGraph(Graph graph); + /** + * This method is responsible for the arrangement of the graph by creating a graph + * of the Jung library and using this graph's coordinates in our front end. + * + * @return a {@link DiagramGeometry} object which represents the diagram's geometry + */ + DiagramGeometry arrangeDiagram(); + + // TODO JavaDoc + void setGraph(Graph graph); } diff --git a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmFactory.java b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmFactory.java index d334b87..ad9cc37 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmFactory.java +++ b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmFactory.java @@ -1,9 +1,12 @@ package model.diagram.arrangement.algorithms; -public class LayoutAlgorithmFactory { +public class LayoutAlgorithmFactory +{ - public static LayoutAlgorithm createLayoutAlgorithm(LayoutAlgorithmType algorithmType) { - return switch (algorithmType) { + public static LayoutAlgorithm createLayoutAlgorithm(LayoutAlgorithmType algorithmType) + { + return switch (algorithmType) + { case SUGIYAMA -> new Sugiyama(); case FRUCHTERMAN_REINGOLD -> new FruchtermanReingold(); case ADVANCED_FRUCHTERMAN_REINGOLD -> new AdvancedFruchtermanReingold(); @@ -11,6 +14,6 @@ public static LayoutAlgorithm createLayoutAlgorithm(LayoutAlgorithmType algorith case ADVANCED_SPRING -> new AdvancedSpring(); case KAMADA_KAWAI -> new KamadaKawai(); }; - } + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java index 6cc8853..af43141 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java +++ b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java @@ -4,26 +4,30 @@ import java.util.HashMap; import java.util.Map; -public enum LayoutAlgorithmType { - SUGIYAMA, - FRUCHTERMAN_REINGOLD, - ADVANCED_FRUCHTERMAN_REINGOLD, - SPRING, - ADVANCED_SPRING, - KAMADA_KAWAI; +public enum LayoutAlgorithmType +{ + SUGIYAMA, + FRUCHTERMAN_REINGOLD, + ADVANCED_FRUCHTERMAN_REINGOLD, + SPRING, + ADVANCED_SPRING, + KAMADA_KAWAI; - private static final Map ALGORITHM_TYPE_MAP; + private static final Map ALGORITHM_TYPE_MAP; - static { - Map map= new HashMap<>(); - for (LayoutAlgorithmType layoutAlgorithmType: LayoutAlgorithmType.values()) { - map.put(layoutAlgorithmType.toString().toLowerCase(), layoutAlgorithmType); - } - ALGORITHM_TYPE_MAP = Collections.unmodifiableMap(map); - } + static + { + Map map = new HashMap<>(); + for (LayoutAlgorithmType layoutAlgorithmType : LayoutAlgorithmType.values()) + { + map.put(layoutAlgorithmType.toString().toLowerCase(), layoutAlgorithmType); + } + ALGORITHM_TYPE_MAP = Collections.unmodifiableMap(map); + } - public static LayoutAlgorithmType get(String algorithmType) { - return ALGORITHM_TYPE_MAP.get(algorithmType.toLowerCase()); - } + public static LayoutAlgorithmType get(String algorithmType) + { + return ALGORITHM_TYPE_MAP.get(algorithmType.toLowerCase()); + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/Spring.java b/src/main/java/model/diagram/arrangement/algorithms/Spring.java index fbf9a9b..8c29a32 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/Spring.java +++ b/src/main/java/model/diagram/arrangement/algorithms/Spring.java @@ -7,48 +7,58 @@ import model.diagram.arrangement.geometry.GeometryNode; -public class Spring implements LayoutAlgorithm{ - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; - - private Graph graph; - - @Override - public void setGraph(Graph graph) { - this.graph = graph; - } - - @Override - public DiagramGeometry arrangeDiagram() { - double maxXdistance = 0.0; - double maxYdistance = 0.0; - DiagramGeometry diagramGeometry = new DiagramGeometry(); - SpringLayout layout = new SpringLayout<>(graph); - layout.setForceMultiplier(0.1); - layout.setRepulsionRange(500); - // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); - @SuppressWarnings("unused") - VisualizationViewer vv = new VisualizationViewer(layout); - for (String vertex : graph.getVertices()) { - GeometryNode geometryNode = new GeometryNode(vertex); - double x = layout.getX(vertex); - double y = layout.getY(vertex); - if (x < MIN_X_WINDOW_VALUE) { - double difference = MIN_X_WINDOW_VALUE - x; - if (difference > maxXdistance) { - maxXdistance = difference; - } - } - if (y < MIN_Y_WINDOW_VALUE) { - double difference = MIN_Y_WINDOW_VALUE - y; - if (difference > maxYdistance) { - maxYdistance = difference; - } - } - diagramGeometry.addGeometry(geometryNode, x, y); - } - diagramGeometry.correctPositions(maxXdistance, maxYdistance); - return diagramGeometry; - } +public class Spring implements LayoutAlgorithm +{ + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; + + private Graph graph; + + + @Override + public void setGraph(Graph graph) + { + this.graph = graph; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + double maxXdistance = 0.0; + double maxYdistance = 0.0; + DiagramGeometry diagramGeometry = new DiagramGeometry(); + SpringLayout layout = new SpringLayout<>(graph); + layout.setForceMultiplier(0.1); + layout.setRepulsionRange(500); + // layout.setSize(new Dimension(GRAPH_X_SIZE, GRAPH_Y_SIZE)); + @SuppressWarnings("unused") + VisualizationViewer vv = new VisualizationViewer<>(layout); + for (String vertex : graph.getVertices()) + { + GeometryNode geometryNode = new GeometryNode(vertex); + double x = layout.getX(vertex); + double y = layout.getY(vertex); + if (x < MIN_X_WINDOW_VALUE) + { + double difference = MIN_X_WINDOW_VALUE - x; + if (difference > maxXdistance) + { + maxXdistance = difference; + } + } + if (y < MIN_Y_WINDOW_VALUE) + { + double difference = MIN_Y_WINDOW_VALUE - y; + if (difference > maxYdistance) + { + maxYdistance = difference; + } + } + diagramGeometry.addGeometry(geometryNode, x, y); + } + diagramGeometry.correctPositions(maxXdistance, maxYdistance); + return diagramGeometry; + } } diff --git a/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java b/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java index a09ab20..493cd1b 100644 --- a/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java +++ b/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java @@ -15,81 +15,101 @@ import model.diagram.arrangement.geometry.DiagramGeometry; import model.diagram.arrangement.geometry.GeometryNode; -public class Sugiyama implements LayoutAlgorithm{ - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; - private final static int VERTEX_X_SIZE = 20; - private final static int VERTEX_Y_SIZE = 20; - private final static int HORIZONTAL_SPACING = 125; - private final static int VERTICAL_SPACING = 50; +public class Sugiyama implements LayoutAlgorithm +{ + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; + private final static int VERTEX_X_SIZE = 20; + private final static int VERTEX_Y_SIZE = 20; + private final static int HORIZONTAL_SPACING = 125; + private final static int VERTICAL_SPACING = 50; - private final Map verticesMap; - private Graph graph; - private SimpleDigraph digraph; + private final Map verticesMap; + private Graph graph; + private SimpleDigraph digraph; - public Sugiyama() { - this.verticesMap = new HashMap<>(); - } - @Override - public void setGraph(Graph graph) { - this.graph = graph; - } + public Sugiyama() + { + this.verticesMap = new HashMap<>(); + } - @Override - public DiagramGeometry arrangeDiagram() { - double maxXdistance = 0.0; - double maxYdistance = 0.0; - DiagramGeometry diagramGeometry = new DiagramGeometry(); - digraph = new SimpleDigraphAdapter<>(); - fillVertexMap(); - fillNeighboursMap(); - DigraphLayoutDimensionProvider dimensionProvider = node -> { - // we use OOAD vertices' size, in order to evaluate vertices coordinates based on our vertices sizes. + + @Override + public void setGraph(Graph graph) + { + this.graph = graph; + } + + + @Override + public DiagramGeometry arrangeDiagram() + { + double maxXdistance = 0.0; + double maxYdistance = 0.0; + DiagramGeometry diagramGeometry = new DiagramGeometry(); + digraph = new SimpleDigraphAdapter<>(); + fillVertexMap(); + fillNeighboursMap(); + DigraphLayoutDimensionProvider dimensionProvider = node -> { + // We use OOAD vertices' size, in order to evaluate vertices coordinates based on our vertices sizes. return new DigraphLayoutDimension(VERTEX_X_SIZE, VERTEX_Y_SIZE); }; - DigrpahLayoutBuilder builder = new SugiyamaBuilder<>(HORIZONTAL_SPACING, VERTICAL_SPACING); - DigraphLayout layout = builder.build(digraph, dimensionProvider); - for (DigraphLayoutNode vertex : layout.getLayoutGraph().vertices()) { - for (Map.Entry entryVertex : verticesMap.entrySet()) { - if (entryVertex.getValue().equals(vertex.getVertex())) { - double x = vertex.getPoint().x; - double y = vertex.getPoint().y; - GeometryNode geometryNode = new GeometryNode(entryVertex.getKey()); - if (vertex.getPoint().x < MIN_X_WINDOW_VALUE) { - double difference = MIN_X_WINDOW_VALUE - x; - if (difference > maxXdistance) { - maxXdistance = difference; - } - } - if (vertex.getPoint().y < MIN_Y_WINDOW_VALUE) { - double difference = MIN_Y_WINDOW_VALUE - y; - if (difference > maxYdistance) { - maxYdistance = difference; - } - } - diagramGeometry.addGeometry(geometryNode, x, y); - break; - } - } - } - diagramGeometry.correctPositions(maxXdistance, maxYdistance); - return diagramGeometry; - } + DigrpahLayoutBuilder builder = new SugiyamaBuilder<>(HORIZONTAL_SPACING, VERTICAL_SPACING); + DigraphLayout layout = builder.build(digraph, dimensionProvider); + for (DigraphLayoutNode vertex : layout.getLayoutGraph().vertices()) + { + for (Map.Entry entryVertex : verticesMap.entrySet()) + { + if (entryVertex.getValue().equals(vertex.getVertex())) + { + double x = vertex.getPoint().x; + double y = vertex.getPoint().y; + GeometryNode geometryNode = new GeometryNode(entryVertex.getKey()); + if (vertex.getPoint().x < MIN_X_WINDOW_VALUE) + { + double difference = MIN_X_WINDOW_VALUE - x; + if (difference > maxXdistance) + { + maxXdistance = difference; + } + } + if (vertex.getPoint().y < MIN_Y_WINDOW_VALUE) + { + double difference = MIN_Y_WINDOW_VALUE - y; + if (difference > maxYdistance) + { + maxYdistance = difference; + } + } + diagramGeometry.addGeometry(geometryNode, x, y); + break; + } + } + } + diagramGeometry.correctPositions(maxXdistance, maxYdistance); + return diagramGeometry; + } + + + private void fillNeighboursMap() + { + for (String edge : graph.getEdges()) + { + String[] vertices = edge.split(" "); + digraph.add(verticesMap.get(vertices[0]), verticesMap.get(vertices[1])); + } + } - private void fillNeighboursMap() { - for (String edge : graph.getEdges()){ - String[] vertices = edge.split(" "); - digraph.add(verticesMap.get(vertices[0]), verticesMap.get(vertices[1])); - } - } - private void fillVertexMap() { - int counter = 1; - for (String vertex : graph.getVertices()) { - verticesMap.put(vertex, counter); - counter += 1; - } - } + private void fillVertexMap() + { + int counter = 1; + for (String vertex : graph.getVertices()) + { + verticesMap.put(vertex, counter); + counter += 1; + } + } } diff --git a/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java b/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java index 47f9991..27a2799 100644 --- a/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java +++ b/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java @@ -5,50 +5,64 @@ import java.util.HashMap; import java.util.Map; -public class DiagramGeometry { - - private final static int MIN_X_WINDOW_VALUE = 25; - private final static int MIN_Y_WINDOW_VALUE = 25; - - private final Map> geometryMap; - - public DiagramGeometry() { - this.geometryMap = new HashMap<>(); - } - - public void addGeometry(GeometryNode key, double x, double y) { - geometryMap.put(key.nodeName(), new Pair<>(x, y)); - } - - public Pair getVertexGeometry(String stringKey){ - return geometryMap.get(stringKey); - } - - public boolean containsKey(String stringKey) { - return geometryMap.containsKey(stringKey); - } - - public void correctPositions(double x, double y) { - // We store minX and minY coordinates of the system, in order to bring the graph to match the left side - // and upper side of the window. - double minX = Double.POSITIVE_INFINITY; - double minY = Double.POSITIVE_INFINITY; - double xDifference; - double yDifference; - for(Map.Entry> entry : geometryMap.entrySet()) { - double newX = entry.getValue().getValue0() + x; - double newY = entry.getValue().getValue1() + y; - geometryMap.put(entry.getKey(), new Pair<>(entry.getValue().getValue0() + x, entry.getValue().getValue1() + y)); - if (newX < minX) { - minX = newX; - } - if (newY < minY) { - minY = newY; - } - } - xDifference = minX - MIN_X_WINDOW_VALUE; - yDifference = minY - MIN_Y_WINDOW_VALUE; +public class DiagramGeometry +{ + + private final static int MIN_X_WINDOW_VALUE = 25; + private final static int MIN_Y_WINDOW_VALUE = 25; + + private final Map> geometryMap; + + + public DiagramGeometry() + { + this.geometryMap = new HashMap<>(); + } + + + public void addGeometry(GeometryNode key, double x, double y) + { + geometryMap.put(key.nodeName(), new Pair<>(x, y)); + } + + + public Pair getVertexGeometry(String stringKey) + { + return geometryMap.get(stringKey); + } + + + public boolean containsKey(String stringKey) + { + return geometryMap.containsKey(stringKey); + } + + + public void correctPositions(double x, double y) + { + // We store minX and minY coordinates of the system, in order to bring the graph + // to match the left side and upper side of the window. + double minX = Double.POSITIVE_INFINITY; + double minY = Double.POSITIVE_INFINITY; + double xDifference; + double yDifference; + for (Map.Entry> entry : geometryMap.entrySet()) + { + double newX = entry.getValue().getValue0() + x; + double newY = entry.getValue().getValue1() + y; + geometryMap.put(entry.getKey(), new Pair<>(entry.getValue().getValue0() + x, entry.getValue().getValue1() + y)); + if (newX < minX) + { + minX = newX; + } + if (newY < minY) + { + minY = newY; + } + } + xDifference = minX - MIN_X_WINDOW_VALUE; + yDifference = minY - MIN_Y_WINDOW_VALUE; geometryMap.replaceAll((k, v) -> new Pair<>(v.getValue0() - xDifference, v.getValue1() - yDifference)); - } + } } diff --git a/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java b/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java index 9b712f8..5c0a58f 100644 --- a/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java +++ b/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java @@ -14,81 +14,92 @@ import java.util.List; import java.util.Map; -public class ClassifierVertexSerializer implements JsonSerializer { +public class ClassifierVertexSerializer implements JsonSerializer +{ - @Override - public JsonElement serialize(ClassifierVertex classifierVertex, - Type type, - JsonSerializationContext jsonSerializationContext) { - JsonObject jsonObject = new JsonObject(); - String name = classifierVertex.getName(); - Path path = classifierVertex.getPath(); - String vertexType = classifierVertex.getVertexType().toString(); - jsonObject.addProperty("name", name); - jsonObject.addProperty("path", path.toString()); - jsonObject.addProperty("vertexType", vertexType); - jsonObject.addProperty("coordinate_x", classifierVertex.getCoordinate().getX()); - jsonObject.addProperty("coordinate_y", classifierVertex.getCoordinate().getY()); - jsonObject.add("methods", serializeMethods(classifierVertex)); - jsonObject.add("fields", serializeFields(classifierVertex)); - jsonObject.add("arcs", serializeArcs(classifierVertex)); + @Override + public JsonElement serialize(ClassifierVertex classifierVertex, + Type type, + JsonSerializationContext jsonSerializationContext) + { + JsonObject jsonObject = new JsonObject(); + String name = classifierVertex.getName(); + Path path = classifierVertex.getPath(); + String vertexType = classifierVertex.getVertexType().toString(); + jsonObject.addProperty("name", name); + jsonObject.addProperty("path", path.toString()); + jsonObject.addProperty("vertexType", vertexType); + jsonObject.addProperty("coordinate_x", classifierVertex.getCoordinate().x()); + jsonObject.addProperty("coordinate_y", classifierVertex.getCoordinate().y()); + jsonObject.add("methods", serializeMethods(classifierVertex)); + jsonObject.add("fields", serializeFields(classifierVertex)); + jsonObject.add("arcs", serializeArcs(classifierVertex)); - return jsonObject; - } + return jsonObject; + } - private JsonArray serializeMethods(ClassifierVertex classifierVertex) { - Gson gson = new Gson(); - List methods = classifierVertex.getMethods(); - JsonArray methodsArray = new JsonArray(methods.size()); - for (ClassifierVertex.Method method: methods) { - JsonObject methodObject = new JsonObject(); - String methodName = method.name(); - String returnType = method.returnType(); - String modifier = method.modifier().toString(); - Map parameters = method.parameters(); - String json = gson.toJson(parameters); - methodObject.addProperty("name", methodName); - methodObject.addProperty("returnType", returnType); - methodObject.addProperty("modifier", modifier); - methodObject.addProperty("parameters", json); - methodsArray.add(methodObject); - } - return methodsArray; - } + private JsonArray serializeMethods(ClassifierVertex classifierVertex) + { + Gson gson = new Gson(); + List methods = classifierVertex.getMethods(); + JsonArray methodsArray = new JsonArray(methods.size()); + for (ClassifierVertex.Method method : methods) + { + JsonObject methodObject = new JsonObject(); + String methodName = method.name(); + String returnType = method.returnType(); + String modifier = method.modifier().toString(); + Map parameters = method.parameters(); + String json = gson.toJson(parameters); + methodObject.addProperty("name", methodName); + methodObject.addProperty("returnType", returnType); + methodObject.addProperty("modifier", modifier); + methodObject.addProperty("parameters", json); - private JsonArray serializeFields(ClassifierVertex classifierVertex) { - List fields = classifierVertex.getFields(); - JsonArray fieldsArray = new JsonArray(fields.size()); + methodsArray.add(methodObject); + } + return methodsArray; + } - for (ClassifierVertex.Field field: fields) { - JsonObject fieldObject = new JsonObject(); - String fieldName = field.name(); - String returnType = field.type(); - String modifier = field.modifier().toString(); - fieldObject.addProperty("name", fieldName); - fieldObject.addProperty("returnType", returnType); - fieldObject.addProperty("modifier", modifier); - fieldsArray.add(fieldObject); - } - return fieldsArray; - } - private JsonArray serializeArcs(ClassifierVertex classifierVertex) { - List> arcs = classifierVertex.getArcs(); - JsonArray arcsArray = new JsonArray(arcs.size()); + private JsonArray serializeFields(ClassifierVertex classifierVertex) + { + List fields = classifierVertex.getFields(); + JsonArray fieldsArray = new JsonArray(fields.size()); - for (Arc sinkVertexArc : arcs) { - JsonObject arcObject = new JsonObject(); - String source = sinkVertexArc.sourceVertex().getName(); - String target = sinkVertexArc.targetVertex().getName(); - String arcType = sinkVertexArc.arcType().toString(); - arcObject.addProperty("source", source); - arcObject.addProperty("target", target); - arcObject.addProperty("arcType", arcType); - arcsArray.add(arcObject); - } - return arcsArray; - } + for (ClassifierVertex.Field field : fields) + { + JsonObject fieldObject = new JsonObject(); + String fieldName = field.name(); + String returnType = field.type(); + String modifier = field.modifier().toString(); + fieldObject.addProperty("name", fieldName); + fieldObject.addProperty("returnType", returnType); + fieldObject.addProperty("modifier", modifier); + fieldsArray.add(fieldObject); + } + return fieldsArray; + } + + + private JsonArray serializeArcs(ClassifierVertex classifierVertex) + { + List> arcs = classifierVertex.getArcs(); + JsonArray arcsArray = new JsonArray(arcs.size()); + + for (Arc sinkVertexArc : arcs) + { + JsonObject arcObject = new JsonObject(); + String source = sinkVertexArc.sourceVertex().getName(); + String target = sinkVertexArc.targetVertex().getName(); + String arcType = sinkVertexArc.arcType().toString(); + arcObject.addProperty("source", source); + arcObject.addProperty("target", target); + arcObject.addProperty("arcType", arcType); + arcsArray.add(arcObject); + } + return arcsArray; + } } diff --git a/src/main/java/model/diagram/exportation/CoordinatesUpdater.java b/src/main/java/model/diagram/exportation/CoordinatesUpdater.java index eca0e96..db97f2d 100644 --- a/src/main/java/model/diagram/exportation/CoordinatesUpdater.java +++ b/src/main/java/model/diagram/exportation/CoordinatesUpdater.java @@ -11,58 +11,75 @@ import java.util.logging.Level; import java.util.logging.Logger; -public class CoordinatesUpdater { - private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - - private PackageDiagram packageDiagram; - private ClassDiagram classDiagram; - - public CoordinatesUpdater(PackageDiagram packageDiagram) { - this.packageDiagram = packageDiagram; - } - - public CoordinatesUpdater(ClassDiagram classDiagram) { - this.classDiagram = classDiagram; - } - - public void updatePackageCoordinates(Collection> vertexCollection, - SmartGraphPanel graphView) { - if (vertexCollection == null) { - logger.log(Level.WARNING, "Vertex Collection is null"); - return; - } - - for(Vertex vertex : vertexCollection) { - double x = graphView.getVertexPositionX(vertex); - double y = graphView.getVertexPositionY(vertex); - for (PackageVertex packageVertex : packageDiagram.getGraphNodes().keySet()) { - if (!packageVertex.getName().equals(vertex.element())) { - continue; - } - - packageVertex.createCoordinate(x, y); - } - } - } - - public void updateClassCoordinates(Collection> vertexCollection, - SmartGraphPanel graphView) { - if (vertexCollection == null) { - logger.log(Level.WARNING, "Vertex Collection is null"); - return; - } - - for(Vertex vertex : vertexCollection) { - double x = graphView.getVertexPositionX(vertex); - double y = graphView.getVertexPositionY(vertex); - for (ClassifierVertex classifierVertex : classDiagram.getGraphNodes().keySet()) { - if (!classifierVertex.getName().equals(vertex.element())) { - continue; - } - - classifierVertex.updateCoordinate(x, y); - } - } - } +public class CoordinatesUpdater +{ + private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + + private PackageDiagram packageDiagram; + private ClassDiagram classDiagram; + + + public CoordinatesUpdater(PackageDiagram packageDiagram) + { + this.packageDiagram = packageDiagram; + } + + + public CoordinatesUpdater(ClassDiagram classDiagram) + { + this.classDiagram = classDiagram; + } + + + public void updatePackageCoordinates(Collection> vertexCollection, + SmartGraphPanel graphView) + { + if (vertexCollection == null) + { + logger.log(Level.WARNING, "Trying to update tha package's coordinates with a null vertex Collection"); + return; + } + + for (Vertex vertex : vertexCollection) + { + double x = graphView.getVertexPositionX(vertex); + double y = graphView.getVertexPositionY(vertex); + for (PackageVertex packageVertex : packageDiagram.getGraphNodes().keySet()) + { + if (!packageVertex.getName().equals(vertex.element())) + { + continue; + } + + packageVertex.setCoordinate(x, y); + } + } + } + + + public void updateClassCoordinates(Collection> vertexCollection, + SmartGraphPanel graphView) + { + if (vertexCollection == null) + { + logger.log(Level.WARNING, "Trying to update tha class's coordinates with a null vertex Collection"); + return; + } + + for (Vertex vertex : vertexCollection) + { + double x = graphView.getVertexPositionX(vertex); + double y = graphView.getVertexPositionY(vertex); + for (ClassifierVertex classifierVertex : classDiagram.getGraphNodes().keySet()) + { + if (!classifierVertex.getName().equals(vertex.element())) + { + continue; + } + + classifierVertex.setCoordinate(x, y); + } + } + } } diff --git a/src/main/java/model/diagram/exportation/DiagramExporter.java b/src/main/java/model/diagram/exportation/DiagramExporter.java index e9bbded..1d529ac 100644 --- a/src/main/java/model/diagram/exportation/DiagramExporter.java +++ b/src/main/java/model/diagram/exportation/DiagramExporter.java @@ -3,13 +3,14 @@ import java.io.File; import java.nio.file.Path; -public interface DiagramExporter { +public interface DiagramExporter +{ - /** - * This method is responsible for exporting the corresponding diagram type. - * - * @param exportPath the path of the exported file - * @return the created File - */ - File exportDiagram(Path exportPath); + /** + * This method is responsible for exporting the corresponding diagram type. + * + * @param exportPath the path of the exported file + * @return the created File + */ + File exportDiagram(Path exportPath); } diff --git a/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java b/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java index 9c3c483..d1b2b5e 100644 --- a/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java +++ b/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java @@ -7,28 +7,33 @@ import java.io.File; import java.nio.file.Path; -public class GraphMLClassDiagramExporter implements DiagramExporter { - - private final GraphMLFile graphMLFile; - private final StringBuilder graphMLNodeBuffer; - private final StringBuilder graphMLEdgeBuffer; - - public GraphMLClassDiagramExporter(ClassDiagram classDiagram) { - GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagram); - GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagram); - - graphMLNodeBuffer = graphMLClassifierVertex.convertSinkVertex(); - graphMLEdgeBuffer = graphMLClassifierVertexArc.convertSinkVertexArc(); - graphMLFile = new GraphMLFile(); - } - - @Override - public File exportDiagram(Path exportPath) { - graphMLFile.createGraphMLFile(exportPath); - graphMLFile.writeToBuffer(graphMLNodeBuffer); - graphMLFile.writeToBuffer(graphMLEdgeBuffer); - graphMLFile.closeGraphMLFile(); - return graphMLFile.getGraphMLFile(); - } +public class GraphMLClassDiagramExporter implements DiagramExporter +{ + + private final GraphMLFile graphMLFile; + private final StringBuilder graphMLNodeBuffer; + private final StringBuilder graphMLEdgeBuffer; + + + public GraphMLClassDiagramExporter(ClassDiagram classDiagram) + { + GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagram); + GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagram); + + graphMLNodeBuffer = graphMLClassifierVertex.convertSinkVertex(); + graphMLEdgeBuffer = graphMLClassifierVertexArc.convertSinkVertexArc(); + graphMLFile = new GraphMLFile(); + } + + + @Override + public File exportDiagram(Path exportPath) + { + graphMLFile.createGraphMLFile(exportPath); + graphMLFile.writeToBuffer(graphMLNodeBuffer); + graphMLFile.writeToBuffer(graphMLEdgeBuffer); + graphMLFile.closeGraphMLFile(); + return graphMLFile.getGraphMLFile(); + } } diff --git a/src/main/java/model/diagram/exportation/GraphMLFile.java b/src/main/java/model/diagram/exportation/GraphMLFile.java index 003b060..388cc8a 100644 --- a/src/main/java/model/diagram/exportation/GraphMLFile.java +++ b/src/main/java/model/diagram/exportation/GraphMLFile.java @@ -7,42 +7,56 @@ import java.io.IOException; import java.nio.file.Path; -public class GraphMLFile { - - private FileWriter graphMLWriter; - private StringBuilder graphMLBuffer; - private File graphMLFile; - - public void createGraphMLFile(Path graphMLSavePath) { - try { - graphMLFile = graphMLSavePath.toFile(); - graphMLWriter = new FileWriter(graphMLFile); - graphMLBuffer = new StringBuilder(); - graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLPrefix()); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - - - public void closeGraphMLFile() { - try { - graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSuffix()); - graphMLWriter.write(graphMLBuffer.toString()); - graphMLWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - - public void writeToBuffer(StringBuilder buffer) { - graphMLBuffer.append(buffer); - } - - public File getGraphMLFile() { - return graphMLFile; - } +public class GraphMLFile +{ + + private FileWriter graphMLWriter; + private StringBuilder graphMLBuffer; + private File graphMLFile; + + + public void createGraphMLFile(Path graphMLSavePath) + { + try + { + graphMLFile = graphMLSavePath.toFile(); + graphMLWriter = new FileWriter(graphMLFile); + graphMLBuffer = new StringBuilder(); + graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLPrefix()); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + public void closeGraphMLFile() + { + try + { + graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSuffix()); + graphMLWriter.write(graphMLBuffer.toString()); + graphMLWriter.close(); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + public void writeToBuffer(StringBuilder buffer) + { + graphMLBuffer.append(buffer); + } + + + public File getGraphMLFile() + { + return graphMLFile; + } } diff --git a/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java b/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java index 084dc25..33f8601 100644 --- a/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java +++ b/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java @@ -7,32 +7,39 @@ import java.io.File; import java.nio.file.Path; -public class GraphMLPackageDiagramExporter implements DiagramExporter { - - private final GraphMLFile graphMLFile; - private final StringBuilder graphMLNodeBuffer; - private final StringBuilder graphMLEdgeBuffer; - - public GraphMLPackageDiagramExporter(PackageDiagram packageDiagram) { - GraphMLPackageVertex graphMLPackageVertex = new GraphMLPackageVertex(packageDiagram); - GraphMLPackageVertexArc graphMLPackageVertexArc = new GraphMLPackageVertexArc(packageDiagram); - - graphMLNodeBuffer = graphMLPackageVertex.convertVertex(); - graphMLEdgeBuffer = graphMLPackageVertexArc.convertVertexArc(); - graphMLFile = new GraphMLFile(); - } - - @Override - public File exportDiagram(Path exportPath) { - graphMLFile.createGraphMLFile(exportPath); - generateGraphMLGraph(graphMLNodeBuffer, graphMLEdgeBuffer); - graphMLFile.closeGraphMLFile(); - return graphMLFile.getGraphMLFile(); - } - - private void generateGraphMLGraph(StringBuilder nodeBuffer, - StringBuilder edgeBuffer) { - graphMLFile.writeToBuffer(nodeBuffer); - graphMLFile.writeToBuffer(edgeBuffer); - } +public class GraphMLPackageDiagramExporter implements DiagramExporter +{ + + private final GraphMLFile graphMLFile; + private final StringBuilder graphMLNodeBuffer; + private final StringBuilder graphMLEdgeBuffer; + + + public GraphMLPackageDiagramExporter(PackageDiagram packageDiagram) + { + GraphMLPackageVertex graphMLPackageVertex = new GraphMLPackageVertex(packageDiagram); + GraphMLPackageVertexArc graphMLPackageVertexArc = new GraphMLPackageVertexArc(packageDiagram); + + graphMLNodeBuffer = graphMLPackageVertex.convertVertex(); + graphMLEdgeBuffer = graphMLPackageVertexArc.convertVertexArc(); + graphMLFile = new GraphMLFile(); + } + + + @Override + public File exportDiagram(Path exportPath) + { + graphMLFile.createGraphMLFile(exportPath); + generateGraphMLGraph(graphMLNodeBuffer, graphMLEdgeBuffer); + graphMLFile.closeGraphMLFile(); + return graphMLFile.getGraphMLFile(); + } + + + private void generateGraphMLGraph(StringBuilder nodeBuffer, + StringBuilder edgeBuffer) + { + graphMLFile.writeToBuffer(nodeBuffer); + graphMLFile.writeToBuffer(edgeBuffer); + } } diff --git a/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java b/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java index f7806ef..ce773a6 100644 --- a/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java +++ b/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java @@ -10,31 +10,39 @@ import java.io.IOException; import java.nio.file.Path; -public class JavaFXClassDiagramExporter implements DiagramExporter { - - private final ClassDiagram classDiagram; - - public JavaFXClassDiagramExporter(ClassDiagram diagram) { - this.classDiagram = diagram; - } - - @Override - public File exportDiagram(Path exportPath) { - File graphSaveFile = exportPath.toFile(); - try (FileWriter fileWriter = new FileWriter(graphSaveFile)) { - Gson gson = new GsonBuilder() - .registerTypeAdapter(ClassifierVertex.class, - new ClassifierVertexSerializer()) - .create(); - - String json = gson.toJson(classDiagram.getDiagram().keySet()); - fileWriter.write(json); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - - return graphSaveFile; - } +public class JavaFXClassDiagramExporter implements DiagramExporter +{ + + private final ClassDiagram classDiagram; + + + public JavaFXClassDiagramExporter(ClassDiagram diagram) + { + this.classDiagram = diagram; + } + + + @Override + public File exportDiagram(Path exportPath) + { + File graphSaveFile = exportPath.toFile(); + try (FileWriter fileWriter = new FileWriter(graphSaveFile)) + { + Gson gson = new GsonBuilder() + .registerTypeAdapter(ClassifierVertex.class, + new ClassifierVertexSerializer()) + .create(); + + String json = gson.toJson(classDiagram.getDiagram().keySet()); + fileWriter.write(json); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + return graphSaveFile; + } } diff --git a/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java b/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java index f6baf95..f039d49 100644 --- a/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java +++ b/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java @@ -10,30 +10,38 @@ import java.io.IOException; import java.nio.file.Path; -public class JavaFXPackageDiagramExporter implements DiagramExporter { - - private final PackageDiagram packageDiagram; - - public JavaFXPackageDiagramExporter(PackageDiagram packageDiagram) { - this.packageDiagram = packageDiagram; - } - - @Override - public File exportDiagram(Path exportPath) { - File graphSaveFile = exportPath.toFile(); - try (FileWriter fileWriter = new FileWriter(graphSaveFile)) { - Gson gson = new GsonBuilder() - .registerTypeAdapter(PackageVertex.class, - new PackageVertexSerializer()) - .create(); - String json = gson.toJson(packageDiagram.getDiagram().keySet()); - fileWriter.write(json); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - - return graphSaveFile; - } +public class JavaFXPackageDiagramExporter implements DiagramExporter +{ + + private final PackageDiagram packageDiagram; + + + public JavaFXPackageDiagramExporter(PackageDiagram packageDiagram) + { + this.packageDiagram = packageDiagram; + } + + + @Override + public File exportDiagram(Path exportPath) + { + File graphSaveFile = exportPath.toFile(); + try (FileWriter fileWriter = new FileWriter(graphSaveFile)) + { + Gson gson = new GsonBuilder() + .registerTypeAdapter(PackageVertex.class, + new PackageVertexSerializer()) + .create(); + String json = gson.toJson(packageDiagram.getDiagram().keySet()); + fileWriter.write(json); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + return graphSaveFile; + } } diff --git a/src/main/java/model/diagram/exportation/PackageVertexSerializer.java b/src/main/java/model/diagram/exportation/PackageVertexSerializer.java index ec7b13f..8916aaf 100644 --- a/src/main/java/model/diagram/exportation/PackageVertexSerializer.java +++ b/src/main/java/model/diagram/exportation/PackageVertexSerializer.java @@ -15,93 +15,106 @@ import java.nio.file.Path; import java.util.List; -public class PackageVertexSerializer implements JsonSerializer { - - @Override - public JsonElement serialize(PackageVertex packageVertex, - Type type, - JsonSerializationContext jsonSerializationContext) { - JsonObject jsonObject = new JsonObject(); - String name = packageVertex.getName(); - Path path = packageVertex.getPath(); - String vertexType = packageVertex.getVertexType().toString(); - - jsonObject.addProperty("name", name); - jsonObject.addProperty("path", path.toString()); - jsonObject.addProperty("vertexType", vertexType); - jsonObject.addProperty("coordinate_x", packageVertex.getCoordinate().getX()); - jsonObject.addProperty("coordinate_y", packageVertex.getCoordinate().getY()); - jsonObject.add("sinkVertices", serializeSinkVertices(packageVertex)); - jsonObject.add("parent", serializeParentVertex(packageVertex)); - jsonObject.add("neighbours", serializeNeighbourVertices(packageVertex)); - jsonObject.add("arcs", serializeArcs(packageVertex)); - - return jsonObject; - } - - private JsonArray serializeSinkVertices(PackageVertex packageVertex) { - List sinkVertices = packageVertex.getSinkVertices(); - JsonArray sinkVerticesArray = new JsonArray(sinkVertices.size()); - for (ClassifierVertex classifierVertex : sinkVertices) { - Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, - new ClassifierVertexSerializer()) - .create(); - String json = gson.toJson(classifierVertex); - sinkVerticesArray.add(json); - } - return sinkVerticesArray; - } - - private JsonObject serializeParentVertex(PackageVertex packageVertex) { - PackageVertex parentPackageVertex = packageVertex.getParentVertex(); - JsonObject parentObject = new JsonObject(); - String name = parentPackageVertex.getName(); - String path = parentPackageVertex.getPath().toString(); - String type = parentPackageVertex.getModifierType().toString(); - - parentObject.addProperty("name", name); - parentObject.addProperty("path", path); - parentObject.addProperty("vertexType", type); - - return parentObject; - } - - private JsonArray serializeNeighbourVertices(PackageVertex packageVertex) { - List neighbourVertices = packageVertex.getNeighbourVertices(); - JsonArray neighbourVerticesArray = new JsonArray(neighbourVertices.size()); - - for (PackageVertex v: neighbourVertices) { - JsonObject neighbourVertexObject = new JsonObject(); - String name = v.getName(); - String path = v.getPath().toString(); - String vertexType = v.getVertexType().toString(); - String parentName = v.getParentVertex().getName(); - - neighbourVertexObject.addProperty("name", name); - neighbourVertexObject.addProperty("path", path); - neighbourVertexObject.addProperty("vertexType", vertexType); - neighbourVertexObject.addProperty("parentName", parentName); - neighbourVerticesArray.add(neighbourVertexObject); - } - return neighbourVerticesArray; - } - - private JsonArray serializeArcs(PackageVertex packageVertex) { - List> arcs = packageVertex.getArcs(); - JsonArray arcsArray = new JsonArray(arcs.size()); - - for (Arc vertexArc : arcs) { - JsonObject arcObject = new JsonObject(); - String source = vertexArc.sourceVertex().getName(); - String target = vertexArc.targetVertex().getName(); - String arcType = vertexArc.arcType().toString(); - - arcObject.addProperty("source", source); - arcObject.addProperty("target", target); - arcObject.addProperty("arcType", arcType); - arcsArray.add(arcObject); - } - return arcsArray; - } +public class PackageVertexSerializer implements JsonSerializer +{ + + @Override + public JsonElement serialize(PackageVertex packageVertex, + Type type, + JsonSerializationContext jsonSerializationContext) + { + JsonObject jsonObject = new JsonObject(); + String name = packageVertex.getName(); + Path path = packageVertex.getPath(); + String vertexType = packageVertex.getVertexType().toString(); + + jsonObject.addProperty("name", name); + jsonObject.addProperty("path", path.toString()); + jsonObject.addProperty("vertexType", vertexType); + jsonObject.addProperty("coordinate_x", packageVertex.getCoordinate().x()); + jsonObject.addProperty("coordinate_y", packageVertex.getCoordinate().y()); + jsonObject.add("sinkVertices", serializeSinkVertices(packageVertex)); + jsonObject.add("parent", serializeParentVertex(packageVertex)); + jsonObject.add("neighbours", serializeNeighbourVertices(packageVertex)); + jsonObject.add("arcs", serializeArcs(packageVertex)); + + return jsonObject; + } + + + private JsonArray serializeSinkVertices(PackageVertex packageVertex) + { + List sinkVertices = packageVertex.getSinkVertices(); + JsonArray sinkVerticesArray = new JsonArray(sinkVertices.size()); + for (ClassifierVertex classifierVertex : sinkVertices) + { + Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, + new ClassifierVertexSerializer()) + .create(); + String json = gson.toJson(classifierVertex); + sinkVerticesArray.add(json); + } + return sinkVerticesArray; + } + + + private JsonObject serializeParentVertex(PackageVertex packageVertex) + { + PackageVertex parentPackageVertex = packageVertex.getParentVertex(); + JsonObject parentObject = new JsonObject(); + String name = parentPackageVertex.getName(); + String path = parentPackageVertex.getPath().toString(); + String type = parentPackageVertex.getModifierType().toString(); + + parentObject.addProperty("name", name); + parentObject.addProperty("path", path); + parentObject.addProperty("vertexType", type); + + return parentObject; + } + + + private JsonArray serializeNeighbourVertices(PackageVertex packageVertex) + { + List neighbourVertices = packageVertex.getNeighbourVertices(); + JsonArray neighbourVerticesArray = new JsonArray(neighbourVertices.size()); + + for (PackageVertex v : neighbourVertices) + { + JsonObject neighbourVertexObject = new JsonObject(); + String name = v.getName(); + String path = v.getPath().toString(); + String vertexType = v.getVertexType().toString(); + String parentName = v.getParentVertex().getName(); + + neighbourVertexObject.addProperty("name", name); + neighbourVertexObject.addProperty("path", path); + neighbourVertexObject.addProperty("vertexType", vertexType); + neighbourVertexObject.addProperty("parentName", parentName); + neighbourVerticesArray.add(neighbourVertexObject); + } + return neighbourVerticesArray; + } + + + private JsonArray serializeArcs(PackageVertex packageVertex) + { + List> arcs = packageVertex.getArcs(); + JsonArray arcsArray = new JsonArray(arcs.size()); + + for (Arc vertexArc : arcs) + { + JsonObject arcObject = new JsonObject(); + String source = vertexArc.sourceVertex().getName(); + String target = vertexArc.targetVertex().getName(); + String arcType = vertexArc.arcType().toString(); + + arcObject.addProperty("source", source); + arcObject.addProperty("target", target); + arcObject.addProperty("arcType", arcType); + arcsArray.add(arcObject); + } + return arcsArray; + } } diff --git a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java index ca795dd..e16fc50 100644 --- a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java +++ b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java @@ -14,89 +14,104 @@ import java.io.InputStream; import java.nio.file.Path; -public class PlantUMLClassDiagramImageExporter implements DiagramExporter { - - private final StringBuilder bufferBody; - - public PlantUMLClassDiagramImageExporter(ClassDiagram diagram) { - PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram); - StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex(); - PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram); - StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc(); - bufferBody = plantUMLNodeBuffer - .append("\n\n") - .append(plantUMLEdgeBuffer) - .append("\n @enduml"); - } - - @Override - public File exportDiagram(Path exportPath) { - File plantUMLFile = exportPath.toFile(); - String plantUMLCode = getClassText(); - plantUMLCode += bufferBody; - exportImage(plantUMLFile, plantUMLCode); - return plantUMLFile; - } - - private void exportImage(File plantUMLFile, String plantCode) { - try (ByteArrayOutputStream png = new ByteArrayOutputStream()) { - SourceStringReader reader = new SourceStringReader(plantCode); - reader.outputImage(png).getDescription(); - - byte[] data = png.toByteArray(); - InputStream in = new ByteArrayInputStream(data); - BufferedImage convImg = ImageIO.read(in); - int width = convImg.getWidth(); - int wrapWidth = 150; - if (width == 4096) { - try (ByteArrayOutputStream newPng = new ByteArrayOutputStream()) - { - plantCode = wrapWidthChanger(plantCode, wrapWidth); - reader = new SourceStringReader(plantCode); - reader.outputImage(newPng).getDescription(); - data = newPng.toByteArray(); - in = new ByteArrayInputStream(data); - convImg = ImageIO.read(in); - } - } - ImageIO.write(convImg, "png", plantUMLFile); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - - private String wrapWidthChanger(String plantCode, int wrapWidth){ - String updatedString; - //if (counter == 0) { - int indexOfNewLine = plantCode.indexOf("\n"); - String firstPart = plantCode.substring(0, indexOfNewLine + 1); - String secondPart = plantCode.substring(indexOfNewLine + 1); - updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart; - // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // - // KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE // - // DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. // - // POP UP MESSAGE CAN BE ADDED TO INFORM THE USER THAT THE IMAGE HE // - // REQUESTED IS OVER 4096x4096 SO WE REDUCE THE WRAPWIDTH TO REDUCE // - // EXTRACTED IMAGE'S WIDTH. NOW THE USER CAN SEE MORE CLASSES. // - // }else { // - // String[] lines = plantCode.split("\n"); // - // lines[1] = "skinparam wrapWidth " + wrapWidth; // - // updatedString = String.join("\n", lines); // - // } // - // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // - return updatedString; - } - - private String getClassText() { - return """ - @startuml - skinparam class { - BackgroundColor lightyellow - BorderColor black - ArrowColor black - } - - """; - } +public class PlantUMLClassDiagramImageExporter implements DiagramExporter +{ + + private final StringBuilder bufferBody; + + + public PlantUMLClassDiagramImageExporter(ClassDiagram diagram) + { + PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram); + StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex(); + PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram); + StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc(); + bufferBody = plantUMLNodeBuffer + .append("\n\n") + .append(plantUMLEdgeBuffer) + .append("\n @enduml"); + } + + + @Override + public File exportDiagram(Path exportPath) + { + File plantUMLFile = exportPath.toFile(); + String plantUMLCode = getClassText(); + plantUMLCode += bufferBody; + exportImage(plantUMLFile, plantUMLCode); + return plantUMLFile; + } + + + private void exportImage(File plantUMLFile, String plantCode) + { + try (ByteArrayOutputStream png = new ByteArrayOutputStream()) + { + SourceStringReader reader = new SourceStringReader(plantCode); + reader.outputImage(png).getDescription(); + + byte[] data = png.toByteArray(); + InputStream in = new ByteArrayInputStream(data); + BufferedImage convImg = ImageIO.read(in); + int width = convImg.getWidth(); + int wrapWidth = 150; + if (width == 4096) + { + try (ByteArrayOutputStream newPng = new ByteArrayOutputStream()) + { + plantCode = wrapWidthChanger(plantCode, wrapWidth); + reader = new SourceStringReader(plantCode); + reader.outputImage(newPng).getDescription(); + data = newPng.toByteArray(); + in = new ByteArrayInputStream(data); + convImg = ImageIO.read(in); + } + } + ImageIO.write(convImg, "png", plantUMLFile); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + private String wrapWidthChanger(String plantCode, int wrapWidth) + { + String updatedString; + //if (counter == 0) { + int indexOfNewLine = plantCode.indexOf("\n"); + String firstPart = plantCode.substring(0, indexOfNewLine + 1); + String secondPart = plantCode.substring(indexOfNewLine + 1); + updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart; + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + // KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE // + // DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. // + // POP UP MESSAGE CAN BE ADDED TO INFORM THE USER THAT THE IMAGE HE // + // REQUESTED IS OVER 4096x4096 SO WE REDUCE THE WRAPWIDTH TO REDUCE // + // EXTRACTED IMAGE'S WIDTH. NOW THE USER CAN SEE MORE CLASSES. // + // }else { // + // String[] lines = plantCode.split("\n"); // + // lines[1] = "skinparam wrapWidth " + wrapWidth; // + // updatedString = String.join("\n", lines); // + // } // + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + return updatedString; + } + + + private String getClassText() + { + return """ + @startuml + skinparam class { + BackgroundColor lightyellow + BorderColor black + ArrowColor black + } + + """; + } } \ No newline at end of file diff --git a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java index b687fac..24b46d5 100644 --- a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java +++ b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java @@ -10,48 +10,60 @@ import java.io.IOException; import java.nio.file.Path; -public class PlantUMLClassDiagramTextExporter implements DiagramExporter { - - private final StringBuilder bufferBody; - - public PlantUMLClassDiagramTextExporter(ClassDiagram diagram) { - PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram); - StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex(); - PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram); - StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc(); - bufferBody = plantUMLNodeBuffer - .append("\n\n") - .append(plantUMLEdgeBuffer) - .append("\n @enduml"); - } - - @Override - public File exportDiagram(Path exportPath) { - File plantUMLFile = exportPath.toFile(); - String plantUMLCode = getClassText(); - plantUMLCode += bufferBody; - writeFile(plantUMLFile, plantUMLCode); - return plantUMLFile; - } - - private void writeFile(File plantUMLFile, String plantCode) { - try (BufferedWriter writer = new BufferedWriter(new FileWriter(plantUMLFile))) { - writer.write(plantCode); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - - private String getClassText() { - return """ - @startuml - skinparam class { - BackgroundColor lightyellow - BorderColor black - ArrowColor black - } - - """; - } +public class PlantUMLClassDiagramTextExporter implements DiagramExporter +{ + + private final StringBuilder bufferBody; + + + public PlantUMLClassDiagramTextExporter(ClassDiagram diagram) + { + PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram); + StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex(); + PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram); + StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc(); + bufferBody = plantUMLNodeBuffer + .append("\n\n") + .append(plantUMLEdgeBuffer) + .append("\n @enduml"); + } + + + @Override + public File exportDiagram(Path exportPath) + { + File plantUMLFile = exportPath.toFile(); + String plantUMLCode = getClassText(); + plantUMLCode += bufferBody; + writeFile(plantUMLFile, plantUMLCode); + return plantUMLFile; + } + + + private void writeFile(File plantUMLFile, String plantCode) + { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(plantUMLFile))) + { + writer.write(plantCode); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + private String getClassText() + { + return """ + @startuml + skinparam class { + BackgroundColor lightyellow + BorderColor black + ArrowColor black + } + + """; + } } diff --git a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java index 04bd202..dce0c99 100644 --- a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java +++ b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java @@ -14,111 +14,131 @@ import java.io.InputStream; import java.nio.file.Path; -public class PlantUMLPackageDiagramImageExporter implements DiagramExporter { - - private final StringBuilder bufferBody; - - public PlantUMLPackageDiagramImageExporter(PackageDiagram diagram) { - PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram); - StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex(); - PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram); - StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc(); - bufferBody = plantUMLNodeBuffer - .append("\n\n") - .append(plantUMLEdgeBuffer) - .append("\n @enduml"); - } - - @Override - public File exportDiagram(Path exportPath) { - File plantUMLFile = exportPath.toFile(); - String plantUMLCode = getPackageText(); - plantUMLCode += bufferBody; - plantUMLCode = dotChanger(plantUMLCode); - exportImage(plantUMLFile, plantUMLCode); - return plantUMLFile; - } - - private void exportImage(File plantUMLFile, String plantCode) { - try (ByteArrayOutputStream png = new ByteArrayOutputStream()) { - SourceStringReader reader = new SourceStringReader(plantCode); - reader.outputImage(png).getDescription(); - - byte[] data = png.toByteArray(); - InputStream in = new ByteArrayInputStream(data); - BufferedImage convImg = ImageIO.read(in); - int width = convImg.getWidth(); - int wrapWidth = 150; - //int stringChangerCounter = 0; - if (width == 4096) { - try (ByteArrayOutputStream newPng = new ByteArrayOutputStream()) - { - plantCode = wrapWidthChanger(plantCode, wrapWidth); - reader = new SourceStringReader(plantCode); - reader.outputImage(newPng).getDescription(); - data = newPng.toByteArray(); - in = new ByteArrayInputStream(data); - convImg = ImageIO.read(in); - width = convImg.getWidth(); - } - } - ImageIO.write(convImg, "png", plantUMLFile); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - - private String wrapWidthChanger(String plantCode, int wrapWidth){ - String updatedString; - int indexOfNewLine = plantCode.indexOf("\n"); - String firstPart = plantCode.substring(0, indexOfNewLine + 1); - String secondPart = plantCode.substring(indexOfNewLine + 1); - updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart; - // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // - // KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE // - // DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. // - // POP UP MESSAGE CAN BE ADDED TO INFORM THE USER THAT THE IMAGE HE // - // REQUESTED IS OVER 4096x4096 SO WE REDUCE THE WRAPWIDTH TO REDUCE // - // EXTRACTED IMAGE'S WIDTH. NOW THE USER CAN SEE MORE CLASSES. // - // }else { // - // String[] lines = plantCode.split("\n"); // - // lines[1] = "skinparam wrapWidth " + wrapWidth; // - // updatedString = String.join("\n", lines); // - // } // - // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // - return updatedString; - } - - private String dotChanger(String plantUMLCode) { - StringBuilder newString = new StringBuilder(); - String[] lines = plantUMLCode.split("\n"); - for (String line: lines) { - String[] splittedLine = line.split(" "); - for (String word: splittedLine) { - String newWord = word; - if (word.contains(".") && !word.contains("..")) { - newWord = word.replace(".", "_"); - newWord = newWord.replace("-", "_"); - } - newString.append(newWord).append(" "); - } - newString.append("\n"); - } - return newString.toString(); - } - - private String getPackageText() { - return """ - @startuml - skinparam package { - BackgroundColor lightyellow - BorderColor black - ArrowColor black - Shadowing true - } - - """; - } +public class PlantUMLPackageDiagramImageExporter implements DiagramExporter +{ + + private final StringBuilder bufferBody; + + + public PlantUMLPackageDiagramImageExporter(PackageDiagram diagram) + { + PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram); + StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex(); + PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram); + StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc(); + bufferBody = plantUMLNodeBuffer + .append("\n\n") + .append(plantUMLEdgeBuffer) + .append("\n @enduml"); + } + + + @Override + public File exportDiagram(Path exportPath) + { + File plantUMLFile = exportPath.toFile(); + String plantUMLCode = getPackageText(); + plantUMLCode += bufferBody; + plantUMLCode = dotChanger(plantUMLCode); + exportImage(plantUMLFile, plantUMLCode); + return plantUMLFile; + } + + + private void exportImage(File plantUMLFile, String plantCode) + { + try (ByteArrayOutputStream png = new ByteArrayOutputStream()) + { + SourceStringReader reader = new SourceStringReader(plantCode); + reader.outputImage(png).getDescription(); + + byte[] data = png.toByteArray(); + InputStream in = new ByteArrayInputStream(data); + BufferedImage convImg = ImageIO.read(in); + int width = convImg.getWidth(); + int wrapWidth = 150; + //int stringChangerCounter = 0; + if (width == 4096) + { + try (ByteArrayOutputStream newPng = new ByteArrayOutputStream()) + { + plantCode = wrapWidthChanger(plantCode, wrapWidth); + reader = new SourceStringReader(plantCode); + reader.outputImage(newPng).getDescription(); + data = newPng.toByteArray(); + in = new ByteArrayInputStream(data); + convImg = ImageIO.read(in); + width = convImg.getWidth(); + } + } + ImageIO.write(convImg, "png", plantUMLFile); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + private String wrapWidthChanger(String plantCode, int wrapWidth) + { + String updatedString; + int indexOfNewLine = plantCode.indexOf("\n"); + String firstPart = plantCode.substring(0, indexOfNewLine + 1); + String secondPart = plantCode.substring(indexOfNewLine + 1); + updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart; + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + // KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE // + // DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. // + // POP UP MESSAGE CAN BE ADDED TO INFORM THE USER THAT THE IMAGE HE // + // REQUESTED IS OVER 4096x4096 SO WE REDUCE THE WRAPWIDTH TO REDUCE // + // EXTRACTED IMAGE'S WIDTH. NOW THE USER CAN SEE MORE CLASSES. // + // }else { // + // String[] lines = plantCode.split("\n"); // + // lines[1] = "skinparam wrapWidth " + wrapWidth; // + // updatedString = String.join("\n", lines); // + // } // + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + return updatedString; + } + + + private String dotChanger(String plantUMLCode) + { + StringBuilder newString = new StringBuilder(); + String[] lines = plantUMLCode.split("\n"); + for (String line : lines) + { + String[] splittedLine = line.split(" "); + for (String word : splittedLine) + { + String newWord = word; + if (word.contains(".") && !word.contains("..")) + { + newWord = word.replace(".", "_"); + newWord = newWord.replace("-", "_"); + } + newString.append(newWord).append(" "); + } + newString.append("\n"); + } + return newString.toString(); + } + + + private String getPackageText() + { + return """ + @startuml + skinparam package { + BackgroundColor lightyellow + BorderColor black + ArrowColor black + Shadowing true + } + + """; + } } diff --git a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java index 8fe5c42..a6149b0 100644 --- a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java +++ b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java @@ -10,68 +10,85 @@ import java.io.IOException; import java.nio.file.Path; -public class PlantUMLPackageDiagramTextExporter implements DiagramExporter { +public class PlantUMLPackageDiagramTextExporter implements DiagramExporter +{ - private final StringBuilder bufferBody; + private final StringBuilder bufferBody; - public PlantUMLPackageDiagramTextExporter(PackageDiagram diagram) { - PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram); - StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex(); - PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram); - StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc(); - bufferBody = plantUMLNodeBuffer - .append("\n\n") - .append(plantUMLEdgeBuffer) - .append("\n @enduml"); - } - @Override - public File exportDiagram(Path exportPath) { - File plantUMLFile = exportPath.toFile(); - String plantUMLCode = getPackageText(); - plantUMLCode += bufferBody; - plantUMLCode = dotChanger(plantUMLCode); - writeFile(plantUMLFile, plantUMLCode); - return plantUMLFile; - } + public PlantUMLPackageDiagramTextExporter(PackageDiagram diagram) + { + PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram); + StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex(); + PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram); + StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc(); + bufferBody = plantUMLNodeBuffer + .append("\n\n") + .append(plantUMLEdgeBuffer) + .append("\n @enduml"); + } - private void writeFile(File plantUMLFile, String plantCode) { - try (BufferedWriter writer = new BufferedWriter(new FileWriter(plantUMLFile))) { - writer.write(plantCode); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - private String dotChanger(String plantUMLCode) { - StringBuilder newString = new StringBuilder(); - String[] lines = plantUMLCode.split("\n"); - for (String line: lines) { - String[] splittedLine = line.split(" "); - for (String word: splittedLine) { - String newWord = word; - if (word.contains(".") && !word.contains("..")) { - newWord = word.replace(".", "_"); - newWord = newWord.replace("-", "_"); - } - newString.append(newWord).append(" "); - } - newString.append("\n"); - } - return newString.toString(); - } + @Override + public File exportDiagram(Path exportPath) + { + File plantUMLFile = exportPath.toFile(); + String plantUMLCode = getPackageText(); + plantUMLCode += bufferBody; + plantUMLCode = dotChanger(plantUMLCode); + writeFile(plantUMLFile, plantUMLCode); + return plantUMLFile; + } - private String getPackageText() { - return """ - @startuml - skinparam package { - BackgroundColor lightyellow - BorderColor black - ArrowColor black - Shadowing true - } - """; - } + private void writeFile(File plantUMLFile, String plantCode) + { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(plantUMLFile))) + { + writer.write(plantCode); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + private String dotChanger(String plantUMLCode) + { + StringBuilder newString = new StringBuilder(); + String[] lines = plantUMLCode.split("\n"); + for (String line : lines) + { + String[] splittedLine = line.split(" "); + for (String word : splittedLine) + { + String newWord = word; + if (word.contains(".") && !word.contains("..")) + { + newWord = word.replace(".", "_"); + newWord = newWord.replace("-", "_"); + } + newString.append(newWord).append(" "); + } + newString.append("\n"); + } + return newString.toString(); + } + + + private String getPackageText() + { + return """ + @startuml + skinparam package { + BackgroundColor lightyellow + BorderColor black + ArrowColor black + Shadowing true + } + + """; + } } diff --git a/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java b/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java index 85043f8..ce3c386 100644 --- a/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java +++ b/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java @@ -10,68 +10,85 @@ import java.util.Map; import java.util.stream.Collectors; -public class GraphMLClassifierVertex { - - private static final String CLASS_COLOR = "#FF9900"; - private static final String INTERFACE_COLOR = "#3366FF"; - - private final StringBuilder graphMLBuffer; - private final ClassDiagram classDiagram; - - public GraphMLClassifierVertex(ClassDiagram classDiagram) { - this.classDiagram = classDiagram; - graphMLBuffer = new StringBuilder(); - } - - public StringBuilder convertSinkVertex() { - for (Map.Entry sinkVertex: classDiagram.getGraphNodes().entrySet()) { - graphMLBuffer.append(GraphMLSyntax.getInstance() - .getGraphMLSinkVertexSyntax(getSinkVertexDescription(sinkVertex.getKey(), - sinkVertex.getValue(), - classDiagram.getGraphMLDiagramGeometry().get(sinkVertex.getValue())))); - } - return graphMLBuffer; - } - - private List getSinkVertexDescription(ClassifierVertex classifierVertex, - int nodeId, - Pair nodeGeometry) { - return Arrays.asList(String.valueOf(nodeId), - getSinkVertexColor(classifierVertex), - classifierVertex.getName(), - getSinkVertexFields(classifierVertex), - getSinkVertexMethods(classifierVertex), - String.valueOf(nodeGeometry.getValue0()), - String.valueOf(nodeGeometry.getValue1())); - } - - private String getSinkVertexMethods(ClassifierVertex classifierVertex) { - if (classifierVertex.getMethods().isEmpty()) { - return ""; - } - return classifierVertex.getMethods() - .stream() - .map(method -> method.returnType() + " " + method.name()) - .collect(Collectors.joining("\n")); - } - - private String getSinkVertexFields(ClassifierVertex classifierVertex) { - if (classifierVertex.getFields().isEmpty()) { - return ""; - } - return classifierVertex.getFields() - .stream() - .map(field -> String.join(" ", - field.type(), - field.name())) - .collect(Collectors.joining("\n")); - } - - private String getSinkVertexColor(ClassifierVertex leafNode) { - if (leafNode.getVertexType().equals(VertexType.INTERFACE)) { - return INTERFACE_COLOR; - } - return CLASS_COLOR; - } +public class GraphMLClassifierVertex +{ + + private static final String CLASS_COLOR = "#FF9900"; + private static final String INTERFACE_COLOR = "#3366FF"; + + private final StringBuilder graphMLBuffer; + private final ClassDiagram classDiagram; + + + public GraphMLClassifierVertex(ClassDiagram classDiagram) + { + this.classDiagram = classDiagram; + graphMLBuffer = new StringBuilder(); + } + + + public StringBuilder convertSinkVertex() + { + for (Map.Entry sinkVertex : classDiagram.getGraphNodes().entrySet()) + { + graphMLBuffer.append(GraphMLSyntax.getInstance() + .getGraphMLSinkVertexSyntax(getSinkVertexDescription(sinkVertex.getKey(), + sinkVertex.getValue(), + classDiagram.getGraphMLDiagramGeometry().get(sinkVertex.getValue())))); + } + return graphMLBuffer; + } + + + private List getSinkVertexDescription(ClassifierVertex classifierVertex, + int nodeId, + Pair nodeGeometry) + { + return Arrays.asList(String.valueOf(nodeId), + getSinkVertexColor(classifierVertex), + classifierVertex.getName(), + getSinkVertexFields(classifierVertex), + getSinkVertexMethods(classifierVertex), + String.valueOf(nodeGeometry.getValue0()), + String.valueOf(nodeGeometry.getValue1())); + } + + + private String getSinkVertexMethods(ClassifierVertex classifierVertex) + { + if (classifierVertex.getMethods().isEmpty()) + { + return ""; + } + return classifierVertex.getMethods() + .stream() + .map(method -> method.returnType() + " " + method.name()) + .collect(Collectors.joining("\n")); + } + + + private String getSinkVertexFields(ClassifierVertex classifierVertex) + { + if (classifierVertex.getFields().isEmpty()) + { + return ""; + } + return classifierVertex.getFields() + .stream() + .map(field -> String.join(" ", + field.type(), + field.name())) + .collect(Collectors.joining("\n")); + } + + + private String getSinkVertexColor(ClassifierVertex leafNode) + { + if (leafNode.getVertexType().equals(VertexType.INTERFACE)) + { + return INTERFACE_COLOR; + } + return CLASS_COLOR; + } } diff --git a/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java b/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java index 500ef6d..85b6754 100644 --- a/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java +++ b/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java @@ -9,48 +9,61 @@ import java.util.List; import java.util.Set; -public class GraphMLClassifierVertexArc { - - private static final int EDGE_TYPE = 0; - private static final int EDGES_SOURCE_TYPE = 1; - private static final int EDGES_TARGET_TYPE = 2; - - private final StringBuilder graphMLBuffer; - private final ClassDiagram classDiagram; - - public GraphMLClassifierVertexArc(ClassDiagram classDiagram) { - this.classDiagram = classDiagram; - graphMLBuffer = new StringBuilder(); - } - - public StringBuilder convertSinkVertexArc() { - List> arcs = new ArrayList<>(); - for (Set> arcSet: classDiagram.getDiagram().values()) { - arcs.addAll(arcSet); - } - - int edgeId = 0; - for (Arc arc: arcs) { - graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSinkVertexArcSyntax(getEdgesProperties(arc, edgeId))); - edgeId++; - } - return graphMLBuffer; - } - - private List getEdgesProperties(Arc relationship, Integer edgeId) { - return Arrays.asList(String.valueOf(edgeId), String.valueOf(classDiagram.getGraphNodes().get(relationship.sourceVertex())), - String.valueOf(classDiagram.getGraphNodes().get(relationship.targetVertex())), identifyEdgeType(relationship).get(EDGE_TYPE), - identifyEdgeType(relationship).get(EDGES_SOURCE_TYPE), identifyEdgeType(relationship).get(EDGES_TARGET_TYPE)); - } - - private List identifyEdgeType(Arc relationship){ - return switch (relationship.arcType()) { - case DEPENDENCY -> Arrays.asList("dashed", "none", "plain"); - case AGGREGATION -> Arrays.asList("line", "white_diamond", "none"); - case ASSOCIATION -> Arrays.asList("line", "none", "standard"); - case EXTENSION -> Arrays.asList("line", "none", "white_delta"); - default -> Arrays.asList("dashed", "none", "white_delta"); - }; - } +public class GraphMLClassifierVertexArc +{ + + private static final int EDGE_TYPE = 0; + private static final int EDGES_SOURCE_TYPE = 1; + private static final int EDGES_TARGET_TYPE = 2; + + private final StringBuilder graphMLBuffer; + private final ClassDiagram classDiagram; + + + public GraphMLClassifierVertexArc(ClassDiagram classDiagram) + { + this.classDiagram = classDiagram; + graphMLBuffer = new StringBuilder(); + } + + + public StringBuilder convertSinkVertexArc() + { + List> arcs = new ArrayList<>(); + for (Set> arcSet : classDiagram.getDiagram().values()) + { + arcs.addAll(arcSet); + } + + int edgeId = 0; + for (Arc arc : arcs) + { + graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSinkVertexArcSyntax(getEdgesProperties(arc, edgeId))); + edgeId++; + } + return graphMLBuffer; + } + + + private List getEdgesProperties(Arc relationship, + int edgeId) + { + return Arrays.asList(String.valueOf(edgeId), String.valueOf(classDiagram.getGraphNodes().get(relationship.sourceVertex())), + String.valueOf(classDiagram.getGraphNodes().get(relationship.targetVertex())), identifyEdgeType(relationship).get(EDGE_TYPE), + identifyEdgeType(relationship).get(EDGES_SOURCE_TYPE), identifyEdgeType(relationship).get(EDGES_TARGET_TYPE)); + } + + + private List identifyEdgeType(Arc relationship) + { + return switch (relationship.arcType()) + { + case DEPENDENCY -> Arrays.asList("dashed", "none", "plain"); + case AGGREGATION -> Arrays.asList("line", "white_diamond", "none"); + case ASSOCIATION -> Arrays.asList("line", "none", "standard"); + case EXTENSION -> Arrays.asList("line", "none", "white_delta"); + default -> Arrays.asList("dashed", "none", "white_delta"); + }; + } } diff --git a/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java b/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java index de65706..4650ace 100644 --- a/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java +++ b/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java @@ -8,32 +8,40 @@ import java.util.List; import java.util.Map; -public class GraphMLPackageVertex { - - private final StringBuilder graphMLBuffer; - private final PackageDiagram packageDiagram; - - public GraphMLPackageVertex(PackageDiagram packageDiagram) { - this.packageDiagram = packageDiagram; - graphMLBuffer = new StringBuilder(); - } - - public StringBuilder convertVertex() { - for (Map.Entry entry: packageDiagram.getGraphNodes().entrySet()) { - graphMLBuffer.append(GraphMLSyntax.getInstance() - .getGraphMLVertexSyntax(getVertexDescription(entry.getKey(), - entry.getValue(), - packageDiagram.getGraphMLDiagramGeometry().get(entry.getValue())))); - } - return graphMLBuffer; - } - - private List getVertexDescription(PackageVertex packageNode, - int nodeId, - Pair nodeGeometry) { - return Arrays.asList(String.valueOf(nodeId), packageNode.getName(), - String.valueOf(nodeGeometry.getValue0()), - String.valueOf(nodeGeometry.getValue1())); - } +public class GraphMLPackageVertex +{ + + private final StringBuilder graphMLBuffer; + private final PackageDiagram packageDiagram; + + + public GraphMLPackageVertex(PackageDiagram packageDiagram) + { + this.packageDiagram = packageDiagram; + graphMLBuffer = new StringBuilder(); + } + + + public StringBuilder convertVertex() + { + for (Map.Entry entry : packageDiagram.getGraphNodes().entrySet()) + { + graphMLBuffer.append(GraphMLSyntax.getInstance() + .getGraphMLVertexSyntax(getVertexDescription(entry.getKey(), + entry.getValue(), + packageDiagram.getGraphMLDiagramGeometry().get(entry.getValue())))); + } + return graphMLBuffer; + } + + + private List getVertexDescription(PackageVertex packageNode, + int nodeId, + Pair nodeGeometry) + { + return Arrays.asList(String.valueOf(nodeId), packageNode.getName(), + String.valueOf(nodeGeometry.getValue0()), + String.valueOf(nodeGeometry.getValue1())); + } } diff --git a/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java b/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java index ccece9a..8e16868 100644 --- a/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java +++ b/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java @@ -9,33 +9,42 @@ import java.util.List; import java.util.Set; -public class GraphMLPackageVertexArc { - private final StringBuilder graphMLBuffer; - private final PackageDiagram packageDiagram; - - public GraphMLPackageVertexArc(PackageDiagram packageDiagram) { - this.packageDiagram = packageDiagram; - graphMLBuffer = new StringBuilder(); - } - - public StringBuilder convertVertexArc() { - List> arcs = new ArrayList<>(); - for (Set> arcSet: packageDiagram.getDiagram().values()) { - arcs.addAll(arcSet); - } - int edgeId = 0; - for (Arc arc: arcs) { - graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLVertexArcSyntax(getVertexArcProperties(arc, edgeId))); - edgeId++; - } - return graphMLBuffer; - } - - private List getVertexArcProperties(Arc relationship, Integer edgeId) { - return - Arrays.asList(String.valueOf(edgeId), - String.valueOf(packageDiagram.getGraphNodes().get(relationship.sourceVertex())), - String.valueOf(packageDiagram.getGraphNodes().get(relationship.targetVertex()))); - } +public class GraphMLPackageVertexArc +{ + private final StringBuilder graphMLBuffer; + private final PackageDiagram packageDiagram; + + + public GraphMLPackageVertexArc(PackageDiagram packageDiagram) + { + this.packageDiagram = packageDiagram; + graphMLBuffer = new StringBuilder(); + } + + + public StringBuilder convertVertexArc() + { + List> arcs = new ArrayList<>(); + for (Set> arcSet : packageDiagram.getDiagram().values()) + { + arcs.addAll(arcSet); + } + int edgeId = 0; + for (Arc arc : arcs) + { + graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLVertexArcSyntax(getVertexArcProperties(arc, edgeId))); + edgeId++; + } + return graphMLBuffer; + } + + + private List getVertexArcProperties(Arc relationship, + int edgeId) + { + return Arrays.asList(String.valueOf(edgeId), + String.valueOf(packageDiagram.getGraphNodes().get(relationship.sourceVertex())), + String.valueOf(packageDiagram.getGraphNodes().get(relationship.targetVertex()))); + } } diff --git a/src/main/java/model/diagram/graphml/GraphMLSyntax.java b/src/main/java/model/diagram/graphml/GraphMLSyntax.java index 151dac6..0d706cb 100644 --- a/src/main/java/model/diagram/graphml/GraphMLSyntax.java +++ b/src/main/java/model/diagram/graphml/GraphMLSyntax.java @@ -2,136 +2,153 @@ import java.util.List; -public class GraphMLSyntax { - - private static GraphMLSyntax instance; - - private GraphMLSyntax() {} - - public String getGraphMLPrefix(){ - return """ - - - - - - - - - - - - - - - - - """; - } - - public String getGraphMLSuffix() { - return """ - - - - - - """; - } - - public String getGraphMLSinkVertexSyntax(List sinkVertexDescription) { - return String.format(""" - - - - - - - - - %s - - %s - %s - - - - - """, - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()), - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_X_COORDINATE.getId()), - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_Y_COORDINATE.getId()), - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_COLOR.getId()), - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_NAME.getId()), - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_FIELDS.getId()), - sinkVertexDescription.get(GraphMLSyntaxIds.NODE_METHODS.getId())); - } - - public String getGraphMLVertexSyntax(List vertexDescription) { - return String.format(""" - - - - - - - - %s - - - - """, - vertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()), - vertexDescription.get(GraphMLSyntaxIds.PACKAGE_X_COORDINATE.getId()), - vertexDescription.get(GraphMLSyntaxIds.PACKAGE_Y_COORDINATE.getId()), - vertexDescription.get(GraphMLSyntaxIds.PACKAGE_NAME.getId())); - } - - public String getGraphMLSinkVertexArcSyntax(List sinkVertexArcDescription) { - return String.format(""" - - - - - - - - - - - """, - sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()), - sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()), - sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId()), - sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TYPE.getId()), - sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_SOURCE_TYPE.getId()), - sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_TARGET_TYPE.getId())); - } - - public String getGraphMLVertexArcSyntax(List vertexArcDescription) { - return String.format(""" - - - - - - - - - - - \ - """, - vertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()), - vertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()), - vertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId())); - } - - public static GraphMLSyntax getInstance(){ - if (instance == null) { - instance = new GraphMLSyntax(); - } - return instance; - } +public class GraphMLSyntax +{ + private static GraphMLSyntax instance; + + + public String getGraphMLPrefix() + { + return """ + + + + + + + + + + + + + + + + + """; + } + + + public String getGraphMLSuffix() + { + return """ + + + + + + """; + } + + + public String getGraphMLSinkVertexSyntax(List sinkVertexDescription) + { + return String.format(""" + + + + + + + + + %s + + %s + %s + + + + + """, + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()), + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_X_COORDINATE.getId()), + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_Y_COORDINATE.getId()), + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_COLOR.getId()), + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_NAME.getId()), + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_FIELDS.getId()), + sinkVertexDescription.get(GraphMLSyntaxIds.NODE_METHODS.getId())); + } + + + public String getGraphMLVertexSyntax(List vertexDescription) + { + return String.format(""" + + + + + + + + %s + + + + """, + vertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()), + vertexDescription.get(GraphMLSyntaxIds.PACKAGE_X_COORDINATE.getId()), + vertexDescription.get(GraphMLSyntaxIds.PACKAGE_Y_COORDINATE.getId()), + vertexDescription.get(GraphMLSyntaxIds.PACKAGE_NAME.getId())); + } + + + public String getGraphMLSinkVertexArcSyntax(List sinkVertexArcDescription) + { + return String.format(""" + + + + + + + + + + + """, + sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()), + sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()), + sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId()), + sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TYPE.getId()), + sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_SOURCE_TYPE.getId()), + sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_TARGET_TYPE.getId())); + } + + + public String getGraphMLVertexArcSyntax(List vertexArcDescription) + { + return String.format(""" + + + + + + + + + + + \ + """, + vertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()), + vertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()), + vertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId())); + } + + + public static GraphMLSyntax getInstance() + { + if (instance == null) + { + instance = new GraphMLSyntax(); + } + return instance; + } + + + /** Singleton. Do not instantiate. */ + private GraphMLSyntax() {} } diff --git a/src/main/java/model/diagram/graphml/GraphMLSyntaxIds.java b/src/main/java/model/diagram/graphml/GraphMLSyntaxIds.java index 4d4108f..5c03399 100644 --- a/src/main/java/model/diagram/graphml/GraphMLSyntaxIds.java +++ b/src/main/java/model/diagram/graphml/GraphMLSyntaxIds.java @@ -1,29 +1,33 @@ package model.diagram.graphml; -public enum GraphMLSyntaxIds { - NODE_ID (0), - NODE_COLOR (1), - NODE_NAME (2), - NODE_FIELDS (3), - NODE_METHODS (4), - NODE_X_COORDINATE (5), - NODE_Y_COORDINATE (6), - EDGE_ID (0), - EDGE_SOURCE (1), - EDGE_TARGET (2), - EDGE_TYPE (3), - EDGES_SOURCE_TYPE (4), - EDGES_TARGET_TYPE (5), - PACKAGE_X_COORDINATE (2), - PACKAGE_Y_COORDINATE (3), - PACKAGE_NAME (1); +public enum GraphMLSyntaxIds +{ + NODE_ID (0), + NODE_COLOR (1), + NODE_NAME (2), + NODE_FIELDS (3), + NODE_METHODS (4), + NODE_X_COORDINATE (5), + NODE_Y_COORDINATE (6), + EDGE_ID (0), + EDGE_SOURCE (1), + EDGE_TARGET (2), + EDGE_TYPE (3), + EDGES_SOURCE_TYPE (4), + EDGES_TARGET_TYPE (5), + PACKAGE_X_COORDINATE(2), + PACKAGE_Y_COORDINATE(3), + PACKAGE_NAME (1); private final int id; - GraphMLSyntaxIds(int id) { + + GraphMLSyntaxIds(int id) + { this.id = id; } + public int getId() { return id; diff --git a/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java b/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java index 3a97b72..ed87581 100644 --- a/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java +++ b/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java @@ -18,78 +18,94 @@ import java.util.ArrayList; import java.util.List; -public class ClassifierVertexDeserializer implements JsonDeserializer { - private ClassifierVertex classifierVertex; +public class ClassifierVertexDeserializer implements JsonDeserializer +{ + private ClassifierVertex classifierVertex; - @Override - public ClassifierVertex deserialize(JsonElement jsonElement, - Type type, - JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - JsonObject jsonObject = jsonElement.getAsJsonObject(); - String name = jsonObject.get("name").getAsString(); - String path = jsonObject.get("path").getAsString(); - String vertexType = jsonObject.get("vertexType").getAsString(); - if (VertexType.get(vertexType).equals(VertexType.PACKAGE)) { - throw new JsonParseException("Wrong diagram type"); - } - classifierVertex = new ClassifierVertex(Path.of(path), name, VertexType.get(vertexType)); - if (jsonObject.has("coordinate_x") && jsonObject.has("coordinate_x")) { - double coordinateX = jsonObject.get("coordinate_x").getAsDouble(); - double coordinateY = jsonObject.get("coordinate_y").getAsDouble(); - classifierVertex.updateCoordinate(coordinateX, coordinateY); - } - deserializeMethods(jsonObject); - deserializeFields(jsonObject); - deserializeArcs(jsonObject); - return classifierVertex; - } + @Override + public ClassifierVertex deserialize(JsonElement jsonElement, + Type type, + JsonDeserializationContext jsonDeserializationContext) throws JsonParseException + { + JsonObject jsonObject = jsonElement.getAsJsonObject(); + String name = jsonObject.get("name").getAsString(); + String path = jsonObject.get("path").getAsString(); + String vertexType = jsonObject.get("vertexType").getAsString(); + if (VertexType.get(vertexType).equals(VertexType.PACKAGE)) + { + throw new JsonParseException("Wrong diagram type"); + } + classifierVertex = new ClassifierVertex(Path.of(path), name, VertexType.get(vertexType)); + if (jsonObject.has("coordinate_x") && jsonObject.has("coordinate_x")) + { + double coordinateX = jsonObject.get("coordinate_x").getAsDouble(); + double coordinateY = jsonObject.get("coordinate_y").getAsDouble(); + classifierVertex.setCoordinate(coordinateX, coordinateY); + } + deserializeMethods(jsonObject); + deserializeFields(jsonObject); + deserializeArcs(jsonObject); - private void deserializeMethods(JsonObject jsonObject) { - JsonArray methods = jsonObject.get("methods").getAsJsonArray(); - Gson gson = new Gson(); - for (int i = 0; i < methods.size(); i++) { - JsonObject method = methods.get(i).getAsJsonObject(); - String methodName = method.get("name").getAsString(); - String returnType = method.get("returnType").getAsString(); - String modifier = method.get("modifier").getAsString(); - String parameters = method.get("parameters").getAsString(); - classifierVertex.addMethod(methodName, - returnType, - ModifierType.get(modifier), - gson.fromJson(parameters, - new TypeToken<>() {}.getType()) - ); - } - } + return classifierVertex; + } - private void deserializeFields(JsonObject jsonObject) { - JsonArray fields = jsonObject.get("fields").getAsJsonArray(); - for (int i = 0; i < fields.size(); i++) { - JsonObject fieldObject = fields.get(i).getAsJsonObject(); - String fieldName = fieldObject.get("name").getAsString(); - String returnType = fieldObject.get("returnType").getAsString(); - String modifierType = fieldObject.get("modifier").getAsString(); - classifierVertex.addField(fieldName, - returnType, - ModifierType.get(modifierType) - ); - } - } - private void deserializeArcs(JsonObject jsonObject) { - List> arcs = new ArrayList<>(); - JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray(); - for (int i = 0; i < arcsArray.size(); i++) { - JsonObject arcObject = arcsArray.get(i).getAsJsonObject(); - String sourceVertex = arcObject.get("source").getAsString(); - String targetVertex = arcObject.get("target").getAsString(); - String arcType = arcObject.get("arcType").getAsString(); - arcs.add(new Triplet<>(sourceVertex, - targetVertex, - arcType)); - } - classifierVertex.setDeserializedArcs(arcs); - } + private void deserializeMethods(JsonObject jsonObject) + { + JsonArray methods = jsonObject.get("methods").getAsJsonArray(); + Gson gson = new Gson(); + for (int i = 0; i < methods.size(); i++) + { + JsonObject method = methods.get(i).getAsJsonObject(); + String methodName = method.get("name").getAsString(); + String returnType = method.get("returnType").getAsString(); + String modifier = method.get("modifier").getAsString(); + String parameters = method.get("parameters").getAsString(); + classifierVertex.addMethod(methodName, + returnType, + ModifierType.get(modifier), + gson.fromJson(parameters, + new TypeToken<>() + { + }.getType()) + ); + } + } + + + private void deserializeFields(JsonObject jsonObject) + { + JsonArray fields = jsonObject.get("fields").getAsJsonArray(); + for (int i = 0; i < fields.size(); i++) + { + JsonObject fieldObject = fields.get(i).getAsJsonObject(); + String fieldName = fieldObject.get("name").getAsString(); + String returnType = fieldObject.get("returnType").getAsString(); + String modifierType = fieldObject.get("modifier").getAsString(); + classifierVertex.addField(fieldName, + returnType, + ModifierType.get(modifierType) + ); + } + } + + + private void deserializeArcs(JsonObject jsonObject) + { + List> arcs = new ArrayList<>(); + JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray(); + for (int i = 0; i < arcsArray.size(); i++) + { + JsonObject arcObject = arcsArray.get(i).getAsJsonObject(); + String sourceVertex = arcObject.get("source").getAsString(); + String targetVertex = arcObject.get("target").getAsString(); + String arcType = arcObject.get("arcType").getAsString(); + arcs.add(new Triplet<>(sourceVertex, + targetVertex, + arcType)); + } + classifierVertex.setDeserializedArcs(arcs); + } } diff --git a/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java b/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java index dfa104c..d666514 100644 --- a/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java +++ b/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java @@ -17,51 +17,65 @@ import java.util.Optional; import java.util.Set; -public class JavaFXClassDiagramLoader { +public class JavaFXClassDiagramLoader +{ - private final Path graphSavePath; + private final Path graphSavePath; - public JavaFXClassDiagramLoader(Path graphSavePath) { - this.graphSavePath = graphSavePath; - } - public Set loadDiagram() throws JsonParseException { - Set sinkVertices = new HashSet<>(); - try { - byte[] encodedBytes = Files.readAllBytes(graphSavePath); - String json = new String(encodedBytes, StandardCharsets.ISO_8859_1); - Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, - new ClassifierVertexDeserializer()) - .create(); + public JavaFXClassDiagramLoader(Path graphSavePath) + { + this.graphSavePath = graphSavePath; + } - ClassifierVertex[] sinkVerticesArray = gson.fromJson(json, ClassifierVertex[].class); - Collections.addAll(sinkVertices, sinkVerticesArray); - deserializeArcs(sinkVertices); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - return sinkVertices; - } - private void deserializeArcs(Set sinkVertices) { - for (ClassifierVertex classifierVertex : sinkVertices) { - List> deserializedArcs = classifierVertex.getDeserializedArcs(); - for (Triplet arc: deserializedArcs) { - Optional sourceVertex = sinkVertices - .stream() - .filter(sinkVertex1 -> sinkVertex1.getName().equals(arc.getValue0())) - .findFirst(); - Optional targetVertex = sinkVertices - .stream() - .filter(sinkVertex1 -> sinkVertex1.getName().equals(arc.getValue1())) - .findFirst(); - if (sourceVertex.isEmpty() || targetVertex.isEmpty()) { - continue; - } - classifierVertex.addArc(sourceVertex.get(), targetVertex.get(), ArcType.get(arc.getValue2())); - } - } - } + public Set loadDiagram() throws JsonParseException + { + Set sinkVertices = new HashSet<>(); + try + { + byte[] encodedBytes = Files.readAllBytes(graphSavePath); + String json = new String(encodedBytes, StandardCharsets.ISO_8859_1); + Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, + new ClassifierVertexDeserializer()) + .create(); + + ClassifierVertex[] sinkVerticesArray = gson.fromJson(json, ClassifierVertex[].class); + Collections.addAll(sinkVertices, sinkVerticesArray); + deserializeArcs(sinkVertices); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + return sinkVertices; + } + + + private void deserializeArcs(Set sinkVertices) + { + for (ClassifierVertex classifierVertex : sinkVertices) + { + List> deserializedArcs = classifierVertex.getDeserializedArcs(); + for (Triplet arc : deserializedArcs) + { + Optional sourceVertex = sinkVertices + .stream() + .filter(sinkVertex1 -> sinkVertex1.getName().equals(arc.getValue0())) + .findFirst(); + Optional targetVertex = sinkVertices + .stream() + .filter(sinkVertex1 -> sinkVertex1.getName().equals(arc.getValue1())) + .findFirst(); + if (sourceVertex.isEmpty() || + targetVertex.isEmpty()) + { + continue; + } + classifierVertex.addArc(sourceVertex.get(), targetVertex.get(), ArcType.get(arc.getValue2())); + } + } + } } diff --git a/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java b/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java index e7c9c2d..25283d2 100644 --- a/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java +++ b/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java @@ -15,81 +15,108 @@ import java.util.Collection; import java.util.Set; -public class JavaFXClassVisualization implements JavaFXVisualization { - - private final ClassDiagram classDiagram; - private static SmartGraphPanel graphView; - private static Collection> vertexCollection; - - public JavaFXClassVisualization(ClassDiagram diagram) { - this.classDiagram = diagram; - } - - @Override - public SmartGraphPanel createGraphView() { - Graph graph = createGraph(); - vertexCollection = graph.vertices(); - graphView = new SmartGraphPanel<>(graph, - new SmartCircularSortedPlacementStrategy()); - setSinkVertexCustomStyle(); - return graphView; - } - - @Override - public Collection> getVertexCollection(){ - return vertexCollection; - } - - private Graph createGraph() { - Digraph directedGraph = new DigraphEdgeList<>(); - for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()) { - directedGraph.insertVertex(classifierVertex.getName()); - } - insertSinkVertexArcs(directedGraph); - return directedGraph; - } - - private void insertSinkVertexArcs(Digraph directedGraph){ - for (Set> arcs : classDiagram.getDiagram().values()) { - for (Arc arc: arcs) { - if (arc.arcType().equals(ArcType.AGGREGATION)) { - directedGraph.insertEdge(arc.targetVertex().getName(), - arc.sourceVertex().getName(), - arc.targetVertex().getName() + "_" + arc.sourceVertex().getName() + "_" + arc.arcType()); - } else { - directedGraph.insertEdge(arc.sourceVertex().getName(), - arc.targetVertex().getName(), - arc.sourceVertex().getName() + "_" + arc.targetVertex().getName() + "_" + arc.arcType()); - } - } - } - } - - private void setSinkVertexCustomStyle() { - for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()){ - if (classifierVertex.getVertexType().equals(VertexType.INTERFACE)) { - graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexInterface"); - } else { - graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexPackage"); - } - } - } - - @Override - public SmartGraphPanel getLoadedGraph() { - for (Vertex vertex : vertexCollection) { - for (ClassifierVertex classifierVertex: classDiagram.getDiagram().keySet()){ - if (!classifierVertex.getName().equals(vertex.element())) { - continue; - } - graphView.setVertexPosition(vertex, - classifierVertex.getCoordinate().getX(), - classifierVertex.getCoordinate().getY()); - break; +public class JavaFXClassVisualization implements JavaFXVisualization +{ + + private final ClassDiagram classDiagram; + private SmartGraphPanel graphView; + private Collection> vertexCollection; + + + public JavaFXClassVisualization(ClassDiagram diagram) + { + this.classDiagram = diagram; + } + + + @Override + public SmartGraphPanel createGraphView() + { + Graph graph = createGraph(); + vertexCollection = graph.vertices(); + graphView = new SmartGraphPanel<>(graph, new SmartCircularSortedPlacementStrategy()); + setSinkVertexCustomStyle(); + return graphView; + } + + + @Override + public Collection> getVertexCollection() + { + return vertexCollection; + } + + + private Graph createGraph() + { + Digraph directedGraph = new DigraphEdgeList<>(); + for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()) + { + directedGraph.insertVertex(classifierVertex.getName()); + } + insertSinkVertexArcs(directedGraph); + return directedGraph; + } + + + private void insertSinkVertexArcs(Digraph directedGraph) + { + for (Set> arcs : classDiagram.getDiagram().values()) + { + for (Arc arc : arcs) + { + if (arc.arcType().equals(ArcType.AGGREGATION)) + { + directedGraph.insertEdge(arc.targetVertex().getName(), + arc.sourceVertex().getName(), + arc.targetVertex().getName() + "_" + arc.sourceVertex().getName() + "_" + arc.arcType()); + } + else + { + directedGraph.insertEdge(arc.sourceVertex().getName(), + arc.targetVertex().getName(), + arc.sourceVertex().getName() + "_" + arc.targetVertex().getName() + "_" + arc.arcType()); + } + } + } + } + + + private void setSinkVertexCustomStyle() + { + for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()) + { + if (classifierVertex.getVertexType().equals(VertexType.INTERFACE)) + { + graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexInterface"); + } + else + { + graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexPackage"); + } + } + } + + + @Override + public SmartGraphPanel getLoadedGraph() + { + for (Vertex vertex : vertexCollection) + { + for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()) + { + if (!classifierVertex.getName().equals(vertex.element())) + { + continue; + } + graphView.setVertexPosition(vertex, + classifierVertex.getCoordinate().x(), + classifierVertex.getCoordinate().y()); + break; } - } + } - return graphView; - } + return graphView; + } } diff --git a/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java b/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java index 390f287..a372bcf 100644 --- a/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java +++ b/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java @@ -17,48 +17,61 @@ import java.util.Optional; import java.util.Set; -public class JavaFXPackageDiagramLoader { +public class JavaFXPackageDiagramLoader +{ - private final Path graphSavePath; + private final Path graphSavePath; - public JavaFXPackageDiagramLoader(Path graphSavePath) { - this.graphSavePath = graphSavePath; - } - public Set loadDiagram() throws JsonParseException { - Set vertices = new HashSet<>(); - try { - byte[] encodedBytes = Files.readAllBytes(graphSavePath); - String json = new String(encodedBytes, StandardCharsets.ISO_8859_1); - Gson gson = new GsonBuilder().registerTypeAdapter(PackageVertex.class, - new PackageVertexDeserializer()) - .create(); - PackageVertex[] verticesArray = gson.fromJson(json, PackageVertex[].class); - Collections.addAll(vertices, verticesArray); - deserializeArcs(vertices); - } catch (IOException e) { - e.printStackTrace(); - } - return vertices; - } + public JavaFXPackageDiagramLoader(Path graphSavePath) + { + this.graphSavePath = graphSavePath; + } - private void deserializeArcs(Set vertices) { - for (PackageVertex vertex: vertices) { - List> deserializedArcs = vertex.getDeserializedArcs(); - for (Triplet arc: deserializedArcs) { - Optional sourceVertex = vertices - .stream() - .filter(vertex1 -> vertex1.getName().equals(arc.getValue0())) - .findFirst(); - Optional targetVertex = vertices - .stream() - .filter(vertex1 -> vertex1.getName().equals(arc.getValue1())) - .findFirst(); - if (sourceVertex.isEmpty() || targetVertex.isEmpty()) { - continue; - } - vertex.addArc(sourceVertex.get(), targetVertex.get(), ArcType.get(arc.getValue2())); - } - } - } + + public Set loadDiagram() throws JsonParseException + { + Set vertices = new HashSet<>(); + try + { + byte[] encodedBytes = Files.readAllBytes(graphSavePath); + String json = new String(encodedBytes, StandardCharsets.ISO_8859_1); + Gson gson = new GsonBuilder().registerTypeAdapter(PackageVertex.class, + new PackageVertexDeserializer()) + .create(); + PackageVertex[] verticesArray = gson.fromJson(json, PackageVertex[].class); + Collections.addAll(vertices, verticesArray); + deserializeArcs(vertices); + } + catch (IOException e) + { + e.printStackTrace(); + } + return vertices; + } + + + private void deserializeArcs(Set vertices) + { + for (PackageVertex vertex : vertices) + { + List> deserializedArcs = vertex.getDeserializedArcs(); + for (Triplet arc : deserializedArcs) + { + Optional sourceVertex = vertices + .stream() + .filter(vertex1 -> vertex1.getName().equals(arc.getValue0())) + .findFirst(); + Optional targetVertex = vertices + .stream() + .filter(vertex1 -> vertex1.getName().equals(arc.getValue1())) + .findFirst(); + if (sourceVertex.isEmpty() || targetVertex.isEmpty()) + { + continue; + } + vertex.addArc(sourceVertex.get(), targetVertex.get(), ArcType.get(arc.getValue2())); + } + } + } } diff --git a/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java b/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java index a5388aa..217fb8e 100644 --- a/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java +++ b/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java @@ -15,85 +15,114 @@ import java.util.Collection; import java.util.Set; -public class JavaFXPackageVisualization implements JavaFXVisualization { - - private final PackageDiagram packageDiagram; - private SmartGraphPanel graphView; - private Collection> vertexCollection; - - public JavaFXPackageVisualization(PackageDiagram diagram) { - this.packageDiagram = diagram; - } - - @Override - public SmartGraphPanel createGraphView() { - Graph graph = createGraph(); - vertexCollection = graph.vertices(); - graphView = new SmartGraphPanel<>(graph, - new SmartCircularSortedPlacementStrategy()); - setVertexCustomStyle(); - return graphView; - } - - @Override - public Collection> getVertexCollection(){ - return vertexCollection; - } - - private Graph createGraph() { - Digraph directedGraph = new DigraphEdgeList<>(); - for (PackageVertex vertex: packageDiagram.getDiagram().keySet()) { - if (vertex.getSinkVertices().isEmpty()) { - continue; - } - directedGraph.insertVertex(vertex.getName()); +public class JavaFXPackageVisualization implements JavaFXVisualization +{ + + private final PackageDiagram packageDiagram; + private SmartGraphPanel graphView; + private Collection> vertexCollection; + + + public JavaFXPackageVisualization(PackageDiagram diagram) + { + this.packageDiagram = diagram; + } + + + @Override + public SmartGraphPanel createGraphView() + { + Graph graph = createGraph(); + vertexCollection = graph.vertices(); + graphView = new SmartGraphPanel<>(graph, new SmartCircularSortedPlacementStrategy()); + setVertexCustomStyle(); + return graphView; + } + + + @Override + public Collection> getVertexCollection() + { + return vertexCollection; + } + + + private Graph createGraph() + { + Digraph directedGraph = new DigraphEdgeList<>(); + for (PackageVertex vertex : packageDiagram.getDiagram().keySet()) + { + if (vertex.getSinkVertices().isEmpty()) + { + continue; + } + directedGraph.insertVertex(vertex.getName()); + } + insertVertexArcs(directedGraph); + return directedGraph; + } + + + private void insertVertexArcs(Digraph directedGraph) + { + for (Set> arcs : packageDiagram.getDiagram().values()) + { + for (Arc arc : arcs) + { + if (arc.arcType().equals(ArcType.AGGREGATION)) + { + directedGraph.insertEdge(arc.targetVertex().getName(), + arc.sourceVertex().getName(), + arc.targetVertex().getName() + "_" + arc.sourceVertex().getName() + "_" + arc.arcType()); + } + else + { + directedGraph.insertEdge(arc.sourceVertex().getName(), + arc.targetVertex().getName(), + arc.sourceVertex().getName() + "_" + arc.targetVertex().getName() + "_" + arc.arcType()); + } + } + } + } + + + private void setVertexCustomStyle() + { + for (PackageVertex vertex : packageDiagram.getDiagram().keySet()) + { + if (vertex.getVertexType().equals(VertexType.INTERFACE)) + { + graphView.getStylableVertex(vertex.getName()).setStyleClass("vertexInterface"); + } + else + { + if (vertex.getSinkVertices().isEmpty()) + { + continue; + } + graphView.getStylableVertex(vertex.getName()).setStyleClass("vertexPackage"); + } + } + } + + + @Override + public SmartGraphPanel getLoadedGraph() + { + for (Vertex vertex : vertexCollection) + { + for (PackageVertex packageVertex : packageDiagram.getDiagram().keySet()) + { + if (!packageVertex.getName().equals(vertex.element())) + { + continue; + } + graphView.setVertexPosition(vertex, + packageVertex.getCoordinate().x(), + packageVertex.getCoordinate().y()); + break; + } } - insertVertexArcs(directedGraph); - return directedGraph; - } - - private void insertVertexArcs(Digraph directedGraph){ - for (Set> arcs : packageDiagram.getDiagram().values()) { - for (Arc arc: arcs) { - if (arc.arcType().equals(ArcType.AGGREGATION)) { - directedGraph.insertEdge(arc.targetVertex().getName(), - arc.sourceVertex().getName(), - arc.targetVertex().getName() + "_" + arc.sourceVertex().getName() + "_" + arc.arcType()); - } else { - directedGraph.insertEdge(arc.sourceVertex().getName(), - arc.targetVertex().getName(), - arc.sourceVertex().getName() + "_" +arc.targetVertex().getName() + "_" + arc.arcType()); - } - } - } - } - - private void setVertexCustomStyle() { - for (PackageVertex vertex: packageDiagram.getDiagram().keySet()){ - if (vertex.getVertexType().equals(VertexType.INTERFACE)) { - graphView.getStylableVertex(vertex.getName()).setStyleClass("vertexInterface"); - } else { - if (vertex.getSinkVertices().isEmpty()) { - continue; - } - graphView.getStylableVertex(vertex.getName()).setStyleClass("vertexPackage"); - } - } - } - - @Override - public SmartGraphPanel getLoadedGraph() { - for (Vertex vertex : vertexCollection) { - for (PackageVertex packageVertex: packageDiagram.getDiagram().keySet()){ - if (!packageVertex.getName().equals(vertex.element())) { - continue; - } - graphView.setVertexPosition(vertex, - packageVertex.getCoordinate().getX(), - packageVertex.getCoordinate().getY()); - break; - } - } - return graphView; - } + return graphView; + } } diff --git a/src/main/java/model/diagram/javafx/JavaFXVisualization.java b/src/main/java/model/diagram/javafx/JavaFXVisualization.java index b7b83ff..0aa711c 100644 --- a/src/main/java/model/diagram/javafx/JavaFXVisualization.java +++ b/src/main/java/model/diagram/javafx/JavaFXVisualization.java @@ -5,18 +5,19 @@ import com.brunomnsilva.smartgraph.graph.Vertex; import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel; -public interface JavaFXVisualization { +public interface JavaFXVisualization +{ - /** - * This method is responsible for create the GraphView object that will be rendered in the front-end. - * - * @return the {@link SmartGraphPanel} created - */ - SmartGraphPanel createGraphView(); + /** + * This method is responsible for create the GraphView object that will be rendered in the front-end. + * + * @return the {@link SmartGraphPanel} created + */ + SmartGraphPanel createGraphView(); - // TODO Add Javadoc - Collection> getVertexCollection(); + // TODO Add Javadoc + Collection> getVertexCollection(); - // TODO Add Javadoc - SmartGraphPanel getLoadedGraph(); + // TODO Add Javadoc + SmartGraphPanel getLoadedGraph(); } diff --git a/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java b/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java index a5d64d7..7b3a1b9 100644 --- a/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java +++ b/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java @@ -18,74 +18,92 @@ import java.util.ArrayList; import java.util.List; -public class PackageVertexDeserializer implements JsonDeserializer { - - private PackageVertex packageVertex; - - @Override - public PackageVertex deserialize(JsonElement jsonElement, - Type type, - JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - JsonObject jsonObject = jsonElement.getAsJsonObject(); - String path = jsonObject.get("path").getAsString(); - String vertexType = jsonObject.get("vertexType").getAsString(); - - if (!VertexType.get(vertexType).equals(VertexType.PACKAGE)) { - throw new JsonParseException("Wrong diagram type"); - } - - JsonObject parent = jsonObject.get("parent").getAsJsonObject(); - String parentName = parent.get("name").getAsString(); - packageVertex = new PackageVertex(Path.of(path), VertexType.get(vertexType), parentName); - if (jsonObject.has("coordinate_x") && jsonObject.has("coordinate_x")) { - double coordinateX = jsonObject.get("coordinate_x").getAsDouble(); - double coordinateY = jsonObject.get("coordinate_y").getAsDouble(); - packageVertex.createCoordinate(coordinateX, coordinateY); - } - deserializeSinkVertices(jsonObject); - deserializeNeighbourVertices(jsonObject); - deserializeArcs(jsonObject); - - return packageVertex; - } - - private void deserializeSinkVertices(JsonObject jsonObject) { - JsonArray sinkVertices = jsonObject.get("sinkVertices").getAsJsonArray(); - for (int i = 0; i < sinkVertices.size(); i++) { - String json = sinkVertices.get(i).getAsString(); - Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, - new ClassifierVertexDeserializer()) - .create(); - ClassifierVertex classifierVertex = gson.fromJson(json, - ClassifierVertex.class); - packageVertex.addSinkVertex(classifierVertex); - } - } - - private void deserializeNeighbourVertices(JsonObject jsonObject) { - JsonArray neighbourVertices = jsonObject.get("neighbours").getAsJsonArray(); - for (int i = 0; i < neighbourVertices.size(); i++) { - JsonObject vertexObject = neighbourVertices.get(i).getAsJsonObject(); - String path = vertexObject.get("path").getAsString(); - String vertexType = vertexObject.get("vertexType").getAsString(); - String parentName = vertexObject.get("parentName").getAsString(); - packageVertex.addNeighbourVertex(new PackageVertex(Path.of(path), - VertexType.get(vertexType), - parentName)); - } - } - - private void deserializeArcs(JsonObject jsonObject) { - JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray(); - List> arcs = new ArrayList<>(); - for (int i = 0; i < arcsArray.size(); i++) { - JsonObject arcObject = arcsArray.get(i).getAsJsonObject(); - String sourceVertex = arcObject.get("source").getAsString(); - String targetVertex = arcObject.get("target").getAsString(); - String arcType = arcObject.get("arcType").getAsString(); - arcs.add(new Triplet<>(sourceVertex, targetVertex, arcType)); - } - packageVertex.setDeserializedArcs(arcs); - } +public class PackageVertexDeserializer implements JsonDeserializer +{ + + private PackageVertex packageVertex; + + + @Override + public PackageVertex deserialize(JsonElement jsonElement, + Type type, + JsonDeserializationContext jsonDeserializationContext) throws JsonParseException + { + JsonObject jsonObject = jsonElement.getAsJsonObject(); + String path = jsonObject.get("path").getAsString(); + String vertexType = jsonObject.get("vertexType").getAsString(); + + if (!VertexType.get(vertexType).equals(VertexType.PACKAGE)) + { + throw new JsonParseException("Wrong diagram type"); + } + + JsonObject parent = jsonObject.get("parent").getAsJsonObject(); + String parentName = parent.get("name").getAsString(); + packageVertex = new PackageVertex(Path.of(path), + VertexType.get(vertexType), + parentName); + + if (jsonObject.has("coordinate_x") && + jsonObject.has("coordinate_x")) + { + double coordinateX = jsonObject.get("coordinate_x").getAsDouble(); + double coordinateY = jsonObject.get("coordinate_y").getAsDouble(); + packageVertex.setCoordinate(coordinateX, coordinateY); + } + deserializeSinkVertices(jsonObject); + deserializeNeighbourVertices(jsonObject); + deserializeArcs(jsonObject); + + return packageVertex; + } + + + private void deserializeSinkVertices(JsonObject jsonObject) + { + JsonArray sinkVertices = jsonObject.get("sinkVertices").getAsJsonArray(); + for (int i = 0; i < sinkVertices.size(); i++) + { + String json = sinkVertices.get(i).getAsString(); + Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, + new ClassifierVertexDeserializer()) + .create(); + ClassifierVertex classifierVertex = gson.fromJson(json, + ClassifierVertex.class); + packageVertex.addSinkVertex(classifierVertex); + } + } + + + private void deserializeNeighbourVertices(JsonObject jsonObject) + { + JsonArray neighbourVertices = jsonObject.get("neighbours").getAsJsonArray(); + for (int i = 0; i < neighbourVertices.size(); i++) + { + JsonObject vertexObject = neighbourVertices.get(i).getAsJsonObject(); + String path = vertexObject.get("path").getAsString(); + String vertexType = vertexObject.get("vertexType").getAsString(); + String parentName = vertexObject.get("parentName").getAsString(); + packageVertex.addNeighbourVertex(new PackageVertex(Path.of(path), + VertexType.get(vertexType), + parentName)); + } + } + + + private void deserializeArcs(JsonObject jsonObject) + { + JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray(); + List> arcs = new ArrayList<>(); + for (int i = 0; i < arcsArray.size(); i++) + { + JsonObject arcObject = arcsArray.get(i).getAsJsonObject(); + String sourceVertex = arcObject.get("source").getAsString(); + String targetVertex = arcObject.get("target").getAsString(); + String arcType = arcObject.get("arcType").getAsString(); + arcs.add(new Triplet<>(sourceVertex, targetVertex, arcType)); + } + packageVertex.setDeserializedArcs(arcs); + } } diff --git a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java index e6f4701..e7841b9 100644 --- a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java +++ b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java @@ -8,70 +8,99 @@ import java.util.List; import java.util.stream.Collectors; -public class PlantUMLClassifierVertex { - - private final ClassDiagram classDiagram; - - public PlantUMLClassifierVertex(ClassDiagram diagram) { - classDiagram = diagram; - } - - public StringBuilder convertSinkVertex() { - return new StringBuilder( - classDiagram.getDiagram().keySet() - .stream() - .map(sinkVertex -> - sinkVertex.getVertexType() + " " + sinkVertex.getName() + " {\n" + - convertFields(sinkVertex) + convertMethods(sinkVertex) + "}") - .collect(Collectors.joining("\n\n"))); - } - - private String convertFields(ClassifierVertex classifierVertex) { - if (classifierVertex.getFields().isEmpty()) { - return ""; - } - return classifierVertex.getFields() - .stream() - .map(field -> getVisibility(field.modifier()) + field.name() + ": " + field.type()) - .collect(Collectors.joining("\n")) + "\n"; - } - - private String convertMethods(ClassifierVertex classifierVertex) { - StringBuilder plantUMLMethods = new StringBuilder(); - List constructors = classifierVertex.getMethods() - .stream() - .filter(method -> method.returnType().equals("Constructor")) - .sorted(Comparator.comparingInt(method -> method.parameters().size())) - .collect(Collectors.toList()); - convertMethod(plantUMLMethods, constructors); - - List methods = classifierVertex.getMethods() - .stream() - .filter(method -> !method.returnType().equals("Constructor")) - .collect(Collectors.toList()); - convertMethod(plantUMLMethods, methods); - - return plantUMLMethods.toString(); - } - - private void convertMethod(StringBuilder plantUMLMethods, List methods) { - for (ClassifierVertex.Method method: methods) { - plantUMLMethods.append(getVisibility(method.modifier())).append(method.name()).append("(") - .append(method.parameters().entrySet() - .stream() - .map(parameter -> parameter.getValue() + " " + parameter.getKey()) - .collect(Collectors.joining(", "))) - .append("): ").append(method.returnType()).append("\n"); - } - } - - private String getVisibility(ModifierType visibilityEnum) { - return switch (visibilityEnum) { - case PRIVATE -> "-"; - case PUBLIC -> "+"; - case PROTECTED -> "#"; - default -> "~"; - }; - } +public class PlantUMLClassifierVertex +{ + + private final ClassDiagram classDiagram; + + + public PlantUMLClassifierVertex(ClassDiagram diagram) + { + classDiagram = diagram; + } + + + public StringBuilder convertSinkVertex() + { + return new StringBuilder( + classDiagram + .getDiagram() + .keySet() + .stream() + .map(sinkVertex -> + sinkVertex.getVertexType() + " " + sinkVertex.getName() + " {\n" + + convertFields(sinkVertex) + convertMethods(sinkVertex) + "}") + .collect(Collectors.joining("\n\n"))); + } + + + private String convertFields(ClassifierVertex classifierVertex) + { + if (classifierVertex.getFields().isEmpty()) + { + return ""; + } + return classifierVertex + .getFields() + .stream() + .map(field -> getVisibility(field.modifier()) + field.name() + ": " + field.type()) + .collect(Collectors.joining("\n")) + "\n"; + } + + + private String convertMethods(ClassifierVertex classifierVertex) + { + StringBuilder plantUMLMethods = new StringBuilder(); + List constructors = classifierVertex + .getMethods() + .stream() + .filter(method -> method.returnType().equals("Constructor")) + .sorted(Comparator.comparingInt(method -> method.parameters().size())) + .collect(Collectors.toList()); + convertMethod(plantUMLMethods, constructors); + + List methods = classifierVertex + .getMethods() + .stream() + .filter(method -> !method.returnType().equals("Constructor")) + .collect(Collectors.toList()); + convertMethod(plantUMLMethods, methods); + + return plantUMLMethods.toString(); + } + + + private void convertMethod(StringBuilder plantUMLMethods, + List methods) + { + for (ClassifierVertex.Method method : methods) + { + plantUMLMethods + .append(getVisibility(method.modifier())) + .append(method.name()) + .append("(") + .append(method + .parameters() + .entrySet() + .stream() + .map(parameter -> parameter.getValue() + " " + parameter.getKey()) + .collect(Collectors.joining(", "))) + .append("): ") + .append(method.returnType()) + .append("\n"); + } + } + + + private String getVisibility(ModifierType visibilityEnum) + { + return switch (visibilityEnum) + { + case PRIVATE -> "-"; + case PUBLIC -> "+"; + case PROTECTED -> "#"; + default -> "~"; + }; + } } diff --git a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java index f59b6af..35d2e9f 100644 --- a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java +++ b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java @@ -10,34 +10,45 @@ import java.util.Set; import java.util.stream.Collectors; -public class PlantUMLClassifierVertexArc { - - private final ClassDiagram classDiagram; - - public PlantUMLClassifierVertexArc(ClassDiagram diagram) { - this.classDiagram = diagram; - } - - public StringBuilder convertSinkVertexArc() { - return new StringBuilder(classDiagram.getDiagram().values() - .stream().flatMap(sinkVertexStream -> sinkVertexStream - .stream() - .map(sinkVertexArc -> String.join(" ", - sinkVertexArc.sourceVertex().getName(), - getRelationship(sinkVertexArc.arcType()), - sinkVertexArc.targetVertex().getName()))) - .collect(Collectors.joining("\n"))); - } - - private String getRelationship(ArcType relationshipType) { - return switch (relationshipType) { - case EXTENSION -> "--|>"; - case AGGREGATION -> "o--"; - case DEPENDENCY -> "..>"; - case IMPLEMENTATION -> "..|>"; - // ASSOCIATION - default -> "-->"; - }; - } +public class PlantUMLClassifierVertexArc +{ + + private final ClassDiagram classDiagram; + + + public PlantUMLClassifierVertexArc(ClassDiagram diagram) + { + this.classDiagram = diagram; + } + + + public StringBuilder convertSinkVertexArc() + { + return new StringBuilder(classDiagram + .getDiagram() + .values() + .stream() + .flatMap(sinkVertexStream -> sinkVertexStream + .stream() + .map(sinkVertexArc -> String.join(" ", + sinkVertexArc.sourceVertex().getName(), + getRelationship(sinkVertexArc.arcType()), + sinkVertexArc.targetVertex().getName()))) + .collect(Collectors.joining("\n"))); + } + + + private String getRelationship(ArcType relationshipType) + { + return switch (relationshipType) + { + case EXTENSION -> "--|>"; + case AGGREGATION -> "o--"; + case DEPENDENCY -> "..>"; + case IMPLEMENTATION -> "..|>"; + // ASSOCIATION + default -> "-->"; + }; + } } diff --git a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java index a2cae18..cf525de 100644 --- a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java +++ b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java @@ -4,19 +4,26 @@ import java.util.stream.Collectors; -public class PlantUMLPackageVertex { +public class PlantUMLPackageVertex +{ - private final PackageDiagram packageDiagram; + private final PackageDiagram packageDiagram; - public PlantUMLPackageVertex(PackageDiagram diagram) { - this.packageDiagram = diagram; - } - public StringBuilder convertVertex() { - return new StringBuilder(packageDiagram.getDiagram().keySet() - .stream() - .map(vertex -> vertex.getVertexType() + " " + vertex.getName() + " {\n" + "}\n") - .collect(Collectors.joining("\n"))); - } + public PlantUMLPackageVertex(PackageDiagram diagram) + { + this.packageDiagram = diagram; + } + + + public StringBuilder convertVertex() + { + return new StringBuilder(packageDiagram + .getDiagram() + .keySet() + .stream() + .map(vertex -> vertex.getVertexType() + " " + vertex.getName() + " {\n" + "}\n") + .collect(Collectors.joining("\n"))); + } } diff --git a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java index a0dc037..8518185 100644 --- a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java +++ b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java @@ -10,36 +10,46 @@ import java.util.Set; import java.util.stream.Collectors; -public class PlantUMLPackageVertexArc { - - private final PackageDiagram packageDiagram; - - public PlantUMLPackageVertexArc(PackageDiagram diagram) { - this.packageDiagram = diagram; - } - - public StringBuilder convertVertexArc() { - return new StringBuilder(packageDiagram.getDiagram().values() - .stream() - .flatMap(vertexArcStream -> vertexArcStream - .stream() - .map(vertexArc -> - String.join(" ", - vertexArc.sourceVertex().getName(), - getRelationship(vertexArc.arcType()), - vertexArc.targetVertex().getName()))) - .collect(Collectors.joining("\n"))); - } - - private String getRelationship(ArcType relationshipType) { - return switch (relationshipType) { - case EXTENSION -> "--|>"; - case AGGREGATION -> "o--"; - case DEPENDENCY -> "..>"; - case IMPLEMENTATION -> "..|>"; - // ASSOCIATION - default -> "-->"; - }; - } +public class PlantUMLPackageVertexArc +{ + + private final PackageDiagram packageDiagram; + + + public PlantUMLPackageVertexArc(PackageDiagram diagram) + { + this.packageDiagram = diagram; + } + + + public StringBuilder convertVertexArc() + { + return new StringBuilder(packageDiagram + .getDiagram() + .values() + .stream() + .flatMap(vertexArcStream -> vertexArcStream + .stream() + .map(vertexArc -> + String.join(" ", + vertexArc.sourceVertex().getName(), + getRelationship(vertexArc.arcType()), + vertexArc.targetVertex().getName()))) + .collect(Collectors.joining("\n"))); + } + + + private String getRelationship(ArcType relationshipType) + { + return switch (relationshipType) + { + case EXTENSION -> "--|>"; + case AGGREGATION -> "o--"; + case DEPENDENCY -> "..>"; + case IMPLEMENTATION -> "..|>"; + // ASSOCIATION + default -> "-->"; + }; + } } diff --git a/src/main/java/model/graph/Arc.java b/src/main/java/model/graph/Arc.java index 1ae3f11..6e86982 100644 --- a/src/main/java/model/graph/Arc.java +++ b/src/main/java/model/graph/Arc.java @@ -1,5 +1,5 @@ package model.graph; -public record Arc (T sourceVertex, - T targetVertex, - ArcType arcType) {} \ No newline at end of file +public record Arc(T sourceVertex, + T targetVertex, + ArcType arcType) {} \ No newline at end of file diff --git a/src/main/java/model/graph/ArcType.java b/src/main/java/model/graph/ArcType.java index 1c79de3..6a6775b 100644 --- a/src/main/java/model/graph/ArcType.java +++ b/src/main/java/model/graph/ArcType.java @@ -7,40 +7,48 @@ public enum ArcType implements Comparator { - DEPENDENCY (0), - EXTENSION (1), - IMPLEMENTATION(2), - AGGREGATION (3), - ASSOCIATION (4); - - private static final Map DEGREE_MAP; - - private final int degree; - - static { - Map map = new HashMap<>(); - for (ArcType arcType: ArcType.values()) { - map.put(arcType.toString().toLowerCase(), arcType); - } - DEGREE_MAP = Collections.unmodifiableMap(map); - } - - ArcType(int degree) { - this.degree = degree; - } - - public static ArcType get(String arcTypeName) { - return DEGREE_MAP.get(arcTypeName.toLowerCase().trim()); - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } - - @Override - public int compare(ArcType o1, ArcType o2) - { - return Integer.compare(o1.degree, o2.degree); - } + DEPENDENCY (0), + EXTENSION (1), + IMPLEMENTATION(2), + AGGREGATION (3), + ASSOCIATION (4); + + private static final Map DEGREE_MAP; + + private final int degree; + + static + { + Map map = new HashMap<>(); + for (ArcType arcType : ArcType.values()) + { + map.put(arcType.toString().toLowerCase(), arcType); + } + DEGREE_MAP = Collections.unmodifiableMap(map); + } + + ArcType(int degree) + { + this.degree = degree; + } + + + public static ArcType get(String arcTypeName) + { + return DEGREE_MAP.get(arcTypeName.toLowerCase().trim()); + } + + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } + + + @Override + public int compare(ArcType o1, ArcType o2) + { + return Integer.compare(o1.degree, o2.degree); + } } diff --git a/src/main/java/model/graph/ClassifierVertex.java b/src/main/java/model/graph/ClassifierVertex.java index f943047..5541410 100644 --- a/src/main/java/model/graph/ClassifierVertex.java +++ b/src/main/java/model/graph/ClassifierVertex.java @@ -7,82 +7,123 @@ import java.util.List; import java.util.Map; -public class ClassifierVertex { - - private final List> arcs; - private final List methods; - private final List fields; - private final VertexType vertexType; - private final Path path; - private final String name; - private final VertexCoordinate coordinate; - private List> deserializedArcs; - - public ClassifierVertex(Path path, - String name, - VertexType vertexType) { - this.vertexType = vertexType; - this.path = path; - this.name = name; - arcs = new ArrayList<>(); - methods = new ArrayList<>(); - fields = new ArrayList<>(); - coordinate = new VertexCoordinate(); - } - - - public void updateCoordinate(double x, double y) { - coordinate.x = x; - coordinate.y = y; - } - - public void addArc(ClassifierVertex sourceVertex, ClassifierVertex targetVertex, ArcType arcType) { - arcs.add(new Arc<>(sourceVertex, targetVertex, arcType)); - } - - public void addMethod(String name, String returnType, ModifierType modifier, Map parameters) { - methods.add(new Method(name, returnType, modifier, parameters)); - } - - public void addField(String name, String type, ModifierType modifier) { - fields.add(new Field(name, type, modifier)); - } - - public void setDeserializedArcs(List> deserializedArcs) { - this.deserializedArcs = deserializedArcs; - } - - public List> getDeserializedArcs() { - return deserializedArcs; - } - - public VertexType getVertexType() { - return vertexType; - } - - public List> getArcs() { - return arcs; - } - - public Path getPath() { - return path; - } - - public String getName() { - return name; - } - - public List getMethods() { - return methods; - } - - public List getFields() { - return fields; - } - - public VertexCoordinate getCoordinate() { +public class ClassifierVertex +{ + + private final List> arcs; + private final List methods; + private final List fields; + private final VertexType vertexType; + private final Path path; + private final String name; + private VertexCoordinate coordinate; + private List> deserializedArcs; + + + public ClassifierVertex(Path path, + String name, + VertexType vertexType) + { + this.vertexType = vertexType; + this.path = path; + this.name = name; + coordinate = new VertexCoordinate(0, 0); + arcs = new ArrayList<>(); + methods = new ArrayList<>(); + fields = new ArrayList<>(); + } + + + public void setCoordinate(double x, double y) + { + coordinate = new VertexCoordinate(x, y); + } + + + public void addArc(ClassifierVertex sourceVertex, + ClassifierVertex targetVertex, + ArcType arcType) + { + arcs.add(new Arc<>(sourceVertex, + targetVertex, + arcType)); + } + + + public void addMethod(String name, + String returnType, + ModifierType modifier, + Map parameters) + { + methods.add(new Method(name, + returnType, + modifier, + parameters)); + } + + + public void addField(String name, + String type, + ModifierType modifier) + { + fields.add(new Field(name, + type, + modifier)); + } + + + public void setDeserializedArcs(List> deserializedArcs) + { + this.deserializedArcs = deserializedArcs; + } + + + public List> getDeserializedArcs() + { + return deserializedArcs; + } + + + public VertexType getVertexType() + { + return vertexType; + } + + + public List> getArcs() + { + return arcs; + } + + + public Path getPath() + { + return path; + } + + + public String getName() + { + return name; + } + + + public List getMethods() + { + return methods; + } + + + public List getFields() + { + return fields; + } + + + public VertexCoordinate getCoordinate() + { return coordinate; - } + } public record Method(String name, diff --git a/src/main/java/model/graph/ModifierType.java b/src/main/java/model/graph/ModifierType.java index 02c3545..4aa058b 100644 --- a/src/main/java/model/graph/ModifierType.java +++ b/src/main/java/model/graph/ModifierType.java @@ -4,29 +4,35 @@ import java.util.HashMap; import java.util.Map; -public enum ModifierType { - PRIVATE, - PUBLIC, - PROTECTED, - PACKAGE_PRIVATE; - - private static final Map MODIFIER_TYPE; - - static { - Map temp = new HashMap<>(); - for (ModifierType modifierType: ModifierType.values()) { - temp.put(modifierType.toString().toLowerCase(), modifierType); - } - MODIFIER_TYPE = Collections.unmodifiableMap(temp); - } - - public static ModifierType get(String modifier) { - return MODIFIER_TYPE.get(modifier.toLowerCase().trim()); - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } +public enum ModifierType +{ + PRIVATE, + PUBLIC, + PROTECTED, + PACKAGE_PRIVATE; + + private static final Map MODIFIER_TYPE; + + static + { + Map temp = new HashMap<>(); + for (ModifierType modifierType : ModifierType.values()) + { + temp.put(modifierType.toString().toLowerCase(), modifierType); + } + MODIFIER_TYPE = Collections.unmodifiableMap(temp); + } + + public static ModifierType get(String modifier) + { + return MODIFIER_TYPE.get(modifier.toLowerCase().trim()); + } + + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/model/graph/PackageVertex.java b/src/main/java/model/graph/PackageVertex.java index 31c6e0c..40e398b 100644 --- a/src/main/java/model/graph/PackageVertex.java +++ b/src/main/java/model/graph/PackageVertex.java @@ -6,96 +6,134 @@ import java.util.ArrayList; import java.util.List; -public class PackageVertex { - - private static final ModifierType VERTEX_MODIFIER_TYPE = ModifierType.PACKAGE_PRIVATE; - - private final List> arcs; - private final List sinkVertices; - private final List neighbourVertices; - private final VertexType vertexType; - private final Path path; - private final String name; - private final VertexCoordinate coordinate; - private List> deserializedArcs; - private PackageVertex parentPackageVertex; - - public PackageVertex(Path path, - VertexType vertexType, - String parentName) { - this.path = path; - this.vertexType = vertexType; - this.arcs = new ArrayList<>(); - this.sinkVertices = new ArrayList<>(); - this.neighbourVertices = new ArrayList<>(); - this.coordinate = new VertexCoordinate(); - this.name = parentName.isEmpty() ? path.getFileName().toString() : String.join(".", - parentName, - path.getFileName().toString()); - } - - - public void createCoordinate(double x, double y) { - coordinate.x = x; - coordinate.y = y; - } - - public void addArc(PackageVertex sourceVertex, PackageVertex targetVertex, ArcType arcType) { - arcs.add(new Arc<>(sourceVertex, targetVertex, arcType)); - } - - public void addSinkVertex(ClassifierVertex classifierVertex) { - sinkVertices.add(classifierVertex); - } - - public void addNeighbourVertex(PackageVertex vertex) { - neighbourVertices.add(vertex); - } - - public void setParentNode(PackageVertex parentPackageVertex) { - this.parentPackageVertex = parentPackageVertex; - } - - public void setDeserializedArcs(List> deserializedArcs) { - this.deserializedArcs = deserializedArcs; - } - - public List> getDeserializedArcs() { - return deserializedArcs; - } - - public List> getArcs() { - return arcs; - } - - public List getSinkVertices() { - return sinkVertices; - } - - public List getNeighbourVertices() { - return neighbourVertices; - } - - public Path getPath() { - return path; - } - - public String getName() { - return name; - } - - public VertexType getVertexType() { - return vertexType; - } - - public PackageVertex getParentVertex() { - return parentPackageVertex; - } - - public ModifierType getModifierType() { return VERTEX_MODIFIER_TYPE; } - - public VertexCoordinate getCoordinate() { - return coordinate; - } +public class PackageVertex +{ + + private static final ModifierType VERTEX_MODIFIER_TYPE = ModifierType.PACKAGE_PRIVATE; + + private final List> arcs; + private final List sinkVertices; + private final List neighbourVertices; + private final VertexType vertexType; + private final Path path; + private final String name; + private VertexCoordinate coordinate; + private List> deserializedArcs; + private PackageVertex parentPackageVertex; + + + public PackageVertex(Path path, + VertexType vertexType, + String parentName) + { + this.path = path; + this.vertexType = vertexType; + sinkVertices = new ArrayList<>(); + arcs = new ArrayList<>(); + neighbourVertices = new ArrayList<>(); + coordinate = new VertexCoordinate(0, 0); + name = parentName.isEmpty() ? + path.getFileName().toString() : + String.join(".", + parentName, + path.getFileName().toString()); + } + + + public void setCoordinate(double x, double y) + { + coordinate = new VertexCoordinate(x, y); + } + + + public void addArc(PackageVertex sourceVertex, + PackageVertex targetVertex, + ArcType arcType) + { + arcs.add(new Arc<>(sourceVertex, + targetVertex, + arcType)); + } + + + public void addSinkVertex(ClassifierVertex classifierVertex) + { + sinkVertices.add(classifierVertex); + } + + + public void addNeighbourVertex(PackageVertex vertex) + { + neighbourVertices.add(vertex); + } + + + public void setParentNode(PackageVertex parentPackageVertex) + { + this.parentPackageVertex = parentPackageVertex; + } + + + public void setDeserializedArcs(List> deserializedArcs) + { + this.deserializedArcs = deserializedArcs; + } + + + public List> getDeserializedArcs() + { + return deserializedArcs; + } + + + public List> getArcs() + { + return arcs; + } + + + public List getSinkVertices() + { + return sinkVertices; + } + + + public List getNeighbourVertices() + { + return neighbourVertices; + } + + + public Path getPath() + { + return path; + } + + + public String getName() + { + return name; + } + + + public VertexType getVertexType() + { + return vertexType; + } + + + public PackageVertex getParentVertex() + { + return parentPackageVertex; + } + + + public ModifierType getModifierType() {return VERTEX_MODIFIER_TYPE;} + + + public VertexCoordinate getCoordinate() + { + return coordinate; + } } diff --git a/src/main/java/model/graph/VertexCoordinate.java b/src/main/java/model/graph/VertexCoordinate.java index ce6412e..15478c4 100644 --- a/src/main/java/model/graph/VertexCoordinate.java +++ b/src/main/java/model/graph/VertexCoordinate.java @@ -1,18 +1,3 @@ package model.graph; -public class VertexCoordinate { - public double x; - public double y; - - public VertexCoordinate() {} - - - public double getX() { - return x; - } - - public double getY() { - return y; - } - -} +public record VertexCoordinate(double x, double y) {} diff --git a/src/main/java/model/graph/VertexType.java b/src/main/java/model/graph/VertexType.java index 9896f73..c9400d2 100644 --- a/src/main/java/model/graph/VertexType.java +++ b/src/main/java/model/graph/VertexType.java @@ -4,29 +4,35 @@ import java.util.HashMap; import java.util.Map; -public enum VertexType { - CLASS, - INTERFACE, - ENUM, - PACKAGE; - - public static final Map VERTEX_TYPE; - - static { - Map map = new HashMap<>(); - for (VertexType vertexType: VertexType.values()) { - map.put(vertexType.toString().toLowerCase(), vertexType); - } - VERTEX_TYPE = Collections.unmodifiableMap(map); - } - - public static VertexType get(String vertexType) { - return VERTEX_TYPE.get(vertexType.toLowerCase().trim()); - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } +public enum VertexType +{ + CLASS, + INTERFACE, + ENUM, + PACKAGE; + + public static final Map VERTEX_TYPE; + + static + { + Map map = new HashMap<>(); + for (VertexType vertexType : VertexType.values()) + { + map.put(vertexType.toString().toLowerCase(), vertexType); + } + VERTEX_TYPE = Collections.unmodifiableMap(map); + } + + public static VertexType get(String vertexType) + { + return VERTEX_TYPE.get(vertexType.toLowerCase().trim()); + } + + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/parser/FileVisitor.java b/src/main/java/parser/FileVisitor.java index c6d3c71..aeeb706 100644 --- a/src/main/java/parser/FileVisitor.java +++ b/src/main/java/parser/FileVisitor.java @@ -34,43 +34,47 @@ /** * This class is responsible for the creation of the AST of a Java source file using Javaparser. - * Using the different visitors, it parses the file's inheritance declarations, constructor, methods parameters, - * return types, field & local variable declarations as well as the instantiated objects that aren't assigned to a variable. + * Using the different visitors, it parses the file's inheritance declarations, + * constructor, methods parameters, return types, field & local variable declarations + * as well as the instantiated objects that aren't assigned to a variable. */ -public class FileVisitor { - private final InheritanceVisitor inheritanceVisitor = new InheritanceVisitor(); - private final ConstructorVisitor constructorVisitor = new ConstructorVisitor(); - private final FieldVisitor fieldNameVisitor = new FieldVisitor(); - private final MethodVisitor methodNameVisitor = new MethodVisitor(); - private final EnumVisitor enumVisitor = new EnumVisitor(); - private final MemberVisitor memberVisitor = new MemberVisitor(); - private final VariableVisitor variableVisitor = new VariableVisitor(); - private final ObjectCreationVisitor objectCreationVisitor = new ObjectCreationVisitor(); - private final ImportVisitor importVisitor = new ImportVisitor(); - private final LeafNodeBuilder leafNodeBuilder; - private final Map variablesMap; - private final List objectTypes; - private final List methods; - private final List fields; - private final List innerClasses; - private final Path path; - private final List imports; - private final List createdObjects; - private final List unassignedObjects; - private final List implementedInterfaces; - private final List enums; - private final List records; - private NodeType nodeType; - private boolean isClassOrInterface; - private String baseClass; - private String nodeName; +public class FileVisitor +{ + private final InheritanceVisitor inheritanceVisitor = new InheritanceVisitor(); + private final ConstructorVisitor constructorVisitor = new ConstructorVisitor(); + private final FieldVisitor fieldNameVisitor = new FieldVisitor(); + private final MethodVisitor methodNameVisitor = new MethodVisitor(); + private final EnumVisitor enumVisitor = new EnumVisitor(); + private final MemberVisitor memberVisitor = new MemberVisitor(); + private final VariableVisitor variableVisitor = new VariableVisitor(); + private final ObjectCreationVisitor objectCreationVisitor = new ObjectCreationVisitor(); + private final ImportVisitor importVisitor = new ImportVisitor(); + private final LeafNodeBuilder leafNodeBuilder; + private final Map variablesMap; + private final List objectTypes; + private final List methods; + private final List fields; + private final List innerClasses; + private final Path path; + private final List imports; + private final List createdObjects; + private final List unassignedObjects; + private final List implementedInterfaces; + private final List enums; + private final List records; + private NodeType nodeType; + private boolean isClassOrInterface; + private String baseClass; + private String nodeName; + /** * The FileVisitor's default constructor * * @param parentNode the LeafNode representing the Java source file that we are visiting */ - public FileVisitor(PackageNode parentNode, Path path) { + public FileVisitor(PackageNode parentNode, Path path) + { this.path = path; leafNodeBuilder = new LeafNodeBuilder(parentNode, path); createdObjects = new ArrayList<>(); @@ -89,271 +93,329 @@ public FileVisitor(PackageNode parentNode, Path path) { nodeType = null; } - /** - * This method is responsible for the creation of the AST. - */ - public LeafNode createAST() { - try { - StaticJavaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17); - CompilationUnit compilationUnit = StaticJavaParser.parse(path.toFile()); - - isClassOrInterface = false; - compilationUnit.accept(inheritanceVisitor, null); - - if (!isClassOrInterface) { - compilationUnit.accept(enumVisitor, null); - } else { - compilationUnit.accept(importVisitor, null); - compilationUnit.accept(memberVisitor, null); - compilationUnit.accept(constructorVisitor, null); - compilationUnit.accept(fieldNameVisitor, null); - compilationUnit.accept(variableVisitor, null); - compilationUnit.accept(methodNameVisitor, null); - compilationUnit.accept(objectCreationVisitor, null); - unassignedObjects.addAll(populateCreatedObjects()); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - - return leafNodeBuilder.setNodeType(nodeType) - .setBaseClass(baseClass) - .setFields(fields) - .setCreatedObjects(unassignedObjects) - .setMethods(methods) - .setNodeName(nodeName) - .setVariables(variablesMap) - .setImports(imports) - .setRecords(records) - .setInnerClasses(innerClasses) - .setImplementedInterface(implementedInterfaces) - .setInnerEnums(enums) - .build(); - } - - private class InheritanceVisitor extends VoidVisitorAdapter { - - @Override - public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void arg) { - super.visit(classOrInterfaceDeclaration, arg); - isClassOrInterface = true; - - // Inner Class case. - if (!path.endsWith(classOrInterfaceDeclaration.getNameAsString() + ".java")) { - String innerBaseClass = ""; - if (!classOrInterfaceDeclaration.getExtendedTypes().isEmpty()) { - innerBaseClass = classOrInterfaceDeclaration.getExtendedTypes().get(0).getNameAsString(); - } - List innerImplementedInterfaces = new ArrayList<>(); - for (ClassOrInterfaceType c: classOrInterfaceDeclaration.getImplementedTypes()) { - innerImplementedInterfaces.add(c.getNameAsString()); - } - // Create the leaf node for the inner class. - LeafNodeBuilder innerLeafNodeBuilder = new LeafNodeBuilder(null, Paths.get("")); - LeafNode innerClass = innerLeafNodeBuilder - .setNodeName(classOrInterfaceDeclaration.getNameAsString()) - .setBaseClass(innerBaseClass) - .setImplementedInterface(innerImplementedInterfaces) - .build(); - innerClasses.add(innerClass); - return; - } - - nodeName = classOrInterfaceDeclaration.getNameAsString(); - NodeType localNodeType; - if (classOrInterfaceDeclaration.isInterface()) { - localNodeType = NodeType.INTERFACE; - } else { - localNodeType = NodeType.CLASS; - classOrInterfaceDeclaration.getExtendedTypes() - .forEach(classOrInterfaceType -> baseClass = classOrInterfaceType.getNameAsString()); - } - - nodeType = localNodeType; - classOrInterfaceDeclaration.getImplementedTypes() - .forEach(classOrInterfaceType -> implementedInterfaces.add(classOrInterfaceType.getNameAsString())); - - } - } - - private class ConstructorVisitor extends VoidVisitorAdapter { - - @Override - public void visit(ConstructorDeclaration constructorDeclaration, Void arg) { - super.visit(constructorDeclaration, arg); - - ModifierType modifierType; - if (constructorDeclaration.getModifiers().isEmpty()) { - modifierType = ModifierType.PACKAGE_PRIVATE; - } else { - modifierType = ModifierType.get(constructorDeclaration.getModifiers().get(0).toString()); - } - - Map parameters = new HashMap<>(); - constructorDeclaration.getParameters() - .forEach(parameter -> parameters.put(parameter.getNameAsString(), - getType(parameter.getTypeAsString()))); - methods.add(new LeafNode.Method(constructorDeclaration.getNameAsString(), - "Constructor", - modifierType, - parameters)); - } - } - - private class FieldVisitor extends VoidVisitorAdapter { - private ModifierType modifierType; - - @Override - public void visit(FieldDeclaration fieldDeclaration, Void arg) { - super.visit(fieldDeclaration, arg); - - fieldDeclaration.getVariables().forEach(variable -> { - if (fieldDeclaration.getModifiers().isEmpty()) { - this.modifierType = ModifierType.PACKAGE_PRIVATE; - } else { - this.modifierType = ModifierType.get(fieldDeclaration.getModifiers().get(0).toString()); - } - fields.add(new LeafNode.Field(variable.getNameAsString(), - getType(variable.getTypeAsString()), - modifierType)); - }); - } - } - - private class VariableVisitor extends VoidVisitorAdapter { - - @Override - public void visit(VariableDeclarationExpr variableDeclarationExpr, Void arg) { - super.visit(variableDeclarationExpr, null); - - Pattern pattern = Pattern.compile("[A-Za-z0-9]+ [A-Za-z0-9]+ = new ([A-Za-z0-9]+)\\([A-Za-z0-9]*[, A-Za-z0-9*]*\\)"); - Matcher matcher = pattern.matcher(variableDeclarationExpr.toString()); - if (!matcher.find()) { - return; - } - objectTypes.add(matcher.group(1)); - variableDeclarationExpr.getVariables() - .forEach(variableDeclaration -> variablesMap.put(variableDeclaration.getNameAsString(), - getType(variableDeclaration.getTypeAsString()))); - } - } - - private class MethodVisitor extends VoidVisitorAdapter { - - @Override - public void visit(MethodDeclaration methodDeclaration, Void arg) { - super.visit(methodDeclaration, arg); - - ModifierType modifierType; - if (methodDeclaration.getModifiers().isEmpty()) { - modifierType = ModifierType.PACKAGE_PRIVATE; - } else { - modifierType = ModifierType.get(methodDeclaration.getModifiers().get(0).toString()); - } - Map parameters = new HashMap<>(); - methodDeclaration.getParameters() - .forEach(parameter -> parameters.put(parameter.getNameAsString(), - getType(parameter.getTypeAsString()))); - methods.add(new LeafNode.Method(methodDeclaration.getNameAsString(), - getType(methodDeclaration.getTypeAsString()), - modifierType, - parameters)); - } - } - - private class ObjectCreationVisitor extends VoidVisitorAdapter { - - @Override - public void visit(ObjectCreationExpr objectCreationExpr, Void arg) { - super.visit(objectCreationExpr, arg); - - createdObjects.add(getType(objectCreationExpr.asObjectCreationExpr().getType().asString())); - } - - } - - private class EnumVisitor extends VoidVisitorAdapter { - - @Override - public void visit(EnumDeclaration enumDeclaration, Void arg) { - super.visit(enumDeclaration, arg); - nodeName = enumDeclaration.getNameAsString(); - nodeType = NodeType.ENUM; - } - - } - - private class MemberVisitor extends VoidVisitorAdapter { - - public void visit(EnumDeclaration enumDeclaration, Void arg) { - super.visit(enumDeclaration, arg); - - enums.add(enumDeclaration.getNameAsString()); - } - - public void visit(RecordDeclaration n, Void arg) { - super.visit(n, arg); - - records.add(n.getNameAsString()); - } - - } - - private class ImportVisitor extends VoidVisitorAdapter { - - public void visit(ImportDeclaration importDeclaration, Void arg) { - super.visit(importDeclaration, arg); - - imports.add(importDeclaration - .getNameAsString() - .replaceFirst("^import ", "").trim() - .replaceAll(";$", "")); - } - - } - - private List populateCreatedObjects() { + /** + * This method is responsible for the creation of the AST. + */ + public LeafNode createAST() + { + try + { + StaticJavaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17); + CompilationUnit compilationUnit = StaticJavaParser.parse(path.toFile()); + + isClassOrInterface = false; + compilationUnit.accept(inheritanceVisitor, null); + + if (!isClassOrInterface) + { + compilationUnit.accept(enumVisitor, null); + } + else + { + compilationUnit.accept(importVisitor, null); + compilationUnit.accept(memberVisitor, null); + compilationUnit.accept(constructorVisitor, null); + compilationUnit.accept(fieldNameVisitor, null); + compilationUnit.accept(variableVisitor, null); + compilationUnit.accept(methodNameVisitor, null); + compilationUnit.accept(objectCreationVisitor, null); + unassignedObjects.addAll(populateCreatedObjects()); + } + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + + return leafNodeBuilder.setNodeType(nodeType) + .setBaseClass(baseClass) + .setFields(fields) + .setCreatedObjects(unassignedObjects) + .setMethods(methods) + .setNodeName(nodeName) + .setVariables(variablesMap) + .setImports(imports) + .setRecords(records) + .setInnerClasses(innerClasses) + .setImplementedInterface(implementedInterfaces) + .setInnerEnums(enums) + .build(); + } + + + private class InheritanceVisitor extends VoidVisitorAdapter + { + + @Override + public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void arg) + { + super.visit(classOrInterfaceDeclaration, arg); + isClassOrInterface = true; + + // Inner Class case. + if (!path.endsWith(classOrInterfaceDeclaration.getNameAsString() + ".java")) + { + String innerBaseClass = ""; + if (!classOrInterfaceDeclaration.getExtendedTypes().isEmpty()) + { + innerBaseClass = classOrInterfaceDeclaration.getExtendedTypes().get(0).getNameAsString(); + } + List innerImplementedInterfaces = new ArrayList<>(); + for (ClassOrInterfaceType c : classOrInterfaceDeclaration.getImplementedTypes()) + { + innerImplementedInterfaces.add(c.getNameAsString()); + } + // Create the leaf node for the inner class. + LeafNodeBuilder innerLeafNodeBuilder = new LeafNodeBuilder(null, Paths.get("")); + LeafNode innerClass = innerLeafNodeBuilder + .setNodeName(classOrInterfaceDeclaration.getNameAsString()) + .setBaseClass(innerBaseClass) + .setImplementedInterface(innerImplementedInterfaces) + .build(); + innerClasses.add(innerClass); + return; + } + + nodeName = classOrInterfaceDeclaration.getNameAsString(); + NodeType localNodeType; + if (classOrInterfaceDeclaration.isInterface()) + { + localNodeType = NodeType.INTERFACE; + } + else + { + localNodeType = NodeType.CLASS; + classOrInterfaceDeclaration.getExtendedTypes() + .forEach(classOrInterfaceType -> baseClass = classOrInterfaceType.getNameAsString()); + } + + nodeType = localNodeType; + classOrInterfaceDeclaration.getImplementedTypes() + .forEach(classOrInterfaceType -> implementedInterfaces.add(classOrInterfaceType.getNameAsString())); + + } + } + + private class ConstructorVisitor extends VoidVisitorAdapter + { + + @Override + public void visit(ConstructorDeclaration constructorDeclaration, Void arg) + { + super.visit(constructorDeclaration, arg); + + ModifierType modifierType; + if (constructorDeclaration.getModifiers().isEmpty()) + { + modifierType = ModifierType.PACKAGE_PRIVATE; + } + else + { + modifierType = ModifierType.get(constructorDeclaration.getModifiers().get(0).toString()); + } + + Map parameters = new HashMap<>(); + constructorDeclaration.getParameters() + .forEach(parameter -> parameters.put(parameter.getNameAsString(), + getType(parameter.getTypeAsString()))); + methods.add(new LeafNode.Method(constructorDeclaration.getNameAsString(), + "Constructor", + modifierType, + parameters)); + } + } + + private class FieldVisitor extends VoidVisitorAdapter + { + private ModifierType modifierType; + + + @Override + public void visit(FieldDeclaration fieldDeclaration, Void arg) + { + super.visit(fieldDeclaration, arg); + + fieldDeclaration.getVariables().forEach(variable -> { + if (fieldDeclaration.getModifiers().isEmpty()) + { + this.modifierType = ModifierType.PACKAGE_PRIVATE; + } + else + { + this.modifierType = ModifierType.get(fieldDeclaration.getModifiers().get(0).toString()); + } + fields.add(new LeafNode.Field(variable.getNameAsString(), + getType(variable.getTypeAsString()), + modifierType)); + }); + } + } + + private class VariableVisitor extends VoidVisitorAdapter + { + + @Override + public void visit(VariableDeclarationExpr variableDeclarationExpr, Void arg) + { + super.visit(variableDeclarationExpr, null); + + Pattern pattern = Pattern.compile("[A-Za-z0-9]+ [A-Za-z0-9]+ = new ([A-Za-z0-9]+)\\([A-Za-z0-9]*[, A-Za-z0-9*]*\\)"); + Matcher matcher = pattern.matcher(variableDeclarationExpr.toString()); + if (!matcher.find()) + { + return; + } + objectTypes.add(matcher.group(1)); + variableDeclarationExpr.getVariables() + .forEach(variableDeclaration -> variablesMap.put(variableDeclaration.getNameAsString(), + getType(variableDeclaration.getTypeAsString()))); + } + } + + private class MethodVisitor extends VoidVisitorAdapter + { + + @Override + public void visit(MethodDeclaration methodDeclaration, Void arg) + { + super.visit(methodDeclaration, arg); + + ModifierType modifierType; + if (methodDeclaration.getModifiers().isEmpty()) + { + modifierType = ModifierType.PACKAGE_PRIVATE; + } + else + { + modifierType = ModifierType.get(methodDeclaration.getModifiers().get(0).toString()); + } + Map parameters = new HashMap<>(); + methodDeclaration.getParameters() + .forEach(parameter -> parameters.put(parameter.getNameAsString(), + getType(parameter.getTypeAsString()))); + methods.add(new LeafNode.Method(methodDeclaration.getNameAsString(), + getType(methodDeclaration.getTypeAsString()), + modifierType, + parameters)); + } + } + + private class ObjectCreationVisitor extends VoidVisitorAdapter + { + + @Override + public void visit(ObjectCreationExpr objectCreationExpr, Void arg) + { + super.visit(objectCreationExpr, arg); + + createdObjects.add(getType(objectCreationExpr.asObjectCreationExpr().getType().asString())); + } + + } + + private class EnumVisitor extends VoidVisitorAdapter + { + + @Override + public void visit(EnumDeclaration enumDeclaration, Void arg) + { + super.visit(enumDeclaration, arg); + + nodeName = enumDeclaration.getNameAsString(); + nodeType = NodeType.ENUM; + } + + } + + private class MemberVisitor extends VoidVisitorAdapter + { + + public void visit(EnumDeclaration enumDeclaration, Void arg) + { + super.visit(enumDeclaration, arg); + + enums.add(enumDeclaration.getNameAsString()); + } + + + public void visit(RecordDeclaration n, Void arg) + { + super.visit(n, arg); + + records.add(n.getNameAsString()); + } + + } + + private class ImportVisitor extends VoidVisitorAdapter + { + + public void visit(ImportDeclaration importDeclaration, Void arg) + { + super.visit(importDeclaration, arg); + + imports.add(importDeclaration + .getNameAsString() + .replaceFirst("^import ", "").trim() + .replaceAll(";$", "")); + } + + } + + + private List populateCreatedObjects() + { List notAssignedCreatedObjects = filterAssignedCreatedObjects(fields.stream() - .map(LeafNode.Field::fieldType) - .collect(Collectors.toCollection(ArrayList::new)), - createdObjects); - notAssignedCreatedObjects = filterAssignedCreatedObjects(new ArrayList<>(variablesMap.values()), - notAssignedCreatedObjects); - notAssignedCreatedObjects = filterAssignedCreatedObjects(objectTypes, - notAssignedCreatedObjects); + .map(LeafNode.Field::fieldType) + .collect(Collectors.toCollection(ArrayList::new)), + createdObjects); + notAssignedCreatedObjects = filterAssignedCreatedObjects(new ArrayList<>(variablesMap.values()), + notAssignedCreatedObjects); + notAssignedCreatedObjects = filterAssignedCreatedObjects(objectTypes, + notAssignedCreatedObjects); return notAssignedCreatedObjects; - } - - private List filterAssignedCreatedObjects(List assignedObjects, - List createdObjects) { - List newList = new ArrayList<>(); - Collections.sort(assignedObjects); - Collections.sort(createdObjects); - int i = 0; - int j = 0; - - main: - while (i < createdObjects.size()) { - while (j < assignedObjects.size()) { - if (createdObjects.get(i).equals(assignedObjects.get(j))) { - j++; - } else { - newList.add(createdObjects.get(i)); - } - i++; - if (i == createdObjects.size()) { - break main; - } - } - newList.add(createdObjects.get(i)); - i++; - } - return newList; - } - - private static String getType(String type) { - return type.replaceAll("<", "[").replaceAll(">", "]"); - } + } + + + private List filterAssignedCreatedObjects(List assignedObjects, + List createdObjects) + { + List newList = new ArrayList<>(); + Collections.sort(assignedObjects); + Collections.sort(createdObjects); + int i = 0; + int j = 0; + + main: + while (i < createdObjects.size()) + { + while (j < assignedObjects.size()) + { + if (createdObjects.get(i).equals(assignedObjects.get(j))) + { + j++; + } + else + { + newList.add(createdObjects.get(i)); + } + i++; + if (i == createdObjects.size()) + { + break main; + } + } + newList.add(createdObjects.get(i)); + i++; + } + return newList; + } + + + private static String getType(String type) + { + return type.replaceAll("<", "[").replaceAll(">", "]"); + } } diff --git a/src/main/java/parser/IRelationshipIdentifier.java b/src/main/java/parser/IRelationshipIdentifier.java index 9bdefea..df0b6fa 100644 --- a/src/main/java/parser/IRelationshipIdentifier.java +++ b/src/main/java/parser/IRelationshipIdentifier.java @@ -11,25 +11,26 @@ import java.util.Set; /** - * This class is responsible for the creation of the branches between the Java - * source files. The branches have a type, e.g., inheritance, implementation. + * This class is responsible for the creation of the branches between the Java source files. + * The branches have a type, e.g., inheritance, implementation. * The branches are also directed with a starting and an ending node. */ -public interface IRelationshipIdentifier { +public interface IRelationshipIdentifier +{ - /** - * This method is responsible for creating the relationships of the package and leaf nodes. - * - * @param packageNodes The collection of package nodes that have been parsed. - * @return The collection of relationships that were created. - */ - Map>> createLeafNodesRelationships(Map packageNodes); + /** + * This method is responsible for creating the relationships of the package and leaf nodes. + * + * @param packageNodes The collection of package nodes that have been parsed. + * @return The collection of relationships that were created. + */ + Map>> createLeafNodesRelationships(Map packageNodes); - /** - * This method identifies the package node relationships by parsing the created leaf node relationships. - * - * @param leafNodeRelationships The relationships that were created by {@link Parser#createRelationships(Map)}. - * @return The package node relationships that were created by parsing the leaf node relationships. - */ - Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships); + /** + * This method identifies the package node relationships by parsing the created leaf node relationships. + * + * @param leafNodeRelationships The relationships that were created by {@link Parser#createRelationships(Map)}. + * @return The package node relationships that were created by parsing the leaf node relationships. + */ + Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships); } diff --git a/src/main/java/parser/Interpreter.java b/src/main/java/parser/Interpreter.java index 39fb5cc..a33beed 100644 --- a/src/main/java/parser/Interpreter.java +++ b/src/main/java/parser/Interpreter.java @@ -20,161 +20,210 @@ import java.util.Map; import java.util.Set; -public class Interpreter { +public class Interpreter +{ - private static final ParserType PARSER_TYPE = ParserType.JAVAPARSER; + private static final ParserType PARSER_TYPE = ParserType.JAVAPARSER; - private final Map packageNodeVertexMap; - private final Map leafNodeSinkVertexMap; - private final Map vertices; - private final Map sinkVertices; - private Map>> packageNodeRelationships; - private Map>> leafNodeRelationships; - private Map packageNodes; + private final Map packageNodeVertexMap; + private final Map leafNodeSinkVertexMap; + private final Map vertices; + private final Map sinkVertices; + private Map>> packageNodeRelationships; + private Map>> leafNodeRelationships; + private Map packageNodes; - public Interpreter() { + + public Interpreter() + { vertices = new HashMap<>(); sinkVertices = new HashMap<>(); packageNodeVertexMap = new HashMap<>(); leafNodeSinkVertexMap = new HashMap<>(); } - public void parseProject(Path sourcePackagePath) { + + public void parseProject(Path sourcePackagePath) + { Parser projectParser = ProjectParserFactory.createProjectParser(PARSER_TYPE); packageNodes = projectParser.parseSourcePackage(sourcePackagePath); leafNodeRelationships = projectParser.createRelationships(packageNodes); packageNodeRelationships = projectParser.identifyPackageNodeRelationships(leafNodeRelationships); } - public void convertTreeToGraph() { - packageNodes = PackageNodeCleaner.removeNonPackageNodes(packageNodes); - populateVertexMaps(); - addVertexArcs(); - leafNodeSinkVertexMap.values() - .forEach(sinkVertex -> sinkVertices.put(sinkVertex.getPath(), sinkVertex)); - packageNodeVertexMap.values() - .forEach(vertex -> vertices.put(vertex.getPath(), vertex)); - } - - private void populateVertexMaps() { - for (PackageNode packageNode: packageNodes.values()) { - PackageVertex vertex = packageNodeVertexMap - .computeIfAbsent(packageNode, k -> - new PackageVertex(packageNode.getPath(), - TypeConverter.convertVertexType(packageNode.getNodeType()), - packageNode.getParentNode().getNodeName())); - - for (LeafNode leafNode: packageNode.getLeafNodes().values()) { - vertex.addSinkVertex(leafNodeSinkVertexMap.computeIfAbsent(leafNode, k -> createSinkVertex(leafNode))); - } - } - for (PackageNode packageNode: packageNodes.values()) { - packageNodeVertexMap.get(packageNode) - .setParentNode(packageNodeVertexMap.getOrDefault(packageNode.getParentNode(), - new PackageVertex(Paths.get(""), - VertexType.PACKAGE, - ""))); - - for (PackageNode subNode: packageNode.getSubNodes().values()) { - packageNodeVertexMap.get(packageNode).addNeighbourVertex(packageNodeVertexMap.get(subNode)); - } - } - } - - private void addVertexArcs() { - for (PackageNode packageNode: packageNodes.values()) { - PackageVertex vertex = packageNodeVertexMap.get(packageNode); - if (packageNodeRelationships.containsKey(packageNode)) { - for (Relationship relationship : packageNodeRelationships.get(packageNode)) { - vertex.addArc(vertex, - packageNodeVertexMap.get(relationship.endingNode()), - TypeConverter.convertRelationshipType(relationship.relationshipType())); - } - addSinkVertexArcs(packageNode); - } - } - } - - private void addSinkVertexArcs(PackageNode packageNode) { - for (LeafNode leafNode: packageNode.getLeafNodes().values()) { - ClassifierVertex classifierVertex = leafNodeSinkVertexMap.get(leafNode); - if (leafNodeRelationships.containsKey(leafNode)) { - for (Relationship relationship : leafNodeRelationships.get(leafNode)) { - classifierVertex.addArc(classifierVertex, - leafNodeSinkVertexMap.get(relationship.endingNode()), - TypeConverter.convertRelationshipType(relationship.relationshipType())); - } - } - } - } - - private ClassifierVertex createSinkVertex(LeafNode leafNode) { - ClassifierVertex classifierVertex = new ClassifierVertex(leafNode.path(), - leafNode.nodeName(), - TypeConverter.convertVertexType(leafNode.nodeType())); - leafNode.fields() - .forEach(field -> - classifierVertex.addField(field.fieldNames(), - field.fieldType(), - TypeConverter.convertModifierType(field.modifierType()))); - leafNode.methods() - .forEach((method) -> - classifierVertex.addMethod(method.methodName(), - method.returnType(), - TypeConverter.convertModifierType(method.modifierType()), - method.parameters())); - return classifierVertex; - } - - public Map getPackageNodes() { - return packageNodes; - } - - public Map getVertices() { - return vertices; - } - - public Map getSinkVertices() { - return sinkVertices; - } - public Map>> getPackageNodeRelationships() { - return packageNodeRelationships; - } - - public Map>> getLeafNodeRelationships() { - return leafNodeRelationships; - } - - private static class TypeConverter { - - private static VertexType convertVertexType(NodeType nodeType) { - return switch (nodeType) { - case CLASS -> VertexType.CLASS; - case INTERFACE -> VertexType.INTERFACE; - case ENUM -> VertexType.ENUM; - case PACKAGE -> VertexType.PACKAGE; - }; - } - - private static ArcType convertRelationshipType(RelationshipType relationshipType) { - return switch (relationshipType) { - case DEPENDENCY -> ArcType.DEPENDENCY; - case ASSOCIATION -> ArcType.ASSOCIATION; - case AGGREGATION -> ArcType.AGGREGATION; - case IMPLEMENTATION -> ArcType.IMPLEMENTATION; - case EXTENSION -> ArcType.EXTENSION; - }; - } - - private static model.graph.ModifierType convertModifierType(ModifierType modifierType) { - return switch (modifierType) { - case PRIVATE -> model.graph.ModifierType.PRIVATE; - case PUBLIC -> model.graph.ModifierType.PUBLIC; - case PROTECTED -> model.graph.ModifierType.PROTECTED; - case PACKAGE_PRIVATE -> model.graph.ModifierType.PACKAGE_PRIVATE; - }; - } - } + public void convertTreeToGraph() + { + packageNodes = PackageNodeCleaner.removeNonPackageNodes(packageNodes); + populateVertexMaps(); + addVertexArcs(); + leafNodeSinkVertexMap + .values() + .forEach(sinkVertex -> sinkVertices.put(sinkVertex.getPath(), sinkVertex)); + packageNodeVertexMap + .values() + .forEach(vertex -> vertices.put(vertex.getPath(), vertex)); + } + + + private void populateVertexMaps() + { + for (PackageNode packageNode : packageNodes.values()) + { + PackageVertex vertex = packageNodeVertexMap + .computeIfAbsent(packageNode, k -> + new PackageVertex(packageNode.getPath(), + TypeConverter.convertVertexType(packageNode.getNodeType()), + packageNode.getParentNode().getNodeName())); + + for (LeafNode leafNode : packageNode.getLeafNodes().values()) + { + vertex.addSinkVertex(leafNodeSinkVertexMap.computeIfAbsent(leafNode, k -> createSinkVertex(leafNode))); + } + } + for (PackageNode packageNode : packageNodes.values()) + { + packageNodeVertexMap.get(packageNode) + .setParentNode(packageNodeVertexMap.getOrDefault(packageNode.getParentNode(), + new PackageVertex(Paths.get(""), + VertexType.PACKAGE, + ""))); + + for (PackageNode subNode : packageNode.getSubNodes().values()) + { + packageNodeVertexMap.get(packageNode).addNeighbourVertex(packageNodeVertexMap.get(subNode)); + } + } + } + + + private void addVertexArcs() + { + for (PackageNode packageNode : packageNodes.values()) + { + PackageVertex vertex = packageNodeVertexMap.get(packageNode); + if (packageNodeRelationships.containsKey(packageNode)) + { + for (Relationship relationship : packageNodeRelationships.get(packageNode)) + { + vertex.addArc(vertex, + packageNodeVertexMap.get(relationship.endingNode()), + TypeConverter.convertRelationshipType(relationship.relationshipType())); + } + addSinkVertexArcs(packageNode); + } + } + } + + + private void addSinkVertexArcs(PackageNode packageNode) + { + for (LeafNode leafNode : packageNode.getLeafNodes().values()) + { + ClassifierVertex classifierVertex = leafNodeSinkVertexMap.get(leafNode); + if (leafNodeRelationships.containsKey(leafNode)) + { + for (Relationship relationship : leafNodeRelationships.get(leafNode)) + { + classifierVertex.addArc(classifierVertex, + leafNodeSinkVertexMap.get(relationship.endingNode()), + TypeConverter.convertRelationshipType(relationship.relationshipType())); + } + } + } + } + + + private ClassifierVertex createSinkVertex(LeafNode leafNode) + { + ClassifierVertex classifierVertex = new ClassifierVertex(leafNode.path(), + leafNode.nodeName(), + TypeConverter.convertVertexType(leafNode.nodeType())); + leafNode + .fields() + .forEach(field -> + classifierVertex.addField(field.fieldNames(), + field.fieldType(), + TypeConverter.convertModifierType(field.modifierType()))); + leafNode + .methods() + .forEach((method) -> + classifierVertex.addMethod(method.methodName(), + method.returnType(), + TypeConverter.convertModifierType(method.modifierType()), + method.parameters())); + return classifierVertex; + } + + + public Map getPackageNodes() + { + return packageNodes; + } + + + public Map getVertices() + { + return vertices; + } + + + public Map getSinkVertices() + { + return sinkVertices; + } + + + public Map>> getPackageNodeRelationships() + { + return packageNodeRelationships; + } + + + public Map>> getLeafNodeRelationships() + { + return leafNodeRelationships; + } + + + private static class TypeConverter + { + + private static VertexType convertVertexType(NodeType nodeType) + { + return switch (nodeType) + { + case CLASS -> VertexType.CLASS; + case INTERFACE -> VertexType.INTERFACE; + case ENUM -> VertexType.ENUM; + case PACKAGE -> VertexType.PACKAGE; + }; + } + + + private static ArcType convertRelationshipType(RelationshipType relationshipType) + { + return switch (relationshipType) + { + case DEPENDENCY -> ArcType.DEPENDENCY; + case ASSOCIATION -> ArcType.ASSOCIATION; + case AGGREGATION -> ArcType.AGGREGATION; + case IMPLEMENTATION -> ArcType.IMPLEMENTATION; + case EXTENSION -> ArcType.EXTENSION; + }; + } + + + private static model.graph.ModifierType convertModifierType(ModifierType modifierType) + { + return switch (modifierType) + { + case PRIVATE -> model.graph.ModifierType.PRIVATE; + case PUBLIC -> model.graph.ModifierType.PUBLIC; + case PROTECTED -> model.graph.ModifierType.PROTECTED; + case PACKAGE_PRIVATE -> model.graph.ModifierType.PACKAGE_PRIVATE; + }; + } + } } diff --git a/src/main/java/parser/PackageNodeCleaner.java b/src/main/java/parser/PackageNodeCleaner.java index 25f7183..7391381 100644 --- a/src/main/java/parser/PackageNodeCleaner.java +++ b/src/main/java/parser/PackageNodeCleaner.java @@ -6,38 +6,48 @@ import java.util.HashMap; import java.util.Map; -public class PackageNodeCleaner { - - public static Map removeNonPackageNodes(Map packageNodes) { - Map validPackageNodes = new HashMap<>(); - for (PackageNode packageNode: packageNodes.values()) { - if (isPackageNodeValid(packageNode)) { - validPackageNodes.put(packageNode.getPath(), packageNode); - continue; - } - PackageNode parentNode = packageNode.getParentNode(); - if (parentNode.getPath().toString().isEmpty()) { - continue; - } - parentNode.getSubNodes().remove(packageNode.getPath()); - } - - return validPackageNodes; - } - - private static boolean isPackageNodeValid(PackageNode packageNode) { - if (packageNode.getSubNodes().isEmpty()) { - return packageNode.isValid(); - } - - boolean flag = false; - for (PackageNode childNode: packageNode.getSubNodes().values()) { - flag = isPackageNodeValid(childNode); - if (flag) { - break; - } - } - - return flag || packageNode.isValid(); - } +public class PackageNodeCleaner +{ + + public static Map removeNonPackageNodes(Map packageNodes) + { + Map validPackageNodes = new HashMap<>(); + for (PackageNode packageNode : packageNodes.values()) + { + if (isPackageNodeValid(packageNode)) + { + validPackageNodes.put(packageNode.getPath(), packageNode); + continue; + } + PackageNode parentNode = packageNode.getParentNode(); + if (parentNode.getPath().toString().isEmpty()) + { + continue; + } + parentNode.getSubNodes().remove(packageNode.getPath()); + } + + return validPackageNodes; + } + + + private static boolean isPackageNodeValid(PackageNode packageNode) + { + if (packageNode.getSubNodes().isEmpty()) + { + return packageNode.isValid(); + } + + boolean flag = false; + for (PackageNode childNode : packageNode.getSubNodes().values()) + { + flag = isPackageNodeValid(childNode); + if (flag) + { + break; + } + } + + return flag || packageNode.isValid(); + } } diff --git a/src/main/java/parser/ProjectParser.java b/src/main/java/parser/ProjectParser.java index 08d5a42..88f1a4d 100644 --- a/src/main/java/parser/ProjectParser.java +++ b/src/main/java/parser/ProjectParser.java @@ -12,59 +12,76 @@ import java.util.Map; import java.util.Set; -public class ProjectParser implements Parser { - - private final Map packageNodes; - - public ProjectParser() { - this.packageNodes = new HashMap<>(); - } - - - @Override - public Map parseSourcePackage(Path sourcePackagePath) { - PackageNode sourcePackage = new PackageNode(sourcePackagePath); - packageNodes.put(sourcePackage.getPath(), sourcePackage); - parseFolder(sourcePackage); - return packageNodes; - } - - @Override - public Map>> createRelationships(Map packageNodes) { - IRelationshipIdentifier relationshipIdentifier = new RelationshipIdentifier(); - return relationshipIdentifier.createLeafNodesRelationships(packageNodes); - } - - @Override - public Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships) { - IRelationshipIdentifier relationshipIdentifier = new RelationshipIdentifier(); - return relationshipIdentifier.identifyPackageNodeRelationships(leafNodeRelationships); - } - - private void parseFolder(PackageNode currentNode) { - try (DirectoryStream filesStream = Files.newDirectoryStream(currentNode.getPath())) { - for (Path path: filesStream) { - if (Files.isDirectory(path)) { - PackageNode subNode = new PackageNode(currentNode, path); - packageNodes.put(subNode.getPath(), subNode); - currentNode.getSubNodes().put(subNode.getPath(), subNode); - parseFolder(subNode); - } - else if (isJavaSourceFile(path)) { - FileVisitor fileVisitor = new FileVisitor(currentNode, path); - LeafNode leafNode = fileVisitor.createAST(); - currentNode.getLeafNodes().put(leafNode.nodeName(), leafNode); - } - } - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - - - private boolean isJavaSourceFile(Path filePath) { - return filePath.normalize().toString().toLowerCase().endsWith(".java"); - } +public class ProjectParser implements Parser +{ + + private final Map packageNodes; + + + public ProjectParser() + { + this.packageNodes = new HashMap<>(); + } + + + @Override + public Map parseSourcePackage(Path sourcePackagePath) + { + PackageNode sourcePackage = new PackageNode(sourcePackagePath); + packageNodes.put(sourcePackage.getPath(), sourcePackage); + parseFolder(sourcePackage); + return packageNodes; + } + + + @Override + public Map>> createRelationships(Map packageNodes) + { + IRelationshipIdentifier relationshipIdentifier = new RelationshipIdentifier(); + return relationshipIdentifier.createLeafNodesRelationships(packageNodes); + } + + + @Override + public Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships) + { + IRelationshipIdentifier relationshipIdentifier = new RelationshipIdentifier(); + return relationshipIdentifier.identifyPackageNodeRelationships(leafNodeRelationships); + } + + + private void parseFolder(PackageNode currentNode) + { + try (DirectoryStream filesStream = Files.newDirectoryStream(currentNode.getPath())) + { + for (Path path : filesStream) + { + if (Files.isDirectory(path)) + { + PackageNode subNode = new PackageNode(currentNode, path); + packageNodes.put(subNode.getPath(), subNode); + currentNode.getSubNodes().put(subNode.getPath(), subNode); + parseFolder(subNode); + } + else if (isJavaSourceFile(path)) + { + FileVisitor fileVisitor = new FileVisitor(currentNode, path); + LeafNode leafNode = fileVisitor.createAST(); + currentNode.getLeafNodes().put(leafNode.nodeName(), leafNode); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + private boolean isJavaSourceFile(Path filePath) + { + return filePath.normalize().toString().toLowerCase().endsWith(".java"); + } } diff --git a/src/main/java/parser/RelationshipIdentifier.java b/src/main/java/parser/RelationshipIdentifier.java index c6e6aad..750bdfc 100644 --- a/src/main/java/parser/RelationshipIdentifier.java +++ b/src/main/java/parser/RelationshipIdentifier.java @@ -14,100 +14,134 @@ import java.util.Set; import java.util.stream.Collectors; -public class RelationshipIdentifier implements IRelationshipIdentifier { - private final Map>> leafNodeRelationships; - private final List leafNodes; +public class RelationshipIdentifier implements IRelationshipIdentifier +{ + private final Map>> leafNodeRelationships; + private final List leafNodes; - public RelationshipIdentifier() { + + public RelationshipIdentifier() + { leafNodes = new ArrayList<>(); leafNodeRelationships = new HashMap<>(); } - @Override - public Map>> createLeafNodesRelationships(Map packageNodes) { - packageNodes.values().forEach(packageNode -> leafNodes.addAll(packageNode.getLeafNodes().values())); - for (int i = 0; i < leafNodes.size(); i++) { - for (int j = i+1; j < leafNodes.size(); j++) { - checkRelationship(i, j); - checkRelationship(j, i); - } - } - return leafNodeRelationships; - } - @Override - public Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships) { - Map>> packageNodeRelationships = new HashMap<>(); - ArrayList> relationships = leafNodeRelationships.values() - .stream() - .flatMap(Set::stream) - .collect(Collectors.toCollection(ArrayList::new)); - - for (Relationship relationship: relationships) { - if (relationship.startingNode().parentNode().equals(relationship.endingNode().parentNode())) { - continue; - } - packageNodeRelationships.computeIfAbsent(relationship.startingNode().parentNode(), - packageNode -> new HashSet<>()).add(new Relationship<>(relationship.startingNode().parentNode(), - relationship.endingNode().parentNode(), - RelationshipType.DEPENDENCY)); - } - return packageNodeRelationships; - } + @Override + public Map>> createLeafNodesRelationships(Map packageNodes) + { + packageNodes.values().forEach(packageNode -> leafNodes.addAll(packageNode.getLeafNodes().values())); + for (int i = 0; i < leafNodes.size(); i++) + { + for (int j = i + 1; j < leafNodes.size(); j++) + { + checkRelationship(i, j); + checkRelationship(j, i); + } + } + return leafNodeRelationships; + } - private boolean isAssociation(int i, int j) { - return doesRelationshipExist(leafNodes.get(i).fields() - .stream() - .map(LeafNode.Field::fieldType) - .collect(Collectors.toCollection(ArrayList::new)), - leafNodes.get(j).nodeName()); - } - private boolean isAggregation(int i, int j) { - return isRelationshipAggregation(leafNodes.get(i).fields() - .stream() - .map(LeafNode.Field::fieldType) - .collect(Collectors.toCollection(ArrayList::new)), - leafNodes.get(j).nodeName()); - } + @Override + public Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships) + { + Map>> packageNodeRelationships = new HashMap<>(); + ArrayList> relationships = leafNodeRelationships + .values() + .stream() + .flatMap(Set::stream) + .collect(Collectors.toCollection(ArrayList::new)); - private boolean doesRelationshipExist(List leafNodesTypes, - String leafNodesName) { - for (String leafNodesType : leafNodesTypes) { - if (doesFieldBelongToClass(leafNodesType, leafNodesName)) { - return true; - } - } - return false; - } + for (Relationship relationship : relationships) + { + if (relationship.startingNode().parentNode().equals(relationship.endingNode().parentNode())) + { + continue; + } + packageNodeRelationships.computeIfAbsent(relationship.startingNode().parentNode(), + packageNode -> new HashSet<>()).add(new Relationship<>(relationship.startingNode().parentNode(), + relationship.endingNode().parentNode(), + RelationshipType.DEPENDENCY)); + } + return packageNodeRelationships; + } - private boolean isRelationshipAggregation(List leafNodesTypes, - String leafNodesName) { - for (String leafNodeType: leafNodesTypes) { - if (isFieldOfTypeCollection(leafNodeType, leafNodesName) && - doesFieldBelongToClass(leafNodeType, leafNodesName)) { - return true; - } - } - return false; - } - private boolean doesFieldBelongToClass(String leafNodesType, - String leafNodesName) { - String[] types = leafNodesType - .replace("[", ",") - .replace("]", ",") - .split(","); - for (String type: types) { - if (leafNodesName.equals(type)) { - return true; - } - } - return false; - } + private boolean isAssociation(int i, int j) + { + return doesRelationshipExist(leafNodes + .get(i) + .fields() + .stream() + .map(LeafNode.Field::fieldType) + .collect(Collectors.toCollection(ArrayList::new)), + leafNodes.get(j).nodeName()); + } + + + private boolean isAggregation(int i, int j) + { + return isRelationshipAggregation(leafNodes + .get(i) + .fields() + .stream() + .map(LeafNode.Field::fieldType) + .collect(Collectors.toCollection(ArrayList::new)), + leafNodes.get(j).nodeName()); + } + + + private boolean doesRelationshipExist(List leafNodesTypes, + String leafNodesName) + { + for (String leafNodesType : leafNodesTypes) + { + if (doesFieldBelongToClass(leafNodesType, leafNodesName)) + { + return true; + } + } + return false; + } + + + private boolean isRelationshipAggregation(List leafNodesTypes, + String leafNodesName) + { + for (String leafNodeType : leafNodesTypes) + { + if (isFieldOfTypeCollection(leafNodeType, leafNodesName) && + doesFieldBelongToClass(leafNodeType, leafNodesName)) + { + return true; + } + } + return false; + } + + + private boolean doesFieldBelongToClass(String leafNodesType, + String leafNodesName) + { + String[] types = leafNodesType + .replace("[", ",") + .replace("]", ",") + .split(","); + for (String type : types) + { + if (leafNodesName.equals(type)) + { + return true; + } + } + return false; + } + private boolean isFieldOfTypeCollection(String s, - String leafNodesName) { + String leafNodesName) + { return s.contains(leafNodesName+"[") || s.startsWith("List") || s.startsWith("ArrayList") || @@ -121,9 +155,11 @@ private boolean isFieldOfTypeCollection(String s, s.startsWith("Queue"); } + private void createRelationship(int i, int j, - RelationshipType relationshipType) { + RelationshipType relationshipType) + { leafNodeRelationships .computeIfAbsent(leafNodes.get(i), leafNode -> new HashSet<>()) .add(new Relationship<>(leafNodes.get(i), @@ -131,51 +167,67 @@ private void createRelationship(int i, relationshipType)); } - private void checkRelationship(int i, int j) { - List imports = leafNodes.get(i).imports(); - boolean isImported = imports - .stream() - .anyMatch(imprt -> (String.format("%s.%s", - leafNodes.get(j).parentNode().getNodeName(), - leafNodes.get(j).nodeName())).endsWith(imprt) || - (String.format("%s.*", - leafNodes.get(j).parentNode().getNodeName())).endsWith(imprt)); - - if (!isImported && !isSubNode(i, j)) { - return; - } - if (isDependency(i, j)) { - createRelationship(i, j, RelationshipType.DEPENDENCY); - } - if (isAggregation(i, j)) { - createRelationship(i, j, RelationshipType.AGGREGATION); - } else if (isAssociation(i, j)) { - createRelationship(i, j, RelationshipType.ASSOCIATION); - } - if (isExtension(i, j)) { - createRelationship(i, j, RelationshipType.EXTENSION); - } - if (isImplementation(i, j)) { - createRelationship(i, j, RelationshipType.IMPLEMENTATION); - } - } + private void checkRelationship(int i, int j) + { + List imports = leafNodes.get(i).imports(); + boolean isImported = imports + .stream() + .anyMatch(imprt -> (String.format("%s.%s", + leafNodes.get(j).parentNode().getNodeName(), + leafNodes.get(j).nodeName())).endsWith(imprt) || + (String.format("%s.*", + leafNodes.get(j).parentNode().getNodeName())).endsWith(imprt)); - private boolean isSubNode(int i, int j) { - PackageNode node = leafNodes.get(j).parentNode(); - while (true) { - if (node.equals(leafNodes.get(i).parentNode())) { - return true; - } - - if (node.getPath().toString().isEmpty()) { - return false; - } - node = node.getParentNode(); - } - } + if (!isImported && !isSubNode(i, j)) + { + return; + } + if (isDependency(i, j)) + { + createRelationship(i, j, RelationshipType.DEPENDENCY); + } + if (isAggregation(i, j)) + { + createRelationship(i, j, RelationshipType.AGGREGATION); + } + else if (isAssociation(i, j)) + { + createRelationship(i, j, RelationshipType.ASSOCIATION); + } - private boolean isDependency(int i, int j) { + if (isExtension(i, j)) + { + createRelationship(i, j, RelationshipType.EXTENSION); + } + if (isImplementation(i, j)) + { + createRelationship(i, j, RelationshipType.IMPLEMENTATION); + } + } + + + private boolean isSubNode(int i, int j) + { + PackageNode node = leafNodes.get(j).parentNode(); + while (true) + { + if (node.equals(leafNodes.get(i).parentNode())) + { + return true; + } + + if (node.getPath().toString().isEmpty()) + { + return false; + } + node = node.getParentNode(); + } + } + + + private boolean isDependency(int i, int j) + { if (doesRelationshipExist(leafNodes.get(i).getMethodParameterTypes(), leafNodes.get(j).nodeName()) || doesRelationshipExist(leafNodes.get(i).getMethodReturnTypes(), @@ -188,43 +240,55 @@ private boolean isDependency(int i, int j) { leafNodes.get(j).nodeName()); } - private boolean isExtension(int i, int j) { - // First check if any of the inner classes of i extends j. - List innerClassesI = leafNodes.get(i).innerClasses(); - boolean anyInnerClassExtendJ = innerClassesI.stream() - .anyMatch(leafNode -> leafNode.baseClass().equals(leafNodes.get(j).nodeName())); - if (anyInnerClassExtendJ) { - return true; - } - if (leafNodes.get(i).baseClass().isEmpty()) { - return false; - } - return leafNodes.get(i).baseClass().equals(leafNodes.get(j).nodeName()); - } + private boolean isExtension(int i, int j) + { + // First check if any of the inner classes of i extends j. + List innerClassesI = leafNodes.get(i).innerClasses(); + boolean anyInnerClassExtendJ = innerClassesI.stream() + .anyMatch(leafNode -> leafNode.baseClass().equals(leafNodes.get(j).nodeName())); + if (anyInnerClassExtendJ) + { + return true; + } - private boolean isImplementation(int i, int j) { - // First check if any of the inner classes of i implements j. - List innerClassesI = leafNodes.get(i).innerClasses(); - boolean anyInnerClassImplementJ = innerClassesI.stream() - .anyMatch(leafNode -> leafNode.implementedInterfaces().contains(leafNodes.get(j).nodeName())); - if (anyInnerClassImplementJ) { - return true; - } + if (leafNodes.get(i).baseClass().isEmpty()) + { + return false; + } + return leafNodes.get(i).baseClass().equals(leafNodes.get(j).nodeName()); + } - if (leafNodes.get(i).implementedInterfaces().isEmpty()) { - return false; - } - for (String implementedInterface: leafNodes.get(i).implementedInterfaces()) { - if (implementedInterface.equals(leafNodes.get(j).nodeName())) { - return true; - } - } - return false; - } + private boolean isImplementation(int i, int j) + { + // First check if any of the inner classes of i implements j. + List innerClassesI = leafNodes.get(i).innerClasses(); + boolean anyInnerClassImplementJ = innerClassesI.stream() + .anyMatch(leafNode -> leafNode.implementedInterfaces().contains(leafNodes.get(j).nodeName())); + if (anyInnerClassImplementJ) + { + return true; + } - private LeafNode getLeafNode(int i) { - return leafNodes.get(i); - } + if (leafNodes.get(i).implementedInterfaces().isEmpty()) + { + return false; + } + + for (String implementedInterface : leafNodes.get(i).implementedInterfaces()) + { + if (implementedInterface.equals(leafNodes.get(j).nodeName())) + { + return true; + } + } + return false; + } + + + private LeafNode getLeafNode(int i) + { + return leafNodes.get(i); + } } diff --git a/src/main/java/parser/factory/Parser.java b/src/main/java/parser/factory/Parser.java index 08ea06f..841527f 100644 --- a/src/main/java/parser/factory/Parser.java +++ b/src/main/java/parser/factory/Parser.java @@ -9,28 +9,31 @@ import java.util.Map; import java.util.Set; -public interface Parser { +public interface Parser +{ - /** - * This method creates the root of the tree, from the path of the source package, calls the parseFolder method, that's responsible for the parsing of the source's folder and creates an object of the RelationshipIdentifier class with the created nodes in order to create the Relationships. - * - * @param sourcePackagePath the path of the project's source folder - */ - Map parseSourcePackage(Path sourcePackagePath); + /** + * This method creates the root of the tree, from the path of the source package, calls the parseFolder method, + * that's responsible for the parsing of the source's folder and creates an object of the RelationshipIdentifier + * class with the created nodes in order to create the Relationships. + * + * @param sourcePackagePath the path of the project's source folder + */ + Map parseSourcePackage(Path sourcePackagePath); - /** - * This method creates the relationships among the nodes of the tree - * - * @param packageNodes The collection of package nodes that have been parsed. - * @return The collection of relationships that were created. - */ - Map>> createRelationships(Map packageNodes); + /** + * This method creates the relationships among the nodes of the tree + * + * @param packageNodes The collection of package nodes that have been parsed. + * @return The collection of relationships that were created. + */ + Map>> createRelationships(Map packageNodes); - /** - * This method identifies the package node relationships by parsing the created leaf node relationships. - * - * @param leafNodeRelationships The relationships that were created by {@link Parser#createRelationships(Map)}. - * @return The package node relationships that were created by parsing the leaf node relationships. - */ - Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships); + /** + * This method identifies the package node relationships by parsing the created leaf node relationships. + * + * @param leafNodeRelationships The relationships that were created by {@link Parser#createRelationships(Map)}. + * @return The package node relationships that were created by parsing the leaf node relationships. + */ + Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships); } diff --git a/src/main/java/parser/factory/ParserType.java b/src/main/java/parser/factory/ParserType.java index a120589..251a5f4 100644 --- a/src/main/java/parser/factory/ParserType.java +++ b/src/main/java/parser/factory/ParserType.java @@ -1,6 +1,7 @@ package parser.factory; -public enum ParserType { - JDT, - JAVAPARSER +public enum ParserType +{ + JDT, + JAVAPARSER } diff --git a/src/main/java/parser/factory/ProjectParserFactory.java b/src/main/java/parser/factory/ProjectParserFactory.java index cfbdaf8..96ccb5c 100644 --- a/src/main/java/parser/factory/ProjectParserFactory.java +++ b/src/main/java/parser/factory/ProjectParserFactory.java @@ -2,12 +2,15 @@ import parser.ProjectParser; -public class ProjectParserFactory { +public class ProjectParserFactory +{ - public static Parser createProjectParser(ParserType parserType) { - if (parserType.equals(ParserType.JDT)) { - throw new RuntimeException(); - } - return new ProjectParser(); - } + public static Parser createProjectParser(ParserType parserType) + { + if (parserType.equals(ParserType.JDT)) + { + throw new RuntimeException(); + } + return new ProjectParser(); + } } diff --git a/src/main/java/parser/tree/LeafNode.java b/src/main/java/parser/tree/LeafNode.java index 77ea81c..6b6b028 100644 --- a/src/main/java/parser/tree/LeafNode.java +++ b/src/main/java/parser/tree/LeafNode.java @@ -22,22 +22,34 @@ public record LeafNode(Path path, List createdObjects) { - public List getMethodReturnTypes() { - return methods.stream().map(method -> method.returnType).collect(Collectors.toCollection(ArrayList::new)); - } - - public List getMethodParameterTypes() { - return methods.stream().flatMap(method -> method.parameters().values().stream()).collect(Collectors.toCollection(ArrayList::new)); - } - - - public record Method(String methodName, - String returnType, - ModifierType modifierType, - Map parameters) {} - - public record Field(String fieldNames, - String fieldType, - ModifierType modifierType) {} + public List getMethodReturnTypes() + { + return methods + .stream() + .map(method -> method.returnType) + .collect(Collectors.toCollection(ArrayList::new)); + } + + + public List getMethodParameterTypes() + { + return methods + .stream() + .flatMap(method -> method + .parameters() + .values() + .stream()) + .collect(Collectors.toCollection(ArrayList::new)); + } + + + public record Method(String methodName, + String returnType, + ModifierType modifierType, + Map parameters) {} + + public record Field(String fieldNames, + String fieldType, + ModifierType modifierType) {} } diff --git a/src/main/java/parser/tree/LeafNodeBuilder.java b/src/main/java/parser/tree/LeafNodeBuilder.java index 78dad85..0239b35 100644 --- a/src/main/java/parser/tree/LeafNodeBuilder.java +++ b/src/main/java/parser/tree/LeafNodeBuilder.java @@ -6,7 +6,8 @@ import java.util.List; import java.util.Map; -public class LeafNodeBuilder { +public class LeafNodeBuilder +{ private final Map variables; private final List methods; private final List fields; @@ -14,7 +15,7 @@ public class LeafNodeBuilder { private final List implementedInterfaces; private final List createdObjects; private final List innerClasses; - private final List innerEnums; + private final List innerEnums; private final List records; private final PackageNode parentNode; private final Path path; @@ -22,9 +23,11 @@ public class LeafNodeBuilder { private String baseClass; private NodeType nodeType; - public LeafNodeBuilder(PackageNode parentNode, Path path) { - this.parentNode = parentNode; - this.path = path; + + public LeafNodeBuilder(PackageNode parentNode, Path path) + { + this.parentNode = parentNode; + this.path = path; implementedInterfaces = new ArrayList<>(); createdObjects = new ArrayList<>(); innerClasses = new ArrayList<>(); @@ -39,67 +42,93 @@ public LeafNodeBuilder(PackageNode parentNode, Path path) { nodeName = ""; } - public LeafNodeBuilder setVariables(Map variables) { + + public LeafNodeBuilder setVariables(Map variables) + { this.variables.putAll(variables); return this; } - public LeafNodeBuilder setInnerClasses(List innerClasses) { + + public LeafNodeBuilder setInnerClasses(List innerClasses) + { this.innerClasses.addAll(innerClasses); return this; } - public LeafNodeBuilder setNodeType(NodeType nodeType) { + + public LeafNodeBuilder setNodeType(NodeType nodeType) + { this.nodeType = nodeType; return this; } - public LeafNodeBuilder setNodeName(String nodeName) { + + public LeafNodeBuilder setNodeName(String nodeName) + { this.nodeName = nodeName; return this; } - public LeafNodeBuilder setBaseClass(String baseClass) { + + public LeafNodeBuilder setBaseClass(String baseClass) + { this.baseClass = baseClass; return this; } - public LeafNodeBuilder setImplementedInterface(List interfaces) { + + public LeafNodeBuilder setImplementedInterface(List interfaces) + { this.implementedInterfaces.addAll(interfaces); return this; } - public LeafNodeBuilder setCreatedObjects(List createdObjects) { + + public LeafNodeBuilder setCreatedObjects(List createdObjects) + { this.createdObjects.addAll(createdObjects); return this; } - public LeafNodeBuilder setInnerEnums(List enums) { + + public LeafNodeBuilder setInnerEnums(List enums) + { this.innerEnums.addAll(enums); return this; } - public LeafNodeBuilder setRecords(List records) { + + public LeafNodeBuilder setRecords(List records) + { this.records.addAll(records); return this; } - public LeafNodeBuilder setImports(List imprts) { + + public LeafNodeBuilder setImports(List imprts) + { this.imports.addAll(imprts); return this; } - public LeafNodeBuilder setMethods(List methods) { + + public LeafNodeBuilder setMethods(List methods) + { this.methods.addAll(methods); return this; } - public LeafNodeBuilder setFields(List fields) { + + public LeafNodeBuilder setFields(List fields) + { this.fields.addAll(fields); return this; } - public LeafNode build() { + + public LeafNode build() + { return new LeafNode(path, nodeName, nodeType, diff --git a/src/main/java/parser/tree/ModifierType.java b/src/main/java/parser/tree/ModifierType.java index bb72227..9e78579 100644 --- a/src/main/java/parser/tree/ModifierType.java +++ b/src/main/java/parser/tree/ModifierType.java @@ -4,29 +4,35 @@ import java.util.HashMap; import java.util.Map; -public enum ModifierType { - PRIVATE, - PUBLIC, - PROTECTED, - PACKAGE_PRIVATE; - - public static final Map MODIFIER_TYPE; - - static { - Map map = new HashMap<>(); - for (ModifierType modifierType: ModifierType.values()) { - map.put(modifierType.toString().toLowerCase(), modifierType); - } - MODIFIER_TYPE = Collections.unmodifiableMap(map); - } - - public static ModifierType get(String modifierType) { - return MODIFIER_TYPE.get(modifierType.toLowerCase().trim()); - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } +public enum ModifierType +{ + PRIVATE, + PUBLIC, + PROTECTED, + PACKAGE_PRIVATE; + + public static final Map MODIFIER_TYPE; + + static + { + Map map = new HashMap<>(); + for (ModifierType modifierType : ModifierType.values()) + { + map.put(modifierType.toString().toLowerCase(), modifierType); + } + MODIFIER_TYPE = Collections.unmodifiableMap(map); + } + + public static ModifierType get(String modifierType) + { + return MODIFIER_TYPE.get(modifierType.toLowerCase().trim()); + } + + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/parser/tree/NodeType.java b/src/main/java/parser/tree/NodeType.java index cd420a9..e62028d 100644 --- a/src/main/java/parser/tree/NodeType.java +++ b/src/main/java/parser/tree/NodeType.java @@ -1,13 +1,16 @@ package parser.tree; -public enum NodeType { - CLASS, - INTERFACE, - ENUM, - PACKAGE; +public enum NodeType +{ + CLASS, + INTERFACE, + ENUM, + PACKAGE; - @Override - public String toString() { - return super.toString().toLowerCase(); - } + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/parser/tree/PackageNode.java b/src/main/java/parser/tree/PackageNode.java index 49b3476..174a64d 100644 --- a/src/main/java/parser/tree/PackageNode.java +++ b/src/main/java/parser/tree/PackageNode.java @@ -9,88 +9,121 @@ import java.util.stream.Stream; /** - * This class is responsible for the implementation of a package node in the tree. + * This class is responsible for the representation of a package node in the tree. * Each has node has a parent node(the parent package), the path of the package folder, - * the nodes children(the sub packages), the nodes leaves(the Java source files inside the - * current package), a flag to identify if a package is empty or not. + * the nodes children(the sub packages), the nodes leaves(the Java source files inside the current package), + * a flag to identify if a package is empty or not. */ -public class PackageNode { - private final Map subNodes; - private final Map leafNodes; - private final Path path; - private final PackageNode parentNode; - private final boolean isValid; - - - public PackageNode(Path path) { - this.path = path; - parentNode = new PackageNode(null, Paths.get("")); - subNodes = new HashMap<>(); - leafNodes = new HashMap<>(); - isValid = isValid(path); - } - - public PackageNode(PackageNode parentNode, Path path) { - this.parentNode = parentNode; - this.path = path; - subNodes = new HashMap<>(); - leafNodes = new HashMap<>(); - isValid = isValid(path); - } - - - private static boolean isValid(Path path) { - boolean isValid; - try (Stream filesStream = Files.list(path)) { - isValid = filesStream.anyMatch(filePath -> filePath.normalize().toString().toLowerCase().endsWith(".java")); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - return isValid; - } - - private static Path getPath(PackageNode parentNode, Path path) { - return Paths.get(String.format("%s/%s", - parentNode.getPath().normalize(), - path.toFile().getName())); - } - - public boolean isValid() { - return isValid; - } - - public Path getPath() { - return path; - } - - public PackageNode getParentNode() { - return parentNode; - } - - public Map getSubNodes() { - return subNodes; - } - - public Map getLeafNodes() { - return leafNodes; - } - - public String getNodeName() { - if (!doesParentNodeExist()) { - return path.getFileName().toString(); - } +public final class PackageNode +{ + private final Map subNodes; + private final Map leafNodes; + private final Path path; + private final PackageNode parentNode; + private final boolean isValid; + + + public PackageNode(Path path) + { + this.path = path; + parentNode = new PackageNode(null, Paths.get("")); + subNodes = new HashMap<>(); + leafNodes = new HashMap<>(); + isValid = isValid(path); + } + + + public PackageNode(PackageNode parentNode, Path path) + { + this.parentNode = parentNode; + this.path = path; + subNodes = new HashMap<>(); + leafNodes = new HashMap<>(); + isValid = isValid(path); + } + + + private static boolean isValid(Path path) + { + boolean isValid; + + try (Stream filesStream = Files.list(path)) + { + isValid = filesStream.anyMatch(filePath -> filePath + .normalize() + .toString() + .toLowerCase() + .endsWith(".java")); + } + catch (IOException e) + { + e.printStackTrace(); + throw new RuntimeException(e); + } + return isValid; + } + + + private static Path getPath(PackageNode parentNode, Path path) + { + return Paths.get(String.format("%s/%s", + parentNode.getPath().normalize(), + path.toFile().getName())); + } + + + public boolean isValid() + { + return isValid; + } + + + public Path getPath() + { + return path; + } + + + public PackageNode getParentNode() + { + return parentNode; + } + + + public Map getSubNodes() + { + return subNodes; + } + + + public Map getLeafNodes() + { + return leafNodes; + } + + + public String getNodeName() + { + if (!doesParentNodeExist()) + { + return path.getFileName().toString(); + } return String.join(".", getParentNode().getNodeName(), path.getFileName().toString()); } - private boolean doesParentNodeExist() { - return getParentNode() != null && !getParentNode().getPath().normalize().toString().isEmpty(); - } - public NodeType getNodeType() { - return NodeType.PACKAGE; - } + private boolean doesParentNodeExist() + { + return getParentNode() != null && + !getParentNode().getPath().normalize().toString().isEmpty(); + } + + + public NodeType getNodeType() + { + return NodeType.PACKAGE; + } } diff --git a/src/main/java/parser/tree/RelationshipType.java b/src/main/java/parser/tree/RelationshipType.java index fcc240b..4e4f9e7 100644 --- a/src/main/java/parser/tree/RelationshipType.java +++ b/src/main/java/parser/tree/RelationshipType.java @@ -1,14 +1,17 @@ package parser.tree; -public enum RelationshipType { - DEPENDENCY, - AGGREGATION, - ASSOCIATION, - EXTENSION, - IMPLEMENTATION; +public enum RelationshipType +{ + DEPENDENCY, + AGGREGATION, + ASSOCIATION, + EXTENSION, + IMPLEMENTATION; - @Override - public String toString() { - return super.toString().toLowerCase(); - } + + @Override + public String toString() + { + return super.toString().toLowerCase(); + } } diff --git a/src/main/java/view/AboutPageController.java b/src/main/java/view/AboutPageController.java index 26a376c..8bccd45 100644 --- a/src/main/java/view/AboutPageController.java +++ b/src/main/java/view/AboutPageController.java @@ -1,5 +1,6 @@ package view; +import javafx.application.HostServices; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.MenuBar; @@ -11,29 +12,39 @@ import java.util.Objects; import java.util.ResourceBundle; -public class AboutPageController implements Initializable { +public class AboutPageController implements Initializable +{ - @FXML - MenuBar menuBar; - @FXML - BorderPane borderPane; + public static final String DOCUMENTATION = "https://drive.google.com/file/d/17h9-hPtQ7GXwKxacQCjEKP51aE3G2JdZ/view"; - public void newProject() { - MenuUtility.openProject(menuBar); - } - public void quitApp() { - MenuUtility.quitApp(menuBar); - } + @FXML + MenuBar menuBar; + @FXML + BorderPane borderPane; - public void aboutPage() { MenuUtility.aboutPage(menuBar); } - public void initialize(URL url, ResourceBundle resourceBundle) { - WebView webView = new WebView(); - webView.setZoom(1.2); - WebEngine webEngine = webView.getEngine(); - URL documentationUrl = Objects.requireNonNull(AboutPageController.class.getResource("/assets/UserDocumentation.html")); - webEngine.load(documentationUrl.toString()); - borderPane.setCenter(webView); - } + public void newProject() + { + MenuUtility.openProject(menuBar); + } + + + public void quitApp() + { + MenuUtility.quitApp(menuBar); + } + + + public void aboutPage() {MenuUtility.aboutPage(menuBar);} + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) + { + WebView webView = new WebView(); + webView.setZoom(1.2); + WebEngine webEngine = webView.getEngine(); + webEngine.load(DOCUMENTATION); + borderPane.setCenter(webView); + } } diff --git a/src/main/java/view/AppStarter.java b/src/main/java/view/AppStarter.java index 28800b5..17fdafb 100644 --- a/src/main/java/view/AppStarter.java +++ b/src/main/java/view/AppStarter.java @@ -1,9 +1,11 @@ package view; -public class AppStarter { +public class AppStarter +{ - public static void main(String[] args) { - AppStarterHelper.main(args); - } + public static void main(String[] args) + { + AppStarterHelper.main(args); + } } diff --git a/src/main/java/view/AppStarterHelper.java b/src/main/java/view/AppStarterHelper.java index 600dfcc..7b833e3 100644 --- a/src/main/java/view/AppStarterHelper.java +++ b/src/main/java/view/AppStarterHelper.java @@ -11,31 +11,38 @@ import java.io.IOException; import java.net.URL; -public class AppStarterHelper extends Application { - - public static void main(String[] args) { - launch(); - } - - @Override - public void start(Stage primaryStage) { - try { - URL url = getClass().getResource("/fxml/ProjectLoadView.fxml"); - Parent root = FXMLLoader.load(url); - Scene scene = new Scene(root); - Image iconImage = new Image(getClass().getResourceAsStream("/assets/logo.png")); - primaryStage.getIcons().add(iconImage); - primaryStage.setTitle("Object Oriented Architecture Diagrammer"); - primaryStage.setScene(scene); - primaryStage.show(); - primaryStage.setOnCloseRequest(e -> { - Platform.exit(); - System.exit(1); - }); - } catch (IOException e) { - e.printStackTrace(); - } - - } +public class AppStarterHelper extends Application +{ + + public static void main(String[] args) + { + launch(); + } + + + @Override + public void start(Stage primaryStage) + { + try + { + URL url = getClass().getResource("/fxml/ProjectLoadView.fxml"); + Parent root = FXMLLoader.load(url); + Scene scene = new Scene(root); + Image iconImage = new Image(getClass().getResourceAsStream("/assets/logo.png")); + primaryStage.getIcons().add(iconImage); + primaryStage.setTitle("Object Oriented Architecture Diagrammer"); + primaryStage.setScene(scene); + primaryStage.show(); + primaryStage.setOnCloseRequest(e -> { + Platform.exit(); + System.exit(1); + }); + } + catch (IOException e) + { + e.printStackTrace(); + } + + } } \ No newline at end of file diff --git a/src/main/java/view/DiagramCreation.java b/src/main/java/view/DiagramCreation.java index a8d1c21..46d31b9 100644 --- a/src/main/java/view/DiagramCreation.java +++ b/src/main/java/view/DiagramCreation.java @@ -9,108 +9,147 @@ import java.io.File; import java.util.List; -public class DiagramCreation { - - @FXML - MenuBar menuBar; - - private static DiagramCreation instance; - private Controller diagramController; - private ProjectTreeView projectTreeView; - private String diagramType; - - private DiagramCreation() { - this.diagramType = ""; - } - - public void createProject(String diagramType) { - if (projectTreeView == null) { - PopupWindow.createPopupInfoWindow("You should load a project first!", "Error"); - return; - } - this.diagramType = diagramType; - diagramController = ControllerFactory.createController("uml", diagramType); - diagramController.createTree(projectTreeView.getSourceFolderPath()); - } - - public void loadProject() { - projectTreeView.setCheckedItems(projectTreeView.getRootItem()); - diagramController.convertTreeToDiagram(getSelectedFiles(diagramType)); - diagramController.arrangeDiagram(); - } - - public void viewProject() { - if (diagramType.isEmpty()) { - PopupWindow.createPopupInfoWindow("You have neither created a diagram nor loaded it yet!", "Error"); - return; - } - if (!wereFilesChosen()) { - PopupWindow.createPopupInfoWindow("You haven't selected any files!", "Error"); - return; - } - viewDiagram(); - } - - private void viewDiagram(){ - DiagramVisualization diagramVisualization = new DiagramVisualization(menuBar); - diagramVisualization.setDiagramController(diagramController); - diagramVisualization.setProjectTreeView(projectTreeView); - diagramVisualization.loadDiagramVisualization(diagramController.visualizeJavaFXGraph()); - } - - public void exportDiagram(){ - File selectedDirectory = FileAndDirectoryUtility.saveFile("Export Diagram", menuBar, "GraphML Files"); - if (selectedDirectory == null) { - return; - } - diagramController.exportDiagramToGraphML(selectedDirectory.toPath()); - } - - public void exportPlantUMLImage() { - File selectedDirectory = FileAndDirectoryUtility.saveFile("Export Diagram As PlantUML", menuBar, "PlantUML Files"); - if (selectedDirectory == null) { - return; - } - diagramController.exportPlantUMLDiagram(selectedDirectory.toPath()); - } - - public void exportPlantUMLText() { - File selectedDirectory = FileAndDirectoryUtility.saveFile("Export PlantUML Text", menuBar, "PlantUML Text Files"); - if (selectedDirectory == null) { - return; - } - diagramController.exportPlantUMLText(selectedDirectory.toPath()); - } - - private List getSelectedFiles(String diagramType) { - if (diagramType.equals("Package")) { - return projectTreeView.getSelectedFiles(projectTreeView.getFolderFiles(), "package"); - } else { - return projectTreeView.getSelectedFiles(projectTreeView.getJavaSourceFiles(), "java"); - } - } - - private boolean wereFilesChosen() { - return !(projectTreeView.getSelectedFiles(projectTreeView.getFolderFiles(), "package").isEmpty() && +public class DiagramCreation +{ + + @FXML + MenuBar menuBar; + + private static DiagramCreation instance; + private Controller diagramController; + private ProjectTreeView projectTreeView; + private String diagramType; + + + private DiagramCreation() + { + this.diagramType = ""; + } + + + public void createProject(String diagramType) + { + if (projectTreeView == null) + { + PopupWindow.createPopupInfoWindow("You should load a project first!", "Error"); + return; + } + this.diagramType = diagramType; + diagramController = ControllerFactory.createController("uml", diagramType); + diagramController.createTree(projectTreeView.getSourceFolderPath()); + } + + + public void loadProject() + { + projectTreeView.setCheckedItems(projectTreeView.getRootItem()); + diagramController.convertTreeToDiagram(getSelectedFiles(diagramType)); + diagramController.arrangeDiagram(); + } + + + public void viewProject() + { + if (diagramType.isEmpty()) + { + PopupWindow.createPopupInfoWindow("You have neither created a diagram nor loaded it yet!", "Error"); + return; + } + if (!wereFilesChosen()) + { + PopupWindow.createPopupInfoWindow("You haven't selected any files!", "Error"); + return; + } + viewDiagram(); + } + + + private void viewDiagram() + { + DiagramVisualization diagramVisualization = new DiagramVisualization(menuBar); + diagramVisualization.setDiagramController(diagramController); + diagramVisualization.setProjectTreeView(projectTreeView); + diagramVisualization.loadDiagramVisualization(diagramController.visualizeJavaFXGraph()); + } + + + public void exportDiagram() + { + File selectedDirectory = FileAndDirectoryUtility.saveFile("Export Diagram", menuBar, "GraphML Files"); + if (selectedDirectory == null) + { + return; + } + diagramController.exportDiagramToGraphML(selectedDirectory.toPath()); + } + + + public void exportPlantUMLImage() + { + File selectedDirectory = FileAndDirectoryUtility.saveFile("Export Diagram As PlantUML", menuBar, "PlantUML Files"); + if (selectedDirectory == null) + { + return; + } + diagramController.exportPlantUMLDiagram(selectedDirectory.toPath()); + } + + + public void exportPlantUMLText() + { + File selectedDirectory = FileAndDirectoryUtility.saveFile("Export PlantUML Text", menuBar, "PlantUML Text Files"); + if (selectedDirectory == null) + { + return; + } + diagramController.exportPlantUMLText(selectedDirectory.toPath()); + } + + + private List getSelectedFiles(String diagramType) + { + if (diagramType.equals("Package")) + { + return projectTreeView.getSelectedFiles(projectTreeView.getFolderFiles(), "package"); + } + else + { + return projectTreeView.getSelectedFiles(projectTreeView.getJavaSourceFiles(), "java"); + } + } + + + private boolean wereFilesChosen() + { + return !(projectTreeView.getSelectedFiles(projectTreeView.getFolderFiles(), "package").isEmpty() && projectTreeView.getSelectedFiles(projectTreeView.getJavaSourceFiles(), "java").isEmpty()); - } - - public void setMenuBar(MenuBar menuBar) { - this.menuBar = menuBar; - } - - public ProjectTreeView getProjectTreeView() { - return projectTreeView; - } - - public void setProjectTreeView(ProjectTreeView projectTreeView) { - this.projectTreeView = projectTreeView; - } - - public static DiagramCreation getInstance(){ - if (instance == null) { - instance = new DiagramCreation(); - } - return instance; - } + } + + + public void setMenuBar(MenuBar menuBar) + { + this.menuBar = menuBar; + } + + + public ProjectTreeView getProjectTreeView() + { + return projectTreeView; + } + + + public void setProjectTreeView(ProjectTreeView projectTreeView) + { + this.projectTreeView = projectTreeView; + } + + + public static DiagramCreation getInstance() + { + if (instance == null) + { + instance = new DiagramCreation(); + } + return instance; + } } diff --git a/src/main/java/view/DiagramCreationController.java b/src/main/java/view/DiagramCreationController.java index 40d19a5..fd17845 100644 --- a/src/main/java/view/DiagramCreationController.java +++ b/src/main/java/view/DiagramCreationController.java @@ -8,64 +8,85 @@ import java.nio.file.Path; -public class DiagramCreationController { - - @FXML - MenuBar menuBar; - @FXML - TreeView treeView; - @FXML - HBox hBox; - @FXML - BorderPane borderPane; - - private ProjectTreeView projectTreeView; - - public void createTreeView(Path sourceFolderPath){ - projectTreeView = new ProjectTreeView(treeView, sourceFolderPath); - projectTreeView.createTreeView(); - } - - public void createDiagram(ActionEvent event) { - createProject(event); - loadProjectFiles(); - viewProject(); - } - - public void createProject(ActionEvent event) { - DiagramCreation.getInstance().setProjectTreeView(projectTreeView); - DiagramCreation.getInstance().setMenuBar(menuBar); - DiagramCreation.getInstance().createProject(((MenuItem) event.getSource()).getText()); - borderPane.setLeft(projectTreeView.treeView); - } - - public void loadProjectFiles() { - DiagramCreation.getInstance().loadProject(); - } - - public void viewProject() { - DiagramCreation.getInstance().viewProject(); - } - - public void openProject() { - MenuUtility.openProject(menuBar); - } - - public void closeProject() { - MenuUtility.closeProject(menuBar); - } - - public void loadDiagram(ActionEvent event) { - FileAndDirectoryUtility.setLoadedDiagramName(MenuUtility.loadDiagram(menuBar, event)); - } - - public void aboutPage() { MenuUtility.aboutPage(menuBar); } - - public void quitApp() { MenuUtility.quitApp(menuBar); } - - public void setProject() { - this.projectTreeView = DiagramCreation.getInstance().getProjectTreeView(); - borderPane.setLeft(projectTreeView.treeView); - DiagramCreation.getInstance().setMenuBar(menuBar); - } +public class DiagramCreationController +{ + + @FXML + MenuBar menuBar; + @FXML + TreeView treeView; + @FXML + HBox hBox; + @FXML + BorderPane borderPane; + + private ProjectTreeView projectTreeView; + + + public void createTreeView(Path sourceFolderPath) + { + projectTreeView = new ProjectTreeView(treeView, sourceFolderPath); + projectTreeView.createTreeView(); + } + + + public void createDiagram(ActionEvent event) + { + createProject(event); + loadProjectFiles(); + viewProject(); + } + + + public void createProject(ActionEvent event) + { + DiagramCreation.getInstance().setProjectTreeView(projectTreeView); + DiagramCreation.getInstance().setMenuBar(menuBar); + DiagramCreation.getInstance().createProject(((MenuItem)event.getSource()).getText()); + borderPane.setLeft(projectTreeView.treeView); + } + + + public void loadProjectFiles() + { + DiagramCreation.getInstance().loadProject(); + } + + + public void viewProject() + { + DiagramCreation.getInstance().viewProject(); + } + + + public void openProject() + { + MenuUtility.openProject(menuBar); + } + + + public void closeProject() + { + MenuUtility.closeProject(menuBar); + } + + + public void loadDiagram(ActionEvent event) + { + FileAndDirectoryUtility.setLoadedDiagramName(MenuUtility.loadDiagram(menuBar, event)); + } + + + public void aboutPage() {MenuUtility.aboutPage(menuBar);} + + + public void quitApp() {MenuUtility.quitApp(menuBar);} + + + public void setProject() + { + this.projectTreeView = DiagramCreation.getInstance().getProjectTreeView(); + borderPane.setLeft(projectTreeView.treeView); + DiagramCreation.getInstance().setMenuBar(menuBar); + } } diff --git a/src/main/java/view/DiagramVisualization.java b/src/main/java/view/DiagramVisualization.java index 62fc597..fb2b809 100644 --- a/src/main/java/view/DiagramVisualization.java +++ b/src/main/java/view/DiagramVisualization.java @@ -14,98 +14,129 @@ import java.util.logging.Level; import java.util.logging.Logger; -public class DiagramVisualization { - private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - - private static final int EDGE_STARTING_NODE = 0; - private static final int EDGE_ENDING_NODE = 1; - private static final int EDGE_TYPE = 2; - - @FXML - MenuBar menuBar; - - private ProjectTreeView projectTreeView; - private Controller diagramController; - private SmartGraphPanel graphView; - - public DiagramVisualization(MenuBar menuBar) { - this.menuBar = menuBar; - } - - public void loadDiagramVisualization(SmartGraphPanel graphView) { - this.graphView = graphView; - try { - URL url = getClass().getResource("/fxml/DiagramVisualizationView.fxml"); - FXMLLoader loader = new FXMLLoader(); - loader.setLocation(url); - Parent diagramVisualizationParent = loader.load(); - DiagramVisualizationController diagramVisualizationController = loader.getController(); - diagramVisualizationController.setDiagramController(diagramController); - diagramVisualizationController.setTreeView(projectTreeView); - addGraphActions(); - diagramVisualizationController.visualizeGraph(graphView); - Scene diagramVisualizationScene = new Scene(diagramVisualizationParent); - Stage window = (Stage) menuBar.getScene().getWindow(); - window.setScene(diagramVisualizationScene); - window.show(); - graphView.init(); - graphView = diagramVisualizationController.applyLayout(); - graphView.update(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void loadLoadedDiagramVisualization(SmartGraphPanel graphView) { - this.graphView = graphView; - try { - URL url = getClass().getResource("/fxml/ProjectLoadView.fxml"); - FXMLLoader loader = new FXMLLoader(); - loader.setLocation(url); - Parent parent = loader.load(); - ProjectLoadController projectLoadController = loader.getController(); - projectLoadController.visualizeGraph(graphView); - projectLoadController.setDiagramController(diagramController); - Scene diagramVisualizationScene = new Scene(parent); - Stage window = (Stage) menuBar.getScene().getWindow(); - window.setScene(diagramVisualizationScene); - window.show(); - try { - graphView = diagramController.visualizeLoadedJavaFXGraph(); - graphView.init(); - graphView.update(); - } catch (IllegalStateException e) { - // Just continue. Handling here the exception to not show the error to the user. - // We do this, because this error doesn't affect the system. - logger.log(Level.WARNING, e.toString()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void addGraphActions() { - addVertexActions(); - addEdgeActions(); - } - - private void addVertexActions() { - graphView.setVertexDoubleClickAction(graphVertex -> - PopupWindow.createPopupInfoWindow(String.format("Vertex contains element: %s", graphVertex.getUnderlyingVertex().element()), - "Node Information")); - } - - private void addEdgeActions() { - graphView.setEdgeDoubleClickAction(graphEdge -> - PopupWindow.createPopupInfoWindow(String.format("Edge starting node: %s", graphEdge.getUnderlyingEdge().element().split("_")[EDGE_STARTING_NODE]) + - "\n" + String.format("Edge ending node: %s", graphEdge.getUnderlyingEdge().element().split("_")[EDGE_ENDING_NODE]) + - "\n" + String.format("Type of relationship: %s", Character.toUpperCase(graphEdge.getUnderlyingEdge().element().split("_")[EDGE_TYPE].charAt(0)) + - graphEdge.getUnderlyingEdge().element().split("_")[EDGE_TYPE].substring(1)), "Edge Information")); - } - - public void setDiagramController(Controller diagramController) { - this.diagramController = diagramController; - } - - public void setProjectTreeView(ProjectTreeView projectTreeView) { this.projectTreeView = projectTreeView; } +public class DiagramVisualization +{ + private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + + private static final int EDGE_STARTING_NODE = 0; + private static final int EDGE_ENDING_NODE = 1; + private static final int EDGE_TYPE = 2; + + @FXML + MenuBar menuBar; + + private ProjectTreeView projectTreeView; + private Controller diagramController; + private SmartGraphPanel graphView; + + + public DiagramVisualization(MenuBar menuBar) + { + this.menuBar = menuBar; + } + + + public void loadDiagramVisualization(SmartGraphPanel graphView) + { + this.graphView = graphView; + try + { + URL url = getClass().getResource("/fxml/DiagramVisualizationView.fxml"); + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(url); + Parent diagramVisualizationParent = loader.load(); + DiagramVisualizationController diagramVisualizationController = loader.getController(); + diagramVisualizationController.setDiagramController(diagramController); + diagramVisualizationController.setTreeView(projectTreeView); + addGraphActions(); + diagramVisualizationController.visualizeGraph(graphView); + Scene diagramVisualizationScene = new Scene(diagramVisualizationParent); + Stage window = (Stage)menuBar.getScene().getWindow(); + window.setScene(diagramVisualizationScene); + window.show(); + graphView.init(); + graphView = diagramVisualizationController.applyLayout(); + graphView.update(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + + public void loadLoadedDiagramVisualization(SmartGraphPanel graphView) + { + this.graphView = graphView; + try + { + URL url = getClass().getResource("/fxml/ProjectLoadView.fxml"); + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(url); + + Parent parent = loader.load(); + ProjectLoadController projectLoadController = loader.getController(); + projectLoadController.visualizeGraph(graphView); + projectLoadController.setDiagramController(diagramController); + Scene diagramVisualizationScene = new Scene(parent); + Stage window = (Stage)menuBar.getScene().getWindow(); + window.setScene(diagramVisualizationScene); + window.show(); + try + { + graphView = diagramController.visualizeLoadedJavaFXGraph(); + graphView.init(); + graphView.update(); + } + catch (IllegalStateException e) + { + // Just continue. Handling here the exception to not show the error to the user. + // We do this, because this error doesn't affect the system. + logger.log(Level.WARNING, e.toString()); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + + public void addGraphActions() + { + addVertexActions(); + addEdgeActions(); + } + + + private void addVertexActions() + { + graphView.setVertexDoubleClickAction(graphVertex -> + PopupWindow.createPopupInfoWindow(String.format("Vertex contains element: %s", + graphVertex.getUnderlyingVertex().element()), + "Node Information")); + } + + + private void addEdgeActions() + { + graphView.setEdgeDoubleClickAction(graphEdge -> + PopupWindow.createPopupInfoWindow(String.format("Edge starting node: %s", + graphEdge.getUnderlyingEdge().element().split("_")[EDGE_STARTING_NODE]) + + "\n" + String.format("Edge ending node: %s", + graphEdge.getUnderlyingEdge().element().split("_")[EDGE_ENDING_NODE]) + + "\n" + String.format("Type of relationship: %s", + Character.toUpperCase(graphEdge.getUnderlyingEdge().element().split("_")[EDGE_TYPE].charAt(0)) + + graphEdge.getUnderlyingEdge().element().split("_")[EDGE_TYPE].substring(1)), + "Edge Information")); + } + + + public void setDiagramController(Controller diagramController) + { + this.diagramController = diagramController; + } + + + public void setProjectTreeView(ProjectTreeView projectTreeView) {this.projectTreeView = projectTreeView;} } diff --git a/src/main/java/view/DiagramVisualizationController.java b/src/main/java/view/DiagramVisualizationController.java index 9345a30..f8e5a41 100644 --- a/src/main/java/view/DiagramVisualizationController.java +++ b/src/main/java/view/DiagramVisualizationController.java @@ -23,165 +23,219 @@ import java.io.IOException; import java.net.URL; -public class DiagramVisualizationController { - - @FXML - BorderPane borderPane; - @FXML - MenuBar menuBar; - - private SmartGraphPanel graphView; - private Controller diagramController; - private ProjectTreeView projectTreeView; - private double graphViewNormalScaleX; - private double graphViewNormalScaleY; - - public void visualizeGraph(SmartGraphPanel graphView) { - this.graphView = graphView; - ContentZoomPane zoomPane = new ContentZoomPane(graphView); - ScrollPane scrollPane = new ScrollPane(zoomPane); - scrollPane.setPannable(false); - graphViewNormalScaleX = graphView.getScaleX(); - graphViewNormalScaleY = graphView.getScaleY(); - String graphViewBackgroundColor = "#F4FFFB"; - Color zoomPaneBackgroundColor = Color.web(graphViewBackgroundColor); - zoomPane.setBackground(new Background(new BackgroundFill(zoomPaneBackgroundColor, null, null))); - graphView.minWidthProperty().bind(borderPane.widthProperty()); - graphView.minHeightProperty().bind(borderPane.heightProperty()); - scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); - scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); - borderPane.setCenter(scrollPane); - setTreeView(projectTreeView); - zoomPane.setOnScroll(event -> { - double zoomFactor = 1.1; - if (event.getDeltaY() >= 0) { - graphView.setScaleX(graphView.getScaleX() * zoomFactor); - graphView.setScaleY(graphView.getScaleY() * zoomFactor); - } else { - graphView.setScaleX(graphView.getScaleX() / zoomFactor); - graphView.setScaleY(graphView.getScaleY() / zoomFactor); - } - }); - } - - public void exportDiagramAsImage() { - try { - File selectedDirectory = FileAndDirectoryUtility.saveFile("Export Diagram as PNG", menuBar,"PNG files"); - if (selectedDirectory == null) { - return; - } - double changeScaleX = graphView.getScaleX(); - double changeScaleY = graphView.getScaleY(); - graphView.setScaleX(graphViewNormalScaleX); - graphView.setScaleY(graphViewNormalScaleY); - WritableImage image = graphView.snapshot(new SnapshotParameters(), null); - ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", selectedDirectory); - graphView.setScaleX(changeScaleX); - graphView.setScaleY(changeScaleY); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void exportDiagramAsText() { - File selectedFile = FileAndDirectoryUtility.saveFile("Save Diagram", menuBar, "Text Files"); - if (selectedFile == null) { - return; - } - diagramController.saveDiagram(selectedFile.toPath()); - } - - public void closeDiagram() { - try { - URL url = MenuUtility.class.getResource("/fxml/DiagramCreationView.fxml"); - FXMLLoader loader = new FXMLLoader(); - loader.setLocation(url); - Parent diagramCreationParent = loader.load(); - - DiagramCreationController diagramCreationController = loader.getController(); - diagramCreationController.setProject(); - - Scene diagramCreationScene = new Scene(diagramCreationParent); - Stage window = (Stage) menuBar.getScene().getWindow(); - window.setScene(diagramCreationScene); - window.show(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void exportDiagramAsGraphML() { - DiagramCreation.getInstance().exportDiagram(); - } - - public void exportDiagramAsPlantUML() { - DiagramCreation.getInstance().exportPlantUMLImage(); - } - - public void exportDiagramAsPlantUMLText() { - DiagramCreation.getInstance().exportPlantUMLText(); - } - - public void aboutPage() { MenuUtility.aboutPage(menuBar); } - - public void showInfoWindow() { - PopupWindow.createPopupInfoWindow("Close the current diagram first!", - "Error"); - } - - public void openProject() { - MenuUtility.openProject(menuBar); - } - - public void closeProject() { - MenuUtility.closeProject(menuBar); - } - - public void quitApp() { - MenuUtility.quitApp(menuBar); - } - - public void setDiagramController(Controller diagramController) { - this.diagramController = diagramController; - } - - public void setTreeView(ProjectTreeView projectTreeView) { - this.projectTreeView = projectTreeView; - borderPane.setLeft(projectTreeView.treeView); - } - - public SmartGraphPanel applyLayout() { - return diagramController.applyLayout(); - } - - public void applySugiyama() { - SmartGraphPanel graphView = diagramController.applySpecificLayout("Sugiyama"); - graphView.update(); - } - - public void applyFruchtermanReingold() { - SmartGraphPanel graphView = diagramController.applySpecificLayout("Fruchterman_Reingold"); - graphView.update(); - } - - public void applyAdvancedFruchtermanReingold() { - SmartGraphPanel graphView = diagramController.applySpecificLayout("Advanced_Fruchterman_Reingold"); - graphView.update(); - } - - public void applySpring() { - SmartGraphPanel graphView = diagramController.applySpecificLayout("Spring"); - graphView.update(); - } - - public void applyAdvancedSpring() { - SmartGraphPanel graphView = diagramController.applySpecificLayout("Advanced_Spring"); - graphView.update(); - } - - public void applyKamadaKawai() { - SmartGraphPanel graphView = diagramController.applySpecificLayout("Kamada_Kawai"); - graphView.update(); - } +public class DiagramVisualizationController +{ + + @FXML + BorderPane borderPane; + @FXML + MenuBar menuBar; + + private SmartGraphPanel graphView; + private Controller diagramController; + private ProjectTreeView projectTreeView; + private double graphViewNormalScaleX; + private double graphViewNormalScaleY; + + + public void visualizeGraph(SmartGraphPanel graphView) + { + this.graphView = graphView; + ContentZoomPane zoomPane = new ContentZoomPane(graphView); + ScrollPane scrollPane = new ScrollPane(zoomPane); + scrollPane.setPannable(false); + + graphViewNormalScaleX = graphView.getScaleX(); + graphViewNormalScaleY = graphView.getScaleY(); + String graphViewBackgroundColor = "#F4FFFB"; + Color zoomPaneBackgroundColor = Color.web(graphViewBackgroundColor); + zoomPane.setBackground(new Background(new BackgroundFill(zoomPaneBackgroundColor, null, null))); + graphView.minWidthProperty().bind(borderPane.widthProperty()); + graphView.minHeightProperty().bind(borderPane.heightProperty()); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + borderPane.setCenter(scrollPane); + setTreeView(projectTreeView); + zoomPane.setOnScroll(event -> { + double zoomFactor = 1.1; + if (event.getDeltaY() >= 0) + { + graphView.setScaleX(graphView.getScaleX() * zoomFactor); + graphView.setScaleY(graphView.getScaleY() * zoomFactor); + } + else + { + graphView.setScaleX(graphView.getScaleX() / zoomFactor); + graphView.setScaleY(graphView.getScaleY() / zoomFactor); + } + }); + } + + + public void exportDiagramAsImage() + { + try + { + File selectedDirectory = FileAndDirectoryUtility.saveFile("Export Diagram as PNG", menuBar, "PNG files"); + if (selectedDirectory == null) + { + return; + } + double changeScaleX = graphView.getScaleX(); + double changeScaleY = graphView.getScaleY(); + graphView.setScaleX(graphViewNormalScaleX); + graphView.setScaleY(graphViewNormalScaleY); + WritableImage image = graphView.snapshot(new SnapshotParameters(), null); + ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", selectedDirectory); + graphView.setScaleX(changeScaleX); + graphView.setScaleY(changeScaleY); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + + public void exportDiagramAsText() + { + File selectedFile = FileAndDirectoryUtility.saveFile("Save Diagram", menuBar, "Text Files"); + if (selectedFile == null) + { + return; + } + diagramController.saveDiagram(selectedFile.toPath()); + } + + + public void closeDiagram() + { + try + { + URL url = MenuUtility.class.getResource("/fxml/DiagramCreationView.fxml"); + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(url); + Parent diagramCreationParent = loader.load(); + + DiagramCreationController diagramCreationController = loader.getController(); + diagramCreationController.setProject(); + + Scene diagramCreationScene = new Scene(diagramCreationParent); + Stage window = (Stage)menuBar.getScene().getWindow(); + window.setScene(diagramCreationScene); + window.show(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + + public void exportDiagramAsGraphML() + { + DiagramCreation.getInstance().exportDiagram(); + } + + + public void exportDiagramAsPlantUML() + { + DiagramCreation.getInstance().exportPlantUMLImage(); + } + + + public void exportDiagramAsPlantUMLText() + { + DiagramCreation.getInstance().exportPlantUMLText(); + } + + + public void aboutPage() {MenuUtility.aboutPage(menuBar);} + + + public void showInfoWindow() + { + PopupWindow.createPopupInfoWindow("Close the current diagram first!", + "Error"); + } + + + public void openProject() + { + MenuUtility.openProject(menuBar); + } + + + public void closeProject() + { + MenuUtility.closeProject(menuBar); + } + + + public void quitApp() + { + MenuUtility.quitApp(menuBar); + } + + + public void setDiagramController(Controller diagramController) + { + this.diagramController = diagramController; + } + + + public void setTreeView(ProjectTreeView projectTreeView) + { + this.projectTreeView = projectTreeView; + borderPane.setLeft(projectTreeView.treeView); + } + + + public SmartGraphPanel applyLayout() + { + return diagramController.applyLayout(); + } + + + public void applySugiyama() + { + SmartGraphPanel graphView = diagramController.applySpecificLayout("Sugiyama"); + graphView.update(); + } + + + public void applyFruchtermanReingold() + { + SmartGraphPanel graphView = diagramController.applySpecificLayout("Fruchterman_Reingold"); + graphView.update(); + } + + + public void applyAdvancedFruchtermanReingold() + { + SmartGraphPanel graphView = diagramController.applySpecificLayout("Advanced_Fruchterman_Reingold"); + graphView.update(); + } + + + public void applySpring() + { + SmartGraphPanel graphView = diagramController.applySpecificLayout("Spring"); + graphView.update(); + } + + + public void applyAdvancedSpring() + { + SmartGraphPanel graphView = diagramController.applySpecificLayout("Advanced_Spring"); + graphView.update(); + } + + + public void applyKamadaKawai() + { + SmartGraphPanel graphView = diagramController.applySpecificLayout("Kamada_Kawai"); + graphView.update(); + } } diff --git a/src/main/java/view/FileAndDirectoryUtility.java b/src/main/java/view/FileAndDirectoryUtility.java index 0c36b78..73d8609 100644 --- a/src/main/java/view/FileAndDirectoryUtility.java +++ b/src/main/java/view/FileAndDirectoryUtility.java @@ -10,73 +10,89 @@ import static java.util.Map.entry; -public class FileAndDirectoryUtility { - - private static File selectedDirectory; - private static String loadedFileName; - - private FileAndDirectoryUtility() { throw new java.lang.UnsupportedOperationException("Not to be instantiated"); } - - public static File chooseDirectory(String windowTitle, MenuBar menuBar) { - DirectoryChooser directoryChooser = new DirectoryChooser(); - directoryChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - directoryChooser.setTitle(windowTitle); - Stage window = (Stage) menuBar.getScene().getWindow(); - selectedDirectory = directoryChooser.showDialog(window); - return selectedDirectory; - } - - public static File saveFile(String windowTitle, MenuBar menuBar, String fileType) { - final Map availableExtensionTypes = Map.ofEntries( - entry("Text Files", "*.txt"), - entry("GraphML Files", "*.graphML"), - entry("PNG files", "*.png"), - entry("PlantUML Files", "*.png"), - entry("PlantUML Text Files", "*.txt")); - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle(windowTitle); - fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(fileType, availableExtensionTypes.get(fileType))); - String[] directoryPath = selectedDirectory.getAbsolutePath().split("//"); - String directoryName = directoryPath[directoryPath.length - 1]; - if (fileType.equals("PlantUML Files") || fileType.equals("PlantUML Text Files")) { - fileChooser.setInitialFileName(String.format(directoryName + "_plantUML%s", availableExtensionTypes.get(fileType).substring(1))); - } else { - fileChooser.setInitialFileName(String.format(directoryName + "_createdDiagram%s", availableExtensionTypes.get(fileType).substring(1))); - } - Stage window = (Stage) menuBar.getScene().getWindow(); - return fileChooser.showSaveDialog(window); - } - - public static File saveLoadedFile(String windowTitle, MenuBar menuBar, String fileType) { - final Map availableExtensionTypes = Map.ofEntries( - entry("Text Files", "*.txt"), - entry("PNG files", "*.png")); - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle(windowTitle); - fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(fileType, availableExtensionTypes.get(fileType))); - if (loadedFileName.contains("_")) { - int lastIndex = loadedFileName.lastIndexOf("_"); - loadedFileName = loadedFileName.substring(0, lastIndex); - } - fileChooser.setInitialFileName(String.format(loadedFileName + "_createdDiagram%s", availableExtensionTypes.get(fileType).substring(1))); - Stage window = (Stage) menuBar.getScene().getWindow(); - return fileChooser.showSaveDialog(window); - } - - public static File loadFile(String windowTitle, MenuBar menuBar) { - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle(windowTitle); - fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Text files", "*.txt")); - fileChooser.setInitialFileName(String.format("createdDiagram%s", ".txt")); - Stage window = (Stage) menuBar.getScene().getWindow(); - return fileChooser.showOpenDialog(window); - } - - public static void setLoadedDiagramName(String loadedFilename) { - loadedFileName = loadedFilename; - } +public class FileAndDirectoryUtility +{ + + private static File selectedDirectory; + private static String loadedFileName; + + + private FileAndDirectoryUtility() {throw new java.lang.UnsupportedOperationException("Not to be instantiated");} + + + public static File chooseDirectory(String windowTitle, MenuBar menuBar) + { + DirectoryChooser directoryChooser = new DirectoryChooser(); + directoryChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + directoryChooser.setTitle(windowTitle); + Stage window = (Stage)menuBar.getScene().getWindow(); + selectedDirectory = directoryChooser.showDialog(window); + return selectedDirectory; + } + + + public static File saveFile(String windowTitle, MenuBar menuBar, String fileType) + { + final Map availableExtensionTypes = Map.ofEntries( + entry("Text Files", "*.txt"), + entry("GraphML Files", "*.graphML"), + entry("PNG files", "*.png"), + entry("PlantUML Files", "*.png"), + entry("PlantUML Text Files", "*.txt")); + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle(windowTitle); + fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(fileType, availableExtensionTypes.get(fileType))); + String[] directoryPath = selectedDirectory.getAbsolutePath().split("//"); + String directoryName = directoryPath[directoryPath.length - 1]; + if (fileType.equals("PlantUML Files") || fileType.equals("PlantUML Text Files")) + { + fileChooser.setInitialFileName(String.format(directoryName + "_plantUML%s", availableExtensionTypes.get(fileType).substring(1))); + } + else + { + fileChooser.setInitialFileName(String.format(directoryName + "_createdDiagram%s", availableExtensionTypes.get(fileType).substring(1))); + } + Stage window = (Stage)menuBar.getScene().getWindow(); + return fileChooser.showSaveDialog(window); + } + + + public static File saveLoadedFile(String windowTitle, MenuBar menuBar, String fileType) + { + final Map availableExtensionTypes = Map.ofEntries( + entry("Text Files", "*.txt"), + entry("PNG files", "*.png")); + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle(windowTitle); + fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(fileType, availableExtensionTypes.get(fileType))); + if (loadedFileName.contains("_")) + { + int lastIndex = loadedFileName.lastIndexOf("_"); + loadedFileName = loadedFileName.substring(0, lastIndex); + } + fileChooser.setInitialFileName(String.format(loadedFileName + "_createdDiagram%s", availableExtensionTypes.get(fileType).substring(1))); + Stage window = (Stage)menuBar.getScene().getWindow(); + return fileChooser.showSaveDialog(window); + } + + + public static File loadFile(String windowTitle, MenuBar menuBar) + { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle(windowTitle); + fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Text files", "*.txt")); + fileChooser.setInitialFileName(String.format("createdDiagram%s", ".txt")); + Stage window = (Stage)menuBar.getScene().getWindow(); + return fileChooser.showOpenDialog(window); + } + + + public static void setLoadedDiagramName(String loadedFilename) + { + loadedFileName = loadedFilename; + } } diff --git a/src/main/java/view/MenuUtility.java b/src/main/java/view/MenuUtility.java index 5cf0bf6..3e0c5fe 100644 --- a/src/main/java/view/MenuUtility.java +++ b/src/main/java/view/MenuUtility.java @@ -16,85 +16,114 @@ import java.net.URL; import java.util.Objects; -public class MenuUtility { - - private MenuUtility(){ - throw new java.lang.UnsupportedOperationException("Not to be instantiated"); - } - - public static void openProject(MenuBar menuBar){ - try { - File selectedDirectory = FileAndDirectoryUtility.chooseDirectory("Load the Project's Source Folder", menuBar); - if (selectedDirectory == null) { - PopupWindow.createPopupInfoWindow("You should select a directory!", "Error"); - return; - } - URL url = MenuUtility.class.getResource("/fxml/DiagramCreationView.fxml"); - FXMLLoader loader = new FXMLLoader(); - loader.setLocation(url); - Parent diagramCreationParent = loader.load(); - - DiagramCreationController diagramCreationController = loader.getController(); - diagramCreationController.createTreeView(selectedDirectory.toPath()); - - Scene diagramCreationScene = new Scene(diagramCreationParent); - Stage window = (Stage) menuBar.getScene().getWindow(); - window.setScene(diagramCreationScene); - window.show(); - } catch (Exception e){ - e.printStackTrace(); - } - } - - public static void closeProject(MenuBar menuBar){ - try { - URL url = MenuUtility.class.getResource("/fxml/ProjectLoadView.fxml"); - Parent diagramCreationParent = FXMLLoader.load(Objects.requireNonNull(url)); - Scene diagramCreationScene = new Scene(diagramCreationParent); - Stage window = (Stage) menuBar.getScene().getWindow(); - window.setScene(diagramCreationScene); - window.show(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void aboutPage(MenuBar menuBar) { - try { - URL url = MenuUtility.class.getResource("/fxml/AboutPageView.fxml"); - Parent aboutPageParent = FXMLLoader.load(Objects.requireNonNull(url)); - Scene diagramCreationScene = new Scene(aboutPageParent); - Stage window = (Stage) menuBar.getScene().getWindow(); - window.setScene(diagramCreationScene); - window.show(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void quitApp(MenuBar menuBar){ - Stage window = (Stage) menuBar.getScene().getWindow(); - window.close(); - } - - public static String loadDiagram(MenuBar menuBar, ActionEvent event) { - Controller diagramController = ControllerFactory.createController("uml", ((MenuItem) event.getSource()).getText()); - File selectedFile = FileAndDirectoryUtility.loadFile(String.format("Load %s Diagram", ((MenuItem) event.getSource()).getText()), menuBar); - if (selectedFile == null) { - return null; - } - try { - DiagramVisualization diagramVisualization = new DiagramVisualization(menuBar); - diagramVisualization.setDiagramController(diagramController); - diagramController.loadDiagram(selectedFile.toPath()); - diagramVisualization.loadLoadedDiagramVisualization(diagramController.visualizeLoadedJavaFXGraph()); - } catch (JsonParseException j) { - if (j.getMessage().equals("Wrong diagram type")) { - PopupWindow.createPopupInfoWindow("You tried to load the wrong type of diagram", "Error"); - } else { - PopupWindow.createPopupInfoWindow("Unsupported type of file", "Error"); - } - } - return selectedFile.getName(); - } +public class MenuUtility +{ + + private MenuUtility() + { + throw new java.lang.UnsupportedOperationException("Not to be instantiated"); + } + + + public static void openProject(MenuBar menuBar) + { + try + { + File selectedDirectory = FileAndDirectoryUtility.chooseDirectory("Load the Project's Source Folder", menuBar); + if (selectedDirectory == null) + { + PopupWindow.createPopupInfoWindow("You should select a directory!", "Error"); + return; + } + URL url = MenuUtility.class.getResource("/fxml/DiagramCreationView.fxml"); + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(url); + Parent diagramCreationParent = loader.load(); + + DiagramCreationController diagramCreationController = loader.getController(); + diagramCreationController.createTreeView(selectedDirectory.toPath()); + + Scene diagramCreationScene = new Scene(diagramCreationParent); + Stage window = (Stage)menuBar.getScene().getWindow(); + window.setScene(diagramCreationScene); + window.show(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + + public static void closeProject(MenuBar menuBar) + { + try + { + URL url = MenuUtility.class.getResource("/fxml/ProjectLoadView.fxml"); + Parent diagramCreationParent = FXMLLoader.load(Objects.requireNonNull(url)); + Scene diagramCreationScene = new Scene(diagramCreationParent); + Stage window = (Stage)menuBar.getScene().getWindow(); + window.setScene(diagramCreationScene); + window.show(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + + public static void aboutPage(MenuBar menuBar) + { + try + { + URL url = MenuUtility.class.getResource("/fxml/AboutPageView.fxml"); + Parent aboutPageParent = FXMLLoader.load(Objects.requireNonNull(url)); + Scene diagramCreationScene = new Scene(aboutPageParent); + Stage window = (Stage)menuBar.getScene().getWindow(); + window.setScene(diagramCreationScene); + window.show(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + + public static void quitApp(MenuBar menuBar) + { + Stage window = (Stage)menuBar.getScene().getWindow(); + window.close(); + } + + + public static String loadDiagram(MenuBar menuBar, ActionEvent event) + { + Controller diagramController = ControllerFactory.createController("uml", ((MenuItem)event.getSource()).getText()); + File selectedFile = FileAndDirectoryUtility.loadFile(String.format("Load %s Diagram", ((MenuItem)event.getSource()).getText()), menuBar); + if (selectedFile == null) + { + return null; + } + try + { + DiagramVisualization diagramVisualization = new DiagramVisualization(menuBar); + diagramVisualization.setDiagramController(diagramController); + diagramController.loadDiagram(selectedFile.toPath()); + diagramVisualization.loadLoadedDiagramVisualization(diagramController.visualizeLoadedJavaFXGraph()); + } + catch (JsonParseException j) + { + if (j.getMessage().equals("Wrong diagram type")) + { + PopupWindow.createPopupInfoWindow("You tried to load the wrong type of diagram", "Error"); + } + else + { + PopupWindow.createPopupInfoWindow("Unsupported type of file", "Error"); + } + } + return selectedFile.getName(); + } } diff --git a/src/main/java/view/PopupWindow.java b/src/main/java/view/PopupWindow.java index ef3684a..638d15b 100644 --- a/src/main/java/view/PopupWindow.java +++ b/src/main/java/view/PopupWindow.java @@ -8,27 +8,31 @@ import javafx.stage.Modality; import javafx.stage.Stage; -public class PopupWindow { +public class PopupWindow +{ - private PopupWindow() { - throw new java.lang.UnsupportedOperationException("Not to be instantiated"); - } + private PopupWindow() + { + throw new java.lang.UnsupportedOperationException("Not to be instantiated"); + } - public static void createPopupInfoWindow(String infoMessage, String popupWindowTitle) { - Stage popupWindow = new Stage(); - popupWindow.initModality(Modality.APPLICATION_MODAL); - popupWindow.setTitle(popupWindowTitle); - Label label1= new Label(infoMessage); - Button closeButton = new Button("Close"); - closeButton.setOnAction(e -> popupWindow.close()); - VBox layout= new VBox(10); - layout.getChildren().addAll(label1, closeButton); - layout.setAlignment(Pos.CENTER); - Scene scene1= new Scene(layout, 300, 150); - scene1.getStylesheets().add("styles/modena_dark.css"); - popupWindow.setScene(scene1); - popupWindow.showAndWait(); - } + public static void createPopupInfoWindow(String infoMessage, String popupWindowTitle) + { + Stage popupWindow = new Stage(); + popupWindow.initModality(Modality.APPLICATION_MODAL); + popupWindow.setTitle(popupWindowTitle); + Label label1 = new Label(infoMessage); + + Button closeButton = new Button("Close"); + closeButton.setOnAction(e -> popupWindow.close()); + VBox layout = new VBox(10); + layout.getChildren().addAll(label1, closeButton); + layout.setAlignment(Pos.CENTER); + Scene scene1 = new Scene(layout, 300, 150); + scene1.getStylesheets().add("styles/modena_dark.css"); + popupWindow.setScene(scene1); + popupWindow.showAndWait(); + } } diff --git a/src/main/java/view/ProjectLoadController.java b/src/main/java/view/ProjectLoadController.java index 020449a..9f27fab 100644 --- a/src/main/java/view/ProjectLoadController.java +++ b/src/main/java/view/ProjectLoadController.java @@ -22,99 +22,127 @@ import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; -public class ProjectLoadController { - - @FXML - MenuBar menuBar; - @FXML - BorderPane borderPane; - @FXML - Menu exportMenu; - - private SmartGraphPanel graphView; - private double graphViewNormalScaleX; - private double graphViewNormalScaleY; - private Controller diagramController; - - public void openProject() { - MenuUtility.openProject(menuBar); - } - - public void closeProject() { - MenuUtility.closeProject(menuBar); - } - - public void quitApp() { - MenuUtility.quitApp(menuBar); - } - - public void aboutPage() { MenuUtility.aboutPage(menuBar); } - - public void loadDiagram(ActionEvent event) { - FileAndDirectoryUtility.setLoadedDiagramName(MenuUtility.loadDiagram(menuBar, event)); - } - - public void visualizeGraph(SmartGraphPanel graphView) { - this.graphView = graphView; - ContentZoomPane zoomPane = new ContentZoomPane(graphView); - ScrollPane scrollPane = new ScrollPane(zoomPane); - scrollPane.setPannable(false); - graphViewNormalScaleX = graphView.getScaleX(); - graphViewNormalScaleY = graphView.getScaleY(); - String graphViewBackgroundColor = "#F4FFFB"; - Color zoomPaneBackgroundColor = Color.web(graphViewBackgroundColor); - zoomPane.setBackground(new Background(new BackgroundFill(zoomPaneBackgroundColor, null, null))); - graphView.minWidthProperty().bind(borderPane.widthProperty()); - graphView.minHeightProperty().bind(borderPane.heightProperty()); - scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); - scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); - borderPane.setCenter(scrollPane); - zoomPane.setOnScroll(event -> { - double zoomFactor = 1.1; - if (event.getDeltaY() >= 0) { - graphView.setScaleX(graphView.getScaleX() * zoomFactor); - graphView.setScaleY(graphView.getScaleY() * zoomFactor); - } else { - graphView.setScaleX(graphView.getScaleX() / zoomFactor); - graphView.setScaleY(graphView.getScaleY() / zoomFactor); - } - }); - exportMenu.setVisible(true); - } - - public void exportDiagramAsImage() { - try { - File selectedDirectory = FileAndDirectoryUtility.saveLoadedFile("Export Diagram as PNG", menuBar,"PNG files"); - if (selectedDirectory == null) { - return; - } - double changeScaleX = graphView.getScaleX(); - double changeScaleY = graphView.getScaleY(); - graphView.setScaleX(graphViewNormalScaleX); - graphView.setScaleY(graphViewNormalScaleY); - WritableImage image = graphView.snapshot(new SnapshotParameters(), null); - ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", selectedDirectory); - graphView.setScaleX(changeScaleX); - graphView.setScaleY(changeScaleY); - }catch (IOException e) { - e.printStackTrace(); - } - } - - public void exportDiagramAsText() { - File selectedFile = FileAndDirectoryUtility.saveLoadedFile("Save Diagram", menuBar, "Text Files"); - if (selectedFile == null) { - return; - } - diagramController.saveDiagram(selectedFile.toPath()); - } - - public void closeDiagram() { - MenuUtility.closeProject(menuBar); - exportMenu.setVisible(false); - } - - public void setDiagramController(Controller diagramController) { - this.diagramController = diagramController; - } +public class ProjectLoadController +{ + + @FXML + MenuBar menuBar; + @FXML + BorderPane borderPane; + @FXML + Menu exportMenu; + + private SmartGraphPanel graphView; + private double graphViewNormalScaleX; + private double graphViewNormalScaleY; + private Controller diagramController; + + + public void openProject() + { + MenuUtility.openProject(menuBar); + } + + + public void closeProject() + { + MenuUtility.closeProject(menuBar); + } + + + public void quitApp() + { + MenuUtility.quitApp(menuBar); + } + + + public void aboutPage() {MenuUtility.aboutPage(menuBar);} + + + public void loadDiagram(ActionEvent event) + { + FileAndDirectoryUtility.setLoadedDiagramName(MenuUtility.loadDiagram(menuBar, event)); + } + + + public void visualizeGraph(SmartGraphPanel graphView) + { + this.graphView = graphView; + ContentZoomPane zoomPane = new ContentZoomPane(graphView); + ScrollPane scrollPane = new ScrollPane(zoomPane); + scrollPane.setPannable(false); + graphViewNormalScaleX = graphView.getScaleX(); + graphViewNormalScaleY = graphView.getScaleY(); + String graphViewBackgroundColor = "#F4FFFB"; + Color zoomPaneBackgroundColor = Color.web(graphViewBackgroundColor); + zoomPane.setBackground(new Background(new BackgroundFill(zoomPaneBackgroundColor, null, null))); + graphView.minWidthProperty().bind(borderPane.widthProperty()); + graphView.minHeightProperty().bind(borderPane.heightProperty()); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + borderPane.setCenter(scrollPane); + zoomPane.setOnScroll(event -> { + double zoomFactor = 1.1; + if (event.getDeltaY() >= 0) + { + graphView.setScaleX(graphView.getScaleX() * zoomFactor); + graphView.setScaleY(graphView.getScaleY() * zoomFactor); + } + else + { + graphView.setScaleX(graphView.getScaleX() / zoomFactor); + graphView.setScaleY(graphView.getScaleY() / zoomFactor); + } + }); + exportMenu.setVisible(true); + } + + + public void exportDiagramAsImage() + { + try + { + File selectedDirectory = FileAndDirectoryUtility.saveLoadedFile("Export Diagram as PNG", menuBar, "PNG files"); + if (selectedDirectory == null) + { + return; + } + double changeScaleX = graphView.getScaleX(); + double changeScaleY = graphView.getScaleY(); + graphView.setScaleX(graphViewNormalScaleX); + graphView.setScaleY(graphViewNormalScaleY); + WritableImage image = graphView.snapshot(new SnapshotParameters(), null); + ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", selectedDirectory); + graphView.setScaleX(changeScaleX); + graphView.setScaleY(changeScaleY); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + + public void exportDiagramAsText() + { + File selectedFile = FileAndDirectoryUtility.saveLoadedFile("Save Diagram", menuBar, "Text Files"); + if (selectedFile == null) + { + return; + } + diagramController.saveDiagram(selectedFile.toPath()); + } + + + public void closeDiagram() + { + MenuUtility.closeProject(menuBar); + exportMenu.setVisible(false); + } + + + public void setDiagramController(Controller diagramController) + { + this.diagramController = diagramController; + } } diff --git a/src/main/java/view/ProjectTreeView.java b/src/main/java/view/ProjectTreeView.java index d0a150a..27465fc 100644 --- a/src/main/java/view/ProjectTreeView.java +++ b/src/main/java/view/ProjectTreeView.java @@ -14,116 +14,161 @@ import java.util.ArrayList; import java.util.List; -public class ProjectTreeView { - - @FXML - TreeView treeView; - - private CheckBoxTreeItem rootItem; - private ObservableSet> checkedItems; - private final List folderFiles; - private final List javaSourceFiles; - private final Path sourceFolderPath; - private final TreeViewResizer resizer; - - public ProjectTreeView(TreeView treeView, Path sourceFolderPath) { - this.sourceFolderPath = sourceFolderPath; - this.treeView = treeView; - folderFiles = new ArrayList<>(); - javaSourceFiles = new ArrayList<>(); - resizer = new TreeViewResizer(); - } - - public void createTreeView(){ - rootItem = new CheckBoxTreeItem<>(sourceFolderPath.normalize().toString() - .substring(sourceFolderPath.normalize().toString().lastIndexOf("/") + 1)); - treeView.setShowRoot(true); - treeView.setCellFactory(CheckBoxTreeCell.forTreeView()); - resizer.makeResizable(treeView); - try (DirectoryStream folderStream = Files.newDirectoryStream(sourceFolderPath)) { - for (Path path: folderStream) { - createTree(path, rootItem); - } - treeView.setRoot(rootItem); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void createTree(Path path, CheckBoxTreeItem parent) { - if (Files.isDirectory(path)) { - folderFiles.add(getRelativePath(path)); - CheckBoxTreeItem treeItem = new CheckBoxTreeItem<>(getRelativePath(path)); - parent.getChildren().add(treeItem); - - try (DirectoryStream filesStream = Files.newDirectoryStream(path)) { - for (Path subPath: filesStream) { - createTree(subPath, treeItem); - } - } catch (Exception e) { - e.printStackTrace(); - } - } else if (isFileExtensionJava(path.normalize().toString())) { - parent.getChildren().add(new CheckBoxTreeItem<>(path.getFileName().toString())); - javaSourceFiles.add(path.getFileName().toString()); - } - } - - private String getRelativePath(Path path) { - return path.normalize().toString().replace(sourceFolderPath.normalize().toString().substring(0, - sourceFolderPath.normalize().toString().lastIndexOf("/") + 1), "").replace("/", "."); - } - - public List getSelectedFiles(List files, String fileType) { - List selectedFiles = new ArrayList<>(); - for (CheckBoxTreeItem c: checkedItems) { - if (!files.contains((String) c.getValue())) { - continue; - } - if (fileType.equals("java")) { - selectedFiles.add(subtractFileExtension((String) c.getValue())); - } else { - selectedFiles.add(((String) c.getValue())); - } - } - return selectedFiles; - } - - public void setCheckedItems(CheckBoxTreeItem rootItem) { - checkedItems = FXCollections.observableSet(); - findCheckedItems(rootItem); - } - - private void findCheckedItems(CheckBoxTreeItem item) { - if (item.isSelected()) { - checkedItems.add(item); - } - for (TreeItem child : item.getChildren()) { - findCheckedItems((CheckBoxTreeItem) child); - } - } - - private boolean isFileExtensionJava(String c) { - return c.toLowerCase().endsWith(".java"); - } - - private String subtractFileExtension(String s) { - return s.substring(0, s.lastIndexOf(".")); - } - - public List getFolderFiles() { - return folderFiles; - } - - public List getJavaSourceFiles() { - return javaSourceFiles; - } - - public CheckBoxTreeItem getRootItem() { - return rootItem; - } - - public Path getSourceFolderPath() { - return sourceFolderPath; - } +public class ProjectTreeView +{ + + @FXML + TreeView treeView; + + private CheckBoxTreeItem rootItem; + private ObservableSet> checkedItems; + private final List folderFiles; + private final List javaSourceFiles; + private final Path sourceFolderPath; + private final TreeViewResizer resizer; + + + public ProjectTreeView(TreeView treeView, Path sourceFolderPath) + { + this.sourceFolderPath = sourceFolderPath; + this.treeView = treeView; + folderFiles = new ArrayList<>(); + javaSourceFiles = new ArrayList<>(); + resizer = new TreeViewResizer(); + } + + + public void createTreeView() + { + rootItem = new CheckBoxTreeItem<>(sourceFolderPath.normalize().toString() + .substring(sourceFolderPath.normalize().toString().lastIndexOf("/") + 1)); + treeView.setShowRoot(true); + treeView.setCellFactory(CheckBoxTreeCell.forTreeView()); + resizer.makeResizable(treeView); + try (DirectoryStream folderStream = Files.newDirectoryStream(sourceFolderPath)) + { + for (Path path : folderStream) + { + createTree(path, rootItem); + } + treeView.setRoot(rootItem); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + + private void createTree(Path path, CheckBoxTreeItem parent) + { + if (Files.isDirectory(path)) + { + folderFiles.add(getRelativePath(path)); + CheckBoxTreeItem treeItem = new CheckBoxTreeItem<>(getRelativePath(path)); + parent.getChildren().add(treeItem); + + try (DirectoryStream filesStream = Files.newDirectoryStream(path)) + { + for (Path subPath : filesStream) + { + createTree(subPath, treeItem); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + else if (isFileExtensionJava(path.normalize().toString())) + { + parent.getChildren().add(new CheckBoxTreeItem<>(path.getFileName().toString())); + javaSourceFiles.add(path.getFileName().toString()); + } + } + + + private String getRelativePath(Path path) + { + return path.normalize().toString().replace(sourceFolderPath.normalize().toString().substring(0, + sourceFolderPath.normalize().toString().lastIndexOf("/") + 1), "").replace("/", "."); + } + + + public List getSelectedFiles(List files, String fileType) + { + List selectedFiles = new ArrayList<>(); + for (CheckBoxTreeItem c : checkedItems) + { + if (!files.contains((String)c.getValue())) + { + continue; + } + if (fileType.equals("java")) + { + selectedFiles.add(subtractFileExtension((String)c.getValue())); + } + else + { + selectedFiles.add(((String)c.getValue())); + } + } + return selectedFiles; + } + + + public void setCheckedItems(CheckBoxTreeItem rootItem) + { + checkedItems = FXCollections.observableSet(); + findCheckedItems(rootItem); + } + + + private void findCheckedItems(CheckBoxTreeItem item) + { + if (item.isSelected()) + { + checkedItems.add(item); + } + for (TreeItem child : item.getChildren()) + { + findCheckedItems((CheckBoxTreeItem)child); + } + } + + + private boolean isFileExtensionJava(String c) + { + return c.toLowerCase().endsWith(".java"); + } + + + private String subtractFileExtension(String s) + { + return s.substring(0, s.lastIndexOf(".")); + } + + + public List getFolderFiles() + { + return folderFiles; + } + + + public List getJavaSourceFiles() + { + return javaSourceFiles; + } + + + public CheckBoxTreeItem getRootItem() + { + return rootItem; + } + + + public Path getSourceFolderPath() + { + return sourceFolderPath; + } } diff --git a/src/main/java/view/TreeViewResizer.java b/src/main/java/view/TreeViewResizer.java index 3e7f04b..c3462bf 100644 --- a/src/main/java/view/TreeViewResizer.java +++ b/src/main/java/view/TreeViewResizer.java @@ -6,67 +6,82 @@ import javafx.scene.layout.Region; // TODO Add Javadoc -public class TreeViewResizer { - - private static final int MIN_TREEVIEW_WIDTH = 100; - private static final int MAX_TREEVIEW_WIDTH = 800; - private Region region; - private double mouseX; - - public TreeViewResizer() { - } - - public void makeResizable(Region region) { - this.region = region; - region.setOnMousePressed(onMousePressedEventHandler); - region.setOnMouseDragged(onMouseDraggedEventHandler); - region.setOnMouseMoved(onMouseMovedEventHandler); - region.setOnMouseReleased(onMouseReleasedEventHandler); - } - - EventHandler onMousePressedEventHandler = event -> { - mouseX = event.getSceneX(); - }; - - EventHandler onMouseDraggedEventHandler = event -> { - double deltaX = event.getSceneX() - mouseX; - - if (!Cursor.DEFAULT.equals(region.getCursor())) { - if (region.getCursor().equals(Cursor.E_RESIZE)) { - double newWidth = region.getWidth() + deltaX; - newWidth = Math.max(MIN_TREEVIEW_WIDTH, Math.min(newWidth, MAX_TREEVIEW_WIDTH)); - region.setPrefWidth(newWidth); - //region.setPrefWidth(region.getWidth() + deltaX); - } else if (region.getCursor().equals(Cursor.W_RESIZE)) { - double newWidth = region.getWidth() - deltaX; - newWidth = Math.max(MIN_TREEVIEW_WIDTH, Math.min(newWidth, MAX_TREEVIEW_WIDTH)); - region.setPrefWidth(newWidth); - //region.setPrefWidth(region.getWidth() - deltaX); - region.setTranslateX(region.getTranslateX() + deltaX); - } - } - - mouseX = event.getSceneX(); - }; - - EventHandler onMouseMovedEventHandler = event -> { - double sceneX = event.getSceneX(); - double nodeX = region.getBoundsInParent().getMinX(); - double nodeWidth = region.getBoundsInParent().getWidth(); - - // By applying different number in the if else statements below, - // we control the 'thickness' of the line that is selected to resize the treeView - - if (sceneX > nodeX + nodeWidth - 10 && sceneX < nodeX + nodeWidth + 10) { - region.setCursor(Cursor.E_RESIZE); - } else if (sceneX > nodeX - 10 && sceneX < nodeX + 10) { - region.setCursor(Cursor.W_RESIZE); - } else { - region.setCursor(Cursor.DEFAULT); - } - }; - - EventHandler onMouseReleasedEventHandler = event -> { - region.setCursor(Cursor.DEFAULT); - }; +public class TreeViewResizer +{ + + private static final int MIN_TREEVIEW_WIDTH = 100; + private static final int MAX_TREEVIEW_WIDTH = 800; + private Region region; + private double mouseX; + + + public TreeViewResizer() + { + } + + + public void makeResizable(Region region) + { + this.region = region; + region.setOnMousePressed(onMousePressedEventHandler); + region.setOnMouseDragged(onMouseDraggedEventHandler); + region.setOnMouseMoved(onMouseMovedEventHandler); + region.setOnMouseReleased(onMouseReleasedEventHandler); + } + + + EventHandler onMousePressedEventHandler = event -> { + mouseX = event.getSceneX(); + }; + + EventHandler onMouseDraggedEventHandler = event -> { + double deltaX = event.getSceneX() - mouseX; + + if (!Cursor.DEFAULT.equals(region.getCursor())) + { + if (region.getCursor().equals(Cursor.E_RESIZE)) + { + double newWidth = region.getWidth() + deltaX; + newWidth = Math.max(MIN_TREEVIEW_WIDTH, Math.min(newWidth, MAX_TREEVIEW_WIDTH)); + region.setPrefWidth(newWidth); + //region.setPrefWidth(region.getWidth() + deltaX); + } + else if (region.getCursor().equals(Cursor.W_RESIZE)) + { + double newWidth = region.getWidth() - deltaX; + newWidth = Math.max(MIN_TREEVIEW_WIDTH, Math.min(newWidth, MAX_TREEVIEW_WIDTH)); + region.setPrefWidth(newWidth); + //region.setPrefWidth(region.getWidth() - deltaX); + region.setTranslateX(region.getTranslateX() + deltaX); + } + } + + mouseX = event.getSceneX(); + }; + + EventHandler onMouseMovedEventHandler = event -> { + double sceneX = event.getSceneX(); + double nodeX = region.getBoundsInParent().getMinX(); + double nodeWidth = region.getBoundsInParent().getWidth(); + + // By applying different number in the if else statements below, + // we control the 'thickness' of the line that is selected to resize the treeView + + if (sceneX > nodeX + nodeWidth - 10 && sceneX < nodeX + nodeWidth + 10) + { + region.setCursor(Cursor.E_RESIZE); + } + else if (sceneX > nodeX - 10 && sceneX < nodeX + 10) + { + region.setCursor(Cursor.W_RESIZE); + } + else + { + region.setCursor(Cursor.DEFAULT); + } + }; + + EventHandler onMouseReleasedEventHandler = event -> { + region.setCursor(Cursor.DEFAULT); + }; } \ No newline at end of file diff --git a/src/main/resources/assets/UserDocumentation.html b/src/main/resources/assets/UserDocumentation.html deleted file mode 100644 index 6cf48c5..0000000 --- a/src/main/resources/assets/UserDocumentation.html +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - - - - - - - - - - - - -
-
Object Oriented Architecture
Diagrammer
User Documentation
Usage
Loading the project
The first step towards the creation of a diagram is to load your desired project. In order to
do that you have to load your project by clicking the menu Project and then Load.
Loading a project
Selecting files
Once you have loaded your project, you must choose the desired files, i.e., the packages or
the Java source files, that will be included in the created diagram. To select your files, simply
check the corresponding boxes in the project’s tree view.
-
Selecting files
Creating the diagram
After you have selected your files, you are ready to create your first diagram. There are two
ways to create a diagram, the direct way and the stepwise way.
-
The direct way is very simple, you just need to select the diagram type, i.e., package or class
diagram.
Creating a diagram, the direct way
For the stepwise way, you first need to create a new diagram, then load the desired files and
then view the created diagram.
Creating a diagram, the stepwise way
-
After you have viewed your diagram, you have the option to export your diagram. The
available exportations are: GraphML, Image(png) and Text.
Exporting a diagram
-
You can view the GraphML file using yEd.
Viewing the diagram via yEd
-
Another feature after you have viewed your diagram is to choose different files and use the
stepwise way to create a new diagram. Instead of creating a new diagram, you just need to
load the new files and view the new diagram.
Closing the current diagram
-
Choose the different files you want to include in the new diagram.
Viewing the new diagram
-
-
- -
- - diff --git a/src/main/resources/fxml/AboutPageView.fxml b/src/main/resources/fxml/AboutPageView.fxml index 56df1ee..3f00d3b 100644 --- a/src/main/resources/fxml/AboutPageView.fxml +++ b/src/main/resources/fxml/AboutPageView.fxml @@ -8,23 +8,23 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/DiagramCreationView.fxml b/src/main/resources/fxml/DiagramCreationView.fxml index 8e49f03..ee517e7 100644 --- a/src/main/resources/fxml/DiagramCreationView.fxml +++ b/src/main/resources/fxml/DiagramCreationView.fxml @@ -42,62 +42,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/DiagramVisualizationView.fxml b/src/main/resources/fxml/DiagramVisualizationView.fxml index bb633d8..a0f6072 100644 --- a/src/main/resources/fxml/DiagramVisualizationView.fxml +++ b/src/main/resources/fxml/DiagramVisualizationView.fxml @@ -10,83 +10,83 @@ - - - - - - - - - - - - - - - + + + + - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/ProjectLoadView.fxml b/src/main/resources/fxml/ProjectLoadView.fxml index a744553..cdabb9c 100644 --- a/src/main/resources/fxml/ProjectLoadView.fxml +++ b/src/main/resources/fxml/ProjectLoadView.fxml @@ -35,50 +35,51 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/styles/smartgraph.properties b/src/main/resources/styles/smartgraph.properties index c0fb6c1..e5c16eb 100644 --- a/src/main/resources/styles/smartgraph.properties +++ b/src/main/resources/styles/smartgraph.properties @@ -4,29 +4,25 @@ # ATTENTION: do not leave any trailing spaces after 'true' or 'false' values # ################################################################################ - # Vertex related configurations # -vertex.allow-user-move = true -vertex.radius = 25 -vertex.tooltip = true -vertex.label = true -vertex.height = 50 - +vertex.allow-user-move=true +vertex.radius=25 +vertex.tooltip=true +vertex.label=true +vertex.height=50 # Edge related configurations # -edge.tooltip = true -edge.label = false +edge.tooltip=true +edge.label=false # only makes sense if displaying a directed graph -edge.arrow = true - +edge.arrow=true # size in pixels (side of a triangle); only for directed graphs -edge.arrowsize = 7 - +edge.arrowsize=7 # (automatic) Force-directed layout related configurations # -- You should experiment with different values for your # -- particular problem, knowing that not all will achieve # -- a stable state -layout.repulsive-force = 25000 -layout.attraction-force = 30 -layout.attraction-scale = 10 +layout.repulsive-force=25000 +layout.attraction-force=30 +layout.attraction-scale=10 diff --git a/src/test/java/manager/ClassDiagramManagerTest.java b/src/test/java/manager/ClassDiagramManagerTest.java index 221352e..8cc090a 100644 --- a/src/test/java/manager/ClassDiagramManagerTest.java +++ b/src/test/java/manager/ClassDiagramManagerTest.java @@ -27,261 +27,286 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class ClassDiagramManagerTest { +public class ClassDiagramManagerTest +{ - @Test - void createSourceProjectTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - SourceProject sourceProject = classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - Map vertices = sourceProject.getInterpreter().getVertices(); - Interpreter interpreter = new Interpreter(); - interpreter.parseProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - interpreter.convertTreeToGraph(); - ArrayList interpreterVertices = new ArrayList<>(interpreter.getVertices().values()); + @Test + void createSourceProjectTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - assertEquals(vertices.size(), interpreterVertices.size()); - for (Map.Entry vertexEntry: vertices.entrySet()) { - PackageVertex optionalPackageVertex = interpreterVertices.stream() - .filter(vertex -> - vertex.getName().equals(vertexEntry.getValue().getName()) && - vertex.getParentVertex().getName().equals(vertexEntry.getValue().getParentVertex().getName())) - .findFirst().orElseGet(Assertions::fail); + SourceProject sourceProject = classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + Map vertices = sourceProject.getInterpreter().getVertices(); + Interpreter interpreter = new Interpreter(); + interpreter.parseProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + interpreter.convertTreeToGraph(); + ArrayList interpreterVertices = new ArrayList<>(interpreter.getVertices().values()); - assertEquals(vertexEntry.getValue().getNeighbourVertices().size(), optionalPackageVertex.getNeighbourVertices().size()); - for (PackageVertex neighbourPackageVertex : vertexEntry.getValue().getNeighbourVertices()) { - Optional optionalNeighbourVertex = optionalPackageVertex.getNeighbourVertices().stream() - .filter(neighbour -> neighbour.getName().equals(neighbourPackageVertex.getName())) - .findAny(); - assertTrue(optionalNeighbourVertex.isPresent()); - } + assertEquals(vertices.size(), interpreterVertices.size()); + for (Map.Entry vertexEntry : vertices.entrySet()) + { + PackageVertex optionalPackageVertex = interpreterVertices.stream() + .filter(vertex -> + vertex.getName().equals(vertexEntry.getValue().getName()) && + vertex.getParentVertex().getName().equals(vertexEntry.getValue().getParentVertex().getName())) + .findFirst().orElseGet(Assertions::fail); - assertEquals(vertexEntry.getValue().getSinkVertices().size(), optionalPackageVertex.getSinkVertices().size()); - for (ClassifierVertex classifierVertex : vertexEntry.getValue().getSinkVertices()) { - Optional optionalSinkVertex = optionalPackageVertex.getSinkVertices().stream() - .filter(sinkVertex1 -> sinkVertex1.getName().equals(classifierVertex.getName())) - .findAny(); - assertTrue(optionalSinkVertex.isPresent()); - } - } - } + assertEquals(vertexEntry.getValue().getNeighbourVertices().size(), optionalPackageVertex.getNeighbourVertices().size()); + for (PackageVertex neighbourPackageVertex : vertexEntry.getValue().getNeighbourVertices()) + { + Optional optionalNeighbourVertex = optionalPackageVertex.getNeighbourVertices().stream() + .filter(neighbour -> neighbour.getName().equals(neighbourPackageVertex.getName())) + .findAny(); + assertTrue(optionalNeighbourVertex.isPresent()); + } - @Test - void populateGraphNodesTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - SourceProject sourceProject = classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", - "ChangeVersionsStrategyCommand", - "Command", - "CommandFactory", - "CreateCommand", - "DisableVersionsManagementCommand", - "EditCommand", - "EnableVersionsManagementCommand", - "LoadCommand", - "RollbackToPreviousVersionCommand", - "SaveCommand")); + assertEquals(vertexEntry.getValue().getSinkVertices().size(), optionalPackageVertex.getSinkVertices().size()); + for (ClassifierVertex classifierVertex : vertexEntry.getValue().getSinkVertices()) + { + Optional optionalSinkVertex = optionalPackageVertex.getSinkVertices().stream() + .filter(sinkVertex1 -> sinkVertex1.getName().equals(classifierVertex.getName())) + .findAny(); + assertTrue(optionalSinkVertex.isPresent()); + } + } + } - Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); - List l1 = new ArrayList<>(); - List l2 = new ArrayList<>(); - assertEquals(sourceProject.getInterpreter().getVertices().get( - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))) - .getSinkVertices().size(), graphNodes.size()); + @Test + void populateGraphNodesTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + SourceProject sourceProject = classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", + "ChangeVersionsStrategyCommand", + "Command", + "CommandFactory", + "CreateCommand", + "DisableVersionsManagementCommand", + "EditCommand", + "EnableVersionsManagementCommand", + "LoadCommand", + "RollbackToPreviousVersionCommand", + "SaveCommand")); - Iterator iter1 = sourceProject.getInterpreter().getVertices() - .get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))) - .getSinkVertices().iterator(); - Iterator> iter2 = graphNodes.entrySet().iterator(); - while(iter1.hasNext() || iter2.hasNext()) { - ClassifierVertex e1 = iter1.next(); - Map.Entry e2 = iter2.next(); - l1.add(e1.getName()); - l2.add(e2.getKey().getName()); - } - Collections.sort(l1); - Collections.sort(l2); - assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1)); - } + Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); - @Test - void createDiagramTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - Map>> testingCreatedDiagram = classDiagramManager.getClassDiagram().getDiagram(); + List l1 = new ArrayList<>(); + List l2 = new ArrayList<>(); + assertEquals(sourceProject.getInterpreter().getVertices().get( + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))) + .getSinkVertices().size(), graphNodes.size()); - Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); - GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); - classDiagramManager.getClassDiagram().setDiagram(graphClassDiagramConverter.convertGraphToClassDiagram()); - ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); - Map>> adjacencyList = shadowCleaner.shadowWeakRelationships(); + Iterator iter1 = sourceProject.getInterpreter().getVertices() + .get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))) + .getSinkVertices().iterator(); + Iterator> iter2 = graphNodes.entrySet().iterator(); + while (iter1.hasNext() || iter2.hasNext()) + { + ClassifierVertex e1 = iter1.next(); + Map.Entry e2 = iter2.next(); + l1.add(e1.getName()); + l2.add(e2.getKey().getName()); + } + Collections.sort(l1); + Collections.sort(l2); + assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1)); + } - assertEquals(adjacencyList, testingCreatedDiagram); - } - @Test - void exportDiagramToGraphMLTest() { - try { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - classDiagramManager.arrangeDiagram(); - File actualFile = classDiagramManager.exportDiagramToGraphML(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.graphML")))); + @Test + void createDiagramTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + Map>> testingCreatedDiagram = classDiagramManager.getClassDiagram().getDiagram(); - DiagramArrangementManagerInterface classDiagramArrangement = new ClassDiagramArrangementManager(classDiagramManager.getClassDiagram()); - classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(classDiagramArrangement.arrangeGraphMLDiagram()); - GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagramManager.getClassDiagram()); - graphMLClassifierVertex.convertSinkVertex(); - GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagramManager.getClassDiagram()); - graphMLClassifierVertexArc.convertSinkVertexArc(); + Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); + GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); + classDiagramManager.getClassDiagram().setDiagram(graphClassDiagramConverter.convertGraphToClassDiagram()); + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); + Map>> adjacencyList = shadowCleaner.shadowWeakRelationships(); - DiagramExporter graphMLExporter = new GraphMLClassDiagramExporter(classDiagramManager.getClassDiagram()); - File expectedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.graphML")))); - assertTrue(FileUtils.contentEquals(expectedFile, actualFile)); - } catch (IOException e) { - e.printStackTrace(); - } - } + assertEquals(adjacencyList, testingCreatedDiagram); + } - @Test - void saveDiagramTest() { - try { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - File testingSavedFile = classDiagramManager.saveDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingSavedFile.txt"))); - DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); - assertTrue(FileUtils.contentEquals(javaFXExporter.exportDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.txt"))), testingSavedFile)); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Test + void exportDiagramToGraphMLTest() + { + try + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + classDiagramManager.arrangeDiagram(); + File actualFile = classDiagramManager.exportDiagramToGraphML(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.graphML")))); - @Test - void loadDiagramTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - Map>> createdDiagram = classDiagramManager.getClassDiagram().getDiagram(); - classDiagramManager.saveDiagram(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt")))); - classDiagramManager.loadDiagram(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt")))); - Map>> loadedDiagram = classDiagramManager.getClassDiagram().getDiagram(); + DiagramArrangementManagerInterface classDiagramArrangement = new ClassDiagramArrangementManager(classDiagramManager.getClassDiagram()); + classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(classDiagramArrangement.arrangeGraphMLDiagram()); + GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagramManager.getClassDiagram()); + graphMLClassifierVertex.convertSinkVertex(); + GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagramManager.getClassDiagram()); + graphMLClassifierVertexArc.convertSinkVertexArc(); - for (ClassifierVertex classifierVertex : createdDiagram.keySet()) { - Optional optionalSinkVertex = loadedDiagram.keySet() - .stream() - .filter(sinkVertex1 -> sinkVertex1.getName().equals(classifierVertex.getName())).findFirst(); - assertTrue(optionalSinkVertex.isPresent()); + DiagramExporter graphMLExporter = new GraphMLClassDiagramExporter(classDiagramManager.getClassDiagram()); + File expectedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.graphML")))); + assertTrue(FileUtils.contentEquals(expectedFile, actualFile)); + } + catch (IOException e) + { + e.printStackTrace(); + } + } - assertEquals(createdDiagram.get(classifierVertex).size(), loadedDiagram.get(optionalSinkVertex.get()).size()); - for (Arc arc: createdDiagram.get(classifierVertex)) { - assertTrue(loadedDiagram.get(optionalSinkVertex.get()) - .stream() - .anyMatch(a -> - a.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - a.targetVertex().getName().equals(arc.targetVertex().getName()) && - a.arcType().equals(arc.arcType()))); - } - } - } + + @Test + void saveDiagramTest() + { + try + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + + File testingSavedFile = classDiagramManager.saveDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingSavedFile.txt"))); + DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); + assertTrue(FileUtils.contentEquals(javaFXExporter.exportDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.txt"))), testingSavedFile)); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + + @Test + void loadDiagramTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + Map>> createdDiagram = classDiagramManager.getClassDiagram().getDiagram(); + classDiagramManager.saveDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); + classDiagramManager.loadDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); + Map>> loadedDiagram = classDiagramManager.getClassDiagram().getDiagram(); + + for (ClassifierVertex classifierVertex : createdDiagram.keySet()) + { + Optional optionalSinkVertex = loadedDiagram.keySet() + .stream() + .filter(sinkVertex1 -> sinkVertex1.getName().equals(classifierVertex.getName())).findFirst(); + assertTrue(optionalSinkVertex.isPresent()); + + assertEquals(createdDiagram.get(classifierVertex).size(), loadedDiagram.get(optionalSinkVertex.get()).size()); + for (Arc arc : createdDiagram.get(classifierVertex)) + { + assertTrue(loadedDiagram.get(optionalSinkVertex.get()) + .stream() + .anyMatch(a -> + a.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + a.targetVertex().getName().equals(arc.targetVertex().getName()) && + a.arcType().equals(arc.arcType()))); + } + } + } } diff --git a/src/test/java/manager/PackageDiagramManagerTest.java b/src/test/java/manager/PackageDiagramManagerTest.java index 7b53134..d7b996f 100644 --- a/src/test/java/manager/PackageDiagramManagerTest.java +++ b/src/test/java/manager/PackageDiagramManagerTest.java @@ -16,48 +16,52 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class PackageDiagramManagerTest { +public class PackageDiagramManagerTest +{ - @Test - void populateGraphMLPackageNodeTest() { - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - SourceProject sourceProject = packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - packageDiagramManager.convertTreeToDiagram(List.of("src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - Map graphNodes = packageDiagramManager.getPackageDiagram().getGraphNodes(); - Map packageNodes = sourceProject.getInterpreter().getVertices(); - packageNodes.remove(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - assertEquals(packageNodes.size(), graphNodes.size()); - Iterator> iter1 = packageNodes.entrySet().iterator(); - Iterator> iter2 = graphNodes.entrySet().iterator(); + @Test + void populateGraphMLPackageNodeTest() + { + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - List l1 = new ArrayList<>(); - List l2 = new ArrayList<>(); - while (iter1.hasNext() || iter2.hasNext()) { - Map.Entry e1 = iter1.next(); - Map.Entry e2 = iter2.next(); - l1.add(e1.getValue().getName()); - l2.add(e2.getKey().getName()); - } - Collections.sort(l1); - Collections.sort(l2); - assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1)); - } + SourceProject sourceProject = packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + packageDiagramManager.convertTreeToDiagram(List.of("src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + Map graphNodes = packageDiagramManager.getPackageDiagram().getGraphNodes(); + Map packageNodes = sourceProject.getInterpreter().getVertices(); + packageNodes.remove(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + assertEquals(packageNodes.size(), graphNodes.size()); + Iterator> iter1 = packageNodes.entrySet().iterator(); + Iterator> iter2 = graphNodes.entrySet().iterator(); + + List l1 = new ArrayList<>(); + List l2 = new ArrayList<>(); + while (iter1.hasNext() || iter2.hasNext()) + { + Map.Entry e1 = iter1.next(); + Map.Entry e2 = iter2.next(); + l1.add(e1.getValue().getName()); + l2.add(e2.getKey().getName()); + } + Collections.sort(l1); + Collections.sort(l2); + assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1)); + } } diff --git a/src/test/java/model/GraphClassDiagramConverterTest.java b/src/test/java/model/GraphClassDiagramConverterTest.java index b94bf23..4cc82bd 100644 --- a/src/test/java/model/GraphClassDiagramConverterTest.java +++ b/src/test/java/model/GraphClassDiagramConverterTest.java @@ -20,51 +20,57 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class GraphClassDiagramConverterTest { +public class GraphClassDiagramConverterTest +{ - @Test - void convertGraphToClassDiagramTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - Set graphNodes = classDiagramManager.getClassDiagram().getGraphNodes().keySet(); - Map>> diagram = classDiagramManager.getClassDiagram().getDiagram(); + @Test + void convertGraphToClassDiagramTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + Set graphNodes = classDiagramManager.getClassDiagram().getGraphNodes().keySet(); + Map>> diagram = classDiagramManager.getClassDiagram().getDiagram(); - List> arcs = new ArrayList<>(); - for (Set> arcSet: diagram.values()) { - arcs.addAll(arcSet); - } + List> arcs = new ArrayList<>(); + for (Set> arcSet : diagram.values()) + { + arcs.addAll(arcSet); + } - GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(diagram.keySet()); - Map>> adjacencyList = graphClassDiagramConverter.convertGraphToClassDiagram(); - classDiagramManager.getClassDiagram().setDiagram(adjacencyList); - ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); - adjacencyList = shadowCleaner.shadowWeakRelationships(); + GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(diagram.keySet()); + Map>> adjacencyList = graphClassDiagramConverter.convertGraphToClassDiagram(); + classDiagramManager.getClassDiagram().setDiagram(adjacencyList); + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); + adjacencyList = shadowCleaner.shadowWeakRelationships(); - Set> actualArcs = new HashSet<>(); - for (Set> value : adjacencyList.values()) { - actualArcs.addAll(value); - } + Set> actualArcs = new HashSet<>(); + for (Set> value : adjacencyList.values()) + { + actualArcs.addAll(value); + } - assertEquals(arcs.size(), actualArcs.size()); - for (Arc arc: actualArcs) { - assertTrue(arcs.contains(arc)); - } + assertEquals(arcs.size(), actualArcs.size()); + for (Arc arc : actualArcs) + { + assertTrue(arcs.contains(arc)); + } - assertEquals(graphNodes.size(), adjacencyList.keySet().size()); - for (ClassifierVertex classifierVertex : adjacencyList.keySet()) { - assertTrue(graphNodes.contains(classifierVertex)); - } - } + assertEquals(graphNodes.size(), adjacencyList.keySet().size()); + for (ClassifierVertex classifierVertex : adjacencyList.keySet()) + { + assertTrue(graphNodes.contains(classifierVertex)); + } + } } diff --git a/src/test/java/model/GraphPackageDiagramConverterTest.java b/src/test/java/model/GraphPackageDiagramConverterTest.java index 988cb5f..92163a2 100644 --- a/src/test/java/model/GraphPackageDiagramConverterTest.java +++ b/src/test/java/model/GraphPackageDiagramConverterTest.java @@ -18,42 +18,47 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class GraphPackageDiagramConverterTest { - - @Test - void convertGraphToPackageDiagramTest() { - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - packageDiagramManager.convertTreeToDiagram(List.of("src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - Map>> diagram = packageDiagramManager.getPackageDiagram().getDiagram(); - - List> arcs = new ArrayList<>(); - for (Set> arcSet: diagram.values()) { - arcs.addAll(arcSet); - } - - GraphPackageDiagramConverter graphPackageDiagramConverter = new GraphPackageDiagramConverter(diagram.keySet()); - Map>> adjacencyList = graphPackageDiagramConverter.convertGraphToPackageDiagram(); - - Set> actualArcs = new HashSet<>(); - for (Set> value : adjacencyList.values()) { - actualArcs.addAll(value); - } - - assertEquals(arcs.size(), actualArcs.size()); - for (Arc vertexArc: actualArcs) { - assertTrue(arcs.contains(vertexArc)); - } - } +public class GraphPackageDiagramConverterTest +{ + + @Test + void convertGraphToPackageDiagramTest() + { + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + packageDiagramManager.convertTreeToDiagram(List.of("src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + Map>> diagram = packageDiagramManager.getPackageDiagram().getDiagram(); + + List> arcs = new ArrayList<>(); + for (Set> arcSet : diagram.values()) + { + arcs.addAll(arcSet); + } + + GraphPackageDiagramConverter graphPackageDiagramConverter = new GraphPackageDiagramConverter(diagram.keySet()); + Map>> adjacencyList = graphPackageDiagramConverter.convertGraphToPackageDiagram(); + + Set> actualArcs = new HashSet<>(); + for (Set> value : adjacencyList.values()) + { + actualArcs.addAll(value); + } + + assertEquals(arcs.size(), actualArcs.size()); + for (Arc vertexArc : actualArcs) + { + assertTrue(arcs.contains(vertexArc)); + } + } } diff --git a/src/test/java/model/ShadowCleanerTest.java b/src/test/java/model/ShadowCleanerTest.java index fc2108d..ea9593a 100644 --- a/src/test/java/model/ShadowCleanerTest.java +++ b/src/test/java/model/ShadowCleanerTest.java @@ -20,131 +20,137 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class ShadowCleanerTest { +public class ShadowCleanerTest +{ - @Test - void shadowWeakRelationshipsTest () { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "ChooseTemplate", - "LatexEditorController", - "VersionsManager", - "DocumentManager", - "Document"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); + @Test + void shadowWeakRelationshipsTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "ChooseTemplate", + "LatexEditorController", + "VersionsManager", + "DocumentManager", + "Document"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); - GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); - Map>> shadowedDiagram = graphClassDiagramConverter.convertGraphToClassDiagram(); - classDiagramManager.getClassDiagram().setDiagram(shadowedDiagram); - int numberOfArcsBeforeShadowCleaner = 0; - for (Set> arcs: shadowedDiagram.values()) { - numberOfArcsBeforeShadowCleaner += arcs.size(); - } - ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); - Map>> diagram = shadowCleaner.shadowWeakRelationships(); - int numberOfArcsAfterShadowCleaner = 0; - for (Set> arcs: diagram.values()) { - numberOfArcsAfterShadowCleaner += arcs.size(); - } - assertEquals(numberOfArcsAfterShadowCleaner + 7, numberOfArcsBeforeShadowCleaner); + GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); + Map>> shadowedDiagram = graphClassDiagramConverter.convertGraphToClassDiagram(); + classDiagramManager.getClassDiagram().setDiagram(shadowedDiagram); + int numberOfArcsBeforeShadowCleaner = 0; + for (Set> arcs : shadowedDiagram.values()) + { + numberOfArcsBeforeShadowCleaner += arcs.size(); + } + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); + Map>> diagram = shadowCleaner.shadowWeakRelationships(); + int numberOfArcsAfterShadowCleaner = 0; + for (Set> arcs : diagram.values()) + { + numberOfArcsAfterShadowCleaner += arcs.size(); + } + assertEquals(numberOfArcsAfterShadowCleaner + 7, numberOfArcsBeforeShadowCleaner); - ClassifierVertex chooseTemplate = diagram.keySet().stream().filter(sinkVertex -> sinkVertex.getName().equals("ChooseTemplate")).findFirst().orElseGet(Assertions::fail); - List> chooseTemplateLatexEditorViewArc = diagram.get(chooseTemplate) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) - .toList(); - assertEquals(1, chooseTemplateLatexEditorViewArc.size()); - assertEquals(ArcType.ASSOCIATION, chooseTemplateLatexEditorViewArc.get(0).arcType()); + ClassifierVertex chooseTemplate = diagram.keySet().stream().filter(sinkVertex -> sinkVertex.getName().equals("ChooseTemplate")).findFirst().orElseGet(Assertions::fail); + List> chooseTemplateLatexEditorViewArc = diagram.get(chooseTemplate) + .stream() + .filter(sinkVertexArc -> + sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) + .toList(); + assertEquals(1, chooseTemplateLatexEditorViewArc.size()); + assertEquals(ArcType.ASSOCIATION, chooseTemplateLatexEditorViewArc.get(0).arcType()); - ClassifierVertex latexEditorView = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("LatexEditorView")) - .findFirst() - .orElseGet(Assertions::fail); - List> latexEditorViewVersionsManagerArc = diagram.get(latexEditorView) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("VersionsManager")) - .toList(); - assertEquals(1, latexEditorViewVersionsManagerArc.size()); - assertEquals(ArcType.ASSOCIATION, latexEditorViewVersionsManagerArc.get(0).arcType()); + ClassifierVertex latexEditorView = diagram + .keySet() + .stream() + .filter(sinkVertex -> + sinkVertex.getName().equals("LatexEditorView")) + .findFirst() + .orElseGet(Assertions::fail); + List> latexEditorViewVersionsManagerArc = diagram.get(latexEditorView) + .stream() + .filter(sinkVertexArc -> + sinkVertexArc.targetVertex().getName().equals("VersionsManager")) + .toList(); + assertEquals(1, latexEditorViewVersionsManagerArc.size()); + assertEquals(ArcType.ASSOCIATION, latexEditorViewVersionsManagerArc.get(0).arcType()); - List> LatexEditorViewLatexEditorControllerArc = diagram.get(latexEditorView) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorController")) - .toList(); - assertEquals(1, LatexEditorViewLatexEditorControllerArc.size()); - assertEquals(ArcType.ASSOCIATION, LatexEditorViewLatexEditorControllerArc.get(0).arcType()); + List> LatexEditorViewLatexEditorControllerArc = diagram.get(latexEditorView) + .stream() + .filter(sinkVertexArc -> + sinkVertexArc.targetVertex().getName().equals("LatexEditorController")) + .toList(); + assertEquals(1, LatexEditorViewLatexEditorControllerArc.size()); + assertEquals(ArcType.ASSOCIATION, LatexEditorViewLatexEditorControllerArc.get(0).arcType()); - List> LatexEditorViewDocumentArc = new ArrayList<>(); - for (Arc classifierVertexArc : diagram.get(latexEditorView)) { - if (classifierVertexArc.targetVertex().getName().equals("Document")) { - LatexEditorViewDocumentArc.add(classifierVertexArc); - } - } - assertEquals(1, LatexEditorViewDocumentArc.size()); - assertEquals(ArcType.ASSOCIATION, LatexEditorViewDocumentArc.get(0).arcType()); + List> LatexEditorViewDocumentArc = new ArrayList<>(); + for (Arc classifierVertexArc : diagram.get(latexEditorView)) + { + if (classifierVertexArc.targetVertex().getName().equals("Document")) + { + LatexEditorViewDocumentArc.add(classifierVertexArc); + } + } + assertEquals(1, LatexEditorViewDocumentArc.size()); + assertEquals(ArcType.ASSOCIATION, LatexEditorViewDocumentArc.get(0).arcType()); - ClassifierVertex mainWindow = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("MainWindow")) - .findFirst() - .orElseGet(Assertions::fail); - List> mainWindowLatexEditorViewArc = diagram - .get(mainWindow) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) - .toList(); - assertEquals(1, mainWindowLatexEditorViewArc.size()); - assertEquals(ArcType.ASSOCIATION, mainWindowLatexEditorViewArc.get(0).arcType()); + ClassifierVertex mainWindow = diagram + .keySet() + .stream() + .filter(sinkVertex -> + sinkVertex.getName().equals("MainWindow")) + .findFirst() + .orElseGet(Assertions::fail); + List> mainWindowLatexEditorViewArc = diagram + .get(mainWindow) + .stream() + .filter(sinkVertexArc -> + sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) + .toList(); + assertEquals(1, mainWindowLatexEditorViewArc.size()); + assertEquals(ArcType.ASSOCIATION, mainWindowLatexEditorViewArc.get(0).arcType()); - ClassifierVertex versionsManager = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("VersionsManager")) - .findFirst() - .orElseGet(Assertions::fail); - List> versionsManagerLatexEditorViewArc = diagram - .get(versionsManager) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) - .toList(); - assertEquals(1, versionsManagerLatexEditorViewArc.size()); - assertEquals(ArcType.ASSOCIATION, versionsManagerLatexEditorViewArc.get(0).arcType()); + ClassifierVertex versionsManager = diagram + .keySet() + .stream() + .filter(sinkVertex -> + sinkVertex.getName().equals("VersionsManager")) + .findFirst() + .orElseGet(Assertions::fail); + List> versionsManagerLatexEditorViewArc = diagram + .get(versionsManager) + .stream() + .filter(sinkVertexArc -> + sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) + .toList(); + assertEquals(1, versionsManagerLatexEditorViewArc.size()); + assertEquals(ArcType.ASSOCIATION, versionsManagerLatexEditorViewArc.get(0).arcType()); - ClassifierVertex documentManager = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("DocumentManager")) - .findFirst() - .orElseGet(Assertions::fail); - List> documentManagerDocumentArc = diagram - .get(documentManager) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("Document")) - .toList(); - assertEquals(1, documentManagerDocumentArc.size()); - assertEquals(ArcType.AGGREGATION, documentManagerDocumentArc.get(0).arcType()); - } + ClassifierVertex documentManager = diagram + .keySet() + .stream() + .filter(sinkVertex -> + sinkVertex.getName().equals("DocumentManager")) + .findFirst() + .orElseGet(Assertions::fail); + List> documentManagerDocumentArc = diagram + .get(documentManager) + .stream() + .filter(sinkVertexArc -> + sinkVertexArc.targetVertex().getName().equals("Document")) + .toList(); + assertEquals(1, documentManagerDocumentArc.size()); + assertEquals(ArcType.AGGREGATION, documentManagerDocumentArc.get(0).arcType()); + } } diff --git a/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java b/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java index 55af91b..920730d 100644 --- a/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java +++ b/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java @@ -24,58 +24,64 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class GraphMLClassDiagramExporterTest { +public class GraphMLClassDiagramExporterTest +{ - @Test - void exportDiagramTest() { - try { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - classDiagramManager.arrangeDiagram(); - DiagramArrangementManagerInterface classDiagramArrangement = new ClassDiagramArrangementManager(classDiagramManager.getClassDiagram()); - Map> nodesGeometry = classDiagramArrangement.arrangeGraphMLDiagram(); - classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(nodesGeometry); - DiagramExporter graphMLExporter = new GraphMLClassDiagramExporter(classDiagramManager.getClassDiagram()); - File exportedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt")))); - Stream lines = Files.lines(exportedFile.toPath()); - String actualFileContents = lines.collect(Collectors.joining("\n")) + "\n"; - lines.close(); + @Test + void exportDiagramTest() + { + try + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + classDiagramManager.arrangeDiagram(); + DiagramArrangementManagerInterface classDiagramArrangement = new ClassDiagramArrangementManager(classDiagramManager.getClassDiagram()); + Map> nodesGeometry = classDiagramArrangement.arrangeGraphMLDiagram(); + classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(nodesGeometry); + DiagramExporter graphMLExporter = new GraphMLClassDiagramExporter(classDiagramManager.getClassDiagram()); + File exportedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); + Stream lines = Files.lines(exportedFile.toPath()); + String actualFileContents = lines.collect(Collectors.joining("\n")) + "\n"; + lines.close(); - String expectedFileContents = getExpectedFileContents(classDiagramManager); - assertEquals(expectedFileContents, actualFileContents); + String expectedFileContents = getExpectedFileContents(classDiagramManager); + assertEquals(expectedFileContents, actualFileContents); - } catch (IOException e) { - e.printStackTrace(); - } - } + } + catch (IOException e) + { + e.printStackTrace(); + } + } - private static String getExpectedFileContents(ClassDiagramManager classDiagramManager) - { - GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagramManager.getClassDiagram()); - StringBuilder graphMLNodeBuffer = graphMLClassifierVertex.convertSinkVertex(); - GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagramManager.getClassDiagram()); - StringBuilder graphMLEdgeBuffer = graphMLClassifierVertexArc.convertSinkVertexArc(); + + private static String getExpectedFileContents(ClassDiagramManager classDiagramManager) + { + GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagramManager.getClassDiagram()); + StringBuilder graphMLNodeBuffer = graphMLClassifierVertex.convertSinkVertex(); + GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagramManager.getClassDiagram()); + StringBuilder graphMLEdgeBuffer = graphMLClassifierVertexArc.convertSinkVertexArc(); return String.format("%s%s%s%s", GraphMLSyntax.getInstance().getGraphMLPrefix(), graphMLNodeBuffer.toString(), graphMLEdgeBuffer.toString(), GraphMLSyntax.getInstance().getGraphMLSuffix()); - } + } } diff --git a/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java b/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java index 453088a..c4bdf66 100644 --- a/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java +++ b/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java @@ -21,141 +21,153 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class JavaFXClassDiagramExporterTest { +public class JavaFXClassDiagramExporterTest +{ - @Test - void exportDiagramTest() { - try { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); - File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt")))); + @Test + void exportDiagramTest() + { + try + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); + File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); - String expectedJsonString = getExpectedJsonString(); - JsonArray expectedJsonArray = JsonParser.parseString(expectedJsonString).getAsJsonArray(); - JsonArray actualJsonArray = JsonParser.parseString(Files.readAllLines(actualFile.toPath()).get(0)).getAsJsonArray(); - assertEquals(expectedJsonArray.size(), actualJsonArray.size()); - for (JsonElement element: expectedJsonArray) { - for (JsonElement actualElement: actualJsonArray) { - if (!actualElement.getAsJsonObject().get("name").equals(element.getAsJsonObject().get("name"))) { - continue; - } - assertEquals(element.getAsJsonObject().size(), actualElement.getAsJsonObject().size()); + String expectedJsonString = getExpectedJsonString(); + JsonArray expectedJsonArray = JsonParser.parseString(expectedJsonString).getAsJsonArray(); + JsonArray actualJsonArray = JsonParser.parseString(Files.readAllLines(actualFile.toPath()).get(0)).getAsJsonArray(); + assertEquals(expectedJsonArray.size(), actualJsonArray.size()); + for (JsonElement element : expectedJsonArray) + { + for (JsonElement actualElement : actualJsonArray) + { + if (!actualElement.getAsJsonObject().get("name").equals(element.getAsJsonObject().get("name"))) + { + continue; + } + assertEquals(element.getAsJsonObject().size(), actualElement.getAsJsonObject().size()); - JsonArray expectedMethods = JsonParser.parseString(element.getAsJsonObject().get("methods").toString()).getAsJsonArray(); - JsonArray actualMethods = JsonParser.parseString(actualElement.getAsJsonObject().get("methods").toString()).getAsJsonArray(); - Set expectedJsonElementSet = CompareArray.setOfElements(expectedMethods); - Set actualJsonElementSet = CompareArray.setOfElements(actualMethods); - assertEquals(expectedJsonElementSet, actualJsonElementSet); + JsonArray expectedMethods = JsonParser.parseString(element.getAsJsonObject().get("methods").toString()).getAsJsonArray(); + JsonArray actualMethods = JsonParser.parseString(actualElement.getAsJsonObject().get("methods").toString()).getAsJsonArray(); + Set expectedJsonElementSet = CompareArray.setOfElements(expectedMethods); + Set actualJsonElementSet = CompareArray.setOfElements(actualMethods); + assertEquals(expectedJsonElementSet, actualJsonElementSet); - JsonArray expectedFields = JsonParser.parseString(element.getAsJsonObject().get("fields").toString()).getAsJsonArray(); - JsonArray actualFields = JsonParser.parseString(actualElement.getAsJsonObject().get("fields").toString()).getAsJsonArray(); - expectedJsonElementSet = CompareArray.setOfElements(expectedFields); - actualJsonElementSet = CompareArray.setOfElements(actualFields); - assertEquals(expectedJsonElementSet, actualJsonElementSet); + JsonArray expectedFields = JsonParser.parseString(element.getAsJsonObject().get("fields").toString()).getAsJsonArray(); + JsonArray actualFields = JsonParser.parseString(actualElement.getAsJsonObject().get("fields").toString()).getAsJsonArray(); + expectedJsonElementSet = CompareArray.setOfElements(expectedFields); + actualJsonElementSet = CompareArray.setOfElements(actualFields); + assertEquals(expectedJsonElementSet, actualJsonElementSet); - JsonArray expectedArcs = JsonParser.parseString(element.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); - JsonArray actualArcs = JsonParser.parseString(actualElement.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); - expectedJsonElementSet = CompareArray.setOfElements(expectedArcs); - actualJsonElementSet = CompareArray.setOfElements(actualArcs); - assertEquals(expectedJsonElementSet, actualJsonElementSet); - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } + JsonArray expectedArcs = JsonParser.parseString(element.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); + JsonArray actualArcs = JsonParser.parseString(actualElement.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); + expectedJsonElementSet = CompareArray.setOfElements(expectedArcs); + actualJsonElementSet = CompareArray.setOfElements(actualArcs); + assertEquals(expectedJsonElementSet, actualJsonElementSet); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } - private static String getExpectedJsonString() - { - return "[{" + - "\"name\":\"MainWindow\",\"path\":\"C:\\\\Users\\\\user\\\\IntelliJProjects\\\\ObjectOrientedArchitectureDiagrammerDaintiness\\\\src\\\\test\\\\resources\\\\LatexEditor\\\\src\\\\view\\\\MainWindow.java\"," + - "\"vertexType\":\"class\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"methods\":[{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"editContents\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"type\\\":\\\"String\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"initialize\",\"returnType\":\"void\",\"modifier\":\"private\",\"parameters\":\"{}\"}," + - "{\"name\":\"MainWindow\",\"returnType\":\"Constructor\",\"modifier\":\"public\",\"parameters\":\"{\\\"latexEditorView\\\":\\\"LatexEditorView\\\"}\"}]," + - "\"fields\":[{\"name\":\"frame\",\"returnType\":\"JFrame\",\"modifier\":\"private\"}," + - "{\"name\":\"editorPane\",\"returnType\":\"JEditorPane\",\"modifier\":\"private\"}," + - "{\"name\":\"latexEditorView\",\"returnType\":\"LatexEditorView\",\"modifier\":\"private\"}],\"arcs\":[{\"source\":\"MainWindow\",\"target\":\"LatexEditorView\",\"arcType\":\"dependency\"}," + - "{\"source\":\"MainWindow\",\"target\":\"LatexEditorView\",\"arcType\":\"association\"},{\"source\":\"MainWindow\",\"target\":\"ChooseTemplate\",\"arcType\":\"dependency\"}]}," + - "{\"name\":\"OpeningWindow\",\"path\":\"C:\\\\Users\\\\user\\\\IntelliJProjects\\\\ObjectOrientedArchitectureDiagrammerDaintiness\\\\src\\\\test\\\\resources\\\\LatexEditor\\\\src\\\\view\\\\OpeningWindow.java\"," + - "\"vertexType\":\"class\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"methods\":[{\"name\":\"OpeningWindow\",\"returnType\":\"Constructor\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"main\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"args\\\":\\\"String[]\\\"}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"},{\"name\":\"run\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + - "{\"name\":\"initialize\",\"returnType\":\"void\",\"modifier\":\"private\",\"parameters\":\"{}\"}],\"fields\":[{\"name\":\"frame\",\"returnType\":\"JFrame\",\"modifier\":\"private\"}," + - "{\"name\":\"latexEditorView\",\"returnType\":\"LatexEditorView\",\"modifier\":\"private\"}],\"arcs\":[{\"source\":\"OpeningWindow\",\"target\":\"LatexEditorController\",\"arcType\":\"dependency\"}," + - "{\"source\":\"OpeningWindow\",\"target\":\"VersionsManager\",\"arcType\":\"dependency\"},{\"source\":\"OpeningWindow\",\"target\":\"LatexEditorView\",\"arcType\":\"association\"}," + - "{\"source\":\"OpeningWindow\",\"target\":\"ChooseTemplate\",\"arcType\":\"dependency\"},{\"source\":\"OpeningWindow\",\"target\":\"VersionsStrategy\",\"arcType\":\"dependency\"}," + - "{\"source\":\"OpeningWindow\",\"target\":\"VolatileVersionsStrategy\",\"arcType\":\"dependency\"}]}," + - "{\"name\":\"LatexEditorView\",\"path\":\"C:\\\\Users\\\\user\\\\IntelliJProjects\\\\ObjectOrientedArchitectureDiagrammerDaintiness\\\\src\\\\test\\\\resources\\\\LatexEditor\\\\src\\\\view\\\\LatexEditorView.java\"," + - "\"vertexType\":\"class\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"methods\":[{\"name\":\"getStrategy\",\"returnType\":\"String\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"getController\",\"returnType\":\"LatexEditorController\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"setVersionsManager\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"versionsManager\\\":\\\"VersionsManager\\\"}\"}," + - "{\"name\":\"getType\",\"returnType\":\"String\",\"modifier\":\"public\",\"parameters\":\"{}\"},{\"name\":\"setController\"," + - "\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"controller\\\":\\\"LatexEditorController\\\"}\"},{\"name\":\"getFilename\",\"returnType\":\"String\"," + - "\"modifier\":\"public\",\"parameters\":\"{}\"},{\"name\":\"setType\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"type\\\":\\\"String\\\"}\"}," + - "{\"name\":\"loadFromFile\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"getCurrentDocument\",\"returnType\":\"Document\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"getText\",\"returnType\":\"String\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"setCurrentDocument\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"currentDocument\\\":\\\"Document\\\"}\"}," + - "{\"name\":\"getVersionsManager\",\"returnType\":\"VersionsManager\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"setText\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"text\\\":\\\"String\\\"}\"}," + - "{\"name\":\"saveContents\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"setFilename\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"filename\\\":\\\"String\\\"}\"}," + - "{\"name\":\"saveToFile\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + - "{\"name\":\"setStrategy\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"strategy\\\":\\\"String\\\"}\"}]," + - "\"fields\":[{\"name\":\"controller\",\"returnType\":\"LatexEditorController\",\"modifier\":\"private\"}," + - "{\"name\":\"currentDocument\",\"returnType\":\"Document\",\"modifier\":\"private\"}," + - "{\"name\":\"type\",\"returnType\":\"String\",\"modifier\":\"private\"},{\"name\":\"text\",\"returnType\":\"String\",\"modifier\":\"private\"}," + - "{\"name\":\"filename\",\"returnType\":\"String\",\"modifier\":\"private\"},{\"name\":\"strategy\",\"returnType\":\"String\",\"modifier\":\"private\"},{\"name\":\"versionsManager\"," + - "\"returnType\":\"VersionsManager\",\"modifier\":\"private\"}],\"arcs\":[{\"source\":\"LatexEditorView\",\"target\":\"LatexEditorController\",\"arcType\":\"dependency\"}," + - "{\"source\":\"LatexEditorView\",\"target\":\"LatexEditorController\",\"arcType\":\"association\"},{\"source\":\"LatexEditorView\",\"target\":\"VersionsManager\",\"" + - "arcType\":\"dependency\"},{\"source\":\"LatexEditorView\",\"target\":\"VersionsManager\",\"arcType\":\"association\"},{\"source\":\"LatexEditorView\",\"target\":\"Document\"," + - "\"arcType\":\"dependency\"},{\"source\":\"LatexEditorView\",\"target\":\"Document\",\"arcType\":\"association\"}]}]"; - } + private static String getExpectedJsonString() + { + return "[{" + + "\"name\":\"MainWindow\",\"path\":\"C:\\\\Users\\\\user\\\\IntelliJProjects\\\\ObjectOrientedArchitectureDiagrammerDaintiness\\\\src\\\\test\\\\resources\\\\LatexEditor\\\\src\\\\view\\\\MainWindow.java\"," + + "\"vertexType\":\"class\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"methods\":[{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"arg0\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"editContents\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"type\\\":\\\"String\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"initialize\",\"returnType\":\"void\",\"modifier\":\"private\",\"parameters\":\"{}\"}," + + "{\"name\":\"MainWindow\",\"returnType\":\"Constructor\",\"modifier\":\"public\",\"parameters\":\"{\\\"latexEditorView\\\":\\\"LatexEditorView\\\"}\"}]," + + "\"fields\":[{\"name\":\"frame\",\"returnType\":\"JFrame\",\"modifier\":\"private\"}," + + "{\"name\":\"editorPane\",\"returnType\":\"JEditorPane\",\"modifier\":\"private\"}," + + "{\"name\":\"latexEditorView\",\"returnType\":\"LatexEditorView\",\"modifier\":\"private\"}],\"arcs\":[{\"source\":\"MainWindow\",\"target\":\"LatexEditorView\",\"arcType\":\"dependency\"}," + + "{\"source\":\"MainWindow\",\"target\":\"LatexEditorView\",\"arcType\":\"association\"},{\"source\":\"MainWindow\",\"target\":\"ChooseTemplate\",\"arcType\":\"dependency\"}]}," + + "{\"name\":\"OpeningWindow\",\"path\":\"C:\\\\Users\\\\user\\\\IntelliJProjects\\\\ObjectOrientedArchitectureDiagrammerDaintiness\\\\src\\\\test\\\\resources\\\\LatexEditor\\\\src\\\\view\\\\OpeningWindow.java\"," + + "\"vertexType\":\"class\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"methods\":[{\"name\":\"OpeningWindow\",\"returnType\":\"Constructor\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"main\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"args\\\":\\\"String[]\\\"}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"},{\"name\":\"run\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"actionPerformed\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"e\\\":\\\"ActionEvent\\\"}\"}," + + "{\"name\":\"initialize\",\"returnType\":\"void\",\"modifier\":\"private\",\"parameters\":\"{}\"}],\"fields\":[{\"name\":\"frame\",\"returnType\":\"JFrame\",\"modifier\":\"private\"}," + + "{\"name\":\"latexEditorView\",\"returnType\":\"LatexEditorView\",\"modifier\":\"private\"}],\"arcs\":[{\"source\":\"OpeningWindow\",\"target\":\"LatexEditorController\",\"arcType\":\"dependency\"}," + + "{\"source\":\"OpeningWindow\",\"target\":\"VersionsManager\",\"arcType\":\"dependency\"},{\"source\":\"OpeningWindow\",\"target\":\"LatexEditorView\",\"arcType\":\"association\"}," + + "{\"source\":\"OpeningWindow\",\"target\":\"ChooseTemplate\",\"arcType\":\"dependency\"},{\"source\":\"OpeningWindow\",\"target\":\"VersionsStrategy\",\"arcType\":\"dependency\"}," + + "{\"source\":\"OpeningWindow\",\"target\":\"VolatileVersionsStrategy\",\"arcType\":\"dependency\"}]}," + + "{\"name\":\"LatexEditorView\",\"path\":\"C:\\\\Users\\\\user\\\\IntelliJProjects\\\\ObjectOrientedArchitectureDiagrammerDaintiness\\\\src\\\\test\\\\resources\\\\LatexEditor\\\\src\\\\view\\\\LatexEditorView.java\"," + + "\"vertexType\":\"class\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"methods\":[{\"name\":\"getStrategy\",\"returnType\":\"String\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"getController\",\"returnType\":\"LatexEditorController\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"setVersionsManager\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"versionsManager\\\":\\\"VersionsManager\\\"}\"}," + + "{\"name\":\"getType\",\"returnType\":\"String\",\"modifier\":\"public\",\"parameters\":\"{}\"},{\"name\":\"setController\"," + + "\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"controller\\\":\\\"LatexEditorController\\\"}\"},{\"name\":\"getFilename\",\"returnType\":\"String\"," + + "\"modifier\":\"public\",\"parameters\":\"{}\"},{\"name\":\"setType\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"type\\\":\\\"String\\\"}\"}," + + "{\"name\":\"loadFromFile\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"getCurrentDocument\",\"returnType\":\"Document\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"getText\",\"returnType\":\"String\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"setCurrentDocument\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"currentDocument\\\":\\\"Document\\\"}\"}," + + "{\"name\":\"getVersionsManager\",\"returnType\":\"VersionsManager\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"setText\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"text\\\":\\\"String\\\"}\"}," + + "{\"name\":\"saveContents\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"setFilename\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"filename\\\":\\\"String\\\"}\"}," + + "{\"name\":\"saveToFile\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{}\"}," + + "{\"name\":\"setStrategy\",\"returnType\":\"void\",\"modifier\":\"public\",\"parameters\":\"{\\\"strategy\\\":\\\"String\\\"}\"}]," + + "\"fields\":[{\"name\":\"controller\",\"returnType\":\"LatexEditorController\",\"modifier\":\"private\"}," + + "{\"name\":\"currentDocument\",\"returnType\":\"Document\",\"modifier\":\"private\"}," + + "{\"name\":\"type\",\"returnType\":\"String\",\"modifier\":\"private\"},{\"name\":\"text\",\"returnType\":\"String\",\"modifier\":\"private\"}," + + "{\"name\":\"filename\",\"returnType\":\"String\",\"modifier\":\"private\"},{\"name\":\"strategy\",\"returnType\":\"String\",\"modifier\":\"private\"},{\"name\":\"versionsManager\"," + + "\"returnType\":\"VersionsManager\",\"modifier\":\"private\"}],\"arcs\":[{\"source\":\"LatexEditorView\",\"target\":\"LatexEditorController\",\"arcType\":\"dependency\"}," + + "{\"source\":\"LatexEditorView\",\"target\":\"LatexEditorController\",\"arcType\":\"association\"},{\"source\":\"LatexEditorView\",\"target\":\"VersionsManager\",\"" + + "arcType\":\"dependency\"},{\"source\":\"LatexEditorView\",\"target\":\"VersionsManager\",\"arcType\":\"association\"},{\"source\":\"LatexEditorView\",\"target\":\"Document\"," + + "\"arcType\":\"dependency\"},{\"source\":\"LatexEditorView\",\"target\":\"Document\",\"arcType\":\"association\"}]}]"; + } - public static class CompareArray { - public static Set setOfElements(JsonArray arr) { - Set set = new HashSet<>(); - for (JsonElement j : arr) { - set.add(j); - } - return set; - } - } + + public static class CompareArray + { + public static Set setOfElements(JsonArray arr) + { + Set set = new HashSet<>(); + for (JsonElement j : arr) + { + set.add(j); + } + return set; + } + } } diff --git a/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java b/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java index 5200821..687d9e8 100644 --- a/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java +++ b/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java @@ -30,354 +30,459 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class JavaFXPackageDiagramExporterTest { +public class JavaFXPackageDiagramExporterTest +{ - private static String expectedJsonString; - private static String expectedString2; - private static String relativePath; - private static String os; + private static String expectedJsonString; + private static String expectedString2; + private static String relativePath; + private static String os; - // TODO Decouple this - @Test - void exportDiagramTest() { - try { - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))); - packageDiagramManager.convertTreeToDiagram(getPackages()); - DiagramExporter javaFXExporter = new JavaFXPackageDiagramExporter(packageDiagramManager.getPackageDiagram()); - File actualFile = javaFXExporter.exportDiagram(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt"))); + // TODO Decouple this + @Test + void exportDiagramTest() + { + try + { + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))); + packageDiagramManager.convertTreeToDiagram(getPackages()); - JsonArray expectedJsonArray = getJsonArray(); - JsonArray actualJsonArray = JsonParser.parseString(Files.readAllLines(actualFile.toPath()).get(0)).getAsJsonArray(); - assertEquals(expectedJsonArray.size(), actualJsonArray.size()); - for (JsonElement element: expectedJsonArray) { - for (JsonElement actualElement: actualJsonArray) { - if (!actualElement.getAsJsonObject().get("name").equals(element.getAsJsonObject().get("name"))) { - continue; - } - assertEquals(element.getAsJsonObject().size(), actualElement.getAsJsonObject().size()); + DiagramExporter javaFXExporter = new JavaFXPackageDiagramExporter(packageDiagramManager.getPackageDiagram()); + File actualFile = javaFXExporter.exportDiagram(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt"))); - JsonArray expectedArcs = JsonParser.parseString(element.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); - JsonArray actualArcs = JsonParser.parseString(actualElement.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); - Set expectedJsonElementSet = CompareArray.setOfElements(expectedArcs); - Set actualJsonElementSet = CompareArray.setOfElements(actualArcs); - assertEquals(expectedJsonElementSet, actualJsonElementSet); + JsonArray expectedJsonArray = getJsonArray(); + JsonArray actualJsonArray = JsonParser.parseString(Files.readAllLines(actualFile.toPath()).get(0)).getAsJsonArray(); + assertEquals(expectedJsonArray.size(), actualJsonArray.size()); + for (JsonElement element : expectedJsonArray) + { + for (JsonElement actualElement : actualJsonArray) + { + if (!actualElement.getAsJsonObject().get("name").equals(element.getAsJsonObject().get("name"))) + { + continue; + } + assertEquals(element.getAsJsonObject().size(), actualElement.getAsJsonObject().size()); - JsonArray expJson = JsonParser.parseString(element.getAsJsonObject().get("sinkVertices").toString()).getAsJsonArray(); - JsonArray actJson = JsonParser.parseString(actualElement.getAsJsonObject().get("sinkVertices").toString()).getAsJsonArray(); - List expSinkVertices = new ArrayList<>(); - List actSinkVertices = new ArrayList<>(); - for (JsonElement jsonElement: expJson) { - Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, new ClassifierVertexDeserializer()).create(); - expSinkVertices.add(gson.fromJson(jsonElement.getAsString(), ClassifierVertex.class)); - } - for (JsonElement jsonElement: actJson) { - Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, new ClassifierVertexDeserializer()).create(); - actSinkVertices.add(gson.fromJson(jsonElement.getAsString(), ClassifierVertex.class)); - } - for (ClassifierVertex classifierVertex : expSinkVertices) { - Optional optionalSinkVertex = actSinkVertices.stream().filter(sinkVertex1 -> - sinkVertex1.getName().equals(classifierVertex.getName()) && - sinkVertex1.getVertexType().equals(classifierVertex.getVertexType()) && - sinkVertex1.getArcs().size() == classifierVertex.getArcs().size() && - sinkVertex1.getMethods().size() == classifierVertex.getMethods().size() && - sinkVertex1.getFields().size() == classifierVertex.getFields().size()) - .findFirst(); - assertTrue(optionalSinkVertex.isPresent()); + JsonArray expectedArcs = JsonParser.parseString(element.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); + JsonArray actualArcs = JsonParser.parseString(actualElement.getAsJsonObject().get("arcs").toString()).getAsJsonArray(); + Set expectedJsonElementSet = CompareArray.setOfElements(expectedArcs); + Set actualJsonElementSet = CompareArray.setOfElements(actualArcs); + assertEquals(expectedJsonElementSet, actualJsonElementSet); - List fields = optionalSinkVertex.get().getFields(); - for (ClassifierVertex.Field field: classifierVertex.getFields()) { - assertTrue(fields.stream() - .anyMatch(field1 -> - field1.name().equals(field.name()) && - field1.type().equals(field.type()) && - field1.modifier().equals(field.modifier()) - ) - ); - } + JsonArray expJson = JsonParser.parseString(element.getAsJsonObject().get("sinkVertices").toString()).getAsJsonArray(); + JsonArray actJson = JsonParser.parseString(actualElement.getAsJsonObject().get("sinkVertices").toString()).getAsJsonArray(); + List expSinkVertices = new ArrayList<>(); + List actSinkVertices = new ArrayList<>(); + for (JsonElement jsonElement : expJson) + { + Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, new ClassifierVertexDeserializer()).create(); + expSinkVertices.add(gson.fromJson(jsonElement.getAsString(), ClassifierVertex.class)); + } + for (JsonElement jsonElement : actJson) + { + Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class, new ClassifierVertexDeserializer()).create(); + actSinkVertices.add(gson.fromJson(jsonElement.getAsString(), ClassifierVertex.class)); + } + for (ClassifierVertex classifierVertex : expSinkVertices) + { + Optional optionalSinkVertex = actSinkVertices.stream().filter(sinkVertex1 -> + sinkVertex1.getName().equals(classifierVertex.getName()) && + sinkVertex1.getVertexType().equals(classifierVertex.getVertexType()) && + sinkVertex1.getArcs().size() == classifierVertex.getArcs().size() && + sinkVertex1.getMethods().size() == classifierVertex.getMethods().size() && + sinkVertex1.getFields().size() == classifierVertex.getFields().size()) + .findFirst(); + assertTrue(optionalSinkVertex.isPresent()); - List methods = optionalSinkVertex.get().getMethods(); - for (ClassifierVertex.Method method: classifierVertex.getMethods()) { - assertTrue(methods.stream() - .anyMatch(method1 -> - method1.name().equals(method.name()) && - method1.returnType().equals(method.returnType()) && - method1.parameters().equals(method.parameters()) - ) - ); - } + List fields = optionalSinkVertex.get().getFields(); + for (ClassifierVertex.Field field : classifierVertex.getFields()) + { + assertTrue(fields.stream() + .anyMatch(field1 -> + field1.name().equals(field.name()) && + field1.type().equals(field.type()) && + field1.modifier().equals(field.modifier()) + ) + ); + } - List> arcs = optionalSinkVertex.get().getArcs(); - for (Arc arc: classifierVertex.getArcs()) { - assertTrue(arcs.stream() - .anyMatch(sinkVertexArc -> - sinkVertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - sinkVertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && - sinkVertexArc.arcType().equals(arc.arcType()) - ) - ); - } - } + List methods = optionalSinkVertex.get().getMethods(); + for (ClassifierVertex.Method method : classifierVertex.getMethods()) + { + assertTrue(methods.stream() + .anyMatch(method1 -> + method1.name().equals(method.name()) && + method1.returnType().equals(method.returnType()) && + method1.parameters().equals(method.parameters()) + ) + ); + } - JsonArray expectedNeighbours = JsonParser.parseString(element.getAsJsonObject().get("neighbours").toString()).getAsJsonArray(); - JsonArray actualNeighbours = JsonParser.parseString(actualElement.getAsJsonObject().get("neighbours").toString()).getAsJsonArray(); - expectedJsonElementSet = CompareArray.setOfElements(expectedNeighbours); - actualJsonElementSet = CompareArray.setOfElements2(actualNeighbours); - assertEquals(expectedJsonElementSet, actualJsonElementSet); + List> arcs = optionalSinkVertex.get().getArcs(); + for (Arc arc : classifierVertex.getArcs()) + { + assertTrue(arcs.stream() + .anyMatch(sinkVertexArc -> + sinkVertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + sinkVertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && + sinkVertexArc.arcType().equals(arc.arcType()) + ) + ); + } + } - JsonObject expectedParent = JsonParser.parseString(element.getAsJsonObject().get("parent").toString()).getAsJsonObject(); - JsonObject actualParent = JsonParser.parseString(actualElement.getAsJsonObject().get("parent").toString()).getAsJsonObject(); - assertEquals(expectedParent.get("name"), actualParent.get("name")); - assertEquals(expectedParent.get("vertexType"), actualParent.get("vertexType")); - assertEquals(expectedParent.get("path").toString(), actualParent.get("path").toString().replaceAll("\\\\", "\\\\\\\\")); - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } + JsonArray expectedNeighbours = JsonParser.parseString(element.getAsJsonObject().get("neighbours").toString()).getAsJsonArray(); + JsonArray actualNeighbours = JsonParser.parseString(actualElement.getAsJsonObject().get("neighbours").toString()).getAsJsonArray(); + expectedJsonElementSet = CompareArray.setOfElements(expectedNeighbours); + actualJsonElementSet = CompareArray.setOfElements2(actualNeighbours); + assertEquals(expectedJsonElementSet, actualJsonElementSet); - @BeforeAll - public static void setUp(){ - relativePath = Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src")).toString(); + JsonObject expectedParent = JsonParser.parseString(element.getAsJsonObject().get("parent").toString()).getAsJsonObject(); + JsonObject actualParent = JsonParser.parseString(actualElement.getAsJsonObject().get("parent").toString()).getAsJsonObject(); + assertEquals(expectedParent.get("name"), actualParent.get("name")); + assertEquals(expectedParent.get("vertexType"), actualParent.get("vertexType")); + assertEquals(expectedParent.get("path").toString(), actualParent.get("path").toString().replaceAll("\\\\", "\\\\\\\\")); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } - os = System.getProperty("os.name"); - expectedJsonString = "[{\"name\":\"src.view\",\"path\":\"" - + relativePath + "\\\\view\",\"vertexType\":\"package\",\"coordinate_x\":362.0,\"coordinate_y\":25.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"LatexEditorView\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\view\\\\\\\\LatexEditorView.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"getStrategy\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getController\\\",\\\"returnType\\\":\\\"LatexEditorController\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getFilename\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getVersionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setController\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"controller\\\\\\\":\\\\\\\"LatexEditorController\\\\\\\"}\\\"},{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setType\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"setCurrentDocument\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"currentDocument\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"setFilename\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getText\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setVersionsManager\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"setText\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"text\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getCurrentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"controller\\\",\\\"returnType\\\":\\\"LatexEditorController\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"currentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"type\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"text\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"filename\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"association\\\"}]}\",\"{\\\"name\\\":\\\"MainWindow\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\view\\\\\\\\MainWindow.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"editContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"MainWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"editorPane\\\",\\\"returnType\\\":\\\"JEditorPane\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\view\\\\\\\\ChooseTemplate.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"diselectRadioButtons\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{\\\\\\\"radioButton3\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton4\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton1\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton2\\\\\\\":\\\\\\\"JRadioButton\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"previous\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"previous\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"MainWindow\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"OpeningWindow\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"OpeningWindow\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\view\\\\\\\\OpeningWindow.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"main\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"args\\\\\\\":\\\\\\\"String[]\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"OpeningWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"run\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VolatileVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" - + relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.view\",\"target\":\"src.controller\",\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.model\",\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]},{\"name\":\"src.controller\",\"path\":\"" - + relativePath + "\\\\controller\",\"vertexType\":\"package\",\"coordinate_x\":72.0,\"coordinate_y\":70.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"LatexEditorController\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\LatexEditorController.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"LatexEditorController\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"enact\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"command\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"commands\\\",\\\"returnType\\\":\\\"HashMap[String,Command]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LatexEditorController\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorController\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"aggregation\\\"},{\\\"source\\\":\\\"LatexEditorController\\\",\\\"target\\\":\\\"CommandFactory\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" - + relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[{\"name\":\"src.controller.commands\",\"path\":\"\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\",\"vertexType\":\"package\",\"parentName\":\"src.controller\"}],\"arcs\":[{\"source\":\"src.controller\",\"target\":\"src.model\",\"arcType\":\"dependency\"},{\"source\":\"src.controller\",\"target\":\"src.controller.commands\",\"arcType\":\"dependency\"}]},{\"name\":\"src.controller.commands\",\"path\":\"" - + relativePath + "\\\\controller\\\\commands\",\"vertexType\":\"package\",\"coordinate_x\":25.0,\"coordinate_y\":140.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"CreateCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\CreateCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"CreateCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documentManager\\\\\\\":\\\\\\\"DocumentManager\\\\\\\",\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"documentManager\\\",\\\"returnType\\\":\\\"DocumentManager\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"DocumentManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"DocumentManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"AddLatexCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\AddLatexCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"AddLatexCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"AddLatexCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"AddLatexCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"AddLatexCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"SaveCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\SaveCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"SaveCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"SaveCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"SaveCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"SaveCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\ChangeVersionsStrategyCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"Command\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\Command.java\\\",\\\"vertexType\\\":\\\"interface\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[],\\\"arcs\\\":[]}\",\"{\\\"name\\\":\\\"DisableVersionsManagementCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\DisableVersionsManagementCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"DisableVersionsManagementCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"DisableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"DisableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"DisableVersionsManagementCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"LoadCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\LoadCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"LoadCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"getVersionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setVersionsManager\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LoadCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LoadCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LoadCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"CommandFactory\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\CommandFactory.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"CommandFactory\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"createCommand\\\",\\\"returnType\\\":\\\"Command\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"documentManager\\\",\\\"returnType\\\":\\\"DocumentManager\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"DocumentManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"CreateCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"AddLatexCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"SaveCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"DisableVersionsManagementCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"LoadCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"EnableVersionsManagementCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"EditCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"EnableVersionsManagementCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\EnableVersionsManagementCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"EnableVersionsManagementCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"EnableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"EnableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"EnableVersionsManagementCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"EditCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\EditCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"EditCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"EditCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"EditCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"EditCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\RollbackToPreviousVersionCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\"],\"parent\":{\"name\":\"src.controller\",\"path\":\"" - + relativePath + "\\\\\\\\controller\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.controller.commands\",\"target\":\"src.model\",\"arcType\":\"dependency\"}]},{\"name\":\"src.model\",\"path\":\"" - + relativePath + "\\\\model\",\"vertexType\":\"package\",\"coordinate_x\":217.0,\"coordinate_y\":210.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"VersionsManager\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\VersionsManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"setStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"},{\\\"name\\\":\\\"setCurrentVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"changeStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"rollback\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"isEnabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setPreviousVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getStrategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"enable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"VersionsManager\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\",\\\\\\\"versionsStrategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"},{\\\"name\\\":\\\"enableStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"disable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"rollbackToPreviousVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"enabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"association\\\"}]}\",\"{\\\"name\\\":\\\"DocumentManager\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\DocumentManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"createDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"DocumentManager\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getContents\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"templates\\\",\\\"returnType\\\":\\\"HashMap[String,Document]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"DocumentManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"DocumentManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"aggregation\\\"}]}\",\"{\\\"name\\\":\\\"Document\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\Document.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"clone\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"changeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"save\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"setContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getContents\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersionID\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"date\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"copyright\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"versionID\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"author\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"author\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"date\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"copyright\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionID\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"contents\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" - + relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[{\"name\":\"src.model.strategies\",\"path\":\"\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\strategies\",\"vertexType\":\"package\",\"parentName\":\"src.model\"}],\"arcs\":[{\"source\":\"src.model\",\"target\":\"src.view\",\"arcType\":\"dependency\"},{\"source\":\"src.model\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]},{\"name\":\"src.model.strategies\",\"path\":\"" - + relativePath + "\\\\model\\\\strategies\",\"vertexType\":\"package\",\"coordinate_x\":362.0,\"coordinate_y\":280.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"VersionsStrategy\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\VersionsStrategy.java\\\",\\\"vertexType\\\":\\\"interface\\\",\\\"methods\\\":[{\\\"name\\\":\\\"removeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setEntireHistory\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documents\\\\\\\":\\\\\\\"List[Document]\\\\\\\"}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getEntireHistory\\\",\\\"returnType\\\":\\\"List[Document]\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[],\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"VolatileVersionsStrategy\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\VolatileVersionsStrategy.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"VolatileVersionsStrategy\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setEntireHistory\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documents\\\\\\\":\\\\\\\"List[Document]\\\\\\\"}\\\"},{\\\"name\\\":\\\"removeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getEntireHistory\\\",\\\"returnType\\\":\\\"List[Document]\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"history\\\",\\\"returnType\\\":\\\"ArrayList[Document]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"VolatileVersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VolatileVersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"aggregation\\\"},{\\\"source\\\":\\\"VolatileVersionsStrategy\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"VersionsStrategyFactory\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\VersionsStrategyFactory.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"VersionsStrategyFactory\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"createStrategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"strategies\\\",\\\"returnType\\\":\\\"HashMap[String,VersionsStrategy]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"aggregation\\\"},{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"VolatileVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"StableVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"StableVersionsStrategy\\\",\\\"path\\\":\\\"" - + relativePath + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\StableVersionsStrategy.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"removeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setEntireHistory\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documents\\\\\\\":\\\\\\\"List[Document]\\\\\\\"}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getEntireHistory\\\",\\\"returnType\\\":\\\"List[Document]\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionID\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"StableVersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"StableVersionsStrategy\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\"],\"parent\":{\"name\":\"src.model\",\"path\":\"" - + relativePath + "\\\\\\\\model\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.model.strategies\",\"target\":\"src.model\",\"arcType\":\"dependency\"}]}]"; + @BeforeAll + public static void setUp() + { + relativePath = Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src")).toString(); - expectedString2 = "[{\"name\":\"src.model\",\"path\":\"" + - relativePath + "model\",\"vertexType\":\"package\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"VersionsManager\\\",\\\"path\\\":\\\"" + - relativePath + "/model/VersionsManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + - "\\\"methods\\\":[{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"enable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"rollbackToPreviousVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"disable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"enableStrategy\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"changeStrategy\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setStrategy\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"setCurrentVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getStrategy\\\"," + - "\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + - "{\\\"name\\\":\\\"rollback\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + - "{\\\"name\\\":\\\"isEnabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + - "{\\\"name\\\":\\\"VersionsManager\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\",\\\\\\\"versionsStrategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"setPreviousVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}" + - ",{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + - "{\\\"name\\\":\\\"saveContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}]," + - "\\\"fields\\\":[{\\\"name\\\":\\\"enabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"private\\\"}," + - "{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"private\\\"}," + - "{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}]," + - "\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"}," + - "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"}," + - "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"}," + - "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"association\\\"}," + - "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"," + - "\"{\\\"name\\\":\\\"DocumentManager\\\",\\\"path\\\":\\\"" + - relativePath + "/model/DocumentManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + - "\\\"methods\\\":[{\\\"name\\\":\\\"createDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getContents\\\",\\\"returnType\\\":\\\"String\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"DocumentManager\\\"," + - "\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"templates\\\"," + - "\\\"returnType\\\":\\\"HashMap[String,Document]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"DocumentManager\\\"," + - "\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"DocumentManager\\\",\\\"target\\\":\\\"Document\\\"," + - "\\\"arcType\\\":\\\"aggregation\\\"}]}\",\"{\\\"name\\\":\\\"Document\\\",\\\"path\\\":\\\"" + - relativePath + "/model/Document.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + - "\\\"methods\\\":[{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"date\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"copyright\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"versionID\\\\\\\":\\\\\\\"String\\\\\\\"," + - "\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"author\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"clone\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"save\\\",\\\"returnType\\\":\\\"void\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"setContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"changeVersion\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersionID\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getContents\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"author\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"date\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}," + - "{\\\"name\\\":\\\"copyright\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionID\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"contents\\\",\\\"returnType\\\":\\\"String\\\"," + - "\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + - relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[{\"name\":\"src.model.strategies\",\"path\":\"" + - relativePath + "/model/strategies\",\"vertexType\":\"package\",\"parentName\":\"src.model\"}],\"arcs\":[{\"source\":\"src.model\"," + - "\"target\":\"src.view\",\"arcType\":\"dependency\"},{\"source\":\"src.model\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]},{\"name\":\"src.view\",\"path\":\"" + - relativePath + "/view\",\"vertexType\":\"package\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"LatexEditorView\\\",\\\"path\\\":\\\"" + - relativePath + "/view/LatexEditorView.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0,\\\"methods\\\":[{\\\"name\\\":\\\"getText\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setType\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getVersionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getCurrentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveContents\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setCurrentDocument\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"currentDocument\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"setText\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"text\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setFilename\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setStrategy\\\",\\\"returnType\\\":\\\"void\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getStrategy\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getFilename\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setVersionsManager\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"setController\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"controller\\\\\\\":\\\\\\\"LatexEditorController\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getController\\\",\\\"returnType\\\":\\\"LatexEditorController\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"controller\\\",\\\"returnType\\\":\\\"LatexEditorController\\\"," + - "\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"currentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"private\\\"}," + - "{\\\"name\\\":\\\"type\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"text\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}," + - "{\\\"name\\\":\\\"filename\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"String\\\"," + - "\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\"," + - "\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\"," + - "\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"}," + - "{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\"," + - "\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\"," + - "\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"association\\\"}]}\",\"{\\\"name\\\":\\\"MainWindow\\\",\\\"path\\\":\\\"" + - relativePath + "/view/MainWindow.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + - "\\\"methods\\\":[{\\\"name\\\":\\\"MainWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"editContents\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\"," + - "\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"editorPane\\\",\\\"returnType\\\":\\\"JEditorPane\\\",\\\"modifier\\\":\\\"private\\\"}," + - "{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\"," + - "\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\"," + - "\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"path\\\":\\\"" + - relativePath + "/view/ChooseTemplate.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0,\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"returnType\\\":\\\"Constructor\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"previous\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"diselectRadioButtons\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{\\\\\\\"radioButton3\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton4\\\\\\\":\\\\\\\"JRadioButton\\\\\\\"," + - "\\\\\\\"radioButton1\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton2\\\\\\\":\\\\\\\"JRadioButton\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + - "\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\"," + - "\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\"," + - "\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"previous\\\"," + - "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"ChooseTemplate\\\"," + - "\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"LatexEditorView\\\"," + - "\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"MainWindow\\\",\\\"arcType\\\":\\\"dependency\\\"}," + - "{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"OpeningWindow\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"OpeningWindow\\\"," + - "\\\"path\\\":\\\"/home/dimitrios/IdeaProjects/GitHub/ObjectOrientedArchitectureDiagrammer/src/test/resources/LatexEditor/src/view/OpeningWindow.java\\\"," + - "\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0,\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\"," + - "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"OpeningWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + - "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + - "{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"}," + - "{\\\"name\\\":\\\"run\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"main\\\",\\\"returnType\\\":\\\"void\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"args\\\\\\\":\\\\\\\"String[]\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\"," + - "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\"," + - "\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"OpeningWindow\\\"," + - "\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\"," + - "\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VolatileVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\"," + - "\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + - relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.view\"," + - "\"target\":\"src.model\",\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.controller\"," + - "\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]}]"; - } + os = System.getProperty("os.name"); - private JsonArray getJsonArray() { - if (os.equals("Linux")) { - return JsonParser.parseString(expectedString2).getAsJsonArray(); - } else { - return JsonParser.parseString(expectedJsonString).getAsJsonArray(); - } - } + expectedJsonString = "[{\"name\":\"src.view\",\"path\":\"" + + + relativePath + + "\\\\view\",\"vertexType\":\"package\",\"coordinate_x\":362.0,\"coordinate_y\":25.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"LatexEditorView\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\view\\\\\\\\LatexEditorView.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"getStrategy\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getController\\\",\\\"returnType\\\":\\\"LatexEditorController\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getFilename\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getVersionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setController\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"controller\\\\\\\":\\\\\\\"LatexEditorController\\\\\\\"}\\\"},{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setType\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"setCurrentDocument\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"currentDocument\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"setFilename\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getText\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setVersionsManager\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"setText\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"text\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getCurrentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"controller\\\",\\\"returnType\\\":\\\"LatexEditorController\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"currentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"type\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"text\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"filename\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"association\\\"}]}\",\"{\\\"name\\\":\\\"MainWindow\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\view\\\\\\\\MainWindow.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"editContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"MainWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"editorPane\\\",\\\"returnType\\\":\\\"JEditorPane\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\view\\\\\\\\ChooseTemplate.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"diselectRadioButtons\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{\\\\\\\"radioButton3\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton4\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton1\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton2\\\\\\\":\\\\\\\"JRadioButton\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"previous\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"previous\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"MainWindow\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"OpeningWindow\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"OpeningWindow\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\view\\\\\\\\OpeningWindow.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"main\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"args\\\\\\\":\\\\\\\"String[]\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"OpeningWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"run\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VolatileVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + + + relativePath + + "\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.view\",\"target\":\"src.controller\",\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.model\",\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]},{\"name\":\"src.controller\",\"path\":\"" + + + relativePath + + "\\\\controller\",\"vertexType\":\"package\",\"coordinate_x\":72.0,\"coordinate_y\":70.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"LatexEditorController\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\LatexEditorController.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"LatexEditorController\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"enact\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"command\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"commands\\\",\\\"returnType\\\":\\\"HashMap[String,Command]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LatexEditorController\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorController\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"aggregation\\\"},{\\\"source\\\":\\\"LatexEditorController\\\",\\\"target\\\":\\\"CommandFactory\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + + + relativePath + + "\",\"vertexType\":\"package_private\"},\"neighbours\":[{\"name\":\"src.controller.commands\",\"path\":\"\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\",\"vertexType\":\"package\",\"parentName\":\"src.controller\"}],\"arcs\":[{\"source\":\"src.controller\",\"target\":\"src.model\",\"arcType\":\"dependency\"},{\"source\":\"src.controller\",\"target\":\"src.controller.commands\",\"arcType\":\"dependency\"}]},{\"name\":\"src.controller.commands\",\"path\":\"" + + + relativePath + + "\\\\controller\\\\commands\",\"vertexType\":\"package\",\"coordinate_x\":25.0,\"coordinate_y\":140.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"CreateCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\CreateCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"CreateCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documentManager\\\\\\\":\\\\\\\"DocumentManager\\\\\\\",\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"documentManager\\\",\\\"returnType\\\":\\\"DocumentManager\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"DocumentManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"DocumentManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CreateCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"AddLatexCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\AddLatexCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"AddLatexCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"AddLatexCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"AddLatexCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"AddLatexCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"SaveCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\SaveCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"SaveCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"SaveCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"SaveCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"SaveCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\ChangeVersionsStrategyCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"Command\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\Command.java\\\",\\\"vertexType\\\":\\\"interface\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[],\\\"arcs\\\":[]}\",\"{\\\"name\\\":\\\"DisableVersionsManagementCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\DisableVersionsManagementCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"DisableVersionsManagementCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"DisableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"DisableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"DisableVersionsManagementCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"LoadCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\LoadCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"LoadCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"getVersionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setVersionsManager\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LoadCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LoadCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LoadCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"CommandFactory\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\CommandFactory.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"CommandFactory\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"createCommand\\\",\\\"returnType\\\":\\\"Command\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"documentManager\\\",\\\"returnType\\\":\\\"DocumentManager\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"DocumentManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"CreateCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"AddLatexCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"SaveCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"ChangeVersionsStrategyCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"DisableVersionsManagementCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"LoadCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"EnableVersionsManagementCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"EditCommand\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"CommandFactory\\\",\\\"target\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"EnableVersionsManagementCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\EnableVersionsManagementCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"EnableVersionsManagementCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"EnableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"EnableVersionsManagementCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"EnableVersionsManagementCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"EditCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\EditCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"EditCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"EditCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"EditCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"EditCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\controller\\\\\\\\commands\\\\\\\\RollbackToPreviousVersionCommand.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"},{\\\"name\\\":\\\"execute\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"RollbackToPreviousVersionCommand\\\",\\\"target\\\":\\\"Command\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\"],\"parent\":{\"name\":\"src.controller\",\"path\":\"" + + + relativePath + + "\\\\\\\\controller\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.controller.commands\",\"target\":\"src.model\",\"arcType\":\"dependency\"}]},{\"name\":\"src.model\",\"path\":\"" + + + relativePath + + "\\\\model\",\"vertexType\":\"package\",\"coordinate_x\":217.0,\"coordinate_y\":210.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"VersionsManager\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\VersionsManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"setStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"},{\\\"name\\\":\\\"setCurrentVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"changeStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"rollback\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"isEnabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setPreviousVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getStrategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"enable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"VersionsManager\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\",\\\\\\\"versionsStrategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"},{\\\"name\\\":\\\"enableStrategy\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"disable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"rollbackToPreviousVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"enabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"association\\\"}]}\",\"{\\\"name\\\":\\\"DocumentManager\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\DocumentManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"createDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"DocumentManager\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getContents\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"templates\\\",\\\"returnType\\\":\\\"HashMap[String,Document]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"DocumentManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"DocumentManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"aggregation\\\"}]}\",\"{\\\"name\\\":\\\"Document\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\Document.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"clone\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"changeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"save\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"setContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getContents\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersionID\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"date\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"copyright\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"versionID\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"author\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"author\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"date\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"copyright\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionID\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"contents\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + + + relativePath + + "\",\"vertexType\":\"package_private\"},\"neighbours\":[{\"name\":\"src.model.strategies\",\"path\":\"\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\strategies\",\"vertexType\":\"package\",\"parentName\":\"src.model\"}],\"arcs\":[{\"source\":\"src.model\",\"target\":\"src.view\",\"arcType\":\"dependency\"},{\"source\":\"src.model\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]},{\"name\":\"src.model.strategies\",\"path\":\"" + + + relativePath + + "\\\\model\\\\strategies\",\"vertexType\":\"package\",\"coordinate_x\":362.0,\"coordinate_y\":280.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"VersionsStrategy\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\VersionsStrategy.java\\\",\\\"vertexType\\\":\\\"interface\\\",\\\"methods\\\":[{\\\"name\\\":\\\"removeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setEntireHistory\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documents\\\\\\\":\\\\\\\"List[Document]\\\\\\\"}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getEntireHistory\\\",\\\"returnType\\\":\\\"List[Document]\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[],\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"VolatileVersionsStrategy\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\VolatileVersionsStrategy.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"VolatileVersionsStrategy\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setEntireHistory\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documents\\\\\\\":\\\\\\\"List[Document]\\\\\\\"}\\\"},{\\\"name\\\":\\\"removeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getEntireHistory\\\",\\\"returnType\\\":\\\"List[Document]\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"history\\\",\\\"returnType\\\":\\\"ArrayList[Document]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"VolatileVersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VolatileVersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"aggregation\\\"},{\\\"source\\\":\\\"VolatileVersionsStrategy\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\",\"{\\\"name\\\":\\\"VersionsStrategyFactory\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\VersionsStrategyFactory.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"VersionsStrategyFactory\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"createStrategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"strategies\\\",\\\"returnType\\\":\\\"HashMap[String,VersionsStrategy]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"aggregation\\\"},{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"VolatileVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"VersionsStrategyFactory\\\",\\\"target\\\":\\\"StableVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"StableVersionsStrategy\\\",\\\"path\\\":\\\"" + + + relativePath + + "\\\\\\\\model\\\\\\\\strategies\\\\\\\\StableVersionsStrategy.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"methods\\\":[{\\\"name\\\":\\\"removeVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setEntireHistory\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"documents\\\\\\\":\\\\\\\"List[Document]\\\\\\\"}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getEntireHistory\\\",\\\"returnType\\\":\\\"List[Document]\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"versionID\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"StableVersionsStrategy\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"StableVersionsStrategy\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"implementation\\\"}]}\"],\"parent\":{\"name\":\"src.model\",\"path\":\"" + + + relativePath + + "\\\\\\\\model\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.model.strategies\",\"target\":\"src.model\",\"arcType\":\"dependency\"}]}]"; - private List getPackages() { - if (os.equals("Linux")){ - return List.of("src.view", "src.model"); - } else { - return - List.of( - "src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller" - ); - } - } + expectedString2 = "[{\"name\":\"src.model\",\"path\":\"" + + relativePath + "model\",\"vertexType\":\"package\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"VersionsManager\\\",\\\"path\\\":\\\"" + + relativePath + "/model/VersionsManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + + "\\\"methods\\\":[{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"enable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"rollbackToPreviousVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"disable\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"putVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"enableStrategy\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"changeStrategy\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setStrategy\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"setCurrentVersion\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"document\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"getStrategy\\\"," + + "\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + + "{\\\"name\\\":\\\"rollback\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + + "{\\\"name\\\":\\\"isEnabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + + "{\\\"name\\\":\\\"VersionsManager\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\",\\\\\\\"versionsStrategy\\\\\\\":\\\\\\\"VersionsStrategy\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"setPreviousVersion\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}" + + ",{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + + "{\\\"name\\\":\\\"saveContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}]," + + "\\\"fields\\\":[{\\\"name\\\":\\\"enabled\\\",\\\"returnType\\\":\\\"boolean\\\",\\\"modifier\\\":\\\"private\\\"}," + + "{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"VersionsStrategy\\\",\\\"modifier\\\":\\\"private\\\"}," + + "{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}]," + + "\\\"arcs\\\":[{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"}," + + "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"}," + + "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"}," + + "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"association\\\"}," + + "{\\\"source\\\":\\\"VersionsManager\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"," + + "\"{\\\"name\\\":\\\"DocumentManager\\\",\\\"path\\\":\\\"" + + relativePath + "/model/DocumentManager.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + + "\\\"methods\\\":[{\\\"name\\\":\\\"createDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getContents\\\",\\\"returnType\\\":\\\"String\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"DocumentManager\\\"," + + "\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"templates\\\"," + + "\\\"returnType\\\":\\\"HashMap[String,Document]\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"DocumentManager\\\"," + + "\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"DocumentManager\\\",\\\"target\\\":\\\"Document\\\"," + + "\\\"arcType\\\":\\\"aggregation\\\"}]}\",\"{\\\"name\\\":\\\"Document\\\",\\\"path\\\":\\\"" + + relativePath + "/model/Document.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + + "\\\"methods\\\":[{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"Document\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"date\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"copyright\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"versionID\\\\\\\":\\\\\\\"String\\\\\\\"," + + "\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"author\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"clone\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"save\\\",\\\"returnType\\\":\\\"void\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"setContents\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"contents\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"changeVersion\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getVersionID\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getContents\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"author\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"date\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}," + + "{\\\"name\\\":\\\"copyright\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionID\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"contents\\\",\\\"returnType\\\":\\\"String\\\"," + + "\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + + relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[{\"name\":\"src.model.strategies\",\"path\":\"" + + relativePath + "/model/strategies\",\"vertexType\":\"package\",\"parentName\":\"src.model\"}],\"arcs\":[{\"source\":\"src.model\"," + + "\"target\":\"src.view\",\"arcType\":\"dependency\"},{\"source\":\"src.model\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]},{\"name\":\"src.view\",\"path\":\"" + + relativePath + "/view\",\"vertexType\":\"package\",\"coordinate_x\":0.0,\"coordinate_y\":0.0,\"sinkVertices\":[\"{\\\"name\\\":\\\"LatexEditorView\\\",\\\"path\\\":\\\"" + + relativePath + "/view/LatexEditorView.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0,\\\"methods\\\":[{\\\"name\\\":\\\"getText\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setType\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getVersionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getCurrentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"saveContents\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setCurrentDocument\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"currentDocument\\\\\\\":\\\\\\\"Document\\\\\\\"}\\\"},{\\\"name\\\":\\\"setText\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"text\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"saveToFile\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setFilename\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"filename\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"loadFromFile\\\",\\\"returnType\\\":\\\"void\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setStrategy\\\",\\\"returnType\\\":\\\"void\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"strategy\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"getStrategy\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getFilename\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"setVersionsManager\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"versionsManager\\\\\\\":\\\\\\\"VersionsManager\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"setController\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"controller\\\\\\\":\\\\\\\"LatexEditorController\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"getType\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"getController\\\",\\\"returnType\\\":\\\"LatexEditorController\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"controller\\\",\\\"returnType\\\":\\\"LatexEditorController\\\"," + + "\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"currentDocument\\\",\\\"returnType\\\":\\\"Document\\\",\\\"modifier\\\":\\\"private\\\"}," + + "{\\\"name\\\":\\\"type\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"text\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}," + + "{\\\"name\\\":\\\"filename\\\",\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"strategy\\\",\\\"returnType\\\":\\\"String\\\"," + + "\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"versionsManager\\\",\\\"returnType\\\":\\\"VersionsManager\\\"," + + "\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\"," + + "\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"association\\\"}," + + "{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"Document\\\"," + + "\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"LatexEditorView\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"LatexEditorView\\\"," + + "\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"association\\\"}]}\",\"{\\\"name\\\":\\\"MainWindow\\\",\\\"path\\\":\\\"" + + relativePath + "/view/MainWindow.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0," + + "\\\"methods\\\":[{\\\"name\\\":\\\"MainWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"editContents\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"String\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\"," + + "\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"editorPane\\\",\\\"returnType\\\":\\\"JEditorPane\\\",\\\"modifier\\\":\\\"private\\\"}," + + "{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\"," + + "\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"MainWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\"," + + "\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"path\\\":\\\"" + + relativePath + "/view/ChooseTemplate.java\\\",\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0,\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"initialize\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"ChooseTemplate\\\",\\\"returnType\\\":\\\"Constructor\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"previous\\\\\\\":\\\\\\\"String\\\\\\\",\\\\\\\"latexEditorView\\\\\\\":\\\\\\\"LatexEditorView\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"arg0\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"},{\\\"name\\\":\\\"diselectRadioButtons\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{\\\\\\\"radioButton3\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton4\\\\\\\":\\\\\\\"JRadioButton\\\\\\\"," + + "\\\\\\\"radioButton1\\\\\\\":\\\\\\\"JRadioButton\\\\\\\",\\\\\\\"radioButton2\\\\\\\":\\\\\\\"JRadioButton\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\"," + + "\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\"," + + "\\\"returnType\\\":\\\"JFrame\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\"," + + "\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"previous\\\"," + + "\\\"returnType\\\":\\\"String\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"ChooseTemplate\\\"," + + "\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"LatexEditorView\\\"," + + "\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"MainWindow\\\",\\\"arcType\\\":\\\"dependency\\\"}," + + "{\\\"source\\\":\\\"ChooseTemplate\\\",\\\"target\\\":\\\"OpeningWindow\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\",\"{\\\"name\\\":\\\"OpeningWindow\\\"," + + "\\\"path\\\":\\\"/home/dimitrios/IdeaProjects/GitHub/ObjectOrientedArchitectureDiagrammer/src/test/resources/LatexEditor/src/view/OpeningWindow.java\\\"," + + "\\\"vertexType\\\":\\\"class\\\",\\\"coordinate_x\\\":0.0,\\\"coordinate_y\\\":0.0,\\\"methods\\\":[{\\\"name\\\":\\\"actionPerformed\\\"," + + "\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"OpeningWindow\\\",\\\"returnType\\\":\\\"Constructor\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"}," + + "{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}," + + "{\\\"name\\\":\\\"initialize\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"private\\\",\\\"parameters\\\":\\\"{}\\\"}," + + "{\\\"name\\\":\\\"run\\\",\\\"returnType\\\":\\\"void\\\",\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{}\\\"},{\\\"name\\\":\\\"main\\\",\\\"returnType\\\":\\\"void\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"args\\\\\\\":\\\\\\\"String[]\\\\\\\"}\\\"},{\\\"name\\\":\\\"actionPerformed\\\",\\\"returnType\\\":\\\"void\\\"," + + "\\\"modifier\\\":\\\"public\\\",\\\"parameters\\\":\\\"{\\\\\\\"e\\\\\\\":\\\\\\\"ActionEvent\\\\\\\"}\\\"}],\\\"fields\\\":[{\\\"name\\\":\\\"frame\\\",\\\"returnType\\\":\\\"JFrame\\\"," + + "\\\"modifier\\\":\\\"private\\\"},{\\\"name\\\":\\\"latexEditorView\\\",\\\"returnType\\\":\\\"LatexEditorView\\\",\\\"modifier\\\":\\\"private\\\"}],\\\"arcs\\\":[{\\\"source\\\":\\\"OpeningWindow\\\"," + + "\\\"target\\\":\\\"LatexEditorView\\\",\\\"arcType\\\":\\\"association\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"ChooseTemplate\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\"," + + "\\\"target\\\":\\\"VersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"VolatileVersionsStrategy\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\"," + + "\\\"target\\\":\\\"VersionsManager\\\",\\\"arcType\\\":\\\"dependency\\\"},{\\\"source\\\":\\\"OpeningWindow\\\",\\\"target\\\":\\\"LatexEditorController\\\",\\\"arcType\\\":\\\"dependency\\\"}]}\"],\"parent\":{\"name\":\"src\",\"path\":\"" + + relativePath + "\",\"vertexType\":\"package_private\"},\"neighbours\":[],\"arcs\":[{\"source\":\"src.view\"," + + "\"target\":\"src.model\",\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.controller\"," + + "\"arcType\":\"dependency\"},{\"source\":\"src.view\",\"target\":\"src.model.strategies\",\"arcType\":\"dependency\"}]}]"; + } - public static class CompareArray { - public static Set setOfElements(JsonArray arr) { - Set set = new HashSet<>(); - for (JsonElement j : arr) { - set.add(j); - } - return set; - } - public static Set setOfElements2(JsonArray arr) { - Set set = new HashSet<>(); - for (JsonElement j : arr) { - String path = j.getAsJsonObject().get("path").toString(); - if (!os.equals("Linux") && !path.isEmpty()) { - j.getAsJsonObject().addProperty("path", path.substring(0, path.length()-1)); - } - set.add(j); - } - return set; - } - } + private JsonArray getJsonArray() + { + if (os.equals("Linux")) + { + return JsonParser.parseString(expectedString2).getAsJsonArray(); + } + else + { + return JsonParser.parseString(expectedJsonString).getAsJsonArray(); + } + } + + + private List getPackages() + { + if (os.equals("Linux")) + { + return List.of("src.view", "src.model"); + } + else + { + return + List.of( + "src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller" + ); + } + } + + + public static class CompareArray + { + public static Set setOfElements(JsonArray arr) + { + Set set = new HashSet<>(); + for (JsonElement j : arr) + { + set.add(j); + } + return set; + } + + + public static Set setOfElements2(JsonArray arr) + { + Set set = new HashSet<>(); + for (JsonElement j : arr) + { + String path = j.getAsJsonObject().get("path").toString(); + if (!os.equals("Linux") && !path.isEmpty()) + { + j.getAsJsonObject().addProperty("path", path.substring(0, path.length() - 1)); + } + set.add(j); + } + return set; + } + } } diff --git a/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java b/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java index 3bc6f4a..5c76779 100644 --- a/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java +++ b/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java @@ -25,66 +25,74 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class PlantUMLClassDiagramImageExporterTest { +public class PlantUMLClassDiagramImageExporterTest +{ - @Test - void exportDiagramTest() { - try { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - classDiagramManager.convertTreeToDiagram(List.of( - "StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", "VolatileVersionsStrategy", - "VersionsManager", "Document", "DocumentManager") - ); + @Test + void exportDiagramTest() + { + try + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + classDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); + classDiagramManager.convertTreeToDiagram(List.of( + "StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", "VolatileVersionsStrategy", + "VersionsManager", "Document", "DocumentManager") + ); - PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); - String sinkVertexBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); - PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(classDiagramManager.getClassDiagram()); - String sinkVertexArcBuffer = plantUMLEdge.convertSinkVertexArc().toString(); + PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); + String sinkVertexBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); + PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(classDiagramManager.getClassDiagram()); + String sinkVertexArcBuffer = plantUMLEdge.convertSinkVertexArc().toString(); - DiagramExporter plantUMLExporter = new PlantUMLClassDiagramImageExporter(classDiagramManager.getClassDiagram()); - plantUMLExporter.exportDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.png"))); + DiagramExporter plantUMLExporter = new PlantUMLClassDiagramImageExporter(classDiagramManager.getClassDiagram()); + plantUMLExporter.exportDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.png"))); - InputStream in = getExpectedInputStream(sinkVertexBuffer, sinkVertexArcBuffer); + InputStream in = getExpectedInputStream(sinkVertexBuffer, sinkVertexArcBuffer); - BufferedImage convImg = ImageIO.read(in); - ImageIO.write(convImg, "png", Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "actualExportedFile.png")).toFile()); + BufferedImage convImg = ImageIO.read(in); + ImageIO.write(convImg, "png", Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "actualExportedFile.png")).toFile()); - BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.png")).toString()); - BufferedImage actualImage = ImageComparisonUtil.readImageFromResources(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "actualExportedFile.png")).toString()); - ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages(); - assertEquals(ImageComparisonState.MATCH, imageComparisonResult.getImageComparisonState()); - } catch (IOException e) { - e.printStackTrace(); - } - } + BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.png")).toString()); + BufferedImage actualImage = ImageComparisonUtil.readImageFromResources(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "actualExportedFile.png")).toString()); + ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages(); + assertEquals(ImageComparisonState.MATCH, imageComparisonResult.getImageComparisonState()); + } + catch (IOException e) + { + e.printStackTrace(); + } + } - private static InputStream getExpectedInputStream(String sinkVertexBuffer, String sinkVertexArcBuffer) { - byte[] data; - String expected = - "@startuml\n" + - "skinparam class {\n" + - " BackgroundColor lightyellow\n" + - " BorderColor black\n" + - " ArrowColor black\n" + - "}\n" + - sinkVertexBuffer + - "\n\n" + - sinkVertexArcBuffer + - "\n" + - "@enduml"; - try (ByteArrayOutputStream png = new ByteArrayOutputStream()){ - SourceStringReader reader = new SourceStringReader(expected); - reader.outputImage(png).getDescription(); - data = png.toByteArray(); - } - catch (IOException e) { - throw new RuntimeException(e); - } + + private static InputStream getExpectedInputStream(String sinkVertexBuffer, String sinkVertexArcBuffer) + { + byte[] data; + String expected = + "@startuml\n" + + "skinparam class {\n" + + " BackgroundColor lightyellow\n" + + " BorderColor black\n" + + " ArrowColor black\n" + + "}\n" + + sinkVertexBuffer + + "\n\n" + + sinkVertexArcBuffer + + "\n" + + "@enduml"; + try (ByteArrayOutputStream png = new ByteArrayOutputStream()) + { + SourceStringReader reader = new SourceStringReader(expected); + reader.outputImage(png).getDescription(); + data = png.toByteArray(); + } + catch (IOException e) + { + throw new RuntimeException(e); + } assertNotNull(data); return new ByteArrayInputStream(data); - } + } } diff --git a/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java b/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java index 24aaaa4..be97693 100644 --- a/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java +++ b/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java @@ -18,59 +18,64 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class PlantUMLClassDiagramTextExporterTest { +public class PlantUMLClassDiagramTextExporterTest +{ - @Test - void exportDiagramTest() { - try { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", - "VersionsStrategy", - "VersionsStrategyFactory", - "VolatileVersionsStrategy", - "VersionsManager", - "Document", - "DocumentManager")); + @Test + void exportDiagramTest() + { + try + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", + "VersionsStrategy", + "VersionsStrategyFactory", + "VolatileVersionsStrategy", + "VersionsManager", + "Document", + "DocumentManager")); - PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); - String sinkVertexBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); - PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(classDiagramManager.getClassDiagram()); - String sinkVertexArcBuffer = plantUMLEdge.convertSinkVertexArc().toString(); - DiagramExporter graphMLExporter = new PlantUMLClassDiagramTextExporter(classDiagramManager.getClassDiagram()); - File exportedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt")))); - Stream lines = Files.lines(exportedFile.toPath()); - String actualFileContents = lines.collect(Collectors.joining("\n")); - lines.close(); + PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); + String sinkVertexBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); + PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(classDiagramManager.getClassDiagram()); + String sinkVertexArcBuffer = plantUMLEdge.convertSinkVertexArc().toString(); + DiagramExporter graphMLExporter = new PlantUMLClassDiagramTextExporter(classDiagramManager.getClassDiagram()); + File exportedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); + Stream lines = Files.lines(exportedFile.toPath()); + String actualFileContents = lines.collect(Collectors.joining("\n")); + lines.close(); - String expectedFileContents = "@startuml\n" + - "skinparam class {\n" + - " BackgroundColor lightyellow\n" + - " BorderColor black\n" + - " ArrowColor black\n" + - "}\n\n"; + String expectedFileContents = "@startuml\n" + + "skinparam class {\n" + + " BackgroundColor lightyellow\n" + + " BorderColor black\n" + + " ArrowColor black\n" + + "}\n\n"; - expectedFileContents += sinkVertexBuffer + - "\n\n" + - sinkVertexArcBuffer + - "\n @enduml"; - assertEquals(expectedFileContents, actualFileContents); - } catch (IOException e) { - e.printStackTrace(); - } - } + expectedFileContents += sinkVertexBuffer + + "\n\n" + + sinkVertexArcBuffer + + "\n @enduml"; + assertEquals(expectedFileContents, actualFileContents); + } + catch (IOException e) + { + e.printStackTrace(); + } + } } diff --git a/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java b/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java index b1def9c..7e422a2 100644 --- a/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java +++ b/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java @@ -15,51 +15,55 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class GraphMLPackageVertexArcTest { +public class GraphMLPackageVertexArcTest +{ - @Test - void convertVertexArcsToGraphMLTest() { - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - packageDiagramManager.convertTreeToDiagram(List.of("src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - GraphMLPackageVertexArc graphMLPackageVertexArc = new GraphMLPackageVertexArc(packageDiagramManager.getPackageDiagram()); - StringBuilder actual = graphMLPackageVertexArc.convertVertexArc(); + @Test + void convertVertexArcsToGraphMLTest() + { + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + packageDiagramManager.convertTreeToDiagram(List.of("src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + GraphMLPackageVertexArc graphMLPackageVertexArc = new GraphMLPackageVertexArc(packageDiagramManager.getPackageDiagram()); + StringBuilder actual = graphMLPackageVertexArc.convertVertexArc(); - StringBuilder expected = new StringBuilder(); - List> arcs = new ArrayList<>(); - for (Set> arcSet: packageDiagramManager.getPackageDiagram().getDiagram().values()) { - arcs.addAll(arcSet); - } - int edgeId = 0; + StringBuilder expected = new StringBuilder(); + List> arcs = new ArrayList<>(); + for (Set> arcSet : packageDiagramManager.getPackageDiagram().getDiagram().values()) + { + arcs.addAll(arcSet); + } + int edgeId = 0; - for (Arc e: arcs) { - expected.append(String.format(" \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " ", - edgeId, - packageDiagramManager.getPackageDiagram().getGraphNodes().get(e.sourceVertex()), - packageDiagramManager.getPackageDiagram().getGraphNodes().get(e.targetVertex()))); - edgeId++; - } - assertEquals(expected.toString(), actual.toString()); - } + for (Arc e : arcs) + { + expected.append(String.format(" \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " ", + edgeId, + packageDiagramManager.getPackageDiagram().getGraphNodes().get(e.sourceVertex()), + packageDiagramManager.getPackageDiagram().getGraphNodes().get(e.targetVertex()))); + edgeId++; + } + assertEquals(expected.toString(), actual.toString()); + } } diff --git a/src/test/java/model/graphml/GraphMLPackageVertexTest.java b/src/test/java/model/graphml/GraphMLPackageVertexTest.java index f9c5fc5..2a17abe 100644 --- a/src/test/java/model/graphml/GraphMLPackageVertexTest.java +++ b/src/test/java/model/graphml/GraphMLPackageVertexTest.java @@ -16,45 +16,50 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class GraphMLPackageVertexTest { +class GraphMLPackageVertexTest +{ - @Test - void convertVerticesToGraphMLTest() { - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - packageDiagramManager.convertTreeToDiagram(List.of("src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - packageDiagramManager.getPackageDiagram().setGraphMLDiagramGeometry(Map.ofEntries(Map.entry(0, new Pair<>(10.0, 10.0)), - Map.entry(1, new Pair<>(10.0, 10.0)), - Map.entry(2, new Pair<>(10.0, 10.0)), - Map.entry(3, new Pair<>(10.0, 10.0)), - Map.entry(4, new Pair<>(10.0, 10.0)), - Map.entry(5, new Pair<>(10.0, 10.0)))); - GraphMLPackageVertex graphMLPackageVertex = new GraphMLPackageVertex(packageDiagramManager.getPackageDiagram()); - StringBuilder actual = graphMLPackageVertex.convertVertex(); + @Test + void convertVerticesToGraphMLTest() + { + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); + packageDiagramManager.convertTreeToDiagram(List.of("src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + packageDiagramManager.getPackageDiagram().setGraphMLDiagramGeometry(Map.ofEntries(Map.entry(0, new Pair<>(10.0, 10.0)), + Map.entry(1, new Pair<>(10.0, 10.0)), + Map.entry(2, new Pair<>(10.0, 10.0)), + Map.entry(3, new Pair<>(10.0, 10.0)), + Map.entry(4, new Pair<>(10.0, 10.0)), + Map.entry(5, new Pair<>(10.0, 10.0)))); + GraphMLPackageVertex graphMLPackageVertex = new GraphMLPackageVertex(packageDiagramManager.getPackageDiagram()); + StringBuilder actual = graphMLPackageVertex.convertVertex(); - StringBuilder expected = new StringBuilder(); - for (PackageVertex packageNode : packageDiagramManager.getPackageDiagram().getGraphNodes().keySet()) { - expected.append(String.format(" \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " %s\n" + - " \n" + - " \n" + - " \n", - packageDiagramManager.getPackageDiagram().getGraphNodes().get(packageNode), - 10.0, - 10.0, - packageNode.getName())); - } - assertEquals(expected.toString(), actual.toString()); - } + StringBuilder expected = new StringBuilder(); + for (PackageVertex packageNode : packageDiagramManager.getPackageDiagram().getGraphNodes().keySet()) + { + expected.append(String.format(""" + + + + + + + + %s + + + + """, + packageDiagramManager.getPackageDiagram().getGraphNodes().get(packageNode), + 10.0, + 10.0, + packageNode.getName())); + } + assertEquals(expected.toString(), actual.toString()); + } } \ No newline at end of file diff --git a/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java b/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java index ff6cf45..379b092 100644 --- a/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java +++ b/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java @@ -16,67 +16,85 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class GraphMLSinkPackageVertexArcTest { +public class GraphMLSinkPackageVertexArcTest +{ - @Test - void convertSinkVertexArcsToGraphMLTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", - "ChangeVersionsStrategyCommand", - "Command", - "CommandFactory", - "CreateCommand", - "DisableVersionsManagementCommand", - "EditCommand", - "EnableVersionsManagementCommand", - "LoadCommand", - "RollbackToPreviousVersionCommand", - "SaveCommand")); + @Test + void convertSinkVertexArcsToGraphMLTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s".formatted(PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))))); + classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", + "ChangeVersionsStrategyCommand", + "Command", + "CommandFactory", + "CreateCommand", + "DisableVersionsManagementCommand", + "EditCommand", + "EnableVersionsManagementCommand", + "LoadCommand", + "RollbackToPreviousVersionCommand", + "SaveCommand")); - GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagramManager.getClassDiagram()); - StringBuilder actual = graphMLClassifierVertexArc.convertSinkVertexArc(); + GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagramManager.getClassDiagram()); + StringBuilder actual = graphMLClassifierVertexArc.convertSinkVertexArc(); - StringBuilder expected = new StringBuilder(); - List> arcs = new ArrayList<>(); - for (Set> arcSet: classDiagramManager.getClassDiagram().getDiagram().values()) { - arcs.addAll(arcSet); - } - int edgeId = 0; - for (Arc e: arcs) { - expected.append( - String.format("\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n", - edgeId, - classDiagramManager.getClassDiagram().getGraphNodes().get(e.sourceVertex()), - classDiagramManager.getClassDiagram().getGraphNodes().get(e.targetVertex()), - getEdgesDescription(e).get(0), - getEdgesDescription(e).get(1), - getEdgesDescription(e).get(2))); - edgeId++; - } - assertEquals(expected.toString(), actual.toString()); - } + StringBuilder expected = new StringBuilder(); + List> arcs = new ArrayList<>(); + for (Set> arcSet : classDiagramManager.getClassDiagram().getDiagram().values()) + { + arcs.addAll(arcSet); + } + int edgeId = 0; + for (Arc e : arcs) + { + expected.append( + String.format(""" + + + + + + + + + + + """, + edgeId, + classDiagramManager.getClassDiagram().getGraphNodes().get(e.sourceVertex()), + classDiagramManager.getClassDiagram().getGraphNodes().get(e.targetVertex()), + getEdgesDescription(e).get(0), + getEdgesDescription(e).get(1), + getEdgesDescription(e).get(2))); + edgeId++; + } + assertEquals(expected.toString(), actual.toString()); + } - private List getEdgesDescription(Arc relationship) { - return Arrays.asList(identifyEdgeType(relationship).get(0), - identifyEdgeType(relationship).get(1), identifyEdgeType(relationship).get(2)); - } - private List identifyEdgeType(Arc relationship){ - return switch (relationship.arcType()) { - case DEPENDENCY -> Arrays.asList("dashed", "none", "plain"); - case AGGREGATION -> Arrays.asList("line", "white_diamond", "none"); - case ASSOCIATION -> Arrays.asList("line", "none", "standard"); - case EXTENSION -> Arrays.asList("line", "none", "white_delta"); - default -> Arrays.asList("dashed", "none", "white_delta"); - }; - } + + private List getEdgesDescription(Arc relationship) + { + return Arrays.asList(identifyEdgeType(relationship).get(0), + identifyEdgeType(relationship).get(1), identifyEdgeType(relationship).get(2)); + } + + + private List identifyEdgeType(Arc relationship) + { + return switch (relationship.arcType()) + { + case DEPENDENCY -> Arrays.asList("dashed", "none", "plain"); + case AGGREGATION -> Arrays.asList("line", "white_diamond", "none"); + case ASSOCIATION -> Arrays.asList("line", "none", "standard"); + case EXTENSION -> Arrays.asList("line", "none", "white_delta"); + default -> Arrays.asList("dashed", "none", "white_delta"); + }; + } } diff --git a/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java b/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java index 8eb0c66..c9f7e80 100644 --- a/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java +++ b/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java @@ -15,101 +15,117 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class GraphMLSinkPackageVertexTest { +public class GraphMLSinkPackageVertexTest +{ - @Test - void convertSinkVerticesToGraphMLTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", - "ChangeVersionsStrategyCommand", - "Command", - "CommandFactory", - "CreateCommand", - "DisableVersionsManagementCommand", - "EditCommand", - "EnableVersionsManagementCommand", - "LoadCommand", - "RollbackToPreviousVersionCommand", - "SaveCommand")); - classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(Map.ofEntries(Map.entry(0, new Pair<>(10.0, 10.0)), - Map.entry(1, new Pair<>(10.0, 10.0)), - Map.entry(2, new Pair<>(10.0, 10.0)), - Map.entry(3, new Pair<>(10.0, 10.0)), - Map.entry(4, new Pair<>(10.0, 10.0)), - Map.entry(5, new Pair<>(10.0, 10.0)), - Map.entry(6, new Pair<>(10.0, 10.0)), - Map.entry(7, new Pair<>(10.0, 10.0)), - Map.entry(8, new Pair<>(10.0, 10.0)), - Map.entry(9, new Pair<>(10.0, 10.0)), - Map.entry(10, new Pair<>(10.0, 10.0)))); + @Test + void convertSinkVerticesToGraphMLTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", + "ChangeVersionsStrategyCommand", + "Command", + "CommandFactory", + "CreateCommand", + "DisableVersionsManagementCommand", + "EditCommand", + "EnableVersionsManagementCommand", + "LoadCommand", + "RollbackToPreviousVersionCommand", + "SaveCommand")); + classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(Map.ofEntries(Map.entry(0, new Pair<>(10.0, 10.0)), + Map.entry(1, new Pair<>(10.0, 10.0)), + Map.entry(2, new Pair<>(10.0, 10.0)), + Map.entry(3, new Pair<>(10.0, 10.0)), + Map.entry(4, new Pair<>(10.0, 10.0)), + Map.entry(5, new Pair<>(10.0, 10.0)), + Map.entry(6, new Pair<>(10.0, 10.0)), + Map.entry(7, new Pair<>(10.0, 10.0)), + Map.entry(8, new Pair<>(10.0, 10.0)), + Map.entry(9, new Pair<>(10.0, 10.0)), + Map.entry(10, new Pair<>(10.0, 10.0)))); - GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagramManager.getClassDiagram()); - StringBuilder actual = graphMLClassifierVertex.convertSinkVertex(); + GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagramManager.getClassDiagram()); + StringBuilder actual = graphMLClassifierVertex.convertSinkVertex(); - StringBuilder expected = new StringBuilder(); - for (ClassifierVertex leafNode: classDiagramManager.getClassDiagram().getGraphNodes().keySet()) { - expected.append(String.format(" \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " %s\n" + - " \n" + - " %s\n" + - " %s\n" + - " \n" + - " \n" + - " \n" + - " \n", - classDiagramManager.getClassDiagram().getGraphNodes().get(leafNode), - 10.0, - 10.0, - getNodesColor(leafNode), - leafNode.getName(), - getNodesFields(leafNode), - getNodesMethods(leafNode))); - } - assertEquals(expected.toString(), actual.toString()); - } + StringBuilder expected = new StringBuilder(); + for (ClassifierVertex leafNode : classDiagramManager.getClassDiagram().getGraphNodes().keySet()) + { + expected.append(String.format(""" + + + + + + + + + %s + + %s + %s + + + + + """, + classDiagramManager.getClassDiagram().getGraphNodes().get(leafNode), + 10.0, + 10.0, + getNodesColor(leafNode), + leafNode.getName(), + getNodesFields(leafNode), + getNodesMethods(leafNode))); + } + assertEquals(expected.toString(), actual.toString()); + } - private String getNodesFields(ClassifierVertex l) { - if (l.getFields().isEmpty()) { - return ""; - } - StringBuilder fields = new StringBuilder(); - for (ClassifierVertex.Field field: l.getFields()) { - fields.append(field.type()).append(" ").append(field.name()).append("\n"); - } - return fields.deleteCharAt(fields.length() - 1).toString(); - } - private String getNodesMethods(ClassifierVertex l) { - if ((l).getMethods().isEmpty()) { - return ""; - } - StringBuilder methods = new StringBuilder(); - for (ClassifierVertex.Method method: l.getMethods()) { - methods.append(method.returnType()).append(" ").append(method.name()).append("\n"); - } - return methods.deleteCharAt(methods.length() - 1).toString(); - } + private String getNodesFields(ClassifierVertex l) + { + if (l.getFields().isEmpty()) + { + return ""; + } + StringBuilder fields = new StringBuilder(); + for (ClassifierVertex.Field field : l.getFields()) + { + fields.append(field.type()).append(" ").append(field.name()).append("\n"); + } + return fields.deleteCharAt(fields.length() - 1).toString(); + } - private String getNodesColor(ClassifierVertex l) { - if (l.getVertexType().equals(VertexType.INTERFACE)) { - return "#3366FF"; - } - return "#FF9900"; - } + + private String getNodesMethods(ClassifierVertex l) + { + if ((l).getMethods().isEmpty()) + { + return ""; + } + StringBuilder methods = new StringBuilder(); + for (ClassifierVertex.Method method : l.getMethods()) + { + methods.append(method.returnType()).append(" ").append(method.name()).append("\n"); + } + return methods.deleteCharAt(methods.length() - 1).toString(); + } + + + private String getNodesColor(ClassifierVertex l) + { + if (l.getVertexType().equals(VertexType.INTERFACE)) + { + return "#3366FF"; + } + return "#FF9900"; + } } diff --git a/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java b/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java index 763afe4..5de8b5b 100644 --- a/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java +++ b/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java @@ -23,68 +23,81 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class JavaFXClassDiagramLoaderTest { +public class JavaFXClassDiagramLoaderTest +{ - @Test - void loadDiagramTest() { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - List chosenFiles = Arrays.asList("MainWindow", - "LatexEditorView", - "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - classDiagramManager.convertTreeToDiagram(chosenFiles); - Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); + @Test + void loadDiagramTest() + { + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + List chosenFiles = Arrays.asList("MainWindow", + "LatexEditorView", + "OpeningWindow"); - GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); - Map>> createdDiagram = graphClassDiagramConverter.convertGraphToClassDiagram(); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s".formatted(PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))))); + classDiagramManager.convertTreeToDiagram(chosenFiles); + Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); - DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); - File actualFile = javaFXExporter.exportDiagram(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.txt"))); + GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); + Map>> createdDiagram = graphClassDiagramConverter.convertGraphToClassDiagram(); - JavaFXClassDiagramLoader javaFXClassDiagramLoader = new JavaFXClassDiagramLoader(actualFile.toPath()); - Set loadedDiagram = javaFXClassDiagramLoader.loadDiagram(); - assertEquals(createdDiagram.size(), loadedDiagram.size()); - for (ClassifierVertex classifierVertex : createdDiagram.keySet()) { - Optional optionalSinkVertex = loadedDiagram - .stream() - .filter(sinkVertex1 -> - sinkVertex1.getName().equals(classifierVertex.getName()) && - sinkVertex1.getVertexType().equals(classifierVertex.getVertexType())) - .findFirst(); - assertTrue(optionalSinkVertex.isPresent()); + DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); + File actualFile = javaFXExporter.exportDiagram(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.txt"))); - List> arcs = optionalSinkVertex.get().getArcs(); - assertEquals(createdDiagram.get(classifierVertex).size(), arcs.size()); - for (Arc arc: createdDiagram.get(classifierVertex)) { - assertTrue(arcs - .stream() - .anyMatch(sinkVertexArc -> - sinkVertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - sinkVertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && - sinkVertexArc.arcType().equals(arc.arcType()))); - } + JavaFXClassDiagramLoader javaFXClassDiagramLoader = new JavaFXClassDiagramLoader(actualFile.toPath()); + Set loadedDiagram = javaFXClassDiagramLoader.loadDiagram(); + assertEquals(createdDiagram.size(), loadedDiagram.size()); + for (ClassifierVertex classifierVertex : createdDiagram.keySet()) + { + Optional optionalSinkVertex = loadedDiagram + .stream() + .filter(sinkVertex1 -> + sinkVertex1.getName().equals(classifierVertex.getName()) && + sinkVertex1.getVertexType().equals(classifierVertex.getVertexType())) + .findFirst(); + assertTrue(optionalSinkVertex.isPresent()); - List methods = optionalSinkVertex.get().getMethods(); - assertEquals(classifierVertex.getMethods().size(), methods.size()); - for (ClassifierVertex.Method method: classifierVertex.getMethods()) { - assertTrue(methods - .stream() - .anyMatch(method1 -> - method1.name().equals(method.name()) && - method1.returnType().equals(method.returnType()) && - method1.modifier().equals(method.modifier()))); - } + List> arcs = optionalSinkVertex.get().getArcs(); + assertEquals(createdDiagram.get(classifierVertex).size(), arcs.size()); + for (Arc arc : createdDiagram.get(classifierVertex)) + { + assertTrue(arcs + .stream() + .anyMatch(sinkVertexArc -> + sinkVertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + sinkVertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && + sinkVertexArc.arcType().equals(arc.arcType()))); + } - List fields = optionalSinkVertex.get().getFields(); - assertEquals(classifierVertex.getFields().size(), fields.size()); - for (ClassifierVertex.Field field: classifierVertex.getFields()) { - assertTrue(fields - .stream() - .anyMatch(field1 -> - field1.name().equals(field.name()) && - field1.type().equals(field.type()) && - field1.modifier().equals(field.modifier()))); - } - } - } + List methods = optionalSinkVertex.get().getMethods(); + assertEquals(classifierVertex.getMethods().size(), methods.size()); + for (ClassifierVertex.Method method : classifierVertex.getMethods()) + { + assertTrue(methods + .stream() + .anyMatch(method1 -> + method1.name().equals(method.name()) && + method1.returnType().equals(method.returnType()) && + method1.modifier().equals(method.modifier()))); + } + + List fields = optionalSinkVertex.get().getFields(); + assertEquals(classifierVertex.getFields().size(), fields.size()); + for (ClassifierVertex.Field field : classifierVertex.getFields()) + { + assertTrue(fields + .stream() + .anyMatch(field1 -> + field1.name().equals(field.name()) && + field1.type().equals(field.type()) && + field1.modifier().equals(field.modifier()))); + } + } + } } diff --git a/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java b/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java index 563547d..0800d10 100644 --- a/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java +++ b/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java @@ -22,83 +22,89 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class JavaFXPackageDiagramLoaderTest { +public class JavaFXPackageDiagramLoaderTest +{ - @Test - void loadDiagramTest() { - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - packageDiagramManager.convertTreeToDiagram(List.of("src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - Map>> createdDiagram = packageDiagramManager.getPackageDiagram().getDiagram(); + @Test + void loadDiagramTest() + { + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + packageDiagramManager.convertTreeToDiagram(List.of("src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + Map>> createdDiagram = packageDiagramManager.getPackageDiagram().getDiagram(); - DiagramExporter javaFXExporter = new JavaFXPackageDiagramExporter(packageDiagramManager.getPackageDiagram()); - File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt")))); + DiagramExporter javaFXExporter = new JavaFXPackageDiagramExporter(packageDiagramManager.getPackageDiagram()); + File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); - JavaFXPackageDiagramLoader javaFXLoader = new JavaFXPackageDiagramLoader(actualFile.toPath()); - Set loadedDiagram = javaFXLoader.loadDiagram(); - assertEquals(createdDiagram.size(), loadedDiagram.size()); - for (PackageVertex vertex: createdDiagram.keySet()) { - Optional optionalVertex = loadedDiagram - .stream() - .filter(vertex1 -> - vertex1.getName().equals(vertex.getName()) && - vertex1.getVertexType().equals(vertex.getVertexType())) - .findFirst(); - assertTrue(optionalVertex.isPresent()); + JavaFXPackageDiagramLoader javaFXLoader = new JavaFXPackageDiagramLoader(actualFile.toPath()); + Set loadedDiagram = javaFXLoader.loadDiagram(); + assertEquals(createdDiagram.size(), loadedDiagram.size()); + for (PackageVertex vertex : createdDiagram.keySet()) + { + Optional optionalVertex = loadedDiagram + .stream() + .filter(vertex1 -> + vertex1.getName().equals(vertex.getName()) && + vertex1.getVertexType().equals(vertex.getVertexType())) + .findFirst(); + assertTrue(optionalVertex.isPresent()); - List> arcs = optionalVertex.get().getArcs(); - assertEquals(createdDiagram.get(vertex).size(), arcs.size()); - for (Arc arc: createdDiagram.get(vertex)) { - arcs - .stream() - .filter(vertexArc -> - vertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - vertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && - vertexArc.arcType().equals(arc.arcType())) - .findFirst() - .orElseGet(Assertions::fail); - } + List> arcs = optionalVertex.get().getArcs(); + assertEquals(createdDiagram.get(vertex).size(), arcs.size()); + for (Arc arc : createdDiagram.get(vertex)) + { + arcs + .stream() + .filter(vertexArc -> + vertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + vertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && + vertexArc.arcType().equals(arc.arcType())) + .findFirst() + .orElseGet(Assertions::fail); + } - List sinkVertices = optionalVertex.get().getSinkVertices(); - assertEquals(vertex.getSinkVertices().size(), sinkVertices.size()); - for (ClassifierVertex classifierVertex : vertex.getSinkVertices()) { - sinkVertices - .stream() - .filter(sinkVertex1 -> - sinkVertex1.getName().equals(classifierVertex.getName()) && - sinkVertex1.getVertexType().equals(classifierVertex.getVertexType())) - .findFirst() - .orElseGet(Assertions::fail); - } + List sinkVertices = optionalVertex.get().getSinkVertices(); + assertEquals(vertex.getSinkVertices().size(), sinkVertices.size()); + for (ClassifierVertex classifierVertex : vertex.getSinkVertices()) + { + sinkVertices + .stream() + .filter(sinkVertex1 -> + sinkVertex1.getName().equals(classifierVertex.getName()) && + sinkVertex1.getVertexType().equals(classifierVertex.getVertexType())) + .findFirst() + .orElseGet(Assertions::fail); + } - List neighbours = optionalVertex.get().getNeighbourVertices(); - assertEquals(vertex.getNeighbourVertices().size(), neighbours.size()); - for (PackageVertex neighbour: vertex.getNeighbourVertices()) { - neighbours - .stream() - .filter(vertex1 -> - vertex1.getName().equals(neighbour.getName()) && - vertex1.getVertexType().equals(neighbour.getVertexType())) - .findFirst() - .orElseGet(Assertions::fail); - } - } - } + List neighbours = optionalVertex.get().getNeighbourVertices(); + assertEquals(vertex.getNeighbourVertices().size(), neighbours.size()); + for (PackageVertex neighbour : vertex.getNeighbourVertices()) + { + neighbours + .stream() + .filter(vertex1 -> + vertex1.getName().equals(neighbour.getName()) && + vertex1.getVertexType().equals(neighbour.getVertexType())) + .findFirst() + .orElseGet(Assertions::fail); + } + } + } } diff --git a/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java b/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java index 651cfd3..3cc2d96 100644 --- a/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java +++ b/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java @@ -13,34 +13,49 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class PlantUMLClassifierVertexArcTest { - - @Test - void convertSinkVertexArcTest() { - String expectedBuffer = "VersionsStrategy ..> Document\n" + - "DocumentManager o-- Document\n" + - "VersionsStrategyFactory ..> VolatileVersionsStrategy\n" + - "StableVersionsStrategy ..|> VersionsStrategy\n" + - "VersionsStrategyFactory o-- VersionsStrategy\n" + - "StableVersionsStrategy ..> Document\n" + - "VersionsManager --> VersionsStrategy\n" + - "VolatileVersionsStrategy o-- Document\n" + - "VersionsManager ..> Document\n" + - "VersionsStrategyFactory ..> StableVersionsStrategy\n" + - "VolatileVersionsStrategy ..|> VersionsStrategy\n"; - - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", "VolatileVersionsStrategy", - "VersionsManager", "Document", "DocumentManager")); - - PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(classDiagramManager.getClassDiagram()); - String actualBuffer = plantUMLEdge.convertSinkVertexArc().toString(); - - List expectedRelationships = Arrays.asList(expectedBuffer.split("\n")); - List actualRelationships = Arrays.asList(actualBuffer.split("\n")); - Collections.sort(expectedRelationships); - Collections.sort(actualRelationships); - assertEquals(expectedRelationships, actualRelationships); - } +public class PlantUMLClassifierVertexArcTest +{ + + @Test + void convertSinkVertexArcTest() + { + String expectedBuffer = """ + VersionsStrategy ..> Document + DocumentManager o-- Document + VersionsStrategyFactory ..> VolatileVersionsStrategy + StableVersionsStrategy ..|> VersionsStrategy + VersionsStrategyFactory o-- VersionsStrategy + StableVersionsStrategy ..> Document + VersionsManager --> VersionsStrategy + VolatileVersionsStrategy o-- Document + VersionsManager ..> Document + VersionsStrategyFactory ..> StableVersionsStrategy + VolatileVersionsStrategy ..|> VersionsStrategy + """; + + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s".formatted(PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))))); + classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", + "VersionsStrategy", + "VersionsStrategyFactory", + "VolatileVersionsStrategy", + "VersionsManager", + "Document", + "DocumentManager")); + + PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(classDiagramManager.getClassDiagram()); + String actualBuffer = plantUMLEdge.convertSinkVertexArc().toString(); + + List expectedRelationships = Arrays.asList(expectedBuffer.split("\n")); + List actualRelationships = Arrays.asList(actualBuffer.split("\n")); + Collections.sort(expectedRelationships); + Collections.sort(actualRelationships); + assertEquals(expectedRelationships, actualRelationships); + } } diff --git a/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java b/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java index c474dc0..6f8c4dd 100644 --- a/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java +++ b/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java @@ -15,118 +15,121 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class PlantUMLClassifierVertexTest { +public class PlantUMLClassifierVertexTest +{ - @Test - void convertSinkVertexTest() { + @Test + void convertSinkVertexTest() + { - ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", - "VersionsStrategy", - "VersionsStrategyFactory", - "VolatileVersionsStrategy", - "VersionsManager", - "Document", - "DocumentManager")); + ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", + "VersionsStrategy", + "VersionsStrategyFactory", + "VolatileVersionsStrategy", + "VersionsManager", + "Document", + "DocumentManager")); - PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); - String actualBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); + PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); + String actualBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); - List expected = Arrays.asList(EXPECTED_BUFFER.split("\n")); - List actual = Arrays.asList(actualBuffer.split("\n")); + List expected = Arrays.asList(EXPECTED_BUFFER.split("\n")); + List actual = Arrays.asList(actualBuffer.split("\n")); - Collections.sort(expected); - Collections.sort(actual); - assertEquals(expected, actual); - } + Collections.sort(expected); + Collections.sort(actual); + assertEquals(expected, actual); + } - public static final String EXPECTED_BUFFER = """ - class VersionsManager { - -enabled: boolean - -strategy: VersionsStrategy - -latexEditorView: LatexEditorView - +changeStrategy(): void - +setPreviousVersion(): Document - +VersionsManager(LatexEditorView latexEditorView, VersionsStrategy versionsStrategy): Constructor - +setStrategy(VersionsStrategy strategy): void - +saveContents(): void - +enable(): void - +getType(): String - +rollback(): void - +getStrategy(): VersionsStrategy - +isEnabled(): boolean - +disable(): void - +putVersion(Document document): void - +rollbackToPreviousVersion(): void - +enableStrategy(): void - +saveToFile(): void - +setCurrentVersion(Document document): void - +loadFromFile(): void - } - - class VolatileVersionsStrategy { - -history: ArrayList[Document] - +removeVersion(): void - +getVersion(): Document - +VolatileVersionsStrategy(): Constructor - +setEntireHistory(List[Document] documents): void - +putVersion(Document document): void - +getEntireHistory(): List[Document] - } - - interface VersionsStrategy { - +removeVersion(): void - +getVersion(): Document - +setEntireHistory(List[Document] documents): void - +getEntireHistory(): List[Document] - +putVersion(Document document): void - } - - class StableVersionsStrategy { - -versionID: String - +removeVersion(): void - +getVersion(): Document - +setEntireHistory(List[Document] documents): void - +getEntireHistory(): List[Document] - +putVersion(Document document): void - } - - class VersionsStrategyFactory { - -strategies: HashMap[String,VersionsStrategy] - +createStrategy(String type): VersionsStrategy - +VersionsStrategyFactory(): Constructor - } - - class Document { - -author: String - -date: String - -copyright: String - -versionID: String - -contents: String - +Document(String date, String copyright, String versionID, String contents, String author): Constructor - +clone(): Document - +getContents(): String - +Document(): Constructor - +save(String filename): void - +getVersionID(): String - +setContents(String contents): void - +changeVersion(): void - } - - class DocumentManager { - -templates: HashMap[String,Document] - +createDocument(String type): Document - +getContents(String type): String - +DocumentManager(): Constructor - } - - """; + + public static final String EXPECTED_BUFFER = """ + class VersionsManager { + -enabled: boolean + -strategy: VersionsStrategy + -latexEditorView: LatexEditorView + +changeStrategy(): void + +setPreviousVersion(): Document + +VersionsManager(LatexEditorView latexEditorView, VersionsStrategy versionsStrategy): Constructor + +setStrategy(VersionsStrategy strategy): void + +saveContents(): void + +enable(): void + +getType(): String + +rollback(): void + +getStrategy(): VersionsStrategy + +isEnabled(): boolean + +disable(): void + +putVersion(Document document): void + +rollbackToPreviousVersion(): void + +enableStrategy(): void + +saveToFile(): void + +setCurrentVersion(Document document): void + +loadFromFile(): void + } + + class VolatileVersionsStrategy { + -history: ArrayList[Document] + +removeVersion(): void + +getVersion(): Document + +VolatileVersionsStrategy(): Constructor + +setEntireHistory(List[Document] documents): void + +putVersion(Document document): void + +getEntireHistory(): List[Document] + } + + interface VersionsStrategy { + +removeVersion(): void + +getVersion(): Document + +setEntireHistory(List[Document] documents): void + +getEntireHistory(): List[Document] + +putVersion(Document document): void + } + + class StableVersionsStrategy { + -versionID: String + +removeVersion(): void + +getVersion(): Document + +setEntireHistory(List[Document] documents): void + +getEntireHistory(): List[Document] + +putVersion(Document document): void + } + + class VersionsStrategyFactory { + -strategies: HashMap[String,VersionsStrategy] + +createStrategy(String type): VersionsStrategy + +VersionsStrategyFactory(): Constructor + } + + class Document { + -author: String + -date: String + -copyright: String + -versionID: String + -contents: String + +Document(String date, String copyright, String versionID, String contents, String author): Constructor + +clone(): Document + +getContents(): String + +Document(): Constructor + +save(String filename): void + +getVersionID(): String + +setContents(String contents): void + +changeVersion(): void + } + + class DocumentManager { + -templates: HashMap[String,Document] + +createDocument(String type): Document + +getContents(String type): String + +DocumentManager(): Constructor + } + + """; } diff --git a/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java b/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java index 2ba7ccf..47762af 100644 --- a/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java +++ b/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java @@ -6,8 +6,6 @@ import utils.PathConstructor; import java.io.File; -import java.io.IOException; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -15,52 +13,57 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -class PlantUMLPackageVertexArcTest { +class PlantUMLPackageVertexArcTest +{ - private static final String EXPECTED_BUFFER = """ - src.model ..> src.view - src.controller.commands ..> src.model - src.model ..> src.model.strategies - src.view ..> src.model - src.model.strategies ..> src.model - src.controller ..> src.model - src.view ..> src.controller - src.controller ..> src.controller.commands - src.view ..> src.model.strategies - """; + private static final String EXPECTED_BUFFER = """ + src.model ..> src.view + src.controller.commands ..> src.model + src.model ..> src.model.strategies + src.view ..> src.model + src.model.strategies ..> src.model + src.controller ..> src.model + src.view ..> src.controller + src.controller ..> src.controller.commands + src.view ..> src.model.strategies + """; - @Test - void convertVertexArcTest() { - // - // Given - // - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - // - // When - // - packageDiagramManager.convertTreeToDiagram(List.of("src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(packageDiagramManager.getPackageDiagram()); - String actualBuffer = plantUMLEdge.convertVertexArc().toString(); - // - // Then - // - List expectedRelationship = Arrays.asList(EXPECTED_BUFFER.split("\n")); - List actualRelationship = Arrays.asList(actualBuffer.split("\n")); - Collections.sort(expectedRelationship); - Collections.sort(actualRelationship); - assertEquals(expectedRelationship, actualRelationship); - } + + @Test + void convertVertexArcTest() + { + // + // Given + // + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + + // + // When + // + packageDiagramManager.convertTreeToDiagram(List.of("src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(packageDiagramManager.getPackageDiagram()); + String actualBuffer = plantUMLEdge.convertVertexArc().toString(); + + // + // Then + // + List expectedRelationship = Arrays.asList(EXPECTED_BUFFER.split("\n")); + List actualRelationship = Arrays.asList(actualBuffer.split("\n")); + Collections.sort(expectedRelationship); + Collections.sort(actualRelationship); + assertEquals(expectedRelationship, actualRelationship); + } } diff --git a/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java b/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java index 1e03500..412d4bc 100644 --- a/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java +++ b/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java @@ -6,8 +6,6 @@ import utils.PathConstructor; import java.io.File; -import java.io.IOException; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -15,49 +13,52 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class PlantUMLPackageVertexTest { - - @Test - void convertVertexTest() { - - PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - packageDiagramManager.convertTreeToDiagram(List.of("src", - "src.view", - "src.model", - "src.model.strategies", - "src.controller.commands", - "src.controller")); - - PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(packageDiagramManager.getPackageDiagram()); - String actualBuffer = plantUMLPackageVertex.convertVertex().toString(); - - List expected = Arrays.asList(EXPECTED_BUFFER.split("\n")); - List actual = Arrays.asList(actualBuffer.split("\n")); - - Collections.sort(expected); - Collections.sort(actual); - assertEquals(expected, actual); - } - - public static final String EXPECTED_BUFFER = """ - package src.controller { - } - - package src.controller.commands { - } - - package src.model { - } - - package src { - } - - package src.view { - } - - package src.model.strategies { - } - - """; +public class PlantUMLPackageVertexTest +{ + + @Test + void convertVertexTest() + { + + PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); + packageDiagramManager.convertTreeToDiagram(List.of("src", + "src.view", + "src.model", + "src.model.strategies", + "src.controller.commands", + "src.controller")); + + PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(packageDiagramManager.getPackageDiagram()); + String actualBuffer = plantUMLPackageVertex.convertVertex().toString(); + + List expected = Arrays.asList(EXPECTED_BUFFER.split("\n")); + List actual = Arrays.asList(actualBuffer.split("\n")); + + Collections.sort(expected); + Collections.sort(actual); + assertEquals(expected, actual); + } + + + public static final String EXPECTED_BUFFER = """ + package src.controller { + } + + package src.controller.commands { + } + + package src.model { + } + + package src { + } + + package src.view { + } + + package src.model.strategies { + } + + """; } diff --git a/src/test/java/parser/FileVisitorTest.java b/src/test/java/parser/FileVisitorTest.java index c564f34..b9a7ddf 100644 --- a/src/test/java/parser/FileVisitorTest.java +++ b/src/test/java/parser/FileVisitorTest.java @@ -7,7 +7,6 @@ import parser.tree.LeafNode; import parser.tree.NodeType; import parser.tree.PackageNode; -import parser.tree.Relationship; import utils.PathConstructor; import java.io.File; @@ -18,260 +17,277 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class FileVisitorTest { - - ParserType parserType = ParserType.JAVAPARSER; - - @Test - void methodReturnTypesTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath().toString(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); - - LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); - List methodReturnTypesExpected = new ArrayList<>(Arrays.asList("Constructor", - "void")); - List methodReturnTypesActual = addLatexCommand.getMethodReturnTypes(); - - Collections.sort(methodReturnTypesActual); - Collections.sort(methodReturnTypesExpected); - assertTrue(methodReturnTypesActual.size() == methodReturnTypesExpected.size() && - methodReturnTypesExpected.containsAll(methodReturnTypesActual) && - methodReturnTypesActual.containsAll(methodReturnTypesExpected)); - } - - @Test - void methodParameterTypesTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); - - LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); - List methodParameterTypes = new ArrayList<>(List.of("VersionsManager")); - List methodParameterTypesTest = addLatexCommand.getMethodParameterTypes(); - - Collections.sort(methodParameterTypesTest); - Collections.sort(methodParameterTypes); - assertTrue(methodParameterTypesTest.size() == methodParameterTypes.size() && - methodParameterTypes.containsAll(methodParameterTypesTest) && - methodParameterTypesTest.containsAll(methodParameterTypes)); - } - - @Test - void fieldTypesTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages= parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); - LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); - List fieldTypes = new ArrayList<>(List.of("VersionsManager")); - List fieldTypesTest = addLatexCommand - .fields() - .stream() - .map(LeafNode.Field::fieldType) - .sorted() - .collect(Collectors.toCollection(ArrayList::new)); +public class FileVisitorTest +{ + + ParserType parserType = ParserType.JAVAPARSER; + + + @Test + void methodReturnTypesTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath().toString(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))); + + LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); + List methodReturnTypesExpected = new ArrayList<>(Arrays.asList("Constructor", + "void")); + List methodReturnTypesActual = addLatexCommand.getMethodReturnTypes(); + + Collections.sort(methodReturnTypesActual); + Collections.sort(methodReturnTypesExpected); + assertTrue(methodReturnTypesActual.size() == methodReturnTypesExpected.size() && + methodReturnTypesExpected.containsAll(methodReturnTypesActual) && + methodReturnTypesActual.containsAll(methodReturnTypesExpected)); + } + + + @Test + void methodParameterTypesTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))); + + LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); + List methodParameterTypes = new ArrayList<>(List.of("VersionsManager")); + List methodParameterTypesTest = addLatexCommand.getMethodParameterTypes(); + + Collections.sort(methodParameterTypesTest); + Collections.sort(methodParameterTypes); + assertTrue(methodParameterTypesTest.size() == methodParameterTypes.size() && + methodParameterTypes.containsAll(methodParameterTypesTest) && + methodParameterTypesTest.containsAll(methodParameterTypes)); + } + + + @Test + void fieldTypesTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))); + LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); + List fieldTypes = new ArrayList<>(List.of("VersionsManager")); + List fieldTypesTest = addLatexCommand + .fields() + .stream() + .map(LeafNode.Field::fieldType) + .sorted() + .collect(Collectors.toCollection(ArrayList::new)); Collections.sort(fieldTypes); - assertTrue(fieldTypesTest.size() == fieldTypes.size() && - fieldTypes.containsAll(fieldTypesTest) && - fieldTypesTest.containsAll(fieldTypes)); - } - - @Test - void variableTypesTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - "/src/test/resources/LatexEditor/src/controller")); - - LeafNode latexEditorController = commandPackage.getLeafNodes().get("LatexEditorController"); - List variablesTypes = new ArrayList<>(List.of("CommandFactory")); - List variablesTypesTest = new ArrayList<>(latexEditorController.variables().values()); - - Collections.sort(variablesTypesTest); - Collections.sort(variablesTypes); - assertTrue(variablesTypesTest.size() == variablesTypes.size() && - variablesTypes.containsAll(variablesTypesTest) && - variablesTypesTest.containsAll(variablesTypes)); - } - - @Test - void objectCreationTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting")))); - PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); - - LeafNode objectCreationSample = sourcePackage.getLeafNodes().get("ObjectCreationSample"); - List objectsCreatedExpected = new ArrayList<>(List.of("ImplementingClass", - "ImplementingClass", - "ExtensionClass", - "HashMap[String,TestingInterface]")); - List objectsCreatedActual = objectCreationSample.createdObjects(); - - Collections.sort(objectsCreatedActual); - Collections.sort(objectsCreatedExpected); - assertTrue(objectsCreatedActual.size() == objectsCreatedExpected.size() && - objectsCreatedExpected.containsAll(objectsCreatedActual) && - objectsCreatedActual.containsAll(objectsCreatedExpected)); - } - - @Test - void leafNodeTypesTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting")))); - PackageNode inheritancePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); - List classLeafs = new ArrayList<>(); - List interfaceLeafs = new ArrayList<>(); - classLeafs.add(inheritancePackage.getLeafNodes().get("ImplementingClass")); - classLeafs.add(inheritancePackage.getLeafNodes().get("ExtensionClass")); - interfaceLeafs.add(inheritancePackage.getLeafNodes().get("TestingInterface")); - interfaceLeafs.add(inheritancePackage.getLeafNodes().get("TestingInterface2")); - - for (LeafNode l : classLeafs) { - assertEquals(NodeType.CLASS, l.nodeType()); - } - for (LeafNode l : interfaceLeafs) { - assertEquals(NodeType.INTERFACE, l.nodeType()); - } - - PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); - - LeafNode enumTest = sourcePackage.getLeafNodes().get("EnumSample"); - assertEquals(NodeType.ENUM, enumTest.nodeType()); - - LeafNode objectCreationTest = sourcePackage.getLeafNodes().get("ObjectCreationSample"); - assertEquals(NodeType.CLASS, objectCreationTest.nodeType()); - } - - @Test - void innerMembersTest() { - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting")))); - PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); - LeafNode innerClassSample = sourcePackage.getLeafNodes().get("InnerClassSample"); - assertEquals(innerClassSample.innerClasses().get(0).nodeName(), "InnerClass"); - assertEquals(innerClassSample.records().get(0), "RecordSample"); - } - - @Test - void importsTest() { - List expectedImports = List.of("javax.swing.JOptionPane", - "model.strategies.StableVersionsStrategy", - "model.strategies.VersionsStrategy", - "model.strategies.VolatileVersionsStrategy", - "view.LatexEditorView"); - - Parser parser = ProjectParserFactory.createProjectParser(parserType); - - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - "/src/test/resources/LatexEditor/src/model")); - LeafNode versionsManager = commandPackage.getLeafNodes().get("VersionsManager"); - List imports = versionsManager.imports(); - assertEquals(expectedImports, imports); - } + assertTrue(fieldTypesTest.size() == fieldTypes.size() && + fieldTypes.containsAll(fieldTypesTest) && + fieldTypesTest.containsAll(fieldTypes)); + } + + + @Test + void variableTypesTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + "/src/test/resources/LatexEditor/src/controller")); + + LeafNode latexEditorController = commandPackage.getLeafNodes().get("LatexEditorController"); + List variablesTypes = new ArrayList<>(List.of("CommandFactory")); + List variablesTypesTest = new ArrayList<>(latexEditorController.variables().values()); + + Collections.sort(variablesTypesTest); + Collections.sort(variablesTypes); + assertTrue(variablesTypesTest.size() == variablesTypes.size() && + variablesTypes.containsAll(variablesTypesTest) && + variablesTypesTest.containsAll(variablesTypes)); + } + + + @Test + void objectCreationTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting")))); + PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting"))); + + LeafNode objectCreationSample = sourcePackage.getLeafNodes().get("ObjectCreationSample"); + List objectsCreatedExpected = new ArrayList<>(List.of("ImplementingClass", + "ImplementingClass", + "ExtensionClass", + "HashMap[String,TestingInterface]")); + List objectsCreatedActual = objectCreationSample.createdObjects(); + + Collections.sort(objectsCreatedActual); + Collections.sort(objectsCreatedExpected); + assertTrue(objectsCreatedActual.size() == objectsCreatedExpected.size() && + objectsCreatedExpected.containsAll(objectsCreatedActual) && + objectsCreatedActual.containsAll(objectsCreatedExpected)); + } + + + @Test + void leafNodeTypesTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting")))); + PackageNode inheritancePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting"))); + List classLeafs = new ArrayList<>(); + List interfaceLeafs = new ArrayList<>(); + classLeafs.add(inheritancePackage.getLeafNodes().get("ImplementingClass")); + classLeafs.add(inheritancePackage.getLeafNodes().get("ExtensionClass")); + interfaceLeafs.add(inheritancePackage.getLeafNodes().get("TestingInterface")); + interfaceLeafs.add(inheritancePackage.getLeafNodes().get("TestingInterface2")); + + for (LeafNode l : classLeafs) + { + assertEquals(NodeType.CLASS, l.nodeType()); + } + for (LeafNode l : interfaceLeafs) + { + assertEquals(NodeType.INTERFACE, l.nodeType()); + } + + PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting"))); + + LeafNode enumTest = sourcePackage.getLeafNodes().get("EnumSample"); + assertEquals(NodeType.ENUM, enumTest.nodeType()); + + LeafNode objectCreationTest = sourcePackage.getLeafNodes().get("ObjectCreationSample"); + assertEquals(NodeType.CLASS, objectCreationTest.nodeType()); + } + + + @Test + void innerMembersTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting")))); + PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting"))); + LeafNode innerClassSample = sourcePackage.getLeafNodes().get("InnerClassSample"); + assertEquals(innerClassSample.innerClasses().get(0).nodeName(), "InnerClass"); + assertEquals(innerClassSample.records().get(0), "RecordSample"); + } + + + @Test + void importsTest() + { + List expectedImports = List.of("javax.swing.JOptionPane", + "model.strategies.StableVersionsStrategy", + "model.strategies.VersionsStrategy", + "model.strategies.VolatileVersionsStrategy", + "view.LatexEditorView"); + + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + "/src/test/resources/LatexEditor/src/model")); + LeafNode versionsManager = commandPackage.getLeafNodes().get("VersionsManager"); + List imports = versionsManager.imports(); + assertEquals(expectedImports, imports); + } } diff --git a/src/test/java/parser/InterpreterTest.java b/src/test/java/parser/InterpreterTest.java index 9601042..acc9360 100644 --- a/src/test/java/parser/InterpreterTest.java +++ b/src/test/java/parser/InterpreterTest.java @@ -20,114 +20,125 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class InterpreterTest { - - @Test - public void convertTreeToGraphTest() { - Interpreter interpreter = new Interpreter(); - interpreter.parseProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - interpreter.convertTreeToGraph(); - Map packageNodes = interpreter.getPackageNodes(); - Map vertices = interpreter.getVertices(); - assertEquals(packageNodes.size(), vertices.size()); - - for (Map.Entry packageNodeEntry: packageNodes.entrySet()) { - assertTrue(vertices.containsKey(packageNodeEntry.getKey())); - - PackageNode packageNode = packageNodeEntry.getValue(); - PackageVertex vertex = vertices.get(packageNodeEntry.getKey()); - assertEquals(packageNode.getNodeType().toString(), vertex.getVertexType().toString()); - assertEquals(packageNode.getNodeName(), vertex.getName()); - - Map subNodes = packageNode.getSubNodes(); - List neighbours = vertex.getNeighbourVertices(); - assertEquals(subNodes.size(), neighbours.size()); - for (Map.Entry subNode: subNodes.entrySet()) { - assertTrue(neighbours - .stream() - .anyMatch(neighbour1 -> - neighbour1.getPath().toString().equals(subNode.getKey().toString()) && - neighbour1.getName().equals(subNode.getValue().getNodeName()) && - neighbour1.getVertexType().toString().equals(subNode.getValue().getNodeType().toString()))); - } - - Map>> packageNodeRelationships = interpreter.getPackageNodeRelationships(); - - if (!packageNodeRelationships.containsKey(packageNode)) { - continue; - } - - Set> relationships = packageNodeRelationships.get(packageNode); - List> arcs = vertex.getArcs(); - assertEquals(relationships.size(), arcs.size()); - for (Relationship relationship: relationships) { - assertTrue(arcs - .stream() - .anyMatch(a -> - a.arcType().toString().equals(relationship.relationshipType().toString()) && - a.sourceVertex().getPath().equals(relationship.startingNode().getPath()) && - a.targetVertex().getPath().equals(relationship.endingNode().getPath()))); - } - - Map leafNodes = packageNode.getLeafNodes(); - List sinkVertices = vertex.getSinkVertices(); - assertEquals(leafNodes.size(), sinkVertices.size()); - for (Map.Entry leafNodeEntry: leafNodes.entrySet()) { - ClassifierVertex classifierVertex = sinkVertices - .stream() - .filter(sinkVertex1 -> - sinkVertex1.getName().equals(leafNodeEntry.getKey())).findAny().orElseGet(Assertions::fail); - - List leafMethods = leafNodeEntry.getValue().methods(); - List vertexMethods = classifierVertex.getMethods(); - for (LeafNode.Method leafMethod: leafMethods) { - assertTrue(vertexMethods - .stream() - .anyMatch(m -> - m.name().equals(leafMethod.methodName()) && - m.parameters().size() == leafMethod.parameters().size() && - m.parameters().equals(leafMethod.parameters()) && - m.returnType().equals(leafMethod.returnType()) && - m.modifier().toString().equals(leafMethod.modifierType().toString()))); - } - - List leafFields = leafNodeEntry.getValue().fields(); - List vertexFields = classifierVertex.getFields(); - for (LeafNode.Field leafField: leafFields) { - assertTrue(vertexFields - .stream() - .anyMatch(f -> - f.name().equals(leafField.fieldNames()) && - f.type().equals(leafField.fieldType()) && - f.modifier().toString().equals(leafField.modifierType().toString()))); - } - - Map>> leafNodeRelationships = interpreter.getLeafNodeRelationships(); - - if (!leafNodeRelationships.containsKey(leafNodeEntry.getValue())) { - continue; - } - - Set> subNodeRelationships = leafNodeRelationships.get(leafNodeEntry.getValue()); - List> sinkVertexArcs = classifierVertex.getArcs(); - assertEquals(subNodeRelationships.size(), sinkVertexArcs.size()); - for (Relationship relationship: subNodeRelationships) { - assertTrue(sinkVertexArcs - .stream() - .anyMatch(a -> - a.arcType().toString().equals(relationship.relationshipType().toString()) && - a.sourceVertex().getPath().equals(relationship.startingNode().path()) && - a.targetVertex().getPath().equals(relationship.endingNode().path()))); - } - } - } - } +public class InterpreterTest +{ + + @Test + public void convertTreeToGraphTest() + { + Interpreter interpreter = new Interpreter(); + interpreter.parseProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + interpreter.convertTreeToGraph(); + Map packageNodes = interpreter.getPackageNodes(); + Map vertices = interpreter.getVertices(); + assertEquals(packageNodes.size(), vertices.size()); + + for (Map.Entry packageNodeEntry : packageNodes.entrySet()) + { + assertTrue(vertices.containsKey(packageNodeEntry.getKey())); + + PackageNode packageNode = packageNodeEntry.getValue(); + PackageVertex vertex = vertices.get(packageNodeEntry.getKey()); + assertEquals(packageNode.getNodeType().toString(), vertex.getVertexType().toString()); + assertEquals(packageNode.getNodeName(), vertex.getName()); + + Map subNodes = packageNode.getSubNodes(); + List neighbours = vertex.getNeighbourVertices(); + assertEquals(subNodes.size(), neighbours.size()); + for (Map.Entry subNode : subNodes.entrySet()) + { + assertTrue(neighbours + .stream() + .anyMatch(neighbour1 -> + neighbour1.getPath().toString().equals(subNode.getKey().toString()) && + neighbour1.getName().equals(subNode.getValue().getNodeName()) && + neighbour1.getVertexType().toString().equals(subNode.getValue().getNodeType().toString()))); + } + + Map>> packageNodeRelationships = interpreter.getPackageNodeRelationships(); + + if (!packageNodeRelationships.containsKey(packageNode)) + { + continue; + } + + Set> relationships = packageNodeRelationships.get(packageNode); + List> arcs = vertex.getArcs(); + assertEquals(relationships.size(), arcs.size()); + for (Relationship relationship : relationships) + { + assertTrue(arcs + .stream() + .anyMatch(a -> + a.arcType().toString().equals(relationship.relationshipType().toString()) && + a.sourceVertex().getPath().equals(relationship.startingNode().getPath()) && + a.targetVertex().getPath().equals(relationship.endingNode().getPath()))); + } + + Map leafNodes = packageNode.getLeafNodes(); + List sinkVertices = vertex.getSinkVertices(); + assertEquals(leafNodes.size(), sinkVertices.size()); + for (Map.Entry leafNodeEntry : leafNodes.entrySet()) + { + ClassifierVertex classifierVertex = sinkVertices + .stream() + .filter(sinkVertex1 -> + sinkVertex1.getName().equals(leafNodeEntry.getKey())).findAny().orElseGet(Assertions::fail); + + List leafMethods = leafNodeEntry.getValue().methods(); + List vertexMethods = classifierVertex.getMethods(); + for (LeafNode.Method leafMethod : leafMethods) + { + assertTrue(vertexMethods + .stream() + .anyMatch(m -> + m.name().equals(leafMethod.methodName()) && + m.parameters().size() == leafMethod.parameters().size() && + m.parameters().equals(leafMethod.parameters()) && + m.returnType().equals(leafMethod.returnType()) && + m.modifier().toString().equals(leafMethod.modifierType().toString()))); + } + + List leafFields = leafNodeEntry.getValue().fields(); + List vertexFields = classifierVertex.getFields(); + for (LeafNode.Field leafField : leafFields) + { + assertTrue(vertexFields + .stream() + .anyMatch(f -> + f.name().equals(leafField.fieldNames()) && + f.type().equals(leafField.fieldType()) && + f.modifier().toString().equals(leafField.modifierType().toString()))); + } + + Map>> leafNodeRelationships = interpreter.getLeafNodeRelationships(); + + if (!leafNodeRelationships.containsKey(leafNodeEntry.getValue())) + { + continue; + } + + Set> subNodeRelationships = leafNodeRelationships.get(leafNodeEntry.getValue()); + List> sinkVertexArcs = classifierVertex.getArcs(); + assertEquals(subNodeRelationships.size(), sinkVertexArcs.size()); + for (Relationship relationship : subNodeRelationships) + { + assertTrue(sinkVertexArcs + .stream() + .anyMatch(a -> + a.arcType().toString().equals(relationship.relationshipType().toString()) && + a.sourceVertex().getPath().equals(relationship.startingNode().path()) && + a.targetVertex().getPath().equals(relationship.endingNode().path()))); + } + } + } + } } diff --git a/src/test/java/parser/PackageNodeCleanerTest.java b/src/test/java/parser/PackageNodeCleanerTest.java index 222bdc3..ba48796 100644 --- a/src/test/java/parser/PackageNodeCleanerTest.java +++ b/src/test/java/parser/PackageNodeCleanerTest.java @@ -13,124 +13,126 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class PackageNodeCleanerTest { +public class PackageNodeCleanerTest +{ - @Test - void removeNonPackageNodesTest() { - Interpreter interpreter = new Interpreter(); - interpreter.parseProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01")))); + @Test + void removeNonPackageNodesTest() + { + Interpreter interpreter = new Interpreter(); + interpreter.parseProject(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01")))); - Map packageNodes = interpreter.getPackageNodes(); - Map validPackageNodes = PackageNodeCleaner.removeNonPackageNodes(packageNodes); + Map packageNodes = interpreter.getPackageNodes(); + Map validPackageNodes = PackageNodeCleaner.removeNonPackageNodes(packageNodes); - assertEquals(packageNodes.size(), validPackageNodes.size() + 5); + assertEquals(packageNodes.size(), validPackageNodes.size() + 5); - // Valid Package Nodes - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src"))))); - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bookstore"))))); - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "gui"))))); - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01"))))); + // Valid Package Nodes + assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src"))))); + assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bookstore"))))); + assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "gui"))))); + assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01"))))); - // Non Valid Package Nodes - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - ".settings"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bin"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bin", - "bookstore"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bin", - "gui"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "lib"))))); + // Non Valid Package Nodes + assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + ".settings"))))); + assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bin"))))); + assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bin", + "bookstore"))))); + assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bin", + "gui"))))); + assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "lib"))))); - PackageNode sourcePackage = validPackageNodes.get(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01")))); - Map sourcePackageSubNodes = sourcePackage.getSubNodes(); - assertEquals(sourcePackageSubNodes.size(), 1); - assertTrue(sourcePackageSubNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src"))))); - } + PackageNode sourcePackage = validPackageNodes.get(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01")))); + Map sourcePackageSubNodes = sourcePackage.getSubNodes(); + assertEquals(sourcePackageSubNodes.size(), 1); + assertTrue(sourcePackageSubNodes.containsKey(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src"))))); + } } diff --git a/src/test/java/parser/ProjectParserTest.java b/src/test/java/parser/ProjectParserTest.java index 7e84cfc..dfa1154 100644 --- a/src/test/java/parser/ProjectParserTest.java +++ b/src/test/java/parser/ProjectParserTest.java @@ -24,544 +24,553 @@ public class ProjectParserTest { - ParserType parserType = ParserType.JAVAPARSER; - - @Test - void parsingTest() { - - Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packageNodes = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - - PackageNode controllerPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller"))); - List testingLeafNodes = new ArrayList<>(); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller")), - controllerPackage.getPath()); - - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - controllerPackage.getParentNode().getPath()); - - assertTrue(controllerPackage.isValid(), "message"); - Map subNodes = controllerPackage.getSubNodes(); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands")), - subNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))).getPath()); - - for (LeafNode l : controllerPackage.getLeafNodes().values()) { - testingLeafNodes.add(l.path()); - assertEquals(l.parentNode().getPath(), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller"))); - } - Collections.sort(testingLeafNodes); - Collections.sort(CONTROLLERS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == CONTROLLERS_LEAF_NODES.size() && - CONTROLLERS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(CONTROLLERS_LEAF_NODES)); - - testingLeafNodes.clear(); - - PackageNode commandsPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands")), - commandsPackage.getPath()); - - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller")), - commandsPackage.getParentNode().getPath()); - - assertTrue(commandsPackage.isValid()); - subNodes = commandsPackage.getSubNodes(); - assertEquals(0, subNodes.size()); - for (LeafNode l : commandsPackage.getLeafNodes().values()) { - testingLeafNodes.add(l.path()); - assertEquals(l.parentNode().getPath(), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); - } - Collections.sort(testingLeafNodes); - Collections.sort(COMMANDS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == COMMANDS_LEAF_NODES.size() && - COMMANDS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(COMMANDS_LEAF_NODES)); - - testingLeafNodes.clear(); - - PackageNode modelPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model")), - modelPackage.getPath()); - - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - modelPackage.getParentNode().getPath()); - - assertTrue(modelPackage.isValid()); - subNodes = modelPackage.getSubNodes(); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies")), - subNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies"))).getPath()); - for (LeafNode l : modelPackage.getLeafNodes().values()) { - assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + ParserType parserType = ParserType.JAVAPARSER; + + + @Test + void parsingTest() + { + + Parser parser = ProjectParserFactory.createProjectParser(parserType); + Map packageNodes = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + + PackageNode controllerPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller"))); + List testingLeafNodes = new ArrayList<>(); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller")), + controllerPackage.getPath()); + + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + String.format("%s%s", + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))), + controllerPackage.getParentNode().getPath()); + + assertTrue(controllerPackage.isValid(), "message"); + Map subNodes = controllerPackage.getSubNodes(); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands")), + subNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))).getPath()); + + for (LeafNode l : controllerPackage.getLeafNodes().values()) + { + testingLeafNodes.add(l.path()); + assertEquals(l.parentNode().getPath(), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller"))); + } + Collections.sort(testingLeafNodes); + Collections.sort(CONTROLLERS_LEAF_NODES); + assertTrue(testingLeafNodes.size() == CONTROLLERS_LEAF_NODES.size() && + CONTROLLERS_LEAF_NODES.containsAll(testingLeafNodes) && + testingLeafNodes.containsAll(CONTROLLERS_LEAF_NODES)); + + testingLeafNodes.clear(); + + PackageNode commandsPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands")), + commandsPackage.getPath()); + + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller")), + commandsPackage.getParentNode().getPath()); + + assertTrue(commandsPackage.isValid()); + subNodes = commandsPackage.getSubNodes(); + assertEquals(0, subNodes.size()); + for (LeafNode l : commandsPackage.getLeafNodes().values()) + { + testingLeafNodes.add(l.path()); + assertEquals(l.parentNode().getPath(), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))); + } + Collections.sort(testingLeafNodes); + Collections.sort(COMMANDS_LEAF_NODES); + assertTrue(testingLeafNodes.size() == COMMANDS_LEAF_NODES.size() && + COMMANDS_LEAF_NODES.containsAll(testingLeafNodes) && + testingLeafNodes.containsAll(COMMANDS_LEAF_NODES)); + + testingLeafNodes.clear(); + + PackageNode modelPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model"))); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model")), + modelPackage.getPath()); + + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + String.format("%s%s", + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))), + modelPackage.getParentNode().getPath()); + + assertTrue(modelPackage.isValid()); + subNodes = modelPackage.getSubNodes(); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies")), + subNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies"))).getPath()); + for (LeafNode l : modelPackage.getLeafNodes().values()) + { + assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model"))); - testingLeafNodes.add(l.path()); - } - Collections.sort(testingLeafNodes); - Collections.sort(MODELS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == MODELS_LEAF_NODES.size() && - MODELS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(MODELS_LEAF_NODES)); - - testingLeafNodes.clear(); - - PackageNode strategiesPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies")), - strategiesPackage.getPath()); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model")), - strategiesPackage.getParentNode().getPath()); - assertTrue(strategiesPackage.isValid()); - subNodes = strategiesPackage.getSubNodes(); - assertEquals(0, subNodes.size()); - for (LeafNode l : strategiesPackage.getLeafNodes().values()) { - assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + "test", + "resources", + "LatexEditor", + "src", + "model"))); + testingLeafNodes.add(l.path()); + } + Collections.sort(testingLeafNodes); + Collections.sort(MODELS_LEAF_NODES); + assertTrue(testingLeafNodes.size() == MODELS_LEAF_NODES.size() && + MODELS_LEAF_NODES.containsAll(testingLeafNodes) && + testingLeafNodes.containsAll(MODELS_LEAF_NODES)); + + testingLeafNodes.clear(); + + PackageNode strategiesPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies"))); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies")), + strategiesPackage.getPath()); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model")), + strategiesPackage.getParentNode().getPath()); + assertTrue(strategiesPackage.isValid()); + subNodes = strategiesPackage.getSubNodes(); + assertEquals(0, subNodes.size()); + for (LeafNode l : strategiesPackage.getLeafNodes().values()) + { + assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies"))); - testingLeafNodes.add(l.path()); - } - Collections.sort(testingLeafNodes); - Collections.sort(STRATEGIES_LEAF_NODES); - assertTrue(testingLeafNodes.size() == STRATEGIES_LEAF_NODES.size() && - STRATEGIES_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(STRATEGIES_LEAF_NODES)); - - testingLeafNodes.clear(); - - PackageNode viewPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view")), - viewPackage.getPath()); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - viewPackage.getParentNode().getPath()); - assertTrue(viewPackage.isValid()); - subNodes = viewPackage.getSubNodes(); - assertEquals(0, subNodes.size()); - for (LeafNode l : viewPackage.getLeafNodes().values()) { - assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies"))); + testingLeafNodes.add(l.path()); + } + Collections.sort(testingLeafNodes); + Collections.sort(STRATEGIES_LEAF_NODES); + assertTrue(testingLeafNodes.size() == STRATEGIES_LEAF_NODES.size() && + STRATEGIES_LEAF_NODES.containsAll(testingLeafNodes) && + testingLeafNodes.containsAll(STRATEGIES_LEAF_NODES)); + + testingLeafNodes.clear(); + + PackageNode viewPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view"))); - testingLeafNodes.add(l.path()); - } - Collections.sort(testingLeafNodes); - Collections.sort(VIEWS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == VIEWS_LEAF_NODES.size() && - VIEWS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(VIEWS_LEAF_NODES)); - testingLeafNodes.clear(); - - PackageNode sourcePackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - sourcePackage.getPath()); - - assertEquals(Paths.get(""), sourcePackage.getParentNode().getPath()); - assertFalse(sourcePackage.isValid()); - subNodes = sourcePackage.getSubNodes(); - List testingSubPackages = new ArrayList<>(); - for (PackageNode subP : subNodes.values()) { - testingSubPackages.add(subP.getPath()); - } - Collections.sort(testingSubPackages); - Collections.sort(SOURCES_SUB_PACKAGES); - assertTrue(testingSubPackages.size() == SOURCES_SUB_PACKAGES.size() && - SOURCES_SUB_PACKAGES.containsAll(testingSubPackages) && - testingSubPackages.containsAll(SOURCES_SUB_PACKAGES)); - assertEquals(0, sourcePackage.getLeafNodes().size()); - } - - public static final List SOURCES_SUB_PACKAGES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view")))); - - public static final List VIEWS_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "ChooseTemplate.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "LatexEditorView.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "MainWindow.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "OpeningWindow.java")))); - - public static final List CONTROLLERS_LEAF_NODES = new ArrayList<>(List.of(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "LatexEditorController.java")))); - - public static final List STRATEGIES_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "StableVersionsStrategy.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "VersionsStrategy.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "VolatileVersionsStrategy.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "VersionsStrategyFactory.java")))); - - public static final List MODELS_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "Document.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "DocumentManager.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "VersionsManager.java")))); - - public static final List COMMANDS_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "AddLatexCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "Command.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "CommandFactory.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "CreateCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "EditCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "LoadCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "SaveCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "ChangeVersionsStrategyCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "DisableVersionsManagementCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "EnableVersionsManagementCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "RollbackToPreviousVersionCommand.java")))); + "test", + "resources", + "LatexEditor", + "src", + "view"))); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view")), + viewPackage.getPath()); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), String.format("%s%s", + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))), + viewPackage.getParentNode().getPath()); + assertTrue(viewPackage.isValid()); + subNodes = viewPackage.getSubNodes(); + assertEquals(0, subNodes.size()); + for (LeafNode l : viewPackage.getLeafNodes().values()) + { + assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view"))); + testingLeafNodes.add(l.path()); + } + Collections.sort(testingLeafNodes); + Collections.sort(VIEWS_LEAF_NODES); + assertTrue(testingLeafNodes.size() == VIEWS_LEAF_NODES.size() && + VIEWS_LEAF_NODES.containsAll(testingLeafNodes) && + testingLeafNodes.containsAll(VIEWS_LEAF_NODES)); + testingLeafNodes.clear(); + + PackageNode sourcePackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + String.format("%s%s", + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))); + assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + String.format("%s%s", + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src"))), + sourcePackage.getPath()); + + assertEquals(Paths.get(""), sourcePackage.getParentNode().getPath()); + assertFalse(sourcePackage.isValid()); + subNodes = sourcePackage.getSubNodes(); + List testingSubPackages = new ArrayList<>(); + for (PackageNode subP : subNodes.values()) + { + testingSubPackages.add(subP.getPath()); + } + Collections.sort(testingSubPackages); + Collections.sort(SOURCES_SUB_PACKAGES); + assertTrue(testingSubPackages.size() == SOURCES_SUB_PACKAGES.size() && + SOURCES_SUB_PACKAGES.containsAll(testingSubPackages) && + testingSubPackages.containsAll(SOURCES_SUB_PACKAGES)); + assertEquals(0, sourcePackage.getLeafNodes().size()); + } + + + public static final List SOURCES_SUB_PACKAGES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view")))); + + public static final List VIEWS_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "ChooseTemplate.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "LatexEditorView.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "MainWindow.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "OpeningWindow.java")))); + + public static final List CONTROLLERS_LEAF_NODES = new ArrayList<>(List.of(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "LatexEditorController.java")))); + + public static final List STRATEGIES_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "StableVersionsStrategy.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "VersionsStrategy.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "VolatileVersionsStrategy.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "VersionsStrategyFactory.java")))); + + public static final List MODELS_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "Document.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "DocumentManager.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "VersionsManager.java")))); + + public static final List COMMANDS_LEAF_NODES = new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "AddLatexCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "Command.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "CommandFactory.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "CreateCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "EditCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "LoadCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "SaveCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "ChangeVersionsStrategyCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "DisableVersionsManagementCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "EnableVersionsManagementCommand.java")), + Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "RollbackToPreviousVersionCommand.java")))); } diff --git a/src/test/java/utils/PathConstructor.java b/src/test/java/utils/PathConstructor.java index c302e03..3288d41 100644 --- a/src/test/java/utils/PathConstructor.java +++ b/src/test/java/utils/PathConstructor.java @@ -4,26 +4,36 @@ import java.io.IOException; import java.nio.file.Path; -public class PathConstructor { +public class PathConstructor +{ - private PathConstructor() {} - public static String constructPath(String ... strings){ + public static String constructPath(String... strings) + { StringBuilder path = new StringBuilder(); - for (String string: strings) { + for (String string : strings) + { path.append(File.separator).append(string); } return path.toString(); } - public static Path getCurrentPath(){ + + public static Path getCurrentPath() + { Path currentDirectory; - try { + try + { currentDirectory = Path.of(".").toRealPath(); } - catch (IOException e) { + catch (IOException e) + { throw new RuntimeException(e); } return currentDirectory; } + + + /** Utility class. Do not instantiate. */ + private PathConstructor() {} } diff --git a/src/test/resources/BicycleRaceV01/src/bicycleBody/Bicycle.java b/src/test/resources/BicycleRaceV01/src/bicycleBody/Bicycle.java index 94e62de..caa52c3 100644 --- a/src/test/resources/BicycleRaceV01/src/bicycleBody/Bicycle.java +++ b/src/test/resources/BicycleRaceV01/src/bicycleBody/Bicycle.java @@ -4,114 +4,134 @@ import bicycleBreaks.BrakeFactory; import bicyclePedal.IPedal; import bicyclePedal.PedalFactory; + /** -*

Bicycle

-* Class responsible for handling all the functionality -* that is needed for a bicycle. -* -* @version 1.0 -* @since 2017-07-24 -*/ -public class Bicycle { - - public Bicycle(String pedalsName, String breaksName, String name){ - breakFactory = new BrakeFactory(); - pedalFactory = new PedalFactory(); - breaks = breakFactory.constructBrake(breaksName); - pedal = pedalFactory.constructPedal(pedalsName); - velocity = 0.0; - timeRun = 0.0; - this.name = name; - } - - public double getVelocity(){ - return velocity; - } - - public double getTimeRun(){ - return timeRun; - } - - public void computeTime(double distance){ - timeRun += distance/velocity; - } - - public String getName(){ - return name; - } - - public void setOriginalVelocity(double originalVelocity){ - velocity = originalVelocity; - } - - /** - * Computes the velocity of the bicycle - * based on the pedaling rate. - * - * @param rate pedaling rate - * - * @return the computed velocity - */ - public double setPedaling(double rate){ - velocity += pedal.getSpeed(rate); - return velocity; - } - - /** - * Computes the velocity of the bicycle - * based on the given braking force. - * - * @param force braking force - * - * @return the computed velocity - */ - public double setBraking(double force){ - velocity -= breaks.getSpeedReduction(force); - if (velocity < 0) - velocity = 0; - return velocity; - } - - /** - * Reports the information regarding a bicycle - * (velocity and status) - */ - public void reportDetails(){ - - System.out.println(getName() + ": velocity is: " + String.format( "%.2f",getVelocity()) + " and time run is: " + String.format( "%.2f",getTimeRun())); - - if(reportIfDamageExists() == false) - System.out.println("Status: OK"); - else - System.out.println("Status: Broken"); - System.out.println("-------------------"); - } - - public boolean reportIfDamageExists(){ - boolean brokenStatus = false; - if (breaks.reportIfBroken(0.7) == true){ - brokenStatus = true; - System.out.println("Breaks are broken"); - } - if (pedal.reportIfBroken() == true){ - brokenStatus = true; - System.out.println("Pedals are broken"); - } - return brokenStatus; - } - - public boolean equals(Bicycle bicycle){ - if(getName().equals(bicycle.getName())) - return true; - - return false; - } - - private double timeRun; - private String name; - private double velocity; - private IBrakes breaks; - private IPedal pedal; - private BrakeFactory breakFactory; - private PedalFactory pedalFactory; + *

Bicycle

+ * Class responsible for handling all the functionality that is needed for a bicycle. + * + * @version 1.0 + * @since 2017-07-24 + */ +public class Bicycle +{ + + public Bicycle(String pedalsName, String breaksName, String name) + { + breakFactory = new BrakeFactory(); + pedalFactory = new PedalFactory(); + breaks = breakFactory.constructBrake(breaksName); + pedal = pedalFactory.constructPedal(pedalsName); + velocity = 0.0; + timeRun = 0.0; + this.name = name; + } + + + public double getVelocity() + { + return velocity; + } + + + public double getTimeRun() + { + return timeRun; + } + + + public void computeTime(double distance) + { + timeRun += distance / velocity; + } + + + public String getName() + { + return name; + } + + + public void setOriginalVelocity(double originalVelocity) + { + velocity = originalVelocity; + } + + + /** + * Computes the velocity of the bicycle based on the pedaling rate. + * + * @param rate pedaling rate + * @return the computed velocity + */ + public double setPedaling(double rate) + { + velocity += pedal.getSpeed(rate); + return velocity; + } + + + /** + * Computes the velocity of the bicycle based on the given braking force. + * + * @param force braking force + * @return the computed velocity + */ + public double setBraking(double force) + { + velocity -= breaks.getSpeedReduction(force); + if (velocity < 0) + velocity = 0; + return velocity; + } + + + /** + * Reports the information regarding a bicycle (velocity and status) + */ + public void reportDetails() + { + + System.out.println(getName() + ": velocity is: " + String.format("%.2f", getVelocity()) + " and time run is: " + String.format("%.2f", getTimeRun())); + + if (reportIfDamageExists() == false) + System.out.println("Status: OK"); + else + System.out.println("Status: Broken"); + System.out.println("-------------------"); + } + + + public boolean reportIfDamageExists() + { + boolean brokenStatus = false; + if (breaks.reportIfBroken(0.7) == true) + { + brokenStatus = true; + System.out.println("Breaks are broken"); + } + if (pedal.reportIfBroken() == true) + { + brokenStatus = true; + System.out.println("Pedals are broken"); + } + return brokenStatus; + } + + + public boolean equals(Bicycle bicycle) + { + if (getName().equals(bicycle.getName())) + return true; + + return false; + } + + + private double timeRun; + private String name; + private double velocity; + private IBrakes breaks; + private IPedal pedal; + private BrakeFactory breakFactory; + private PedalFactory pedalFactory; } diff --git a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/BrakeFactory.java b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/BrakeFactory.java index 9535b06..baf5935 100644 --- a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/BrakeFactory.java +++ b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/BrakeFactory.java @@ -1,29 +1,28 @@ package bicycleBreaks; /** -*

BrakeFactory

-* Factory class responsible for creating the different -* types of brakes. -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class BrakeFactory { - - /** - * Creates all the different types of objects which are responsible - * for modeling the different kinds of brakes. - * - * @return an IBrake object which is responsible - * for the representation of a brake type. - */ - public IBrakes constructBrake(String concreteClassName){ - if (concreteClassName.equals("NiceBrakes")) - return new NiceBrakes(); - else if (concreteClassName.equals("DuperBrakes")) - return new DuperBrakes(); - - System.out.println("If the code got up to here, you passed a wrong argument to BreakFactory"); - return null; - } + *

BrakeFactory

+ * Factory class responsible for creating the different types of brakes. + * + * @version 1.0 + * @since 2017-07-22 + */ +public class BrakeFactory +{ + + /** + * Creates all the different types of objects which are responsible for modeling the different kinds of brakes. + * + * @return an IBrake object which is responsible for the representation of a brake type. + */ + public IBrakes constructBrake(String concreteClassName) + { + if (concreteClassName.equals("NiceBrakes")) + return new NiceBrakes(); + else if (concreteClassName.equals("DuperBrakes")) + return new DuperBrakes(); + + System.out.println("If the code got up to here, you passed a wrong argument to BreakFactory"); + return null; + } } diff --git a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/DuperBrakes.java b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/DuperBrakes.java index 1baa4e8..06f5157 100644 --- a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/DuperBrakes.java +++ b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/DuperBrakes.java @@ -1,36 +1,36 @@ package bicycleBreaks; + /** -*

DuperBreaks

-* Class responsible for the representation of -* a simple race. -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class DuperBrakes implements IBrakes { - - /** - * Reduces the speed by a factor based on the input - * parameter. - * - * @param excertedForce the value of the force which is applied - * to the break. - * - * @return the actual speed reduction - */ - @Override - public double getSpeedReduction(Double excertedForce){ - return 45*excertedForce; - } + *

DuperBreaks

+ * Class responsible for the representation of a simple race. + * + * @version 1.0 + * @since 2017-07-22 + */ +public class DuperBrakes implements IBrakes +{ + + /** + * Reduces the speed by a factor based on the input parameter. + * + * @param excertedForce the value of the force which is applied to the break. + * @return the actual speed reduction + */ + @Override + public double getSpeedReduction(Double excertedForce) + { + return 45 * excertedForce; + } + - /** - * - * @return always false - */ - @Override - public boolean reportIfBroken(double threshold) { - //Intentional issue, food for thought: parameter unused! - return false; - } + /** + * @return always false + */ + @Override + public boolean reportIfBroken(double threshold) + { + //Intentional issue, food for thought: parameter unused! + return false; + } } diff --git a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/IBrakes.java b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/IBrakes.java index 587eb76..5826a4f 100644 --- a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/IBrakes.java +++ b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/IBrakes.java @@ -1,30 +1,27 @@ package bicycleBreaks; + /** -*

IBrake

-* Interface which provides the basic functionality regarding -* the breaks of a bicycle. -* -* @version 1.0 -* @since 2017-07-22 -*/ -public interface IBrakes { - - /** - * Reduces the speed by a factor based on the input - * parameter. - * - * @param excertedForce the value of the force which is applied - * to the break. - * - * @return the actual speed reduction - */ - public abstract double getSpeedReduction(Double excertedForce); - - /** - * Reports if the brakes are broken. - * - * @return true if the brakes are broken or false otherwise - * - */ - public abstract boolean reportIfBroken(double threshold); + *

IBrake

+ * Interface which provides the basic functionality regarding the breaks of a bicycle. + * + * @version 1.0 + * @since 2017-07-22 + */ +public interface IBrakes +{ + + /** + * Reduces the speed by a factor based on the input parameter. + * + * @param excertedForce the value of the force which is applied to the break. + * @return the actual speed reduction + */ + public abstract double getSpeedReduction(Double excertedForce); + + /** + * Reports if the brakes are broken. + * + * @return true if the brakes are broken or false otherwise + */ + public abstract boolean reportIfBroken(double threshold); } diff --git a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/NiceBrakes.java b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/NiceBrakes.java index 09d5b8c..6aaf8f1 100644 --- a/src/test/resources/BicycleRaceV01/src/bicycleBreaks/NiceBrakes.java +++ b/src/test/resources/BicycleRaceV01/src/bicycleBreaks/NiceBrakes.java @@ -1,48 +1,47 @@ package bicycleBreaks; import java.util.Random; + /** -*

NiceBrakes

-* Class responsible for the representation of -* a type of brakes (NiceBrakes). -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class NiceBrakes implements IBrakes { - - /** - * Reduces the speed by a factor based on the input - * parameter. - * - * @param excertedForce the value of the force which is applied - * to the break. - * - * @return the actual speed reduction - */ - @Override - public double getSpeedReduction(Double excertedForce){ - return 35*excertedForce; - } + *

NiceBrakes

+ * Class responsible for the representation of a type of brakes (NiceBrakes). + * + * @version 1.0 + * @since 2017-07-22 + */ +public class NiceBrakes implements IBrakes +{ + + /** + * Reduces the speed by a factor based on the input parameter. + * + * @param excertedForce the value of the force which is applied to the break. + * @return the actual speed reduction + */ + @Override + public double getSpeedReduction(Double excertedForce) + { + return 35 * excertedForce; + } + + + /** + * Picks a random number in range [0,1] and if this random number is larger than the input threshold then returns false. In any other case, return true. + */ + @Override + public boolean reportIfBroken(double threshold) + { + if ((threshold > 1.0) || (threshold > 1.0)) + { + System.out.println("The threshold for breaks' health should be between 0 and 1"); + System.exit(-1); + } - /** - * Picks a random number in range [0,1] and if this random - * number is larger than the input threshold then returns false. - * In any other case, return true. - * - */ - @Override - public boolean reportIfBroken(double threshold) { - if ((threshold > 1.0) || (threshold > 1.0)){ - System.out.println("The threshold for breaks' health should be between 0 and 1"); - System.exit(-1); - } - - Random randomDice = new Random(); - if (randomDice.nextDouble() > threshold) - return false; - else - return true; - } + Random randomDice = new Random(); + if (randomDice.nextDouble() > threshold) + return false; + else + return true; + } } diff --git a/src/test/resources/BicycleRaceV01/src/bicyclePedal/IPedal.java b/src/test/resources/BicycleRaceV01/src/bicyclePedal/IPedal.java index 2c1bd6e..fb11ee8 100644 --- a/src/test/resources/BicycleRaceV01/src/bicyclePedal/IPedal.java +++ b/src/test/resources/BicycleRaceV01/src/bicyclePedal/IPedal.java @@ -1,30 +1,28 @@ package bicyclePedal; + /** -*

IPedal

-* Interface which provides the basic functionality -* regarding of the pedals of a bicycle. -* -* @version 1.0 -* @since 2017-07-22 -*/ -public interface IPedal { - - /** - * Computes the speed which is provided given the pedaling rate. - * parameter. - * - * @param pedalingRate the rate of the pedaling - * - * @return the actual speed which is achieved - */ - - public abstract double getSpeed(double pedalingRate); - - /** - * Reports if the pedals are broken. - * - * @return true if the pedals are broken or false otherwise - * - */ - public abstract boolean reportIfBroken(); + *

IPedal

+ * Interface which provides the basic functionality regarding of the pedals of a bicycle. + * + * @version 1.0 + * @since 2017-07-22 + */ +public interface IPedal +{ + + /** + * Computes the speed which is provided given the pedaling rate. parameter. + * + * @param pedalingRate the rate of the pedaling + * @return the actual speed which is achieved + */ + + public abstract double getSpeed(double pedalingRate); + + /** + * Reports if the pedals are broken. + * + * @return true if the pedals are broken or false otherwise + */ + public abstract boolean reportIfBroken(); } diff --git a/src/test/resources/BicycleRaceV01/src/bicyclePedal/PedalFactory.java b/src/test/resources/BicycleRaceV01/src/bicyclePedal/PedalFactory.java index f46a475..4ec07c3 100644 --- a/src/test/resources/BicycleRaceV01/src/bicyclePedal/PedalFactory.java +++ b/src/test/resources/BicycleRaceV01/src/bicyclePedal/PedalFactory.java @@ -1,28 +1,28 @@ package bicyclePedal; + /** -*

PedalFactory

-* Factory class responsible for creating the different -* types of pedals. -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class PedalFactory { - - /** - * Creates all the different types of objects which are responsible - * for modeling the different kinds of pedals. - * - * @return an IPedal object which is responsible - * for the representation of a pedal type. - */ - public IPedal constructPedal(String concreteClassName){ - if (concreteClassName.equals("SimplePedal")) - return new SimplePedal(); - else if (concreteClassName.equals("ZuperPedal")) - return new ZuperPedal(); - - System.out.println("If the code got up to here, you passed a wrong argument to PedalFactory"); - return null; - } + *

PedalFactory

+ * Factory class responsible for creating the different types of pedals. + * + * @version 1.0 + * @since 2017-07-22 + */ +public class PedalFactory +{ + + /** + * Creates all the different types of objects which are responsible for modeling the different kinds of pedals. + * + * @return an IPedal object which is responsible for the representation of a pedal type. + */ + public IPedal constructPedal(String concreteClassName) + { + if (concreteClassName.equals("SimplePedal")) + return new SimplePedal(); + else if (concreteClassName.equals("ZuperPedal")) + return new ZuperPedal(); + + System.out.println("If the code got up to here, you passed a wrong argument to PedalFactory"); + return null; + } } diff --git a/src/test/resources/BicycleRaceV01/src/bicyclePedal/SimplePedal.java b/src/test/resources/BicycleRaceV01/src/bicyclePedal/SimplePedal.java index f7d165d..01ad93f 100644 --- a/src/test/resources/BicycleRaceV01/src/bicyclePedal/SimplePedal.java +++ b/src/test/resources/BicycleRaceV01/src/bicyclePedal/SimplePedal.java @@ -3,44 +3,42 @@ import java.util.Random; /** -*

SimplePedal

-* Class responsible for the representation of -* a type of pedals (SimplePedal). -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class SimplePedal implements IPedal { - - /** - * Computes the speed by a factor based on the input - * parameter. - * - * @param pedalingRate the rate of the pedaling - * - * @return the speed which is achieved - */ - @Override - public double getSpeed(double pedalingRate) { - return 35 * pedalingRate; - - } - - /** - * Picks a random number in range [0,1] and if this random - * number is larger than 0.5 then returns false. - * In any other case, return true.Reports if the pedals are broken. - * - * @return true if the pedals are broken or false otherwise - * - */ - @Override - public boolean reportIfBroken() { - Random randomDice = new Random(); - if (randomDice.nextDouble() > 0.6) - return false; - else - return true; - } + *

SimplePedal

+ * Class responsible for the representation of a type of pedals (SimplePedal). + * + * @version 1.0 + * @since 2017-07-22 + */ +public class SimplePedal implements IPedal +{ + + /** + * Computes the speed by a factor based on the input parameter. + * + * @param pedalingRate the rate of the pedaling + * @return the speed which is achieved + */ + @Override + public double getSpeed(double pedalingRate) + { + return 35 * pedalingRate; + + } + + + /** + * Picks a random number in range [0,1] and if this random number is larger than 0.5 then returns false. In any other case, return true.Reports if the pedals are broken. + * + * @return true if the pedals are broken or false otherwise + */ + @Override + public boolean reportIfBroken() + { + Random randomDice = new Random(); + if (randomDice.nextDouble() > 0.6) + return false; + else + return true; + } } diff --git a/src/test/resources/BicycleRaceV01/src/bicyclePedal/ZuperPedal.java b/src/test/resources/BicycleRaceV01/src/bicyclePedal/ZuperPedal.java index a38402e..3583565 100644 --- a/src/test/resources/BicycleRaceV01/src/bicyclePedal/ZuperPedal.java +++ b/src/test/resources/BicycleRaceV01/src/bicyclePedal/ZuperPedal.java @@ -1,35 +1,36 @@ package bicyclePedal; + /** -*

DuperBreaks

-* Class responsible for the representation of -* a type of pedals (DuperBreaks). -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class ZuperPedal implements IPedal { - - /** - * Computes the speed by a factor based on the input - * parameter. - * - * @param pedalingRate the rate of the pedaling - * - * @return the speed which is achieved - */ - @Override - public double getSpeed(double pedalingRate) { - return 45 * pedalingRate + 650; - } + *

DuperBreaks

+ * Class responsible for the representation of a type of pedals (DuperBreaks). + * + * @version 1.0 + * @since 2017-07-22 + */ +public class ZuperPedal implements IPedal +{ + + /** + * Computes the speed by a factor based on the input parameter. + * + * @param pedalingRate the rate of the pedaling + * @return the speed which is achieved + */ + @Override + public double getSpeed(double pedalingRate) + { + return 45 * pedalingRate + 650; + } + - /** - * - * @return always false - */ - @Override - public boolean reportIfBroken() { - // TODO Auto-generated method stub - return false; - } + /** + * @return always false + */ + @Override + public boolean reportIfBroken() + { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/test/resources/BicycleRaceV01/src/mainApplication/BicycleSimpleApplication.java b/src/test/resources/BicycleRaceV01/src/mainApplication/BicycleSimpleApplication.java index 123adbb..31394a6 100644 --- a/src/test/resources/BicycleRaceV01/src/mainApplication/BicycleSimpleApplication.java +++ b/src/test/resources/BicycleRaceV01/src/mainApplication/BicycleSimpleApplication.java @@ -5,87 +5,109 @@ import race.IRace; import race.RaceTypeFactory; -public class BicycleSimpleApplication { - private Scanner reader; - - public BicycleSimpleApplication(){ - reader = new Scanner(System.in); - } - - public Scanner getReader(){ - return reader; - } - - public int chooseType(String message){ - int answer = 0; - while( answer > 2 || answer <= 0){ - System.out.println(message); - answer = reader.nextInt(); - if(answer > 2 || answer <= 0) - System.out.println("Wrong answer! Try again..."); - } - return answer; - } - - - public int printMenu(){ - int answerOperation = 0; - while( answerOperation > 3 || answerOperation <= 0){ - System.out.println("Choose(1-3)\n 1. Add vehicle\n 2. Race\n 3. Exit"); - answerOperation = reader.nextInt(); - if(answerOperation > 3 || answerOperation <= 0) - System.out.println("Wrong answer! Try again..."); - } - - return answerOperation; - } - - public void closeReader(){ - reader.close(); - } - - public static void main(String[] args) { - BicycleSimpleApplication bTester = new BicycleSimpleApplication(); - RaceTypeFactory raceFactory = new RaceTypeFactory(); - IRace r = raceFactory.createRaceWithStages(); - while(true){ - int operation = bTester.printMenu(); - if(operation == 1){ - System.out.println("Choose a name for your bicycle:"); - String name = bTester.getReader().next(); - System.out.println(name); - - int answerBrake = bTester.chooseType("Choose brake type (1/2)\n" - + "1. Nice brakes\n2. Duper brakes"); - int answerPedal = bTester.chooseType("Choose pedal type (1/2)\n" - + "1. Simple pedal\n2. Zuper pedal"); - - System.out.println("Select the initial velocity for your bicycle:"); - double velocity = bTester.getReader().nextDouble(); - - if(answerBrake == 1 && answerPedal == 1){ - r.setupVehicle("SimplePedal", "NiceBrakes", name, velocity); - } - else if(answerBrake == 1 && answerPedal == 2){ - r.setupVehicle("ZuperPedal", "NiceBrakes", name, velocity); - } - else if(answerBrake == 2 && answerPedal == 1){ - r.setupVehicle("SimplePedal", "DuperBrakes", name, velocity); - } - else{//answerBrake == 2 && answerPedal == 2 - r.setupVehicle("ZuperPedal", "DuperBrakes", name, velocity); - } - } - else if(operation == 2){ - r.runRace(); - } - else{ - break; - } - } - - //r.setupVehicles(); - bTester.closeReader(); - } - +public class BicycleSimpleApplication +{ + private Scanner reader; + + + public BicycleSimpleApplication() + { + reader = new Scanner(System.in); + } + + + public Scanner getReader() + { + return reader; + } + + + public int chooseType(String message) + { + int answer = 0; + while (answer > 2 || answer <= 0) + { + System.out.println(message); + answer = reader.nextInt(); + if (answer > 2 || answer <= 0) + System.out.println("Wrong answer! Try again..."); + } + return answer; + } + + + public int printMenu() + { + int answerOperation = 0; + while (answerOperation > 3 || answerOperation <= 0) + { + System.out.println("Choose(1-3)\n 1. Add vehicle\n 2. Race\n 3. Exit"); + answerOperation = reader.nextInt(); + if (answerOperation > 3 || answerOperation <= 0) + System.out.println("Wrong answer! Try again..."); + } + + return answerOperation; + } + + + public void closeReader() + { + reader.close(); + } + + + public static void main(String[] args) + { + BicycleSimpleApplication bTester = new BicycleSimpleApplication(); + RaceTypeFactory raceFactory = new RaceTypeFactory(); + IRace r = raceFactory.createRaceWithStages(); + while (true) + { + int operation = bTester.printMenu(); + if (operation == 1) + { + System.out.println("Choose a name for your bicycle:"); + String name = bTester.getReader().next(); + System.out.println(name); + + int answerBrake = bTester.chooseType("Choose brake type (1/2)\n" + + "1. Nice brakes\n2. Duper brakes"); + int answerPedal = bTester.chooseType("Choose pedal type (1/2)\n" + + "1. Simple pedal\n2. Zuper pedal"); + + System.out.println("Select the initial velocity for your bicycle:"); + double velocity = bTester.getReader().nextDouble(); + + if (answerBrake == 1 && answerPedal == 1) + { + r.setupVehicle("SimplePedal", "NiceBrakes", name, velocity); + } + else if (answerBrake == 1 && answerPedal == 2) + { + r.setupVehicle("ZuperPedal", "NiceBrakes", name, velocity); + } + else if (answerBrake == 2 && answerPedal == 1) + { + r.setupVehicle("SimplePedal", "DuperBrakes", name, velocity); + } + else + {//answerBrake == 2 && answerPedal == 2 + r.setupVehicle("ZuperPedal", "DuperBrakes", name, velocity); + } + } + else if (operation == 2) + { + r.runRace(); + } + else + { + break; + } + } + + //r.setupVehicles(); + bTester.closeReader(); + } + } diff --git a/src/test/resources/BicycleRaceV01/src/race/IRace.java b/src/test/resources/BicycleRaceV01/src/race/IRace.java index 1d6f7e3..e59538c 100644 --- a/src/test/resources/BicycleRaceV01/src/race/IRace.java +++ b/src/test/resources/BicycleRaceV01/src/race/IRace.java @@ -1,24 +1,24 @@ package race; + /** -*

IRace

-* Interface which provides the basic functionality -* for conducting the race. -* -* @version 1.0 -* @since 2017-07-24 -*/ -public interface IRace { - - /** - * Creates the vehicles that are going - * to participate in the race. - */ - public void setupVehicles(); - - public void setupVehicle(String pedalType, String brakeType, String name, double velocity); - - /** - * Executes the race between the vehicles. - */ - public void runRace(); + *

IRace

+ * Interface which provides the basic functionality for conducting the race. + * + * @version 1.0 + * @since 2017-07-24 + */ +public interface IRace +{ + + /** + * Creates the vehicles that are going to participate in the race. + */ + public void setupVehicles(); + + public void setupVehicle(String pedalType, String brakeType, String name, double velocity); + + /** + * Executes the race between the vehicles. + */ + public void runRace(); } diff --git a/src/test/resources/BicycleRaceV01/src/race/RaceTypeFactory.java b/src/test/resources/BicycleRaceV01/src/race/RaceTypeFactory.java index 1ca406c..8963728 100644 --- a/src/test/resources/BicycleRaceV01/src/race/RaceTypeFactory.java +++ b/src/test/resources/BicycleRaceV01/src/race/RaceTypeFactory.java @@ -1,20 +1,20 @@ package race; + /** -*

RaceTypeFactory

-* Class responsible for creating different -* types of objects that represent a race. -* the Book items. -* -* @version 1.0 -* @since 2017-07-24 -*/ -public class RaceTypeFactory { + *

RaceTypeFactory

+ * Class responsible for creating different types of objects that represent a race. the Book items. + * + * @version 1.0 + * @since 2017-07-24 + */ +public class RaceTypeFactory +{ - /** - * @return IRace object responsible for - * modeling the conditions of a race. - */ - public IRace createRaceWithStages(){ - return new RaceWithStages(); - } + /** + * @return IRace object responsible for modeling the conditions of a race. + */ + public IRace createRaceWithStages() + { + return new RaceWithStages(); + } } diff --git a/src/test/resources/BicycleRaceV01/src/race/RaceWithStages.java b/src/test/resources/BicycleRaceV01/src/race/RaceWithStages.java index 77437d0..1f3b8f7 100644 --- a/src/test/resources/BicycleRaceV01/src/race/RaceWithStages.java +++ b/src/test/resources/BicycleRaceV01/src/race/RaceWithStages.java @@ -4,148 +4,166 @@ import java.util.Random; import bicycleBody.Bicycle; + /** -*

RaceWithStages

-* Class responsible for the representation of -* a simple race. -* -* @version 1.0 -* @since 2017-07-22 -*/ -public class RaceWithStages implements IRace{ - - - private int stagePart = 0; - private int totalStageParts = 4; - /*We suppose for simplicity that all the parts - *of the stage have the same length - */ - private double stagePartDistance = 2000; - private ArrayList contestants; - - public RaceWithStages(){ - contestants = new ArrayList(); - } - - private void nextPart(){ - stagePart++; - } - - private boolean hasNextStage(){ - if(stagePart < totalStageParts) - return true; - - return false; - } - - /** - * Sets the rate of the pedaling to a random value - * in range [0,40]. - */ - private void changePedaling(Bicycle contestant){ - Random randomDice = new Random(); - double rate = 40 * randomDice.nextDouble(); - contestant.setPedaling(rate); - System.out.println("Contestant " + contestant.getName() + " pedals with rate " + String.format( "%.2f",rate)); - } - - /** - * Sets the force which is applied to the breaks - * to a random value in range [0,30]. - */ - private void changeBreaks(Bicycle contestant){ - Random randomDice = new Random(); - double force = 30 * randomDice.nextDouble(); - contestant.setBraking(force); - System.out.println("Contestant " + contestant.getName() + " breaks with force " + String.format( "%.2f",force)); - } - - /** - * Decides the winner of the race based - * on the time - * - */ - public void decideWinner(){ - double minTime = Double.MAX_VALUE; - Bicycle winner = null; - - if(contestants.size() == 0){ - System.out.println("There is no winner for this race..."); - return; - } - - for(Bicycle contestant: contestants){ - if(contestant.getTimeRun() < minTime){ - minTime = contestant.getTimeRun(); - winner = contestant; - } - } - System.out.println("Winner Details"); - winner.reportDetails(); - } - - /** - * Executes the race - */ - @Override - public void runRace(){ - while(hasNextStage()){ - System.out.println("====================\nPart: " - + stagePart + "\n"); - ArrayList brokenContestants = new ArrayList(); - for(Bicycle bm: contestants){ - changePedaling(bm); - changeBreaks(bm); - bm.computeTime(stagePartDistance); - //Mark broken contestant - if(bm.reportIfDamageExists()) - brokenContestants.add(bm); - //report contestant's details - bm.reportDetails(); - } - //Remove the contestants that are broken - for(Bicycle brokenContestant: brokenContestants){ - contestants.remove(brokenContestant); - } - nextPart(); - } - System.out.println("End of RaceWithStages\n\n"); - decideWinner(); - } - - - /** - * Creates the vehicles that are going - * to participate in the race. - */ - @Override - public void setupVehicle(String pedalType, String brakeType, String name, double velocity){ - Bicycle bicycleConstructed = new Bicycle(pedalType, brakeType, name); - bicycleConstructed.setOriginalVelocity(velocity); - System.out.println(name + ": velocity at start is: " + bicycleConstructed.getVelocity()); - contestants.add(bicycleConstructed); - } - - /** - * Helper method, constructing 3 bicycles - * to quickly setup a race between the vehicles. - */ - @Override - public void setupVehicles(){ - Bicycle hsyxhRoda = new Bicycle("SimplePedal", "NiceBrakes", "Hsuxi Roda"); - hsyxhRoda.setOriginalVelocity(50); - System.out.println("Hsyxh Roda: velocity at start is: " + hsyxhRoda.getVelocity()); - contestants.add(hsyxhRoda); - - Bicycle afoniRoda = new Bicycle("ZuperPedal", "NiceBrakes", "Afoni Roda"); - afoniRoda.setOriginalVelocity(40); - System.out.println("Afoni Roda: velocity at start is: " + afoniRoda.getVelocity()); - contestants.add(afoniRoda); - - Bicycle plousiaRoda = new Bicycle("ZuperPedal", "DuperBrakes", "Plousia Roda"); - plousiaRoda.setOriginalVelocity(70); - System.out.println("Plousia Roda: velocity at start is: " + plousiaRoda.getVelocity()); - contestants.add(plousiaRoda); - } - + *

RaceWithStages

+ * Class responsible for the representation of a simple race. + * + * @version 1.0 + * @since 2017-07-22 + */ +public class RaceWithStages implements IRace +{ + + + private int stagePart = 0; + private int totalStageParts = 4; + /*We suppose for simplicity that all the parts + *of the stage have the same length + */ + private double stagePartDistance = 2000; + private ArrayList contestants; + + + public RaceWithStages() + { + contestants = new ArrayList(); + } + + + private void nextPart() + { + stagePart++; + } + + + private boolean hasNextStage() + { + if (stagePart < totalStageParts) + return true; + + return false; + } + + + /** + * Sets the rate of the pedaling to a random value in range [0,40]. + */ + private void changePedaling(Bicycle contestant) + { + Random randomDice = new Random(); + double rate = 40 * randomDice.nextDouble(); + contestant.setPedaling(rate); + System.out.println("Contestant " + contestant.getName() + " pedals with rate " + String.format("%.2f", rate)); + } + + + /** + * Sets the force which is applied to the breaks to a random value in range [0,30]. + */ + private void changeBreaks(Bicycle contestant) + { + Random randomDice = new Random(); + double force = 30 * randomDice.nextDouble(); + contestant.setBraking(force); + System.out.println("Contestant " + contestant.getName() + " breaks with force " + String.format("%.2f", force)); + } + + + /** + * Decides the winner of the race based on the time + */ + public void decideWinner() + { + double minTime = Double.MAX_VALUE; + Bicycle winner = null; + + if (contestants.size() == 0) + { + System.out.println("There is no winner for this race..."); + return; + } + + for (Bicycle contestant : contestants) + { + if (contestant.getTimeRun() < minTime) + { + minTime = contestant.getTimeRun(); + winner = contestant; + } + } + System.out.println("Winner Details"); + winner.reportDetails(); + } + + + /** + * Executes the race + */ + @Override + public void runRace() + { + while (hasNextStage()) + { + System.out.println("====================\nPart: " + + stagePart + "\n"); + ArrayList brokenContestants = new ArrayList(); + for (Bicycle bm : contestants) + { + changePedaling(bm); + changeBreaks(bm); + bm.computeTime(stagePartDistance); + //Mark broken contestant + if (bm.reportIfDamageExists()) + brokenContestants.add(bm); + //report contestant's details + bm.reportDetails(); + } + //Remove the contestants that are broken + for (Bicycle brokenContestant : brokenContestants) + { + contestants.remove(brokenContestant); + } + nextPart(); + } + System.out.println("End of RaceWithStages\n\n"); + decideWinner(); + } + + + /** + * Creates the vehicles that are going to participate in the race. + */ + @Override + public void setupVehicle(String pedalType, String brakeType, String name, double velocity) + { + Bicycle bicycleConstructed = new Bicycle(pedalType, brakeType, name); + bicycleConstructed.setOriginalVelocity(velocity); + System.out.println(name + ": velocity at start is: " + bicycleConstructed.getVelocity()); + contestants.add(bicycleConstructed); + } + + + /** + * Helper method, constructing 3 bicycles to quickly setup a race between the vehicles. + */ + @Override + public void setupVehicles() + { + Bicycle hsyxhRoda = new Bicycle("SimplePedal", "NiceBrakes", "Hsuxi Roda"); + hsyxhRoda.setOriginalVelocity(50); + System.out.println("Hsyxh Roda: velocity at start is: " + hsyxhRoda.getVelocity()); + contestants.add(hsyxhRoda); + + Bicycle afoniRoda = new Bicycle("ZuperPedal", "NiceBrakes", "Afoni Roda"); + afoniRoda.setOriginalVelocity(40); + System.out.println("Afoni Roda: velocity at start is: " + afoniRoda.getVelocity()); + contestants.add(afoniRoda); + + Bicycle plousiaRoda = new Bicycle("ZuperPedal", "DuperBrakes", "Plousia Roda"); + plousiaRoda.setOriginalVelocity(70); + System.out.println("Plousia Roda: velocity at start is: " + plousiaRoda.getVelocity()); + contestants.add(plousiaRoda); + } + } diff --git a/src/test/resources/BookstoreAdvancedV01/bin/gui/cart.fxml b/src/test/resources/BookstoreAdvancedV01/bin/gui/cart.fxml index bf76eff..6c4a218 100644 --- a/src/test/resources/BookstoreAdvancedV01/bin/gui/cart.fxml +++ b/src/test/resources/BookstoreAdvancedV01/bin/gui/cart.fxml @@ -8,40 +8,40 @@ - - - - - - - - - - - - - - - - - - - - - -