├── .gitattributes
├── .gitignore
├── LICENSE.md
├── README.md
├── books
├── Khorstmann_Key_Java_Biblioteka_professionala_Tom_1_Osnovy_11_e_izdanie.pdf
└── Patterny_obektno-orientirovannogo_proektirovania_2020.pdf
├── commandsToRemember
├── docs
├── guides
│ └── lab5_guide1.pdf
└── lectures
│ ├── 1st_wrappers_generics_collections_sorting.pdf
│ ├── 2nd_in-out_patterns.pdf
│ ├── 3rd_client-server_lambdas_streamAPI.pdf
│ ├── 4th_databases.pdf
│ ├── 5th_sameAs4th.pdf
│ ├── 6th_patterns.pdf
│ └── 7th_GUI.pdf
├── lab1
├── Dvorkin_Boris_P3131_Lab1_prog.docx
├── Lab1_prog.docx
├── lab1.iml
├── lab_1.iml
└── src
│ ├── Main.java
│ └── arecent.java
├── lab2
├── Java_lab2_theory.txt
├── Lab2_prog.docx
├── Lab2_prog.iml
├── Pokemon.jar
├── UML_diagram.png
├── lab2.iml
└── src
│ ├── META-INF
│ └── MANIFEST.MF
│ ├── Main.java
│ ├── moves
│ ├── BulkUp.java
│ ├── Confide.java
│ ├── DazzlingGleam.java
│ ├── FairyWind.java
│ ├── Flamethrower.java
│ ├── FocusBlast.java
│ ├── HornLeech.java
│ ├── MetalSound.java
│ ├── ShadowBall.java
│ ├── SteelWing.java
│ └── Swagger.java
│ └── pokemons
│ ├── Minior.java
│ ├── Silvally.java
│ ├── TapuFini.java
│ ├── Togekiss.java
│ ├── Togepi.java
│ └── Togetic.java
├── lab3
├── Lab3_prog_UML.puml
├── Programming_theory.md.html
├── Programming_theory.md.pdf
├── READ_BEFORE_LAB
├── UML_true.png
├── lab3.iml
└── src
│ ├── CosmicObjects
│ ├── Constellations.java
│ ├── CosmicObject.java
│ ├── CosmicObjectType.java
│ ├── Earth.java
│ ├── Firmament.java
│ ├── Moon.java
│ └── Sun.java
│ ├── Lab3_prog.iml
│ ├── Main.java
│ ├── Sky
│ └── Sky.java
│ ├── actions
│ ├── Lightable.java
│ ├── Reflectable.java
│ └── Viewable.java
│ └── characters
│ ├── Fuksy.java
│ ├── Human.java
│ ├── ProfessorZvizdochkin.java
│ ├── Seledochka.java
│ └── Znaika.java
├── lab4
├── ALL_Theory_Is_HERE
├── Theory
│ ├── Classes.png
│ ├── Classes_theory.puml
│ ├── bAnonymous.png
│ ├── bLocal.png
│ └── bNested.png
├── UML.png
├── UML.puml
├── lab4.iml
└── src
│ ├── Colors
│ └── Color.java
│ ├── CosmicObjects
│ ├── Constellations.java
│ ├── CosmicBeam.java
│ ├── CosmicObject.java
│ ├── CosmicObjectType.java
│ ├── Earth.java
│ ├── Firmament.java
│ ├── Moon.java
│ └── Sun.java
│ ├── Exceptions
│ ├── SoundException.java
│ └── WeightException.java
│ ├── Humans
│ ├── Astronauts.java
│ └── Human.java
│ ├── Instruments
│ ├── GeoHammer.java
│ ├── IceAxe.java
│ └── Instruments.java
│ ├── Interfaces
│ ├── Affect.java
│ ├── Imagine.java
│ ├── Lightable.java
│ ├── Reflectable.java
│ ├── Shine.java
│ ├── Sound.java
│ └── Viewable.java
│ ├── Main.java
│ ├── Ore
│ ├── AntiLunit.java
│ ├── Lunit.java
│ └── Ore.java
│ ├── PlanetObjects
│ ├── Cave.java
│ ├── Mountains.java
│ ├── PlanetObject.java
│ ├── Rocket.java
│ └── SpaceSuit.java
│ └── Sky
│ └── Sky.java
├── lab5
├── .bash_profile
├── Questions
├── README.md
├── UML.png
├── commons-csv-1.6.jar
├── data.csv
├── dataBackup.csv
├── lab5.iml
├── lab5.jar
├── reports
│ ├── report.docx
│ └── report.pdf
├── script1.txt
├── script2.txt
├── script3.txv
├── src
│ ├── META-INF
│ │ └── MANIFEST.MF
│ ├── Main.java
│ ├── README.md
│ ├── collection
│ │ ├── City
│ │ │ ├── City.java
│ │ │ ├── Climate.java
│ │ │ ├── Coordinates.java
│ │ │ ├── Government.java
│ │ │ ├── Human.java
│ │ │ └── StandardOfLiving.java
│ │ └── comparators
│ │ │ ├── CityComparator.java
│ │ │ └── CityComparatorByMetersAboveSeaLevel.java
│ ├── collectionManagers
│ │ ├── CSVManager.java
│ │ ├── CityManager.java
│ │ ├── CollectionManager.java
│ │ ├── FileManager.java
│ │ ├── IdManager.java
│ │ ├── modeManagers
│ │ │ ├── ModeManager.java
│ │ │ ├── nonUserMode
│ │ │ │ └── CityNonUserManager.java
│ │ │ └── userMode
│ │ │ │ ├── CityCLIManager.java
│ │ │ │ ├── ClimateCLIManager.java
│ │ │ │ ├── CoordinatesCLIManager.java
│ │ │ │ ├── EnumRequester.java
│ │ │ │ ├── GovernmentCLIManager.java
│ │ │ │ ├── HumanCLIManager.java
│ │ │ │ └── StandardOfLivingCLIManager.java
│ │ └── validators
│ │ │ ├── AreaValidator.java
│ │ │ ├── CityValidator.java
│ │ │ ├── CoordinateXValidator.java
│ │ │ ├── CoordinateYValidator.java
│ │ │ ├── InputValidator.java
│ │ │ ├── MetersAboveSeaLevelValidator.java
│ │ │ ├── NameValidator.java
│ │ │ ├── PopulationValidator.java
│ │ │ └── Validator.java
│ ├── commandManagers
│ │ ├── Command.java
│ │ ├── CommandExecutor.java
│ │ ├── CommandInterface.java
│ │ ├── CommandManager.java
│ │ ├── CommandMode.java
│ │ └── commands
│ │ │ ├── Add.java
│ │ │ ├── AddIfMin.java
│ │ │ ├── Clear.java
│ │ │ ├── ExecuteScript.java
│ │ │ ├── Exit.java
│ │ │ ├── Help.java
│ │ │ ├── History.java
│ │ │ ├── Info.java
│ │ │ ├── PrintDescending.java
│ │ │ ├── PrintFieldDescendingMetersAboveSeaLevel.java
│ │ │ ├── RemoveById.java
│ │ │ ├── RemoveGreater.java
│ │ │ ├── Save.java
│ │ │ ├── Show.java
│ │ │ ├── SumOfMetersAboveSeaLevel.java
│ │ │ └── UpdateId.java
│ └── exceptions
│ │ ├── BuildObjectException.java
│ │ ├── CommandInterruptedException.java
│ │ └── UnknownCommandException.java
└── test_script
├── lab6
├── .gitignore
├── README.md
├── build.gradle
├── client
│ ├── build.gradle
│ └── src
│ │ ├── META-INF
│ │ └── MANIFEST.MF
│ │ ├── commandManager
│ │ ├── CommandDescriptionHolder.java
│ │ ├── CommandExecutor.java
│ │ ├── CommandLoaderUtility.java
│ │ ├── CommandMode.java
│ │ └── externalRecievers
│ │ │ ├── ArgumentCityCommandReceiver.java
│ │ │ ├── ExecuteScriptReceiver.java
│ │ │ ├── ExitReceiver.java
│ │ │ └── NonArgumentReceiver.java
│ │ ├── exceptions
│ │ ├── BuildObjectException.java
│ │ ├── CommandInterruptedException.java
│ │ ├── CommandsNotLoadedException.java
│ │ ├── ServerNotAvailableException.java
│ │ ├── StreamInterruptedException.java
│ │ ├── UnknownCommandException.java
│ │ ├── UnsupportedResponseException.java
│ │ └── WrongAmountOfArgumentsException.java
│ │ ├── main
│ │ ├── Main.java
│ │ ├── Utilities.java
│ │ └── resources
│ │ │ └── log4j2.xml
│ │ ├── models
│ │ ├── handlers
│ │ │ ├── ModeManager.java
│ │ │ ├── nonUserMode
│ │ │ │ └── CityNonUserManager.java
│ │ │ └── userMode
│ │ │ │ ├── CityCLIManager.java
│ │ │ │ ├── ClimateCLIManager.java
│ │ │ │ ├── CoordinatesCLIManager.java
│ │ │ │ ├── EnumRequester.java
│ │ │ │ ├── GovernmentCLIManager.java
│ │ │ │ ├── HumanCLIManager.java
│ │ │ │ └── StandardOfLivingCLIManager.java
│ │ └── validators
│ │ │ ├── AreaValidator.java
│ │ │ ├── CityValidator.java
│ │ │ ├── CoordinateXValidator.java
│ │ │ ├── CoordinateYValidator.java
│ │ │ ├── InputValidator.java
│ │ │ ├── MetersAboveSeaLevelValidator.java
│ │ │ ├── NameValidator.java
│ │ │ ├── PopulationValidator.java
│ │ │ └── Validator.java
│ │ ├── requestLogic
│ │ └── requestSenders
│ │ │ ├── ArgumentRequestSender.java
│ │ │ ├── CommandDescriptionsRequestSender.java
│ │ │ ├── CommandRequestSender.java
│ │ │ └── RequestSender.java
│ │ ├── responseLogic
│ │ └── ResponseReader.java
│ │ └── serverLogic
│ │ ├── ServerConnection.java
│ │ ├── ServerConnectionFactory.java
│ │ ├── ServerConnectionHandler.java
│ │ ├── UdpConnectionBlockDecorator.java
│ │ ├── UdpServerConnection.java
│ │ └── UdpServerConnectionFactory.java
├── docs
│ ├── report.docx
│ └── report.pdf
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── server
│ ├── build.gradle
│ └── src
│ │ ├── clientLogic
│ │ └── ClientHandler.java
│ │ ├── collectionStorageManager
│ │ ├── CSVManager.java
│ │ └── FileManager.java
│ │ ├── commandManager
│ │ ├── CommandExporter.java
│ │ ├── CommandManager.java
│ │ ├── ServerCommandManager.java
│ │ └── commands
│ │ │ ├── AddCommand.java
│ │ │ ├── AddIfMinCommand.java
│ │ │ ├── ArgumentConsumer.java
│ │ │ ├── BaseCommand.java
│ │ │ ├── ClearCommand.java
│ │ │ ├── ExecuteScriptCommand.java
│ │ │ ├── ExitCommand.java
│ │ │ ├── HelpCommand.java
│ │ │ ├── HistoryCommand.java
│ │ │ ├── InfoCommand.java
│ │ │ ├── PrintDescendingCommand.java
│ │ │ ├── PrintFieldDescendingMetersAboveSeaLevelCommand.java
│ │ │ ├── RemoveByIdCommand.java
│ │ │ ├── RemoveGreaterCommand.java
│ │ │ ├── SaveCommand.java
│ │ │ ├── ShowCommand.java
│ │ │ ├── SumOfMetersAboveSeaLevelCommand.java
│ │ │ └── UpdateCommand.java
│ │ ├── exceptions
│ │ ├── InvalidRequestException.java
│ │ ├── NotAvailableException.java
│ │ ├── UnknownCommandException.java
│ │ └── UnsupportedRequestException.java
│ │ ├── main
│ │ ├── Main.java
│ │ └── resources
│ │ │ └── log4j2.xml
│ │ ├── models
│ │ ├── comparators
│ │ │ ├── CityComparator.java
│ │ │ └── CityComparatorByMetersAboveSeaLevel.java
│ │ └── handlers
│ │ │ ├── CityHandler.java
│ │ │ ├── CityIDHandler.java
│ │ │ └── CollectionHandler.java
│ │ ├── requestLogic
│ │ ├── CallerBack.java
│ │ ├── RequestReader.java
│ │ ├── StatusRequest.java
│ │ ├── StatusRequestBuilder.java
│ │ ├── requestWorkers
│ │ │ ├── ArgumentCommandClientRequestWorker.java
│ │ │ ├── BaseRequestWorker.java
│ │ │ ├── CommandClientRequestWorker.java
│ │ │ ├── CommandConfigureRequestWorker.java
│ │ │ ├── RequestWorker.java
│ │ │ └── RequestWorkerManager.java
│ │ └── requests
│ │ │ └── ServerRequest.java
│ │ ├── responseLogic
│ │ └── responseSenders
│ │ │ ├── CommandConfigureResponseSender.java
│ │ │ ├── CommandResponseSender.java
│ │ │ └── ResponseSender.java
│ │ └── serverLogic
│ │ ├── DatagramServerConnection.java
│ │ ├── DatagramServerConnectionFactory.java
│ │ ├── ServerConnection.java
│ │ └── ServerConnectionFactory.java
├── settings.gradle
└── shared
│ ├── build.gradle
│ └── src
│ ├── commandLogic
│ ├── CommandDescription.java
│ └── commandReceiverLogic
│ │ ├── ReceiverManager.java
│ │ ├── callers
│ │ ├── ExternalArgumentReceiverCaller.java
│ │ ├── ExternalBaseReceiverCaller.java
│ │ └── ExternalCaller.java
│ │ ├── enums
│ │ └── ReceiverType.java
│ │ ├── handlers
│ │ ├── ArgumentReceiverHandler.java
│ │ ├── NonArgReceiversHandler.java
│ │ └── ReceiverHandler.java
│ │ └── receivers
│ │ ├── ExternalArgumentReceiver.java
│ │ └── ExternalBaseReceiver.java
│ ├── main
│ └── Main.java
│ ├── models
│ ├── City.java
│ ├── Climate.java
│ ├── Coordinates.java
│ ├── Government.java
│ ├── Human.java
│ └── StandardOfLiving.java
│ ├── requests
│ ├── ArgumentCommandClientRequest.java
│ ├── BaseRequest.java
│ ├── CommandClientRequest.java
│ └── CommandDescriptionsRequest.java
│ └── responses
│ ├── BaseResponse.java
│ ├── CommandDescriptionsResponse.java
│ ├── CommandStatusResponse.java
│ └── ErrorResponse.java
├── lab7
├── .gitignore
├── README.md
├── build.gradle
├── client
│ ├── build.gradle
│ ├── client_logs.log
│ └── src
│ │ ├── META-INF
│ │ └── MANIFEST.MF
│ │ ├── client
│ │ └── Client.java
│ │ ├── commandManager
│ │ ├── CommandDescriptionHolder.java
│ │ ├── CommandExecutor.java
│ │ ├── CommandLoaderUtility.java
│ │ ├── CommandMode.java
│ │ └── externalRecievers
│ │ │ ├── ArgumentCityCommandReceiver.java
│ │ │ ├── ExecuteScriptReceiver.java
│ │ │ ├── ExitReceiver.java
│ │ │ └── NonArgumentReceiver.java
│ │ ├── exceptions
│ │ ├── BuildObjectException.java
│ │ ├── CommandInterruptedException.java
│ │ ├── CommandsNotLoadedException.java
│ │ ├── ServerNotAvailableException.java
│ │ ├── StreamInterruptedException.java
│ │ ├── UnknownCommandException.java
│ │ ├── UnsupportedResponseException.java
│ │ └── WrongAmountOfArgumentsException.java
│ │ ├── main
│ │ ├── Main.java
│ │ ├── Utilities.java
│ │ └── resources
│ │ │ └── log4j2.xml
│ │ ├── models
│ │ ├── handlers
│ │ │ ├── ModeManager.java
│ │ │ ├── nonUserMode
│ │ │ │ └── CityNonUserManager.java
│ │ │ └── userMode
│ │ │ │ ├── CityCLIManager.java
│ │ │ │ ├── ClimateCLIManager.java
│ │ │ │ ├── CoordinatesCLIManager.java
│ │ │ │ ├── EnumRequester.java
│ │ │ │ ├── GovernmentCLIManager.java
│ │ │ │ ├── HumanCLIManager.java
│ │ │ │ └── StandardOfLivingCLIManager.java
│ │ └── validators
│ │ │ ├── AreaValidator.java
│ │ │ ├── CityValidator.java
│ │ │ ├── CoordinateXValidator.java
│ │ │ ├── CoordinateYValidator.java
│ │ │ ├── InputValidator.java
│ │ │ ├── MetersAboveSeaLevelValidator.java
│ │ │ ├── NameValidator.java
│ │ │ ├── PopulationValidator.java
│ │ │ └── Validator.java
│ │ ├── requestLogic
│ │ └── requestSenders
│ │ │ ├── ArgumentRequestSender.java
│ │ │ ├── AuthRequestSender.java
│ │ │ ├── CommandDescriptionsRequestSender.java
│ │ │ ├── CommandRequestSender.java
│ │ │ ├── RegRequestSender.java
│ │ │ └── RequestSender.java
│ │ ├── responseLogic
│ │ └── ResponseReader.java
│ │ └── serverLogic
│ │ ├── ServerConnection.java
│ │ ├── ServerConnectionFactory.java
│ │ ├── ServerConnectionHandler.java
│ │ ├── UdpConnectionBlockDecorator.java
│ │ ├── UdpServerConnection.java
│ │ └── UdpServerConnectionFactory.java
├── database
│ ├── Database.drawio
│ ├── Database.drawio.png
│ ├── PostgreSQL_model.sql
│ └── scripts.sql
├── docs
│ ├── report.docx
│ └── report.pdf
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── server
│ ├── build.gradle
│ └── src
│ │ ├── clientLogic
│ │ ├── ClientHandler.java
│ │ └── PasswordHandler.java
│ │ ├── collectionStorageManager
│ │ ├── CSVManager.java
│ │ ├── DatabaseManager.java
│ │ ├── FileManager.java
│ │ └── PostgreSQLManager.java
│ │ ├── commandManager
│ │ ├── CommandExporter.java
│ │ ├── CommandManager.java
│ │ ├── ServerCommandManager.java
│ │ └── commands
│ │ │ ├── AddCommand.java
│ │ │ ├── AddIfMinCommand.java
│ │ │ ├── ArgumentConsumer.java
│ │ │ ├── BaseCommand.java
│ │ │ ├── ClearCommand.java
│ │ │ ├── ExecuteScriptCommand.java
│ │ │ ├── ExitCommand.java
│ │ │ ├── HelpCommand.java
│ │ │ ├── HistoryCommand.java
│ │ │ ├── InfoCommand.java
│ │ │ ├── PrintDescendingCommand.java
│ │ │ ├── PrintFieldDescendingMetersAboveSeaLevelCommand.java
│ │ │ ├── RemoveByIdCommand.java
│ │ │ ├── RemoveGreaterCommand.java
│ │ │ ├── SaveCommand.java
│ │ │ ├── ShowCommand.java
│ │ │ ├── SumOfMetersAboveSeaLevelCommand.java
│ │ │ └── UpdateCommand.java
│ │ ├── exceptions
│ │ ├── InvalidRequestException.java
│ │ ├── NotAvailableException.java
│ │ ├── UnknownCommandException.java
│ │ ├── UnsupportedRequestException.java
│ │ └── UserNotAuthenticatedException.java
│ │ ├── main
│ │ ├── Main.java
│ │ └── resources
│ │ │ ├── db.cfg
│ │ │ └── log4j2.xml
│ │ ├── models
│ │ ├── comparators
│ │ │ ├── CityComparator.java
│ │ │ └── CityComparatorByMetersAboveSeaLevel.java
│ │ └── handlers
│ │ │ ├── CityHandler.java
│ │ │ ├── CityIDHandler.java
│ │ │ └── CollectionHandler.java
│ │ ├── multithreading
│ │ └── MultithreadingManager.java
│ │ ├── requestLogic
│ │ ├── CallerBack.java
│ │ ├── RequestReader.java
│ │ ├── StatusRequest.java
│ │ ├── StatusRequestBuilder.java
│ │ ├── requestWorkers
│ │ │ ├── ArgumentCommandClientRequestWorker.java
│ │ │ ├── AuthWorker.java
│ │ │ ├── BaseRequestWorker.java
│ │ │ ├── CommandClientRequestWorker.java
│ │ │ ├── CommandConfigureRequestWorker.java
│ │ │ ├── RegWorker.java
│ │ │ ├── RequestWorker.java
│ │ │ └── RequestWorkerManager.java
│ │ └── requests
│ │ │ └── ServerRequest.java
│ │ ├── responseLogic
│ │ └── responseSenders
│ │ │ ├── CommandConfigureResponseSender.java
│ │ │ ├── CommandResponseSender.java
│ │ │ └── ResponseSender.java
│ │ └── serverLogic
│ │ ├── DatagramServerConnection.java
│ │ ├── DatagramServerConnectionFactory.java
│ │ ├── ServerConnection.java
│ │ └── ServerConnectionFactory.java
├── settings.gradle
└── shared
│ ├── build.gradle
│ └── src
│ ├── commandLogic
│ ├── CommandDescription.java
│ └── commandReceiverLogic
│ │ ├── ReceiverManager.java
│ │ ├── callers
│ │ ├── ExternalArgumentReceiverCaller.java
│ │ ├── ExternalBaseReceiverCaller.java
│ │ └── ExternalCaller.java
│ │ ├── enums
│ │ └── ReceiverType.java
│ │ ├── handlers
│ │ ├── ArgumentReceiverHandler.java
│ │ ├── NonArgReceiversHandler.java
│ │ └── ReceiverHandler.java
│ │ └── receivers
│ │ ├── ExternalArgumentReceiver.java
│ │ └── ExternalBaseReceiver.java
│ ├── main
│ └── Main.java
│ ├── models
│ ├── City.java
│ ├── Climate.java
│ ├── Coordinates.java
│ ├── Government.java
│ ├── Human.java
│ └── StandardOfLiving.java
│ ├── requests
│ ├── ArgumentCommandClientRequest.java
│ ├── AuthRequest.java
│ ├── BaseRequest.java
│ ├── CommandClientRequest.java
│ ├── CommandDescriptionsRequest.java
│ └── RegRequest.java
│ └── responses
│ ├── AuthResponse.java
│ ├── BaseResponse.java
│ ├── CommandDescriptionsResponse.java
│ ├── CommandStatusResponse.java
│ ├── ErrorResponse.java
│ └── RegResponse.java
├── lab8
├── .gitignore
├── README.html
├── README.md
├── README.pdf
├── README.png
├── build.gradle
├── client
│ ├── build.gradle
│ ├── client_logs.log
│ └── src
│ │ ├── META-INF
│ │ └── MANIFEST.MF
│ │ ├── client
│ │ ├── Client.java
│ │ └── DataHolder.java
│ │ ├── commandManager
│ │ ├── CommandDescriptionHolder.java
│ │ ├── CommandExecutor.java
│ │ ├── CommandLoaderUtility.java
│ │ ├── CommandMode.java
│ │ ├── SingleCommandExecutor.java
│ │ └── externalRecievers
│ │ │ ├── ArgumentCityCommandReceiver.java
│ │ │ ├── ExecuteScriptReceiver.java
│ │ │ ├── ExitReceiver.java
│ │ │ ├── NonArgumentReceiver.java
│ │ │ └── NonArgumentShowReceiver.java
│ │ ├── exceptions
│ │ ├── BuildObjectException.java
│ │ ├── CommandInterruptedException.java
│ │ ├── CommandsNotLoadedException.java
│ │ ├── ServerNotAvailableException.java
│ │ ├── StreamInterruptedException.java
│ │ ├── UnknownCommandException.java
│ │ ├── UnsupportedResponseException.java
│ │ └── WrongAmountOfArgumentsException.java
│ │ ├── gui
│ │ ├── AlertUtility.java
│ │ ├── LocalizationUtility.java
│ │ ├── Main.java
│ │ ├── UTF8Control.java
│ │ ├── collections
│ │ │ ├── CollectionsWindow.java
│ │ │ └── CollectionsWindowController.java
│ │ ├── commands
│ │ │ ├── CommandsWindow.java
│ │ │ └── CommandsWindowController.java
│ │ ├── create
│ │ │ ├── CityManagementWindow.java
│ │ │ └── CityManagementWindowController.java
│ │ ├── edit
│ │ │ ├── EditWindow.java
│ │ │ └── EditWindowController.java
│ │ ├── login
│ │ │ ├── LoginWindow.java
│ │ │ └── LoginWindowController.java
│ │ ├── music
│ │ │ ├── MusicWindow.java
│ │ │ └── MusicWindowController.java
│ │ ├── visualization
│ │ │ ├── VisualizationWindow.java
│ │ │ └── VisualizationWindowController.java
│ │ └── worldMap
│ │ │ └── WorldMapWindow.java
│ │ ├── main
│ │ ├── Main.java
│ │ ├── resources
│ │ │ ├── MessagesBundle_cs.properties
│ │ │ ├── MessagesBundle_en_NZ.properties
│ │ │ ├── MessagesBundle_hr.properties
│ │ │ ├── MessagesBundle_ru.properties
│ │ │ ├── collections
│ │ │ │ ├── collectionsWindow.fxml
│ │ │ │ └── style.css
│ │ │ ├── commands
│ │ │ │ ├── commandsWindow.fxml
│ │ │ │ └── style.css
│ │ │ ├── create
│ │ │ │ ├── createWindow.fxml
│ │ │ │ └── style.css
│ │ │ ├── edit
│ │ │ │ ├── editWindow.fxml
│ │ │ │ └── style.css
│ │ │ ├── fonts
│ │ │ │ ├── YouSheBiaoTiHei Regular.ttf
│ │ │ │ └── ZCOOLXiaoWei-Regular.ttf
│ │ │ ├── icons
│ │ │ │ ├── building.png
│ │ │ │ ├── city.png
│ │ │ │ ├── city2.png
│ │ │ │ ├── geo.png
│ │ │ │ ├── location-pin.png
│ │ │ │ ├── map.png
│ │ │ │ ├── pointer.png
│ │ │ │ ├── spotify (1).png
│ │ │ │ ├── spotify (2).png
│ │ │ │ ├── spotify.png
│ │ │ │ ├── spotify2.png
│ │ │ │ ├── spotify3.png
│ │ │ │ ├── svg
│ │ │ │ │ ├── icon_0.svg
│ │ │ │ │ ├── icon_1.svg
│ │ │ │ │ ├── icon_10.svg
│ │ │ │ │ ├── icon_11.svg
│ │ │ │ │ ├── icon_12.svg
│ │ │ │ │ ├── icon_13.svg
│ │ │ │ │ ├── icon_14.svg
│ │ │ │ │ ├── icon_15.svg
│ │ │ │ │ ├── icon_16.svg
│ │ │ │ │ ├── icon_17.svg
│ │ │ │ │ ├── icon_18.svg
│ │ │ │ │ ├── icon_19.svg
│ │ │ │ │ ├── icon_2.svg
│ │ │ │ │ ├── icon_20.svg
│ │ │ │ │ ├── icon_21.svg
│ │ │ │ │ ├── icon_22.svg
│ │ │ │ │ ├── icon_23.svg
│ │ │ │ │ ├── icon_24.svg
│ │ │ │ │ ├── icon_25.svg
│ │ │ │ │ ├── icon_26.svg
│ │ │ │ │ ├── icon_27.svg
│ │ │ │ │ ├── icon_28.svg
│ │ │ │ │ ├── icon_29.svg
│ │ │ │ │ ├── icon_3.svg
│ │ │ │ │ ├── icon_30.svg
│ │ │ │ │ ├── icon_31.svg
│ │ │ │ │ ├── icon_32.svg
│ │ │ │ │ ├── icon_33.svg
│ │ │ │ │ ├── icon_34.svg
│ │ │ │ │ ├── icon_35.svg
│ │ │ │ │ ├── icon_36.svg
│ │ │ │ │ ├── icon_4.svg
│ │ │ │ │ ├── icon_5.svg
│ │ │ │ │ └── main.png
│ │ │ │ └── thick_building.png
│ │ │ ├── log4j2.xml
│ │ │ ├── login
│ │ │ │ ├── loginWindow.fxml
│ │ │ │ └── style.css
│ │ │ ├── music
│ │ │ │ ├── Sigrid - It Gets Dark.mp3
│ │ │ │ ├── ruesellamusicnet_Falling_In_Reverse_-_Voices_In_My_Head_74364895.mp3
│ │ │ │ ├── ruesellamusicnet_Normandie_-_Ecstasy_63646428.mp3
│ │ │ │ ├── ruesellamusicnet_Normandie_-_White_Flag_60279007.mp3
│ │ │ │ ├── ruesellamusicnet_We_Are_The_Empty_-_Alone_in_the_Snow_47893460.mp3
│ │ │ │ ├── ruesellamusicnet_We_Are_The_Empty_-_Antidote_62786624.mp3
│ │ │ │ ├── ruesellamusicnet_We_Are_The_Empty_-_Beyond_Empty_67152992.mp3
│ │ │ │ └── ruesellamusicnet_We_Are_The_Empty_-_Robots_75606020.mp3
│ │ │ ├── pics
│ │ │ │ └── img.png
│ │ │ ├── scripts
│ │ │ │ ├── alex_script.txt
│ │ │ │ └── worthant_script.txt
│ │ │ ├── visualization
│ │ │ │ ├── style.css
│ │ │ │ └── visualizationWindow.fxml
│ │ │ └── worldMap
│ │ │ │ ├── data.json
│ │ │ │ ├── icon_sprites.js
│ │ │ │ ├── map.html
│ │ │ │ ├── map.js
│ │ │ │ ├── object_manager.html
│ │ │ │ └── object_manager.js
│ │ └── utilities
│ │ │ ├── FilesRenamer.java
│ │ │ ├── GeoJSONGenerator.java
│ │ │ └── Utilities.java
│ │ ├── models
│ │ ├── handlers
│ │ │ ├── ModeManager.java
│ │ │ ├── guiMode
│ │ │ │ └── GUIManager.java
│ │ │ ├── nonUserMode
│ │ │ │ └── CityNonUserManager.java
│ │ │ └── userMode
│ │ │ │ ├── CityCLIManager.java
│ │ │ │ ├── ClimateCLIManager.java
│ │ │ │ ├── CoordinatesCLIManager.java
│ │ │ │ ├── EnumRequester.java
│ │ │ │ ├── GovernmentCLIManager.java
│ │ │ │ ├── HumanCLIManager.java
│ │ │ │ └── StandardOfLivingCLIManager.java
│ │ └── validators
│ │ │ ├── AreaValidator.java
│ │ │ ├── CityValidator.java
│ │ │ ├── CoordinateXValidator.java
│ │ │ ├── CoordinateYValidator.java
│ │ │ ├── InputValidator.java
│ │ │ ├── MetersAboveSeaLevelValidator.java
│ │ │ ├── NameValidator.java
│ │ │ ├── PopulationValidator.java
│ │ │ └── Validator.java
│ │ ├── requestLogic
│ │ └── requestSenders
│ │ │ ├── ArgumentRequestSender.java
│ │ │ ├── AuthRequestSender.java
│ │ │ ├── CommandDescriptionsRequestSender.java
│ │ │ ├── CommandRequestSender.java
│ │ │ ├── GetOwnershipRequestSender.java
│ │ │ ├── RegRequestSender.java
│ │ │ ├── RequestSender.java
│ │ │ └── ShowRequestSender.java
│ │ ├── responseLogic
│ │ └── ResponseReader.java
│ │ └── serverLogic
│ │ ├── ServerConnection.java
│ │ ├── ServerConnectionFactory.java
│ │ ├── ServerConnectionHandler.java
│ │ ├── UdpConnectionBlockDecorator.java
│ │ ├── UdpServerConnection.java
│ │ └── UdpServerConnectionFactory.java
├── database
│ ├── Database.drawio
│ ├── Database.drawio.png
│ ├── PostgreSQL_model.sql
│ └── scripts.sql
├── docs
│ ├── CollectionsWindowController.java
│ ├── VisualizationWindow.java
│ ├── map.html
│ ├── report.docx
│ └── report.pdf
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── server
│ ├── build.gradle
│ └── src
│ │ ├── clientLogic
│ │ ├── ClientHandler.java
│ │ └── PasswordHandler.java
│ │ ├── collectionStorageManager
│ │ ├── CSVManager.java
│ │ ├── DatabaseManager.java
│ │ ├── FileManager.java
│ │ └── PostgreSQLManager.java
│ │ ├── commandManager
│ │ ├── CommandExporter.java
│ │ ├── CommandManager.java
│ │ ├── ServerCommandManager.java
│ │ └── commands
│ │ │ ├── AddCommand.java
│ │ │ ├── AddIfMinCommand.java
│ │ │ ├── ArgumentConsumer.java
│ │ │ ├── BaseCommand.java
│ │ │ ├── ClearCommand.java
│ │ │ ├── ExecuteScriptCommand.java
│ │ │ ├── ExitCommand.java
│ │ │ ├── GetOwnershipCommand.java
│ │ │ ├── HelpCommand.java
│ │ │ ├── HistoryCommand.java
│ │ │ ├── InfoCommand.java
│ │ │ ├── PrintDescendingCommand.java
│ │ │ ├── PrintFieldDescendingMetersAboveSeaLevelCommand.java
│ │ │ ├── RemoveByIdCommand.java
│ │ │ ├── RemoveGreaterCommand.java
│ │ │ ├── SaveCommand.java
│ │ │ ├── ShowCommand.java
│ │ │ ├── SumOfMetersAboveSeaLevelCommand.java
│ │ │ └── UpdateCommand.java
│ │ ├── exceptions
│ │ ├── InvalidRequestException.java
│ │ ├── NotAvailableException.java
│ │ ├── UnknownCommandException.java
│ │ ├── UnsupportedRequestException.java
│ │ └── UserNotAuthenticatedException.java
│ │ ├── main
│ │ ├── ConnectionUtility.java
│ │ ├── Main.java
│ │ └── resources
│ │ │ ├── db.cfg
│ │ │ └── log4j2.xml
│ │ ├── models
│ │ ├── comparators
│ │ │ ├── CityComparator.java
│ │ │ └── CityComparatorByMetersAboveSeaLevel.java
│ │ └── handlers
│ │ │ ├── CityHandler.java
│ │ │ ├── CityIDHandler.java
│ │ │ └── CollectionHandler.java
│ │ ├── multithreading
│ │ └── MultithreadingManager.java
│ │ ├── requestLogic
│ │ ├── CallerBack.java
│ │ ├── RequestReader.java
│ │ ├── StatusRequest.java
│ │ ├── StatusRequestBuilder.java
│ │ ├── requestWorkers
│ │ │ ├── ArgumentCommandClientRequestWorker.java
│ │ │ ├── AuthWorker.java
│ │ │ ├── BaseRequestWorker.java
│ │ │ ├── CommandClientRequestWorker.java
│ │ │ ├── CommandConfigureRequestWorker.java
│ │ │ ├── RegWorker.java
│ │ │ ├── RequestWorker.java
│ │ │ └── RequestWorkerManager.java
│ │ └── requests
│ │ │ └── ServerRequest.java
│ │ ├── responseLogic
│ │ └── responseSenders
│ │ │ ├── CommandConfigureResponseSender.java
│ │ │ ├── CommandResponseSender.java
│ │ │ └── ResponseSender.java
│ │ └── serverLogic
│ │ ├── DatagramServerConnection.java
│ │ ├── DatagramServerConnectionFactory.java
│ │ ├── ServerConnection.java
│ │ └── ServerConnectionFactory.java
├── settings.gradle
└── shared
│ ├── build.gradle
│ └── src
│ ├── commandLogic
│ ├── CommandDescription.java
│ └── commandReceiverLogic
│ │ ├── ReceiverManager.java
│ │ ├── callers
│ │ ├── ExternalArgumentReceiverCaller.java
│ │ ├── ExternalBaseReceiverCaller.java
│ │ └── ExternalCaller.java
│ │ ├── enums
│ │ └── ReceiverType.java
│ │ ├── handlers
│ │ ├── ArgumentReceiverHandler.java
│ │ ├── NonArgReceiversHandler.java
│ │ └── ReceiverHandler.java
│ │ └── receivers
│ │ ├── ExternalArgumentReceiver.java
│ │ └── ExternalBaseReceiver.java
│ ├── main
│ └── Main.java
│ ├── models
│ ├── City.java
│ ├── Climate.java
│ ├── Coordinates.java
│ ├── Government.java
│ ├── Human.java
│ ├── StandardOfLiving.java
│ └── comparators
│ │ ├── CityComparator.java
│ │ └── CityComparatorByMetersAboveSeaLevel.java
│ ├── requests
│ ├── ArgumentCommandClientRequest.java
│ ├── AuthRequest.java
│ ├── BaseRequest.java
│ ├── CommandClientRequest.java
│ ├── CommandDescriptionsRequest.java
│ └── RegRequest.java
│ └── responses
│ ├── AuthResponse.java
│ ├── BaseResponse.java
│ ├── CommandDescriptionsResponse.java
│ ├── CommandStatusResponse.java
│ ├── ErrorResponse.java
│ ├── GetOwnershipResponse.java
│ ├── RegResponse.java
│ └── ShowResponse.java
└── plan.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | books/ filter=lfs diff=lfs merge=lfs -text
2 | *books/ filter=lfs diff=lfs merge=lfs -text
3 | books/* filter=lfs diff=lfs merge=lfs -text
4 | *.pdf filter=lfs diff=lfs merge=lfs -text
5 | *books.pdf filter=lfs diff=lfs merge=lfs -text
6 | *books/*.pdf filter=lfs diff=lfs merge=lfs -text
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Java_labs.iml
2 | .idea
3 | out
--------------------------------------------------------------------------------
/books/Khorstmann_Key_Java_Biblioteka_professionala_Tom_1_Osnovy_11_e_izdanie.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:101967cf144a620b66b39113892096d261371be4c9581d89131c8b8891dc3e18
3 | size 83772309
4 |
--------------------------------------------------------------------------------
/books/Patterny_obektno-orientirovannogo_proektirovania_2020.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:ecd4330f8fb4aeedc369931ff4940d9ccca56ae2fb40e4b2bc2223225145425f
3 | size 6674471
4 |
--------------------------------------------------------------------------------
/commandsToRemember:
--------------------------------------------------------------------------------
1 | 1) alt + f12 -> remapped to alt+t #terminal in intellijidea for not wasting my time on normal console
2 | 2) alt + insert -> remapped to alt+g #generate code
--------------------------------------------------------------------------------
/docs/guides/lab5_guide1.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:30c8b0bdfdfd665b6c49cfe1c084822f943eb3ae570e656d2f283459b0f9c9ca
3 | size 562099
4 |
--------------------------------------------------------------------------------
/docs/lectures/1st_wrappers_generics_collections_sorting.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:9edbefb5a54617fa94272cf4226ad522162d7a4e66f00f0f7696da3696c6956f
3 | size 1671898
4 |
--------------------------------------------------------------------------------
/docs/lectures/2nd_in-out_patterns.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:39c39f025019a9a69017eee0ab87a9fa4c0acf427e131b53681a5e5ded15115d
3 | size 2275599
4 |
--------------------------------------------------------------------------------
/docs/lectures/3rd_client-server_lambdas_streamAPI.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:16de51e688a21117315a2c82419ed4ee2b17604bd7969424eda304bf881dffbd
3 | size 1794657
4 |
--------------------------------------------------------------------------------
/docs/lectures/4th_databases.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:cf2dfc21fd967f8192261c41da0c9872e069892baab414e3156cbc989923fa4c
3 | size 1583572
4 |
--------------------------------------------------------------------------------
/docs/lectures/5th_sameAs4th.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:b34ae9a37188aa56d4f2601c8ecb0a1d94fce38d1cd3be9e46315f18cb710dba
3 | size 1010240
4 |
--------------------------------------------------------------------------------
/docs/lectures/6th_patterns.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:1fbf5126210bade516ce664215f16dba18b5b8a41aeef008b3d24aea43702334
3 | size 3643985
4 |
--------------------------------------------------------------------------------
/docs/lectures/7th_GUI.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:328a217bd233eec9eb338030090d05190d76d3b59b74b0e739e0910f4d44fbd7
3 | size 1228883
4 |
--------------------------------------------------------------------------------
/lab1/Dvorkin_Boris_P3131_Lab1_prog.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab1/Dvorkin_Boris_P3131_Lab1_prog.docx
--------------------------------------------------------------------------------
/lab1/Lab1_prog.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab1/Lab1_prog.docx
--------------------------------------------------------------------------------
/lab1/lab1.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lab1/lab_1.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lab1/src/arecent.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 | class Solution {
3 | public static void main(String args[]) {
4 | // int[] nums = {3, 2, 4};
5 | // switch (nums[0]) {
6 | // case 1:
7 | // case 2:
8 | // System.out.println("Good!");
9 | // break;
10 | // default:
11 | // System.out.println("Lol, bad");
12 | // break;
13 | // }
14 | int a = 2;
15 | int b = 0;
16 | b = b + (a++);
17 | b = b + (++a);
18 | }
19 | }
--------------------------------------------------------------------------------
/lab2/Lab2_prog.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab2/Lab2_prog.docx
--------------------------------------------------------------------------------
/lab2/Lab2_prog.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lab2/Pokemon.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab2/Pokemon.jar
--------------------------------------------------------------------------------
/lab2/UML_diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab2/UML_diagram.png
--------------------------------------------------------------------------------
/lab2/lab2.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lab2/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: Main
3 |
4 |
--------------------------------------------------------------------------------
/lab2/src/Main.java:
--------------------------------------------------------------------------------
1 | import pokemons.*;
2 | import ru.ifmo.se.pokemon.*;
3 |
4 | public class Main {
5 | public static void main(String[] args) {
6 | Battle b = new Battle ();
7 | Minior p1 = new Minior("rtx3090", 5);
8 | TapuFini p2 = new TapuFini("ПчелоВеЧищЕ", 5);
9 | Silvally p3 = new Silvally("АлександрⅠ", 5);
10 | Togekiss p4 = new Togekiss("Клименков", 5);
11 | Togetic p5 = new Togetic("Чернорабочий", 5);
12 | Togepi p6 = new Togepi("Василий", 5);
13 | b.addAlly(p1);
14 | b.addAlly(p2);
15 | b.addAlly(p3);
16 | b.addFoe(p4);
17 | b.addFoe(p5);
18 | b.addFoe(p6);
19 | b.go();
20 | }
21 | }
--------------------------------------------------------------------------------
/lab2/src/moves/BulkUp.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class BulkUp extends StatusMove {
6 | public BulkUp() {
7 | super(Type.FIGHTING, 0, 0);
8 | }
9 |
10 | @Override
11 | protected void applyOppEffects(Pokemon p) {
12 | p.setMod(Stat.ATTACK, 1);
13 | p.setMod(Stat.DEFENSE, 1);
14 | }
15 |
16 | @Override
17 | protected String describe(){
18 | return "is using Bulk Up";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab2/src/moves/Confide.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class Confide extends StatusMove {
6 | public Confide() {
7 | super(Type.NORMAL, 0, 0);
8 | }
9 |
10 | @Override
11 | protected void applyOppEffects(Pokemon p) {
12 | p.setMod(Stat.SPECIAL_ATTACK, -1);
13 | }
14 |
15 | @Override
16 | protected String describe() {
17 | return "is using Confide";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab2/src/moves/DazzlingGleam.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class DazzlingGleam extends SpecialMove {
6 | public DazzlingGleam() {
7 | super(Type.FAIRY, 80, 100);
8 | }
9 |
10 | @Override
11 | protected String describe() {
12 | return "is using Dazzling Gleam";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab2/src/moves/FairyWind.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class FairyWind extends SpecialMove {
6 | public FairyWind() {
7 | super(Type.FAIRY, 40, 100);
8 | }
9 |
10 | @Override
11 | protected String describe() {
12 | return "is using Fairy Wind";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab2/src/moves/Flamethrower.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class Flamethrower extends SpecialMove {
6 | public Flamethrower() {
7 | super(Type.FIRE, 90, 100);
8 | }
9 |
10 | @Override
11 | protected void applyOppEffects(Pokemon p) {
12 | if (Math.random() < 0.1) {
13 | Effect.burn(p);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab2/src/moves/FocusBlast.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class FocusBlast extends SpecialMove {
6 | public FocusBlast() {
7 | super(Type.FIGHTING, 102, 70);
8 | }
9 |
10 | @Override
11 | protected void applyOppEffects(Pokemon p) {
12 | if (Math.random() < 0.1) {
13 | p.setMod(Stat.SPECIAL_DEFENSE, -1);
14 | }
15 | }
16 |
17 | @Override
18 | protected String describe() {
19 | return "is using Focus Blast";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lab2/src/moves/HornLeech.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class HornLeech extends PhysicalMove {
6 | public HornLeech() {
7 | super(Type.GRASS, 75, 100);
8 | }
9 |
10 | @Override
11 | protected void applySelfEffects(Pokemon p) {
12 | p.setMod(Stat.HP, 50);
13 | }
14 |
15 | @Override
16 | protected String describe() {
17 | return "is using Horn Leech";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab2/src/moves/MetalSound.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class MetalSound extends StatusMove {
6 | public MetalSound() {
7 | super(Type.STEEL, 0, 85);
8 | }
9 |
10 | @Override
11 | protected void applyOppEffects(Pokemon p) {
12 | p.setMod(Stat.SPECIAL_DEFENSE, -2);
13 | }
14 |
15 | @Override
16 | protected String describe() {
17 | return "is using Metal Sound";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab2/src/moves/ShadowBall.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class ShadowBall extends SpecialMove {
6 | public ShadowBall() {
7 | super(Type.GHOST, 80, 100);
8 | }
9 |
10 | @Override
11 | protected void applyOppEffects(Pokemon p) {
12 | if (Math.random() < 0.2) {
13 | p.setMod(Stat.SPECIAL_DEFENSE, 2);
14 | }
15 | }
16 |
17 | @Override
18 | protected String describe() {
19 | return "is using Shadow Ball";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lab2/src/moves/SteelWing.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class SteelWing extends PhysicalMove {
6 | public SteelWing() {
7 | super(Type.STEEL, 70, 90);
8 | }
9 |
10 | @Override
11 | protected void applySelfEffects(Pokemon p) {
12 | if(Math.random() < 0.1){
13 | p.setMod(Stat.DEFENSE, 1);
14 | }
15 | }
16 |
17 | @Override
18 | protected String describe() {
19 | return "is using Steel Wing";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lab2/src/moves/Swagger.java:
--------------------------------------------------------------------------------
1 | package moves;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 |
5 | public class Swagger extends StatusMove {
6 | public Swagger() {
7 | super(Type.NORMAL, 0, 85);
8 | }
9 |
10 | @Override
11 | protected void applySelfEffects(Pokemon p) {
12 | p.setMod(Stat.ATTACK, 2);
13 | }
14 |
15 | @Override
16 | protected void applyOppEffects(Pokemon p) {
17 | p.setMod(Stat.ATTACK, 2);
18 | }
19 |
20 | @Override
21 | protected String describe() {
22 | return "is using Swagger";
23 | }
24 | }
--------------------------------------------------------------------------------
/lab2/src/pokemons/Minior.java:
--------------------------------------------------------------------------------
1 | package pokemons;
2 |
3 | import moves.*;
4 | import ru.ifmo.se.pokemon.*;
5 |
6 | public class Minior extends Pokemon {
7 | public Minior(String name, int level) {
8 | super(name, level);
9 | setStats(60, 60, 100, 60, 100, 60);
10 | setType(Type.ROCK, Type.FLYING);
11 | setMove(new Confide(), new Swagger(), new MetalSound(), new ShadowBall());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab2/src/pokemons/Silvally.java:
--------------------------------------------------------------------------------
1 | package pokemons;
2 |
3 | import ru.ifmo.se.pokemon.*;
4 | import moves.*;
5 |
6 | public class Silvally extends Pokemon {
7 | public Silvally(String name, int level) {
8 | super(name, level);
9 | setStats(95, 95, 95, 95,95, 95);
10 | setType(Type.NORMAL);
11 | setMove(new Confide(), new Swagger(), new MetalSound());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab2/src/pokemons/TapuFini.java:
--------------------------------------------------------------------------------
1 | package pokemons;
2 |
3 | import moves.*;
4 | import ru.ifmo.se.pokemon.*;
5 |
6 | public class TapuFini extends Pokemon {
7 | public TapuFini(String name, int level) {
8 | super(name, level);
9 | setStats(70, 75, 115, 95, 130, 85);
10 | setType(Type.WATER, Type.FAIRY);
11 | setMove(new DazzlingGleam(), new HornLeech(), new FocusBlast(), new BulkUp());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab2/src/pokemons/Togekiss.java:
--------------------------------------------------------------------------------
1 | package pokemons;
2 |
3 | import moves.*;
4 |
5 | public class Togekiss extends Togetic{
6 | public Togekiss(String name, int level) {
7 | super(name, level);
8 | setStats(85, 50, 95, 120, 115, 80);
9 | addMove(new SteelWing());
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/lab2/src/pokemons/Togepi.java:
--------------------------------------------------------------------------------
1 | package pokemons;
2 |
3 | import moves.*;
4 | import ru.ifmo.se.pokemon.*;
5 |
6 | public class Togepi extends Pokemon{
7 | public Togepi(String name, int level) {
8 | super(name, level);
9 | setStats(35, 20, 65, 40, 65, 20);
10 | setType(Type.FAIRY);
11 | setMove(new Swagger(), new Flamethrower());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab2/src/pokemons/Togetic.java:
--------------------------------------------------------------------------------
1 | package pokemons;
2 |
3 | import moves.*;
4 |
5 | public class Togetic extends Togepi {
6 | public Togetic(String name, int level) {
7 | super(name, level);
8 | setStats(55, 40, 85, 80, 105, 40);
9 | addMove(new FairyWind());
10 | }
11 | }
--------------------------------------------------------------------------------
/lab3/Programming_theory.md.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:0715d99a45ab9d1448d578b62531aab57fa0874c648d0702c6b33ea0eca9272b
3 | size 503823
4 |
--------------------------------------------------------------------------------
/lab3/READ_BEFORE_LAB:
--------------------------------------------------------------------------------
1 | This UML diagram got accepted, but it is a bit different from final result,
2 | so, because I have literally zero time to change it, do not rely on it this much.
3 | It has a very cool logic, that is the most important thing. But overall,
4 | there is a lot of changes in methods and other stuff in /src directory.
5 |
6 | Go check it yourself now!)
7 |
8 | But overall, this UML is pretty good, not gonna lie.
9 |
--------------------------------------------------------------------------------
/lab3/UML_true.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab3/UML_true.png
--------------------------------------------------------------------------------
/lab3/lab3.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lab3/src/CosmicObjects/Constellations.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | public class Constellations extends CosmicObject{
4 | public Constellations(String name){
5 | super(name, CosmicObjectType.CONSTELLATION);
6 | }
7 |
8 | @Override
9 | public String light(int light) {
10 | return null;
11 | }
12 |
13 | @Override
14 | public String reflect(int otherLight) {
15 | return null;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab3/src/CosmicObjects/CosmicObjectType.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | public enum CosmicObjectType {
4 | STAR,
5 | ASTEROID,
6 | PLANET,
7 | GALAXY,
8 | SATELLITE,
9 | COMET,
10 | NEBULA,
11 | CONSTELLATION,
12 | FIRMAMENT
13 | }
14 |
--------------------------------------------------------------------------------
/lab3/src/CosmicObjects/Earth.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | import actions.Lightable;
4 | import actions.Reflectable;
5 |
6 | public class Earth extends CosmicObject implements Reflectable, Lightable {
7 | public Earth(String name, int id, int brightness, double radius, double mass, String time){
8 | super(name, radius, mass, CosmicObjectType.PLANET, id, brightness, time);
9 | }
10 |
11 | @Override
12 | public String reflect(int otherLight){
13 | return this.getName() + " отражает свет с силой " + otherLight;
14 | }
15 |
16 | @Override
17 | public String light(int light){
18 | return this.getName() + " светит с силой " + light;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab3/src/CosmicObjects/Firmament.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | public class Firmament extends CosmicObject{
4 | public Firmament(String name){
5 | super(name, CosmicObjectType.FIRMAMENT);
6 | }
7 |
8 | @Override
9 | public String light(int light) {
10 | return null;
11 | }
12 |
13 | @Override
14 | public String reflect(int otherLight) {
15 | return null;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab3/src/CosmicObjects/Moon.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | import actions.Lightable;
4 | import actions.Reflectable;
5 |
6 | public class Moon extends CosmicObject implements Reflectable, Lightable {
7 | public Moon(String name, int id, int brightness, double radius, double mass, String time){
8 | super(name, radius, mass, CosmicObjectType.SATELLITE, id, brightness, time);
9 | }
10 |
11 | @Override
12 | public String reflect(int otherLight){
13 | return this.getName() + " отражает свет с силой " + otherLight;
14 | }
15 |
16 | @Override
17 | public String light(int light){
18 | return this.getName() + " светит с силой " + light;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/lab3/src/CosmicObjects/Sun.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | import actions.Lightable;
4 |
5 | public class Sun extends CosmicObject implements Lightable {
6 | public Sun(String name, int id, int brightness, double radius, double mass, String time){
7 | super(name, radius, mass, CosmicObjectType.STAR, id, brightness, time);
8 | }
9 |
10 | @Override
11 | public String light(int light){
12 | return this.getName() + " светит с силой " + light;
13 | }
14 |
15 | @Override
16 | public String reflect(int otherLight) {
17 | return null;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab3/src/Lab3_prog.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lab3/src/Sky/Sky.java:
--------------------------------------------------------------------------------
1 | package Sky;
2 |
3 | import CosmicObjects.CosmicObject;
4 | import actions.Viewable;
5 |
6 | public class Sky implements Viewable {
7 | public Sky(){}
8 |
9 | public String getView(CosmicObject viewPoint){
10 | return viewPoint.getViewPoint();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/lab3/src/actions/Lightable.java:
--------------------------------------------------------------------------------
1 | package actions;
2 |
3 | public interface Lightable {
4 | String light(int light);
5 | }
6 |
--------------------------------------------------------------------------------
/lab3/src/actions/Reflectable.java:
--------------------------------------------------------------------------------
1 | package actions;
2 |
3 | public interface Reflectable {
4 | String reflect(int otherLight);
5 | }
6 |
--------------------------------------------------------------------------------
/lab3/src/actions/Viewable.java:
--------------------------------------------------------------------------------
1 | package actions;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public interface Viewable {
6 | String getView(CosmicObject viewPoint);
7 | }
8 |
--------------------------------------------------------------------------------
/lab3/src/characters/Fuksy.java:
--------------------------------------------------------------------------------
1 | package characters;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public class Fuksy extends Human{
6 | public Fuksy(String name, int id, CosmicObject location){
7 | super(name, id, location);
8 | System.out.println(name + " появился на свет");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/lab3/src/characters/ProfessorZvizdochkin.java:
--------------------------------------------------------------------------------
1 | package characters;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public class ProfessorZvizdochkin extends Human{
6 | public ProfessorZvizdochkin(String name, int id, CosmicObject location) {
7 | super(name, id, location);
8 | System.out.println(name + " появился на свет");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/lab3/src/characters/Seledochka.java:
--------------------------------------------------------------------------------
1 | package characters;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public class Seledochka extends Human{
6 | public Seledochka(String name, int id, CosmicObject location) {
7 | super(name, id, location);
8 | System.out.println(name + " появился на свет");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/lab3/src/characters/Znaika.java:
--------------------------------------------------------------------------------
1 | package characters;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public class Znaika extends Human {
6 | public Znaika(String name, int id, CosmicObject location) {
7 | super(name, id, location);
8 | System.out.println(name + " появился на свет");
9 | }
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/lab4/ALL_Theory_Is_HERE:
--------------------------------------------------------------------------------
1 | click this link and please, don't edit anything. You could add something usefull, but don't erase information and don't do other bad stuff.
2 |
3 | https://docs.google.com/document/d/1Taf-X0wgn1qAw74n5DjuNcbWJqFeCFkURIQ17130BB4/edit?usp=sharing
4 |
--------------------------------------------------------------------------------
/lab4/Theory/Classes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab4/Theory/Classes.png
--------------------------------------------------------------------------------
/lab4/Theory/Classes_theory.puml:
--------------------------------------------------------------------------------
1 | @startmindmap Classes
2 |
3 | *[#ffff33]: Вложенные классы
4 | (Nested classes);
5 | **[#b2ff66]: Статические вложенные классы
6 | (Static nested classes);
7 | **[#FFD765]: Нестатические вложенные
8 | (=внутренние) классы
9 | (Inner classes);
10 |
11 | ***[#ff9999]: Просто внутренние классы
12 | (Inner classes);
13 | ***[#ff99cc]: Локальные внутренние классы
14 | (Local inner classses);
15 | ***[#99ffff]: Анонимные внутренние классы
16 | (Anonymous inner classes);
17 | @endmindmap
--------------------------------------------------------------------------------
/lab4/Theory/bAnonymous.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab4/Theory/bAnonymous.png
--------------------------------------------------------------------------------
/lab4/Theory/bLocal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab4/Theory/bLocal.png
--------------------------------------------------------------------------------
/lab4/Theory/bNested.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab4/Theory/bNested.png
--------------------------------------------------------------------------------
/lab4/UML.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab4/UML.png
--------------------------------------------------------------------------------
/lab4/lab4.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lab4/src/Colors/Color.java:
--------------------------------------------------------------------------------
1 | package Colors;
2 |
3 | public enum Color {
4 | BLACK("чёрный"),
5 | GREEN("зелёный"),
6 | BLUE("голубой"),
7 | EMERALDGREEN("изумрудно-зелёный"),
8 | WHITE("белый"),
9 | BRIGHTWHITE("ярко-белый"),
10 | RED("красный"),
11 | LightCherry("светло-вишнёвый"),
12 | DARKPURPLE("тёмно-фиолетовый"),
13 | BRIGHTBLUE("светло-голубой"),
14 | PURPLE("пурпурный");
15 |
16 | private String name;
17 | Color(String name) {
18 | this.name = name;
19 | }
20 |
21 | public String getName() {
22 | return name;
23 | }
24 |
25 | public static class War {
26 | public String action(Color opp1, Color opp2) {
27 | return "Происходит борьба двух цветов: " + opp1.getName() + " и " + opp2.getName();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/lab4/src/CosmicObjects/Constellations.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | public class Constellations extends CosmicObject{
4 | public Constellations(String name, int id){
5 | super(name, CosmicObjectType.CONSTELLATION, id);
6 | }
7 |
8 | @Override
9 | public String light(int light) {
10 | return null;
11 | }
12 |
13 | @Override
14 | public String reflect(int otherLight) {
15 | return null;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab4/src/CosmicObjects/CosmicObjectType.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | public enum CosmicObjectType {
4 | STAR,
5 | ASTEROID,
6 | PLANET,
7 | GALAXY,
8 | SATELLITE,
9 | COMET,
10 | NEBULA,
11 | CONSTELLATION,
12 | FIRMAMENT,
13 | COSMICBEAM
14 | }
15 |
--------------------------------------------------------------------------------
/lab4/src/CosmicObjects/Firmament.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | public class Firmament extends CosmicObject{
4 | public Firmament(String name, int id){
5 | super(name, CosmicObjectType.FIRMAMENT, id);
6 | }
7 |
8 | @Override
9 | public String light(int light) {
10 | return null;
11 | }
12 |
13 | @Override
14 | public String reflect(int otherLight) {
15 | return null;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab4/src/CosmicObjects/Sun.java:
--------------------------------------------------------------------------------
1 | package CosmicObjects;
2 |
3 | import Exceptions.SoundException;
4 | import Interfaces.Sound;
5 |
6 | public class Sun extends CosmicObject implements Sound {
7 | public Sun(String name, int id, int brightness, double radius, double mass, String time){
8 | super(name, radius, mass, CosmicObjectType.STAR, id, brightness, time);
9 | }
10 |
11 | @Override
12 | public String light(int light){
13 | return this.getName() + " светит с силой " + light;
14 | }
15 |
16 | @Override
17 | public String reflect(int otherLight) {
18 | return null;
19 | }
20 |
21 | @Override
22 | public void sound() throws SoundException {
23 | throw new SoundException("В безвоздушной среде звук не распространяется, мда, надо было на физику ходить в школе.");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lab4/src/Exceptions/SoundException.java:
--------------------------------------------------------------------------------
1 | package Exceptions;
2 |
3 | public class SoundException extends Exception{
4 | public SoundException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Exceptions/WeightException.java:
--------------------------------------------------------------------------------
1 | package Exceptions;
2 |
3 | public class WeightException extends RuntimeException{
4 | public WeightException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Instruments/GeoHammer.java:
--------------------------------------------------------------------------------
1 | package Instruments;
2 |
3 | public class GeoHammer extends Instruments{
4 | public GeoHammer(String type) {
5 | super(type);
6 | System.out.println("Получено достижение 'Каменный век'");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab4/src/Instruments/IceAxe.java:
--------------------------------------------------------------------------------
1 | package Instruments;
2 |
3 | public class IceAxe extends Instruments{
4 | public IceAxe(String type) {
5 | super(type);
6 | System.out.println("Получено достижение 'И кирка без дела ржавеет'");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab4/src/Instruments/Instruments.java:
--------------------------------------------------------------------------------
1 | package Instruments;
2 |
3 | import CosmicObjects.CosmicObject;
4 | import PlanetObjects.PlanetObject;
5 |
6 | /** This class really helps mining some Ore. */
7 | public abstract class Instruments {
8 | private String type;
9 | public Instruments(String type) {
10 | System.out.println("Куётся инструмент " + type);
11 | this.type = type;
12 | }
13 |
14 | public String getType(){
15 | return this.type;
16 | }
17 |
18 | public String bang(PlanetObject surface) {
19 | return this.getType() + " cтучать о " + surface.getName();
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Affect.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public interface Affect {
6 | String affect(int affect, CosmicObject surface);
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Imagine.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | /** This is interface for imagination */
4 | public interface Imagine {
5 | void imagine();
6 | }
7 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Lightable.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | public interface Lightable {
4 | String light(int light);
5 | }
6 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Reflectable.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | public interface Reflectable {
4 | String reflect(int otherLight);
5 | }
6 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Shine.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | public interface Shine {
4 | String shine();
5 | }
6 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Sound.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | import Exceptions.SoundException;
4 |
5 | public interface Sound {
6 | void sound() throws SoundException;
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Interfaces/Viewable.java:
--------------------------------------------------------------------------------
1 | package Interfaces;
2 |
3 | import CosmicObjects.CosmicObject;
4 |
5 | public interface Viewable {
6 | String getView(CosmicObject viewPoint);
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Ore/AntiLunit.java:
--------------------------------------------------------------------------------
1 | package Ore;
2 |
3 | public class AntiLunit extends Ore{
4 | public AntiLunit(String type) {
5 | super(type);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Ore/Lunit.java:
--------------------------------------------------------------------------------
1 | package Ore;
2 |
3 | public class Lunit extends Ore{
4 | public Lunit(String type) {
5 | super(type);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab4/src/Ore/Ore.java:
--------------------------------------------------------------------------------
1 | package Ore;
2 |
3 | /** Just a class for mining some Ore, you know.
4 | * Like we all did in a Minecraft in the good old days. */
5 | public abstract class Ore {
6 | private String type;
7 | public Ore(String type) {
8 | this.type = type;
9 | System.out.println("Сгенерировалась горная порода " + type);
10 | }
11 |
12 | public String getType(){
13 | return this.type;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab4/src/PlanetObjects/Cave.java:
--------------------------------------------------------------------------------
1 | package PlanetObjects;
2 |
3 | import Colors.Color;
4 |
5 | public class Cave extends PlanetObject{
6 | public Cave(String name, int id, Color color) {
7 | super(name, id, color);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/lab4/src/PlanetObjects/Mountains.java:
--------------------------------------------------------------------------------
1 | package PlanetObjects;
2 |
3 | import Colors.Color;
4 |
5 | public class Mountains extends PlanetObject{
6 | public Mountains(String name, int id, Color color) {
7 | super(name, id, color);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/lab4/src/PlanetObjects/Rocket.java:
--------------------------------------------------------------------------------
1 | package PlanetObjects;
2 |
3 | import Colors.Color;
4 | import Exceptions.WeightException;
5 |
6 | public class Rocket extends PlanetObject{
7 | private int weight = 300000;
8 | public Rocket(String name, int id, Color color) {
9 | super(name, id, color);
10 | }
11 |
12 | public int getWeight(){
13 | return this.weight;
14 | }
15 |
16 | public void setWeight(int weight) throws WeightException {
17 | if (weight > 0) {
18 | this.weight = weight;
19 | } else {
20 | throw new WeightException("У тебя чё объект настолько похудел что у него массы нет теперь? Или может она вообще отрицательная? Чё за кек, давай по новой.");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lab4/src/PlanetObjects/SpaceSuit.java:
--------------------------------------------------------------------------------
1 | package PlanetObjects;
2 |
3 | import Colors.Color;
4 | import Exceptions.WeightException;
5 |
6 | public class SpaceSuit extends PlanetObject{
7 | private int weight = 130;
8 | public SpaceSuit(String name, int id, Color color) {
9 | super(name, id, color);
10 | }
11 |
12 | public int getWeight() {
13 | return weight;
14 | }
15 |
16 | public void setWeight(int weight) throws WeightException {
17 | if (weight > 0) {
18 | this.weight = weight;
19 | } else {
20 | throw new WeightException("У тебя чё объект настолько похудел что у него массы нет теперь? Или может она вообще отрицательная? Чё за кек, давай по новой.");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lab4/src/Sky/Sky.java:
--------------------------------------------------------------------------------
1 | package Sky;
2 |
3 | import CosmicObjects.CosmicObject;
4 | import Interfaces.Viewable;
5 |
6 | public class Sky implements Viewable {
7 | public Sky() {
8 | System.out.println("Генерация атмосферы");
9 | }
10 |
11 | public String getView(CosmicObject viewPoint){
12 | return viewPoint.getName();
13 | }
14 |
15 | public String getPicture(String picture) {
16 | return picture;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab5/.bash_profile:
--------------------------------------------------------------------------------
1 | lab5=/home/studs/s368090/data.csv ; export lab5
--------------------------------------------------------------------------------
/lab5/UML.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab5/UML.png
--------------------------------------------------------------------------------
/lab5/commons-csv-1.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab5/commons-csv-1.6.jar
--------------------------------------------------------------------------------
/lab5/data.csv:
--------------------------------------------------------------------------------
1 | id,name,x,y,creationDate,area,population,metersAboveSeaLevel,climate,government,standardOfLiving,governor
2 | 2074407503,Kazan,25,17.0,2023-02-22,200,15000,340.1,OCEANIC,COMMUNISM,VERY_HIGH,Petr
3 | 0,Sevastopol,16,15.0,2023-02-22,450,1345768,41.0,STEPPE,ANARCHY,NIGHTMARE,Artem
4 | -1220593662,Moscow,2143,4356.0,2023-02-22,2135,28376412,650.0,TROPICAL_SAVANNA,DEMARCHY,VERY_HIGH,Vasiliy
5 |
--------------------------------------------------------------------------------
/lab5/dataBackup.csv:
--------------------------------------------------------------------------------
1 | id,name,x,y,creationDate,area,population,metersAboveSeaLevel,climate,government,standardOfLiving,governor
2 | 5512342145403661152,2,2,2.0,2023-03-21,2,2,2.0,OCEANIC,GERONTOCRACY,VERY_HIGH,2
3 |
--------------------------------------------------------------------------------
/lab5/lab5.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lab5/lab5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab5/lab5.jar
--------------------------------------------------------------------------------
/lab5/reports/report.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab5/reports/report.docx
--------------------------------------------------------------------------------
/lab5/reports/report.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:25a6be97f40e169b6d2afca9cc3cad4a9226e1267897a7253d0388ad0df3b7a6
3 | size 1083017
4 |
--------------------------------------------------------------------------------
/lab5/script1.txt:
--------------------------------------------------------------------------------
1 | save
2 | save
3 | show
4 | history
5 | execute_script script1.txt
6 | history
7 | exit
--------------------------------------------------------------------------------
/lab5/script2.txt:
--------------------------------------------------------------------------------
1 | execute_script script1
--------------------------------------------------------------------------------
/lab5/script3.txv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab5/script3.txv
--------------------------------------------------------------------------------
/lab5/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: Main
3 |
4 |
--------------------------------------------------------------------------------
/lab5/src/collection/City/Climate.java:
--------------------------------------------------------------------------------
1 | package collection.City;
2 |
3 | /**
4 | * Enum for different climate types
5 | */
6 | public enum Climate {
7 | TROPICAL_SAVANNA,
8 | OCEANIC,
9 | STEPPE
10 | }
11 |
--------------------------------------------------------------------------------
/lab5/src/collection/City/Government.java:
--------------------------------------------------------------------------------
1 | package collection.City;
2 |
3 | /**
4 | * Enum for different government types
5 | */
6 | public enum Government {
7 | ANARCHY,
8 | GERONTOCRACY,
9 | DEMARCHY,
10 | COMMUNISM,
11 | NOOCRACY
12 | }
13 |
--------------------------------------------------------------------------------
/lab5/src/collection/City/StandardOfLiving.java:
--------------------------------------------------------------------------------
1 | package collection.City;
2 |
3 | /**
4 | * Enum for different StandardOfLiving types
5 | */
6 | public enum StandardOfLiving {
7 | ULTRA_HIGH,
8 | VERY_HIGH,
9 | HIGH,
10 | ULTRA_LOW,
11 | NIGHTMARE
12 | }
13 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/modeManagers/ModeManager.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.modeManagers;
2 |
3 | import exceptions.BuildObjectException;
4 |
5 | /**
6 | * Interface for mode managers that can generate objects.
7 | *
8 | * @param The type of object this manager generates.
9 | */
10 | public interface ModeManager {
11 | /**
12 | * Generates a new object of type T.
13 | *
14 | * @return The newly created object.
15 | * @throws BuildObjectException If an error occurred during object creation.
16 | */
17 | T buildObject() throws BuildObjectException;
18 | }
19 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/AreaValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for Area
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class AreaValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/CoordinateXValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateX
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateXValidator implements Validator {
10 | public String getDescr() {
11 | return "x <= 499";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value <= 499;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/CoordinateYValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateY
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateYValidator implements Validator {
10 | public String getDescr() {
11 | return "value > -27";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value > -274 && value <= Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/InputValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for user input.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class InputValidator{
10 | /**
11 | * Checks if value not null and not blank.
12 | *
13 | * @param value name to validate
14 | * @return true/false -- matches the restrictions
15 | */
16 | boolean canBeNull = false;
17 | public String getDescr() {
18 | return "Validates user input";
19 | }
20 | public boolean validate(String value) {
21 | if (!canBeNull)
22 | return !value.isEmpty() && !value.isBlank();
23 | return true;
24 | }
25 |
26 | public void canBeNull(boolean canBeNull) {
27 | this.canBeNull = canBeNull;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/MetersAboveSeaLevelValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for MetersAboveSeaLevel.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class MetersAboveSeaLevelValidator implements Validator {
10 | public String getDescr() {
11 | return "any value, that fits Double format";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value < Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/NameValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for name field. (City)
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class NameValidator implements Validator {
10 | @Override
11 | public String getDescr() {
12 | return "Validates name field";
13 | }
14 |
15 | /**
16 | * Checks if value not null and not blank.
17 | *
18 | * @see collection.City
19 | * @param value name to validate
20 | * @return true/false -- matches the restrictions
21 | */
22 | @Override
23 | public boolean validate(String value) {
24 | return !value.isEmpty() && !value.isBlank();
25 | }
26 | }
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/PopulationValidator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Implementation of validator for Population.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class PopulationValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab5/src/collectionManagers/validators/Validator.java:
--------------------------------------------------------------------------------
1 | package collectionManagers.validators;
2 |
3 | /**
4 | * Base validator. You should implement it for usage.
5 | *
6 | * @since 2.0
7 | * @param Type of validation value.
8 | */
9 | public interface Validator {
10 | boolean canBeNull = false;
11 |
12 | /**
13 | * Provides validation method.
14 | *
15 | * @param value value to validate
16 | * @return true if value is validate. Otherwise false.
17 | */
18 | boolean validate(T value);
19 |
20 | /**
21 | * Provides description for all validators.
22 | *
23 | * @return String description of validator
24 | */
25 | String getDescr();
26 | }
27 |
--------------------------------------------------------------------------------
/lab5/src/commandManagers/CommandMode.java:
--------------------------------------------------------------------------------
1 | package commandManagers;
2 |
3 | /**
4 | * Contains information about mode of commands behavior
5 | *
6 | * @author boris
7 | * @since 2.0
8 | */
9 | public enum CommandMode {
10 | /**
11 | * Commands will use user-friendly interaction. Envisage that it will be used with System.in scanner
12 | */
13 | CLI_UserMode,
14 | /**
15 | * Commands will use simple interaction w/o user-orientation. Envisage that it will be used with file streams, e.t.c.
16 | */
17 | NonUserMode
18 | }
--------------------------------------------------------------------------------
/lab5/src/exceptions/BuildObjectException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * An exception that is thrown when an object cannot be built.
5 | */
6 | public class BuildObjectException extends Exception {
7 |
8 | /**
9 | * Constructs a new BuildObjectException with the specified detail message.
10 | *
11 | * @param msg the detail message
12 | */
13 | public BuildObjectException(String msg)
14 | {
15 | super(msg);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab5/src/exceptions/CommandInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * An exception that represents an interruption in the execution of a command.
5 | */
6 | public class CommandInterruptedException extends RuntimeException {
7 |
8 | /**
9 | * Constructs a new CommandInterruptedException with the specified cause.
10 | *
11 | * @param cause the cause of the exception
12 | */
13 | public CommandInterruptedException(Exception cause)
14 | {
15 | super(cause);
16 | }
17 | }
--------------------------------------------------------------------------------
/lab5/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message)
13 | {
14 | super(message);
15 | }
16 | }
--------------------------------------------------------------------------------
/lab6/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
30 |
31 | ### Gradle old build ###
32 | build
33 | .gradle
34 | out
35 |
36 | ### Gradle client build ###
37 | client/build/
38 | client/.gradle/
39 | client/out/
40 |
41 | ### Gradle server build ###
42 | /server/build
43 | /server/.gradle/
44 | /server/out/
--------------------------------------------------------------------------------
/lab6/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'idea'
--------------------------------------------------------------------------------
/lab6/client/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: main.Main
3 |
4 |
--------------------------------------------------------------------------------
/lab6/client/src/commandManager/CommandDescriptionHolder.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class CommandDescriptionHolder {
8 |
9 | private static CommandDescriptionHolder instance;
10 | ArrayList commands;
11 |
12 | private CommandDescriptionHolder(ArrayList commands) {
13 | this.commands = commands;
14 | }
15 |
16 | public static void initialize(ArrayList commands) {
17 | instance = new CommandDescriptionHolder(commands);
18 | }
19 |
20 | public static CommandDescriptionHolder getInstance() {
21 | return instance;
22 | }
23 |
24 | public ArrayList getCommands() {
25 | return commands;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/lab6/client/src/commandManager/CommandLoaderUtility.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | import commandLogic.CommandDescription;
4 | import requestLogic.requestSenders.CommandDescriptionsRequestSender;
5 |
6 | import java.util.ArrayList;
7 |
8 | public class CommandLoaderUtility {
9 | public static void initializeCommands() {
10 | ArrayList commands = new CommandDescriptionsRequestSender().sendRequestAndGetCommands();
11 | CommandDescriptionHolder.initialize(commands);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab6/client/src/commandManager/CommandMode.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | /**
4 | * Contains information about mode of commands behavior
5 | *
6 | * @since 1.1
7 | * @author zerumi
8 | */
9 | public enum CommandMode {
10 | /**
11 | * Commands will use user-friendly interaction. Envisage that it will be used with System.in scanner
12 | */
13 | CLI_UserMode,
14 | /**
15 | * Commands will use simple interaction w/o user-orientation. Envisage that it will be used with file streams, e.t.c.
16 | */
17 | NonUserMode
18 | }
19 |
--------------------------------------------------------------------------------
/lab6/client/src/commandManager/externalRecievers/ExitReceiver.java:
--------------------------------------------------------------------------------
1 | package commandManager.externalRecievers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
5 |
6 | import java.util.Objects;
7 |
8 | public class ExitReceiver implements ExternalBaseReceiver {
9 |
10 | @Override
11 | public boolean receiveCommand(CommandDescription command, String[] args) {
12 | if (!Objects.equals(command.getName(), "exit")) return true;
13 |
14 | System.exit(0);
15 | return false;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/BuildObjectException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class BuildObjectException extends Exception {
4 | public BuildObjectException(String msg)
5 | {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/CommandInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class CommandInterruptedException extends RuntimeException {
4 | public CommandInterruptedException(Exception cause)
5 | {
6 | super(cause);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/CommandsNotLoadedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class CommandsNotLoadedException extends Exception {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/ServerNotAvailableException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class ServerNotAvailableException extends Exception {
4 |
5 | public ServerNotAvailableException(String msg) {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/StreamInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class StreamInterruptedException extends Exception {
4 | public StreamInterruptedException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message)
13 | {
14 | super(message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/UnsupportedResponseException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UnsupportedResponseException extends Exception {
4 | public UnsupportedResponseException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/client/src/exceptions/WrongAmountOfArgumentsException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class WrongAmountOfArgumentsException extends Exception {
4 | public WrongAmountOfArgumentsException(String msg)
5 | {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab6/client/src/main/Utilities.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import exceptions.StreamInterruptedException;
4 | import exceptions.WrongAmountOfArgumentsException;
5 |
6 | import java.util.Scanner;
7 | import java.util.concurrent.ThreadLocalRandom;
8 |
9 | public class Utilities {
10 | public static void checkArgumentsOrThrow(int provided, int expected) throws WrongAmountOfArgumentsException {
11 | if (provided - 1 != expected)
12 | throw new WrongAmountOfArgumentsException("Provided " + (provided - 1) + " arguments, expected " + expected);
13 | }
14 |
15 | /**
16 | * Generates a unique ID based on threads
17 | *
18 | * @return the unique ID that was generated
19 | */
20 | public static Long generateId() {
21 | Long id;
22 | id = ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
23 | return id;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lab6/client/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lab6/client/src/models/handlers/ModeManager.java:
--------------------------------------------------------------------------------
1 | package models.handlers;
2 |
3 | import exceptions.BuildObjectException;
4 |
5 | /**
6 | * Interface for mode managers that can generate objects.
7 | *
8 | * @param The type of object this manager generates.
9 | */
10 | public interface ModeManager {
11 | /**
12 | * Generates a new object of type T.
13 | *
14 | * @return The newly created object.
15 | * @throws BuildObjectException If an error occurred during object creation.
16 | */
17 | T buildObject() throws BuildObjectException;
18 | }
19 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/AreaValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for Area
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class AreaValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/CoordinateXValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateX
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateXValidator implements Validator {
10 | public String getDescr() {
11 | return "x <= 499";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value <= 499;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/CoordinateYValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateY
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateYValidator implements Validator {
10 | public String getDescr() {
11 | return "value > -27";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value > -274 && value <= Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/InputValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for user input.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class InputValidator{
10 | /**
11 | * Checks if value not null and not blank.
12 | *
13 | * @param value name to validate
14 | * @return true/false -- matches the restrictions
15 | */
16 | boolean canBeNull = false;
17 | public String getDescr() {
18 | return "Validates user input";
19 | }
20 | public boolean validate(String value) {
21 | if (!canBeNull)
22 | return !value.isEmpty() && !value.isBlank();
23 | return true;
24 | }
25 |
26 | public void canBeNull(boolean canBeNull) {
27 | this.canBeNull = canBeNull;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/MetersAboveSeaLevelValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for MetersAboveSeaLevel.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class MetersAboveSeaLevelValidator implements Validator {
10 | public String getDescr() {
11 | return "any value, that fits Double format";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value < Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/NameValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for name field. (City)
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class NameValidator implements Validator {
10 | @Override
11 | public String getDescr() {
12 | return "Validates name field";
13 | }
14 |
15 | /**
16 | * Checks if value not null and not blank.
17 | *
18 | * @see models.City
19 | * @param value name to validate
20 | * @return true/false -- matches the restrictions
21 | */
22 | @Override
23 | public boolean validate(String value) {
24 | return !value.isEmpty() && !value.isBlank();
25 | }
26 | }
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/PopulationValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for Population.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class PopulationValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/client/src/models/validators/Validator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Base validator. You should implement it for usage.
5 | *
6 | * @since 2.0
7 | * @param Type of validation value.
8 | */
9 | public interface Validator {
10 | boolean canBeNull = false;
11 |
12 | /**
13 | * Provides validation method.
14 | *
15 | * @param value value to validate
16 | * @return true if value is validate. Otherwise false.
17 | */
18 | boolean validate(T value);
19 |
20 | /**
21 | * Provides description for all validators.
22 | *
23 | * @return String description of validator
24 | */
25 | String getDescr();
26 | }
27 |
--------------------------------------------------------------------------------
/lab6/client/src/serverLogic/ServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 |
6 | public interface ServerConnectionFactory {
7 | ServerConnection openConnection(InetAddress host, int port) throws IOException;
8 | }
9 |
--------------------------------------------------------------------------------
/lab6/client/src/serverLogic/ServerConnectionHandler.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | public class ServerConnectionHandler {
4 |
5 | private static ServerConnection currentConnection;
6 |
7 | public static void setServerConnection(ServerConnection connection) {
8 | currentConnection = connection;
9 | }
10 |
11 | public static ServerConnection getCurrentConnection() {
12 | return currentConnection;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab6/client/src/serverLogic/UdpConnectionBlockDecorator.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 |
5 | public class UdpConnectionBlockDecorator extends UdpServerConnection {
6 | private final UdpServerConnection baseConnection;
7 | private final boolean configureBlock;
8 |
9 | public UdpConnectionBlockDecorator(UdpServerConnection baseConnection, boolean configureBlock) throws IOException {
10 | super(baseConnection.channel, baseConnection.address);
11 | this.baseConnection = baseConnection;
12 | this.configureBlock = configureBlock;
13 | baseConnection.channel.configureBlocking(configureBlock);
14 | }
15 |
16 | public boolean getLockState() {
17 | return configureBlock;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab6/client/src/serverLogic/UdpServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 | import java.net.InetSocketAddress;
6 | import java.net.SocketAddress;
7 | import java.nio.channels.DatagramChannel;
8 |
9 | public class UdpServerConnectionFactory implements ServerConnectionFactory {
10 | public ServerConnection openConnection(InetAddress host, int port) throws IOException {
11 | DatagramChannel dc;
12 | SocketAddress addr;
13 | addr = new InetSocketAddress(host, port);
14 | dc = DatagramChannel.open();
15 | return new UdpServerConnection(dc, addr);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/docs/report.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab6/docs/report.docx
--------------------------------------------------------------------------------
/lab6/docs/report.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f8872c5464b1ba1954858d538b61a2c8d0666258163d8f798ac3cfa0a7e1f89a
3 | size 268547
4 |
--------------------------------------------------------------------------------
/lab6/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab6/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/lab6/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/lab6/server/src/commandManager/commands/ArgumentConsumer.java:
--------------------------------------------------------------------------------
1 | package commandManager.commands;
2 |
3 | /**
4 | * Provides Argument Consumer
5 | *
6 | * @param Argument param
7 | * @author worthant
8 | * @since 2.0
9 | */
10 | public interface ArgumentConsumer {
11 | void setObj(T obj);
12 | }
13 |
--------------------------------------------------------------------------------
/lab6/server/src/commandManager/commands/ExecuteScriptCommand.java:
--------------------------------------------------------------------------------
1 | package commandManager.commands;
2 |
3 | import responses.CommandStatusResponse;
4 |
5 | public class ExecuteScriptCommand implements BaseCommand {
6 | private CommandStatusResponse response;
7 | @Override
8 | public String getName() {
9 | return "execute_script";
10 | }
11 |
12 | @Override
13 | public String getDescr() {
14 | return "Reads and executes script from file.";
15 | }
16 |
17 | @Override
18 | public String getArgs() {
19 | return "file_path";
20 | }
21 |
22 | @Override
23 | public void execute(String[] args) throws IllegalArgumentException {
24 | response = CommandStatusResponse.ofString("Server is alive and ready for command executing!");
25 | }
26 |
27 | @Override
28 | public CommandStatusResponse getResponse() {
29 | return response;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lab6/server/src/exceptions/InvalidRequestException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class InvalidRequestException extends Exception {
4 | public InvalidRequestException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/server/src/exceptions/NotAvailableException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 |
7 | public class NotAvailableException extends Exception {
8 |
9 | private static final Logger logger = LogManager.getLogger("com.github.zerumi.lab6");
10 | private final CallerBack deniedClient;
11 |
12 | public NotAvailableException(CallerBack deniedClient) {
13 | this.deniedClient = deniedClient;
14 | logger.info("Denied connection: " + deniedClient);
15 | }
16 |
17 | public CallerBack getDeniedClient() {
18 | return deniedClient;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab6/server/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message) {
13 | super(message);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab6/server/src/exceptions/UnsupportedRequestException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UnsupportedRequestException extends Exception {
4 | public UnsupportedRequestException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/server/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/RequestReader.java:
--------------------------------------------------------------------------------
1 | package requestLogic;
2 |
3 | import requests.BaseRequest;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.ObjectInputStream;
8 |
9 | public class RequestReader {
10 | final InputStream in;
11 |
12 | public RequestReader(InputStream in) {
13 | this.in = in;
14 | }
15 |
16 | public BaseRequest readObject() throws IOException, ClassNotFoundException {
17 | ObjectInputStream ois = new ObjectInputStream(in);
18 | return (BaseRequest) ois.readObject();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/StatusRequest.java:
--------------------------------------------------------------------------------
1 | package requestLogic;
2 |
3 | import java.io.InputStream;
4 |
5 | public class StatusRequest {
6 | private InputStream inputStream;
7 | private CallerBack callerBack;
8 | private int code;
9 |
10 | public InputStream getInputStream() {
11 | return inputStream;
12 | }
13 |
14 | public void setInputStream(InputStream inputStream) {
15 | this.inputStream = inputStream;
16 | }
17 |
18 | public CallerBack getCallerBack() {
19 | return callerBack;
20 | }
21 |
22 | public void setCallerBack(CallerBack callerBack) {
23 | this.callerBack = callerBack;
24 | }
25 |
26 | public int getCode() {
27 | return code;
28 | }
29 |
30 | public void setCode(int code) {
31 | this.code = code;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/requestWorkers/BaseRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.requests.ServerRequest;
6 |
7 | public class BaseRequestWorker implements RequestWorker {
8 |
9 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
10 |
11 | @Override
12 | public void workWithRequest(ServerRequest request) {
13 | logger.info("we've got base request wow");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/requestWorkers/CommandClientRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import commandManager.CommandManager;
4 | import org.apache.logging.log4j.LogManager;
5 | import org.apache.logging.log4j.Logger;
6 | import requestLogic.requests.ServerRequest;
7 | import requests.CommandClientRequest;
8 |
9 | public class CommandClientRequestWorker implements RequestWorker {
10 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
11 |
12 | @Override
13 | public void workWithRequest(ServerRequest request) {
14 | CommandClientRequest requestToWork = (CommandClientRequest) request.getUserRequest();
15 | CommandManager manager = new CommandManager();
16 | manager.executeCommand(requestToWork, request.getFrom(), request.getConnection());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/requestWorkers/CommandConfigureRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandManager.CommandExporter;
5 | import requestLogic.requests.ServerRequest;
6 | import responseLogic.responseSenders.CommandConfigureResponseSender;
7 | import responses.CommandDescriptionsResponse;
8 |
9 | import java.util.ArrayList;
10 |
11 | public class CommandConfigureRequestWorker implements RequestWorker {
12 | @Override
13 | public void workWithRequest(ServerRequest request) {
14 | ArrayList commands = CommandExporter.getCommandsToExport();
15 | CommandDescriptionsResponse response = new CommandDescriptionsResponse(commands);
16 | CommandConfigureResponseSender.sendResponse(response, request.getConnection(), request.getFrom());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/requestWorkers/RequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import requestLogic.requests.ServerRequest;
4 |
5 | public interface RequestWorker {
6 | void workWithRequest(ServerRequest request);
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/server/src/requestLogic/requests/ServerRequest.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requests;
2 |
3 | import requestLogic.CallerBack;
4 | import requests.BaseRequest;
5 | import serverLogic.ServerConnection;
6 |
7 | public class ServerRequest {
8 | private final BaseRequest request;
9 | private final CallerBack from;
10 | private final ServerConnection connection;
11 |
12 | public ServerRequest(BaseRequest request, CallerBack from, ServerConnection connection) {
13 | this.request = request;
14 | this.from = from;
15 | this.connection = connection;
16 | }
17 |
18 | public BaseRequest getUserRequest() {
19 | return request;
20 | }
21 |
22 | public ServerConnection getConnection() {
23 | return connection;
24 | }
25 |
26 | public CallerBack getFrom() {
27 | return from;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab6/server/src/responseLogic/responseSenders/CommandResponseSender.java:
--------------------------------------------------------------------------------
1 | package responseLogic.responseSenders;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 | import responses.CommandStatusResponse;
7 | import serverLogic.ServerConnection;
8 |
9 | import java.io.IOException;
10 |
11 | public class CommandResponseSender {
12 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
13 |
14 | public static void sendResponse(CommandStatusResponse response, ServerConnection connection, CallerBack to) {
15 | try {
16 | if (response != null) {
17 | ResponseSender.sendResponse(response, connection, to);
18 | }
19 | } catch (IOException e) {
20 | logger.fatal("Something went wrong during I/O", e);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lab6/server/src/serverLogic/ServerConnection.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import requestLogic.StatusRequest;
4 |
5 | import java.io.IOException;
6 | import java.net.InetAddress;
7 | import java.net.SocketTimeoutException;
8 |
9 | public interface ServerConnection {
10 | StatusRequest listenAndGetData() throws SocketTimeoutException, IOException;
11 |
12 | void sendData(byte[] data, InetAddress addr, int port);
13 | }
14 |
--------------------------------------------------------------------------------
/lab6/server/src/serverLogic/ServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | public interface ServerConnectionFactory {
4 | ServerConnection initializeServer(int port);
5 |
6 | ServerConnection initializeServer(int port, int timeout);
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'server'
2 | include 'client'
3 | include 'shared'
4 |
5 |
--------------------------------------------------------------------------------
/lab6/shared/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | version '1.2'
4 |
5 | sourceSets.main.java.srcDirs = ['src']
6 |
7 | repositories {
8 | mavenCentral()
9 | }
10 |
11 | dependencies {
12 | implementation 'org.modelmapper:modelmapper:3.1.1'
13 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
14 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
15 | }
16 |
17 | test {
18 | useJUnitPlatform()
19 | }
20 |
21 | jar {
22 | manifest {
23 | attributes(
24 | 'Main-Class': 'main.Main',
25 | 'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
26 | )
27 | }
28 | }
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/CommandDescription.java:
--------------------------------------------------------------------------------
1 | package commandLogic;
2 |
3 | import commandLogic.commandReceiverLogic.callers.ExternalCaller;
4 |
5 | import java.io.Serializable;
6 |
7 | public class CommandDescription implements Serializable {
8 | private final String name;
9 | private final ExternalCaller caller;
10 |
11 | public CommandDescription(String name, ExternalCaller caller) {
12 | this.name = name;
13 | this.caller = caller;
14 | }
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public ExternalCaller getReceiver() {
21 | return caller;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/callers/ExternalArgumentReceiverCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 | import commandLogic.commandReceiverLogic.enums.ReceiverType;
6 | import commandLogic.commandReceiverLogic.receivers.ExternalArgumentReceiver;
7 |
8 | import java.util.ArrayList;
9 |
10 | public class ExternalArgumentReceiverCaller extends ExternalCaller {
11 | @Override
12 | public void callReceivers(ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception {
13 | for (ExternalArgumentReceiver receiver : (ArrayList>) manager.getReceivers(ReceiverType.ArgumentRoute)) {
14 | receiver.receiveCommand(description, lineArgs);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/callers/ExternalBaseReceiverCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 | import commandLogic.commandReceiverLogic.enums.ReceiverType;
6 |
7 | public class ExternalBaseReceiverCaller extends ExternalCaller {
8 | @Override
9 | public void callReceivers(ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception {
10 | var receiver = manager.getReceivers(ReceiverType.NoArgs);
11 | boolean commandCompleted = true;
12 | for (int i = 0; i < receiver.size() && commandCompleted; i++) {
13 | commandCompleted = receiver.get(i).receiveCommand(description, lineArgs);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/callers/ExternalCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 |
6 | import java.io.Serializable;
7 |
8 | public abstract class ExternalCaller implements Serializable {
9 | public abstract void callReceivers(ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception;
10 | }
11 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/enums/ReceiverType.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.enums;
2 |
3 | public enum ReceiverType {
4 | NoArgs,
5 | ArgumentRoute
6 | }
7 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/handlers/NonArgReceiversHandler.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.handlers;
2 |
3 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class NonArgReceiversHandler extends ReceiverHandler {
8 |
9 | private final ArrayList receivers;
10 |
11 | {
12 | receivers = new ArrayList<>();
13 | }
14 |
15 | @Override
16 | public void addReceiver(ExternalBaseReceiver receiver) {
17 | receivers.add(receiver);
18 | }
19 |
20 | @Override
21 | public ArrayList getReceivers() {
22 | return receivers;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/handlers/ReceiverHandler.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.handlers;
2 |
3 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
4 |
5 | import java.util.ArrayList;
6 |
7 | public abstract class ReceiverHandler {
8 | public abstract void addReceiver(ExternalBaseReceiver receiver);
9 |
10 | public abstract ArrayList extends ExternalBaseReceiver> getReceivers();
11 | }
12 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/receivers/ExternalArgumentReceiver.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.receivers;
2 |
3 | public interface ExternalArgumentReceiver extends ExternalBaseReceiver {
4 | T getArguemnt();
5 | }
6 |
--------------------------------------------------------------------------------
/lab6/shared/src/commandLogic/commandReceiverLogic/receivers/ExternalBaseReceiver.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.receivers;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public interface ExternalBaseReceiver {
6 | boolean receiveCommand(CommandDescription command, String[] args) throws Exception;
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/shared/src/main/Main.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | System.out.println("""
6 | Однажды Вася спросил у своего старшего брата-сеньора Пети:
7 | "Петя, зачем вообще нам нужно запускать общую библиотеку классов?"
8 | На что Петя ответил: "Братиш, для того, чтобы практик на защите прочитал этот текст.\"""");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/lab6/shared/src/models/Climate.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different climate types
7 | */
8 | public enum Climate implements Serializable {
9 | TROPICAL_SAVANNA,
10 | OCEANIC,
11 | STEPPE
12 | }
13 |
--------------------------------------------------------------------------------
/lab6/shared/src/models/Government.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different government types
7 | */
8 | public enum Government implements Serializable {
9 | ANARCHY,
10 | GERONTOCRACY,
11 | DEMARCHY,
12 | COMMUNISM,
13 | NOOCRACY
14 | }
15 |
--------------------------------------------------------------------------------
/lab6/shared/src/models/StandardOfLiving.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different StandardOfLiving types
7 | */
8 | public enum StandardOfLiving implements Serializable {
9 | ULTRA_HIGH,
10 | VERY_HIGH,
11 | HIGH,
12 | ULTRA_LOW,
13 | NIGHTMARE
14 | }
15 |
--------------------------------------------------------------------------------
/lab6/shared/src/requests/ArgumentCommandClientRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public class ArgumentCommandClientRequest extends CommandClientRequest {
6 | private final T argument;
7 |
8 | public ArgumentCommandClientRequest(CommandDescription command, String[] lineArgs, T argument) {
9 | super(command, lineArgs);
10 | this.argument = argument;
11 | }
12 |
13 | public T getArgument() {
14 | return argument;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab6/shared/src/requests/BaseRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class BaseRequest implements Serializable {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/lab6/shared/src/requests/CommandClientRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public class CommandClientRequest extends BaseRequest {
6 | private final CommandDescription command;
7 | private final String[] lineArgs;
8 |
9 | public CommandClientRequest(CommandDescription command, String[] lineArgs) {
10 | this.command = command;
11 | this.lineArgs = lineArgs;
12 | }
13 |
14 | public CommandDescription getCommandDescription() {
15 | return command;
16 | }
17 |
18 | public String[] getLineArgs() {
19 | return lineArgs;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lab6/shared/src/requests/CommandDescriptionsRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class CommandDescriptionsRequest extends BaseRequest {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/lab6/shared/src/responses/BaseResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class BaseResponse implements Serializable {
6 | }
7 |
--------------------------------------------------------------------------------
/lab6/shared/src/responses/CommandDescriptionsResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class CommandDescriptionsResponse extends BaseResponse {
8 | private final ArrayList commands;
9 |
10 | public CommandDescriptionsResponse(ArrayList commands) {
11 | this.commands = commands;
12 | }
13 |
14 | public ArrayList getCommands() {
15 | return commands;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab6/shared/src/responses/CommandStatusResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class CommandStatusResponse extends BaseResponse {
4 |
5 | private final String response;
6 | private final int statusCode;
7 |
8 | public CommandStatusResponse(String response, int statusCode) {
9 | this.response = response;
10 | this.statusCode = statusCode;
11 | }
12 |
13 | public static CommandStatusResponse ofString(String s) {
14 | return new CommandStatusResponse(s, 0);
15 | }
16 |
17 | public String getResponse() {
18 | return response;
19 | }
20 |
21 | public int getStatusCode() {
22 | return statusCode;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab6/shared/src/responses/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class ErrorResponse extends BaseResponse {
4 |
5 | private final String msg;
6 |
7 | public ErrorResponse(String msg) {
8 | this.msg = msg;
9 | }
10 |
11 | public String getMsg() {
12 | return msg;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab7/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
30 |
31 | ### Gradle old build ###
32 | build
33 | .gradle
34 | out
35 |
36 | ### Gradle client build ###
37 | client/build/
38 | client/.gradle/
39 | client/out/
40 |
41 | ### Gradle server build ###
42 | /server/build
43 | /server/.gradle/
44 | /server/out/
--------------------------------------------------------------------------------
/lab7/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'idea'
--------------------------------------------------------------------------------
/lab7/client/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: main.Main
3 |
4 |
--------------------------------------------------------------------------------
/lab7/client/src/client/Client.java:
--------------------------------------------------------------------------------
1 | package Client;
2 |
3 | public class Client {
4 | private final String name;
5 | private final char[] passwd;
6 | private static Client instance;
7 |
8 | private Client(String name, char[] passwd) {
9 | this.name = name;
10 | this.passwd = passwd;
11 | }
12 |
13 | public static Client getInstance(String name, char[] passwd) {
14 | if (instance == null) {
15 | instance = new Client(name, passwd);
16 | }
17 | return instance;
18 | }
19 | public static Client getInstance() {
20 | return instance;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public char[] getPasswd() {
28 | return passwd;
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/lab7/client/src/commandManager/CommandDescriptionHolder.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class CommandDescriptionHolder {
8 |
9 | private static CommandDescriptionHolder instance;
10 | ArrayList commands;
11 |
12 | private CommandDescriptionHolder(ArrayList commands) {
13 | this.commands = commands;
14 | }
15 |
16 | public static void initialize(ArrayList commands) {
17 | instance = new CommandDescriptionHolder(commands);
18 | }
19 |
20 | public static CommandDescriptionHolder getInstance() {
21 | return instance;
22 | }
23 |
24 | public ArrayList getCommands() {
25 | return commands;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/lab7/client/src/commandManager/CommandLoaderUtility.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | import commandLogic.CommandDescription;
4 | import requestLogic.requestSenders.CommandDescriptionsRequestSender;
5 |
6 | import java.util.ArrayList;
7 |
8 | public class CommandLoaderUtility {
9 | public static void initializeCommands() {
10 | ArrayList commands = new CommandDescriptionsRequestSender().sendRequestAndGetCommands();
11 | CommandDescriptionHolder.initialize(commands);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab7/client/src/commandManager/CommandMode.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | /**
4 | * Contains information about mode of commands behavior
5 | *
6 | * @since 1.1
7 | * @author zerumi
8 | */
9 | public enum CommandMode {
10 | /**
11 | * Commands will use user-friendly interaction. Envisage that it will be used with System.in scanner
12 | */
13 | CLI_UserMode,
14 | /**
15 | * Commands will use simple interaction w/o user-orientation. Envisage that it will be used with file streams, e.t.c.
16 | */
17 | NonUserMode
18 | }
19 |
--------------------------------------------------------------------------------
/lab7/client/src/commandManager/externalRecievers/ExitReceiver.java:
--------------------------------------------------------------------------------
1 | package commandManager.externalRecievers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
5 |
6 | import java.util.Objects;
7 |
8 | public class ExitReceiver implements ExternalBaseReceiver {
9 |
10 | @Override
11 | public boolean receiveCommand(String name, char[] passwd, CommandDescription command, String[] args) {
12 | if (!Objects.equals(command.getName(), "exit")) return true;
13 |
14 | System.exit(0);
15 | return false;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/BuildObjectException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class BuildObjectException extends Exception {
4 | public BuildObjectException(String msg)
5 | {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/CommandInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class CommandInterruptedException extends RuntimeException {
4 | public CommandInterruptedException(Exception cause)
5 | {
6 | super(cause);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/CommandsNotLoadedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class CommandsNotLoadedException extends Exception {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/ServerNotAvailableException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class ServerNotAvailableException extends Exception {
4 |
5 | public ServerNotAvailableException(String msg) {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/StreamInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class StreamInterruptedException extends Exception {
4 | public StreamInterruptedException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message)
13 | {
14 | super(message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/UnsupportedResponseException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UnsupportedResponseException extends Exception {
4 | public UnsupportedResponseException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/client/src/exceptions/WrongAmountOfArgumentsException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class WrongAmountOfArgumentsException extends Exception {
4 | public WrongAmountOfArgumentsException(String msg)
5 | {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab7/client/src/main/Utilities.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import exceptions.StreamInterruptedException;
4 | import exceptions.WrongAmountOfArgumentsException;
5 |
6 | import java.util.Scanner;
7 | import java.util.concurrent.ThreadLocalRandom;
8 |
9 | public class Utilities {
10 | public static void checkArgumentsOrThrow(int provided, int expected) throws WrongAmountOfArgumentsException {
11 | if (provided - 1 != expected)
12 | throw new WrongAmountOfArgumentsException("Provided " + (provided - 1) + " arguments, expected " + expected);
13 | }
14 |
15 | /**
16 | * Generates a unique ID based on threads
17 | *
18 | * @return the unique ID that was generated
19 | */
20 | public static Long generateId() {
21 | Long id;
22 | id = ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
23 | return id;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lab7/client/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/lab7/client/src/models/handlers/ModeManager.java:
--------------------------------------------------------------------------------
1 | package models.handlers;
2 |
3 | import exceptions.BuildObjectException;
4 |
5 | /**
6 | * Interface for mode managers that can generate objects.
7 | *
8 | * @param The type of object this manager generates.
9 | */
10 | public interface ModeManager {
11 | /**
12 | * Generates a new object of type T.
13 | *
14 | * @return The newly created object.
15 | * @throws BuildObjectException If an error occurred during object creation.
16 | */
17 | T buildObject() throws BuildObjectException;
18 | }
19 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/AreaValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for Area
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class AreaValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/CoordinateXValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateX
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateXValidator implements Validator {
10 | public String getDescr() {
11 | return "x <= 499";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value <= 499;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/CoordinateYValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateY
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateYValidator implements Validator {
10 | public String getDescr() {
11 | return "value > -27";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value > -274 && value <= Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/InputValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for user input.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class InputValidator{
10 | /**
11 | * Checks if value not null and not blank.
12 | *
13 | * @param value name to validate
14 | * @return true/false -- matches the restrictions
15 | */
16 | boolean canBeNull = false;
17 | public String getDescr() {
18 | return "Validates user input";
19 | }
20 | public boolean validate(String value) {
21 | if (!canBeNull)
22 | return !value.isEmpty() && !value.isBlank();
23 | return true;
24 | }
25 |
26 | public void canBeNull(boolean canBeNull) {
27 | this.canBeNull = canBeNull;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/MetersAboveSeaLevelValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for MetersAboveSeaLevel.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class MetersAboveSeaLevelValidator implements Validator {
10 | public String getDescr() {
11 | return "any value, that fits Double format";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value < Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/NameValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for name field. (City)
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class NameValidator implements Validator {
10 | @Override
11 | public String getDescr() {
12 | return "Validates name field";
13 | }
14 |
15 | /**
16 | * Checks if value not null and not blank.
17 | *
18 | * @see models.City
19 | * @param value name to validate
20 | * @return true/false -- matches the restrictions
21 | */
22 | @Override
23 | public boolean validate(String value) {
24 | return !value.isEmpty() && !value.isBlank();
25 | }
26 | }
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/PopulationValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for Population.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class PopulationValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/client/src/models/validators/Validator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Base validator. You should implement it for usage.
5 | *
6 | * @since 2.0
7 | * @param Type of validation value.
8 | */
9 | public interface Validator {
10 | boolean canBeNull = false;
11 |
12 | /**
13 | * Provides validation method.
14 | *
15 | * @param value value to validate
16 | * @return true if value is validate. Otherwise false.
17 | */
18 | boolean validate(T value);
19 |
20 | /**
21 | * Provides description for all validators.
22 | *
23 | * @return String description of validator
24 | */
25 | String getDescr();
26 | }
27 |
--------------------------------------------------------------------------------
/lab7/client/src/serverLogic/ServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 |
6 | public interface ServerConnectionFactory {
7 | ServerConnection openConnection(InetAddress host, int port) throws IOException;
8 | }
9 |
--------------------------------------------------------------------------------
/lab7/client/src/serverLogic/ServerConnectionHandler.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | public class ServerConnectionHandler {
4 |
5 | private static ServerConnection currentConnection;
6 |
7 | public static void setServerConnection(ServerConnection connection) {
8 | currentConnection = connection;
9 | }
10 |
11 | public static ServerConnection getCurrentConnection() {
12 | return currentConnection;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab7/client/src/serverLogic/UdpConnectionBlockDecorator.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 |
5 | public class UdpConnectionBlockDecorator extends UdpServerConnection {
6 | private final UdpServerConnection baseConnection;
7 | private final boolean configureBlock;
8 |
9 | public UdpConnectionBlockDecorator(UdpServerConnection baseConnection, boolean configureBlock) throws IOException {
10 | super(baseConnection.channel, baseConnection.address);
11 | this.baseConnection = baseConnection;
12 | this.configureBlock = configureBlock;
13 | baseConnection.channel.configureBlocking(configureBlock);
14 | }
15 |
16 | public boolean getLockState() {
17 | return configureBlock;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab7/client/src/serverLogic/UdpServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 | import java.net.InetSocketAddress;
6 | import java.net.SocketAddress;
7 | import java.nio.channels.DatagramChannel;
8 |
9 | public class UdpServerConnectionFactory implements ServerConnectionFactory {
10 | public ServerConnection openConnection(InetAddress host, int port) throws IOException {
11 | DatagramChannel dc;
12 | SocketAddress addr;
13 | addr = new InetSocketAddress(host, port);
14 | dc = DatagramChannel.open();
15 | return new UdpServerConnection(dc, addr);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/database/Database.drawio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab7/database/Database.drawio.png
--------------------------------------------------------------------------------
/lab7/database/scripts.sql:
--------------------------------------------------------------------------------
1 | -- How to get all City collections by user_id:
2 | SELECT City.*
3 | FROM City c
4 | JOIN Creator cr ON c.id = cr.city_id
5 | WHERE cr.user_id = ;
--------------------------------------------------------------------------------
/lab7/docs/report.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab7/docs/report.docx
--------------------------------------------------------------------------------
/lab7/docs/report.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:a48b65fae0f748c3968c7a847ad84afda08abeedb65a0db7dc7a5942c47ce0d0
3 | size 207408
4 |
--------------------------------------------------------------------------------
/lab7/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/lab7/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/lab7/server/src/collectionStorageManager/DatabaseManager.java:
--------------------------------------------------------------------------------
1 | package collectionStorageManager;
2 |
3 | import models.City;
4 |
5 | import java.util.ArrayList;
6 |
7 | public interface DatabaseManager {
8 | ArrayList getCollectionFromDatabase();
9 |
10 | void writeCollectionToDatabase();
11 | }
12 |
--------------------------------------------------------------------------------
/lab7/server/src/commandManager/commands/ArgumentConsumer.java:
--------------------------------------------------------------------------------
1 | package commandManager.commands;
2 |
3 | /**
4 | * Provides Argument Consumer
5 | *
6 | * @param Argument param
7 | * @author worthant
8 | * @since 2.0
9 | */
10 | public interface ArgumentConsumer {
11 | void setObj(T obj);
12 | }
13 |
--------------------------------------------------------------------------------
/lab7/server/src/commandManager/commands/ExecuteScriptCommand.java:
--------------------------------------------------------------------------------
1 | package commandManager.commands;
2 |
3 | import responses.CommandStatusResponse;
4 |
5 | public class ExecuteScriptCommand implements BaseCommand {
6 | private CommandStatusResponse response;
7 | @Override
8 | public String getName() {
9 | return "execute_script";
10 | }
11 |
12 | @Override
13 | public String getDescr() {
14 | return "Reads and executes script from file.";
15 | }
16 |
17 | @Override
18 | public String getArgs() {
19 | return "file_path";
20 | }
21 |
22 | @Override
23 | public void execute(String[] args) throws IllegalArgumentException {
24 | response = CommandStatusResponse.ofString("Server is alive and ready for command executing!");
25 | }
26 |
27 | @Override
28 | public CommandStatusResponse getResponse() {
29 | return response;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lab7/server/src/exceptions/InvalidRequestException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class InvalidRequestException extends Exception {
4 | public InvalidRequestException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/server/src/exceptions/NotAvailableException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 |
7 | public class NotAvailableException extends Exception {
8 |
9 | private static final Logger logger = LogManager.getLogger("com.github.zerumi.lab6");
10 | private final CallerBack deniedClient;
11 |
12 | public NotAvailableException(CallerBack deniedClient) {
13 | this.deniedClient = deniedClient;
14 | logger.info("Denied connection: " + deniedClient);
15 | }
16 |
17 | public CallerBack getDeniedClient() {
18 | return deniedClient;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab7/server/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message) {
13 | super(message);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab7/server/src/exceptions/UnsupportedRequestException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UnsupportedRequestException extends Exception {
4 | public UnsupportedRequestException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/server/src/exceptions/UserNotAuthenticatedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UserNotAuthenticatedException extends Exception {
4 | public UserNotAuthenticatedException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/server/src/main/resources/db.cfg:
--------------------------------------------------------------------------------
1 | user = postgres
2 | password = b3514132
3 |
--------------------------------------------------------------------------------
/lab7/server/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lab7/server/src/multithreading/MultithreadingManager.java:
--------------------------------------------------------------------------------
1 | package multithreading;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 |
6 | public class MultithreadingManager {
7 | private static final ExecutorService requestThreadPool = Executors.newFixedThreadPool(4);
8 | private static final ExecutorService responseThreadPool = Executors.newCachedThreadPool();
9 |
10 | public static ExecutorService getRequestThreadPool() {
11 | return requestThreadPool;
12 | }
13 |
14 | public static ExecutorService getResponseThreadPool() {
15 | return responseThreadPool;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/server/src/requestLogic/RequestReader.java:
--------------------------------------------------------------------------------
1 | package requestLogic;
2 |
3 | import requests.BaseRequest;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.ObjectInputStream;
8 |
9 | public class RequestReader {
10 | final InputStream in;
11 |
12 | public RequestReader(InputStream in) {
13 | this.in = in;
14 | }
15 |
16 | public BaseRequest readObject() throws IOException, ClassNotFoundException {
17 | ObjectInputStream ois = new ObjectInputStream(in);
18 | return (BaseRequest) ois.readObject();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab7/server/src/requestLogic/StatusRequest.java:
--------------------------------------------------------------------------------
1 | package requestLogic;
2 |
3 | import java.io.InputStream;
4 |
5 | public class StatusRequest {
6 | private InputStream inputStream;
7 | private CallerBack callerBack;
8 | private int code;
9 |
10 | public InputStream getInputStream() {
11 | return inputStream;
12 | }
13 |
14 | public void setInputStream(InputStream inputStream) {
15 | this.inputStream = inputStream;
16 | }
17 |
18 | public CallerBack getCallerBack() {
19 | return callerBack;
20 | }
21 |
22 | public void setCallerBack(CallerBack callerBack) {
23 | this.callerBack = callerBack;
24 | }
25 |
26 | public int getCode() {
27 | return code;
28 | }
29 |
30 | public void setCode(int code) {
31 | this.code = code;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/lab7/server/src/requestLogic/requestWorkers/BaseRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.requests.ServerRequest;
6 |
7 | public class BaseRequestWorker implements RequestWorker {
8 |
9 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
10 |
11 | @Override
12 | public void workWithRequest(ServerRequest request) {
13 | logger.info("we've got base request wow");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab7/server/src/requestLogic/requestWorkers/CommandConfigureRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandManager.CommandExporter;
5 | import requestLogic.requests.ServerRequest;
6 | import responseLogic.responseSenders.CommandConfigureResponseSender;
7 | import responses.CommandDescriptionsResponse;
8 |
9 | import java.util.ArrayList;
10 |
11 | public class CommandConfigureRequestWorker implements RequestWorker {
12 | @Override
13 | public void workWithRequest(ServerRequest request) {
14 | ArrayList commands = CommandExporter.getCommandsToExport();
15 | CommandDescriptionsResponse response = new CommandDescriptionsResponse(commands);
16 | CommandConfigureResponseSender.sendResponse(response, request.getConnection(), request.getFrom());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab7/server/src/requestLogic/requestWorkers/RequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import requestLogic.requests.ServerRequest;
4 |
5 | public interface RequestWorker {
6 | void workWithRequest(ServerRequest request);
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/server/src/requestLogic/requests/ServerRequest.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requests;
2 |
3 | import requestLogic.CallerBack;
4 | import requests.BaseRequest;
5 | import serverLogic.ServerConnection;
6 |
7 | public class ServerRequest {
8 | private final BaseRequest request;
9 | private final CallerBack from;
10 | private final ServerConnection connection;
11 |
12 | public ServerRequest(BaseRequest request, CallerBack from, ServerConnection connection) {
13 | this.request = request;
14 | this.from = from;
15 | this.connection = connection;
16 | }
17 |
18 | public BaseRequest getUserRequest() {
19 | return request;
20 | }
21 |
22 | public ServerConnection getConnection() {
23 | return connection;
24 | }
25 |
26 | public CallerBack getFrom() {
27 | return from;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab7/server/src/responseLogic/responseSenders/CommandConfigureResponseSender.java:
--------------------------------------------------------------------------------
1 | package responseLogic.responseSenders;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 | import responses.CommandDescriptionsResponse;
7 | import serverLogic.ServerConnection;
8 |
9 | import java.io.IOException;
10 |
11 | public class CommandConfigureResponseSender {
12 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
13 |
14 | public static void sendResponse(CommandDescriptionsResponse response, ServerConnection connection, CallerBack to) {
15 | if (response != null) {
16 | ResponseSender.sendResponse(response, connection, to);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab7/server/src/responseLogic/responseSenders/CommandResponseSender.java:
--------------------------------------------------------------------------------
1 | package responseLogic.responseSenders;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 | import responses.CommandStatusResponse;
7 | import serverLogic.ServerConnection;
8 |
9 | import java.io.IOException;
10 |
11 | public class CommandResponseSender {
12 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
13 |
14 | public static void sendResponse(CommandStatusResponse response, ServerConnection connection, CallerBack to) {
15 | if (response != null) {
16 | ResponseSender.sendResponse(response, connection, to);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab7/server/src/serverLogic/ServerConnection.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import requestLogic.StatusRequest;
4 |
5 | import java.io.IOException;
6 | import java.net.InetAddress;
7 | import java.net.SocketTimeoutException;
8 |
9 | public interface ServerConnection {
10 | StatusRequest listenAndGetData() throws SocketTimeoutException, IOException;
11 |
12 | void sendData(byte[] data, InetAddress addr, int port);
13 | }
14 |
--------------------------------------------------------------------------------
/lab7/server/src/serverLogic/ServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | public interface ServerConnectionFactory {
4 | ServerConnection initializeServer(int port);
5 |
6 | ServerConnection initializeServer(int port, int timeout);
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'server'
2 | include 'client'
3 | include 'shared'
4 |
5 |
--------------------------------------------------------------------------------
/lab7/shared/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | version '1.2'
4 |
5 | sourceSets.main.java.srcDirs = ['src']
6 |
7 | repositories {
8 | mavenCentral()
9 | }
10 |
11 | dependencies {
12 | implementation 'org.modelmapper:modelmapper:3.1.1'
13 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
14 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
15 | }
16 |
17 | test {
18 | useJUnitPlatform()
19 | }
20 |
21 | jar {
22 | manifest {
23 | attributes(
24 | 'Main-Class': 'main.Main',
25 | 'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
26 | )
27 | }
28 | }
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/CommandDescription.java:
--------------------------------------------------------------------------------
1 | package commandLogic;
2 |
3 | import commandLogic.commandReceiverLogic.callers.ExternalCaller;
4 |
5 | import java.io.Serializable;
6 |
7 | public class CommandDescription implements Serializable {
8 | private final String name;
9 | private final ExternalCaller caller;
10 |
11 | public CommandDescription(String name, ExternalCaller caller) {
12 | this.name = name;
13 | this.caller = caller;
14 | }
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public ExternalCaller getReceiver() {
21 | return caller;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/callers/ExternalBaseReceiverCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 | import commandLogic.commandReceiverLogic.enums.ReceiverType;
6 |
7 | public class ExternalBaseReceiverCaller extends ExternalCaller {
8 | @Override
9 | public void callReceivers(String name, char[] passwd, ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception {
10 | var receiver = manager.getReceivers(ReceiverType.NoArgs);
11 | boolean commandCompleted = true;
12 | for (int i = 0; i < receiver.size() && commandCompleted; i++) {
13 | commandCompleted = receiver.get(i).receiveCommand(name, passwd, description, lineArgs);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/callers/ExternalCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 |
6 | import java.io.Serializable;
7 |
8 | public abstract class ExternalCaller implements Serializable {
9 | public abstract void callReceivers(String name, char[] passwd, ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception;
10 | }
11 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/enums/ReceiverType.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.enums;
2 |
3 | public enum ReceiverType {
4 | NoArgs,
5 | ArgumentRoute
6 | }
7 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/handlers/NonArgReceiversHandler.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.handlers;
2 |
3 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class NonArgReceiversHandler extends ReceiverHandler {
8 |
9 | private final ArrayList receivers;
10 |
11 | {
12 | receivers = new ArrayList<>();
13 | }
14 |
15 | @Override
16 | public void addReceiver(ExternalBaseReceiver receiver) {
17 | receivers.add(receiver);
18 | }
19 |
20 | @Override
21 | public ArrayList getReceivers() {
22 | return receivers;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/handlers/ReceiverHandler.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.handlers;
2 |
3 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
4 |
5 | import java.util.ArrayList;
6 |
7 | public abstract class ReceiverHandler {
8 | public abstract void addReceiver(ExternalBaseReceiver receiver);
9 |
10 | public abstract ArrayList extends ExternalBaseReceiver> getReceivers();
11 | }
12 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/receivers/ExternalArgumentReceiver.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.receivers;
2 |
3 | public interface ExternalArgumentReceiver extends ExternalBaseReceiver {
4 | T getArguemnt();
5 | }
6 |
--------------------------------------------------------------------------------
/lab7/shared/src/commandLogic/commandReceiverLogic/receivers/ExternalBaseReceiver.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.receivers;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public interface ExternalBaseReceiver {
6 | boolean receiveCommand(String name, char[] passwd, CommandDescription command, String[] args) throws Exception;
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/shared/src/main/Main.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | System.out.println("""
6 | Однажды Вася спросил у своего старшего брата-сеньора Пети:
7 | "Петя, зачем вообще нам нужно запускать общую библиотеку классов?"
8 | На что Петя ответил: "Братиш, для того, чтобы практик на защите прочитал этот текст.\"""");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/lab7/shared/src/models/Climate.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different climate types
7 | */
8 | public enum Climate implements Serializable {
9 | TROPICAL_SAVANNA,
10 | OCEANIC,
11 | STEPPE
12 | }
13 |
--------------------------------------------------------------------------------
/lab7/shared/src/models/Government.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different government types
7 | */
8 | public enum Government implements Serializable {
9 | ANARCHY,
10 | GERONTOCRACY,
11 | DEMARCHY,
12 | COMMUNISM,
13 | NOOCRACY,
14 | DEMOCRACY
15 | }
16 |
--------------------------------------------------------------------------------
/lab7/shared/src/models/StandardOfLiving.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different StandardOfLiving types
7 | */
8 | public enum StandardOfLiving implements Serializable {
9 | ULTRA_HIGH,
10 | VERY_HIGH,
11 | HIGH,
12 | ULTRA_LOW,
13 | NIGHTMARE
14 | }
15 |
--------------------------------------------------------------------------------
/lab7/shared/src/requests/ArgumentCommandClientRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public class ArgumentCommandClientRequest extends CommandClientRequest {
6 | private final T argument;
7 |
8 | public ArgumentCommandClientRequest(String name, char[] passwd, CommandDescription command, String[] lineArgs, T argument) {
9 | super(name, passwd, command, lineArgs);
10 | this.argument = argument;
11 | }
12 |
13 | public T getArgument() {
14 | return argument;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab7/shared/src/requests/AuthRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class AuthRequest extends BaseRequest {
4 | private final String name;
5 | private final char[] passwd;
6 | public AuthRequest(String name, char[] passwd) {
7 | this.name = name;
8 | this.passwd = passwd;
9 | }
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public char[] getPasswd() {
16 | return passwd;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab7/shared/src/requests/BaseRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class BaseRequest implements Serializable {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/lab7/shared/src/requests/CommandDescriptionsRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class CommandDescriptionsRequest extends BaseRequest {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/lab7/shared/src/requests/RegRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class RegRequest extends BaseRequest {
4 | private final String name;
5 | private final char[] passwd;
6 | public RegRequest(String name, char[] passwd) {
7 | this.name = name;
8 | this.passwd = passwd;
9 | }
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public char[] getPasswd() {
16 | return passwd;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab7/shared/src/responses/AuthResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class AuthResponse extends BaseResponse {
4 | boolean auth;
5 | public AuthResponse(boolean auth) {
6 | this.auth = auth;
7 | }
8 |
9 | public boolean isAuth() {
10 | return auth;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/lab7/shared/src/responses/BaseResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class BaseResponse implements Serializable {
6 | }
7 |
--------------------------------------------------------------------------------
/lab7/shared/src/responses/CommandDescriptionsResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class CommandDescriptionsResponse extends BaseResponse {
8 | private final ArrayList commands;
9 |
10 | public CommandDescriptionsResponse(ArrayList commands) {
11 | this.commands = commands;
12 | }
13 |
14 | public ArrayList getCommands() {
15 | return commands;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab7/shared/src/responses/CommandStatusResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class CommandStatusResponse extends BaseResponse {
4 |
5 | private final String response;
6 | private final int statusCode;
7 |
8 | public CommandStatusResponse(String response, int statusCode) {
9 | this.response = response;
10 | this.statusCode = statusCode;
11 | }
12 |
13 | public static CommandStatusResponse ofString(String s) {
14 | return new CommandStatusResponse(s, 0);
15 | }
16 |
17 | public String getResponse() {
18 | return response;
19 | }
20 |
21 | public int getStatusCode() {
22 | return statusCode;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab7/shared/src/responses/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class ErrorResponse extends BaseResponse {
4 |
5 | private final String msg;
6 |
7 | public ErrorResponse(String msg) {
8 | this.msg = msg;
9 | }
10 |
11 | public String getMsg() {
12 | return msg;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab7/shared/src/responses/RegResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class RegResponse extends BaseResponse{
4 | boolean reg;
5 | public RegResponse(boolean reg) {
6 | this.reg = reg;
7 | }
8 |
9 | public boolean isReg() {
10 | return reg;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/lab8/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
30 |
31 | ### Gradle old build ###
32 | build
33 | .gradle
34 | out
35 |
36 | ### Gradle client build ###
37 | client/build/
38 | client/.gradle/
39 | client/out/
40 |
41 | ### Gradle server build ###
42 | /server/build
43 | /server/.gradle/
44 | /server/out/
--------------------------------------------------------------------------------
/lab8/README.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:cf2db6857c8960f1e036a60b3a7a80faa074ab367ec0522d5a4d828555842f69
3 | size 394301
4 |
--------------------------------------------------------------------------------
/lab8/README.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/README.png
--------------------------------------------------------------------------------
/lab8/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'idea'
--------------------------------------------------------------------------------
/lab8/client/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: main.Main
3 |
4 |
--------------------------------------------------------------------------------
/lab8/client/src/commandManager/CommandDescriptionHolder.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class CommandDescriptionHolder {
8 |
9 | private static CommandDescriptionHolder instance;
10 | ArrayList commands;
11 |
12 | private CommandDescriptionHolder(ArrayList commands) {
13 | this.commands = commands;
14 | }
15 |
16 | public static void initialize(ArrayList commands) {
17 | instance = new CommandDescriptionHolder(commands);
18 | }
19 |
20 | public static CommandDescriptionHolder getInstance() {
21 | return instance;
22 | }
23 |
24 | public ArrayList getCommands() {
25 | return commands;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/lab8/client/src/commandManager/CommandLoaderUtility.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | import commandLogic.CommandDescription;
4 | import requestLogic.requestSenders.CommandDescriptionsRequestSender;
5 |
6 | import java.util.ArrayList;
7 |
8 | public class CommandLoaderUtility {
9 | public static void initializeCommands() {
10 | ArrayList commands = new CommandDescriptionsRequestSender().sendRequestAndGetCommands();
11 | CommandDescriptionHolder.initialize(commands);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lab8/client/src/commandManager/CommandMode.java:
--------------------------------------------------------------------------------
1 | package commandManager;
2 |
3 | /**
4 | * Contains information about mode of commands behavior
5 | *
6 | * @since 1.1
7 | * @author zerumi
8 | */
9 | public enum CommandMode {
10 | /**
11 | * Commands will use user-friendly interaction. Envisage that it will be used with System.in scanner
12 | */
13 | CLI_UserMode,
14 | /**
15 | * Commands will use simple interaction w/o user-orientation. Envisage that it will be used with file streams, e.t.c.
16 | */
17 | NonUserMode,
18 | /**
19 | * Commands will use gui-friendly interaction.
20 | */
21 | GUIMode
22 | }
23 |
--------------------------------------------------------------------------------
/lab8/client/src/commandManager/externalRecievers/ExitReceiver.java:
--------------------------------------------------------------------------------
1 | package commandManager.externalRecievers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
5 |
6 | import java.util.Objects;
7 |
8 | public class ExitReceiver implements ExternalBaseReceiver {
9 |
10 | @Override
11 | public boolean receiveCommand(String name, char[] passwd, CommandDescription command, String[] args) {
12 | if (!Objects.equals(command.getName(), "exit")) return true;
13 |
14 | System.exit(0);
15 | return false;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/BuildObjectException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class BuildObjectException extends Exception {
4 | public BuildObjectException(String msg)
5 | {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/CommandInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class CommandInterruptedException extends RuntimeException {
4 | public CommandInterruptedException(Exception cause)
5 | {
6 | super(cause);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/CommandsNotLoadedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class CommandsNotLoadedException extends Exception {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/ServerNotAvailableException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class ServerNotAvailableException extends Exception {
4 |
5 | public ServerNotAvailableException(String msg) {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/StreamInterruptedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class StreamInterruptedException extends Exception {
4 | public StreamInterruptedException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message)
13 | {
14 | super(message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/UnsupportedResponseException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UnsupportedResponseException extends Exception {
4 | public UnsupportedResponseException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/client/src/exceptions/WrongAmountOfArgumentsException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class WrongAmountOfArgumentsException extends Exception {
4 | public WrongAmountOfArgumentsException(String msg)
5 | {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/lab8/client/src/gui/commands/CommandsWindow.java:
--------------------------------------------------------------------------------
1 | package gui.commands;
2 |
3 | public class CommandsWindow {
4 | }
5 |
--------------------------------------------------------------------------------
/lab8/client/src/gui/commands/CommandsWindowController.java:
--------------------------------------------------------------------------------
1 | package gui.commands;
2 |
3 | public class CommandsWindowController {
4 | }
5 |
--------------------------------------------------------------------------------
/lab8/client/src/gui/edit/EditWindow.java:
--------------------------------------------------------------------------------
1 | package gui.edit;
2 |
3 | public class EditWindow {
4 | }
5 |
--------------------------------------------------------------------------------
/lab8/client/src/gui/edit/EditWindowController.java:
--------------------------------------------------------------------------------
1 | package gui.edit;
2 |
3 | public class EditWindowController {
4 | }
5 |
--------------------------------------------------------------------------------
/lab8/client/src/gui/music/MusicWindowController.java:
--------------------------------------------------------------------------------
1 | package gui.music;
2 |
3 | public class MusicWindowController {
4 | }
5 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/commands/commandsWindow.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/commands/style.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/commands/style.css
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/create/style.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/create/style.css
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/edit/editWindow.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/edit/style.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/edit/style.css
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/fonts/YouSheBiaoTiHei Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/fonts/YouSheBiaoTiHei Regular.ttf
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/fonts/ZCOOLXiaoWei-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/fonts/ZCOOLXiaoWei-Regular.ttf
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/building.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/building.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/city.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/city.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/city2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/city2.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/geo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/geo.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/location-pin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/location-pin.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/map.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/pointer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/pointer.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/spotify (1).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/spotify (1).png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/spotify (2).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/spotify (2).png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/spotify.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/spotify.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/spotify2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/spotify2.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/spotify3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/spotify3.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_10.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_12.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_14.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_16.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_18.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_19.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_21.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_30.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/icon_36.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/svg/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/svg/main.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/icons/thick_building.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/icons/thick_building.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/Sigrid - It Gets Dark.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/Sigrid - It Gets Dark.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_Falling_In_Reverse_-_Voices_In_My_Head_74364895.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_Falling_In_Reverse_-_Voices_In_My_Head_74364895.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_Normandie_-_Ecstasy_63646428.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_Normandie_-_Ecstasy_63646428.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_Normandie_-_White_Flag_60279007.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_Normandie_-_White_Flag_60279007.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Alone_in_the_Snow_47893460.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Alone_in_the_Snow_47893460.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Antidote_62786624.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Antidote_62786624.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Beyond_Empty_67152992.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Beyond_Empty_67152992.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Robots_75606020.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/music/ruesellamusicnet_We_Are_The_Empty_-_Robots_75606020.mp3
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/pics/img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/pics/img.png
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/scripts/alex_script.txt:
--------------------------------------------------------------------------------
1 | add
2 | Mc'Dondonalds
3 | 123
4 | 321
5 | 23456213
6 | 24523452
7 | 1233543
8 | 2
9 | 2
10 | 2
11 | alex
12 |
13 | add
14 | space station
15 | 000
16 | 000
17 | 1346542
18 | 91
19 | 1987564193874562039857203584729835674
20 | 7
21 | 9
22 | 3
23 | alex
24 |
25 | add
26 | old york
27 | 23
28 | 14
29 | 999
30 | 999
31 | 999
32 | 3
33 | 3
34 | 3
35 | alex
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/scripts/worthant_script.txt:
--------------------------------------------------------------------------------
1 | add
2 | rly annoying
3 | 5
4 | 5
5 | 5
6 | 5
7 | 5
8 | 5
9 | 5
10 | 5
11 | worthant
12 |
13 | add
14 | california idk
15 | 345
16 | 543
17 | 1346542
18 | 7267
19 | 13045786
20 | 4
21 | 1
22 | 8
23 | worthant
24 |
25 | add
26 | some cool city
27 | 888
28 | 888
29 | 734
30 | 7543
31 | 2345
32 | 4
33 | 7
34 | 2
35 | worthant
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/visualization/style.css:
--------------------------------------------------------------------------------
1 | .canvas {
2 | -fx-border-color: #797979;
3 | -fx-border-radius: 2;
4 | -fx-font-family: "ZCOOL XiaoWei Regular";
5 | }
6 |
7 | .grid-pane {
8 | -fx-padding: 2;
9 | -fx-hgap: 2;
10 | -fx-vgap: 2;
11 | -fx-background-color: #797979;
12 | }
13 |
14 | .grid-pane .cell {
15 | -fx-background-color: white;
16 | -fx-padding: 10;
17 | -fx-alignment: center;
18 | }
19 |
20 | .borderPane-style {
21 | -fx-background-color: #F2FDF2;
22 | -fx-border-width: 1px;
23 | -fx-border-color: rgba(40, 49, 66, 100);
24 | -fx-border-radius: 0px;
25 | }
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/worldMap/icon_sprites.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/client/src/main/resources/worldMap/icon_sprites.js
--------------------------------------------------------------------------------
/lab8/client/src/main/resources/worldMap/map.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My cities visualization
5 |
6 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lab8/client/src/main/utilities/Utilities.java:
--------------------------------------------------------------------------------
1 | package main.utilities;
2 |
3 | import exceptions.StreamInterruptedException;
4 | import exceptions.WrongAmountOfArgumentsException;
5 |
6 | import java.util.Scanner;
7 | import java.util.concurrent.ThreadLocalRandom;
8 |
9 | public class Utilities {
10 | public static void checkArgumentsOrThrow(int provided, int expected) throws WrongAmountOfArgumentsException {
11 | if (provided - 1 != expected)
12 | throw new WrongAmountOfArgumentsException("Provided " + (provided - 1) + " arguments, expected " + expected);
13 | }
14 |
15 | /**
16 | * Generates a unique ID based on threads
17 | *
18 | * @return the unique ID that was generated
19 | */
20 | public static Long generateId() {
21 | Long id;
22 | id = ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
23 | return id;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lab8/client/src/models/handlers/ModeManager.java:
--------------------------------------------------------------------------------
1 | package models.handlers;
2 |
3 | import exceptions.BuildObjectException;
4 |
5 | /**
6 | * Interface for mode managers that can generate objects.
7 | *
8 | * @param The type of object this manager generates.
9 | */
10 | public interface ModeManager {
11 | /**
12 | * Generates a new object of type T.
13 | *
14 | * @return The newly created object.
15 | * @throws BuildObjectException If an error occurred during object creation.
16 | */
17 | T buildObject() throws BuildObjectException;
18 | }
19 |
--------------------------------------------------------------------------------
/lab8/client/src/models/handlers/guiMode/GUIManager.java:
--------------------------------------------------------------------------------
1 | package models.handlers.guiMode;
2 |
3 | import client.DataHolder;
4 | import exceptions.BuildObjectException;
5 | import models.*;
6 | import models.handlers.ModeManager;
7 |
8 | public class GUIManager implements ModeManager {
9 |
10 | @Override
11 | public City buildObject() throws BuildObjectException {
12 | try {
13 | return DataHolder.getInstance().getCityObject();
14 | } catch (Exception e) {
15 | throw new BuildObjectException("Возникла ошибка в GUIManager");
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/AreaValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for Area
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class AreaValidator implements Validator {
10 | public String getDescr() {
11 | return "Constraints: should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/CoordinateXValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateX
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateXValidator implements Validator {
10 | public String getDescr() {
11 | return "Constraints: 0 <= x <= 1000";
12 | }
13 | @Deprecated
14 | public boolean validateOld(Integer value) {
15 | return value <= 499;
16 | }
17 |
18 | @Override
19 | public boolean validate(Integer value) {return value >= 0 & value <= 1000;}
20 | }
21 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/CoordinateYValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for CoordinateY
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class CoordinateYValidator implements Validator {
10 | public String getDescr() {
11 | return "Constraints: 0 <= y <= 1000";
12 | }
13 | @Deprecated
14 | public boolean validateOld(Double value) {
15 | return value > -274 && value <= Double.MAX_VALUE;
16 | }
17 |
18 | @Override
19 | public boolean validate(Double value) {return value >= 0 & value <= 1000;}
20 | }
21 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/InputValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for user input.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class InputValidator{
10 | /**
11 | * Checks if value not null and not blank.
12 | *
13 | * @param value name to validate
14 | * @return true/false -- matches the restrictions
15 | */
16 | boolean canBeNull = false;
17 | public String getDescr() {
18 | return "Validates user input";
19 | }
20 | public boolean validate(String value) {
21 | if (!canBeNull)
22 | return !value.isEmpty() && !value.isBlank();
23 | return true;
24 | }
25 |
26 | public void canBeNull(boolean canBeNull) {
27 | this.canBeNull = canBeNull;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/MetersAboveSeaLevelValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for MetersAboveSeaLevel.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class MetersAboveSeaLevelValidator implements Validator {
10 | public String getDescr() {
11 | return "any value, that fits Double format";
12 | }
13 | @Override
14 | public boolean validate(Double value) {
15 | return value < Double.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/NameValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for name field. (City)
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class NameValidator implements Validator {
10 | @Override
11 | public String getDescr() {
12 | return "Constraints: shouldn't be empty";
13 | }
14 |
15 | /**
16 | * Checks if value not null and not blank.
17 | *
18 | * @see models.City
19 | * @param value name to validate
20 | * @return true/false -- matches the restrictions
21 | */
22 | @Override
23 | public boolean validate(String value) {
24 | return !value.isEmpty() && !value.isBlank();
25 | }
26 | }
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/PopulationValidator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Implementation of validator for Population.
5 | *
6 | * @since 2.0
7 | * @author boris
8 | */
9 | public class PopulationValidator implements Validator {
10 | public String getDescr() {
11 | return "Should be greater than 0";
12 | }
13 | @Override
14 | public boolean validate(Integer value) {
15 | return value > 0 && value < Integer.MAX_VALUE;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/client/src/models/validators/Validator.java:
--------------------------------------------------------------------------------
1 | package models.validators;
2 |
3 | /**
4 | * Base validator. You should implement it for usage.
5 | *
6 | * @since 2.0
7 | * @param Type of validation value.
8 | */
9 | public interface Validator {
10 | boolean canBeNull = false;
11 |
12 | /**
13 | * Provides validation method.
14 | *
15 | * @param value value to validate
16 | * @return true if value is validate. Otherwise false.
17 | */
18 | boolean validate(T value);
19 |
20 | /**
21 | * Provides description for all validators.
22 | *
23 | * @return String description of validator
24 | */
25 | String getDescr();
26 | }
27 |
--------------------------------------------------------------------------------
/lab8/client/src/serverLogic/ServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 |
6 | public interface ServerConnectionFactory {
7 | ServerConnection openConnection(InetAddress host, int port) throws IOException;
8 | }
9 |
--------------------------------------------------------------------------------
/lab8/client/src/serverLogic/ServerConnectionHandler.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | public class ServerConnectionHandler {
4 |
5 | private static ServerConnection currentConnection;
6 |
7 | public static void setServerConnection(ServerConnection connection) {
8 | currentConnection = connection;
9 | }
10 |
11 | public static ServerConnection getCurrentConnection() {
12 | return currentConnection;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab8/client/src/serverLogic/UdpConnectionBlockDecorator.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 |
5 | public class UdpConnectionBlockDecorator extends UdpServerConnection {
6 | private final UdpServerConnection baseConnection;
7 | private final boolean configureBlock;
8 |
9 | public UdpConnectionBlockDecorator(UdpServerConnection baseConnection, boolean configureBlock) throws IOException {
10 | super(baseConnection.channel, baseConnection.address);
11 | this.baseConnection = baseConnection;
12 | this.configureBlock = configureBlock;
13 | baseConnection.channel.configureBlocking(configureBlock);
14 | }
15 |
16 | public boolean getLockState() {
17 | return configureBlock;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab8/client/src/serverLogic/UdpServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import java.io.IOException;
4 | import java.net.InetAddress;
5 | import java.net.InetSocketAddress;
6 | import java.net.SocketAddress;
7 | import java.nio.channels.DatagramChannel;
8 |
9 | public class UdpServerConnectionFactory implements ServerConnectionFactory {
10 | public ServerConnection openConnection(InetAddress host, int port) throws IOException {
11 | DatagramChannel dc;
12 | SocketAddress addr;
13 | addr = new InetSocketAddress(host, port);
14 | dc = DatagramChannel.open();
15 | return new UdpServerConnection(dc, addr);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/database/Database.drawio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/database/Database.drawio.png
--------------------------------------------------------------------------------
/lab8/database/scripts.sql:
--------------------------------------------------------------------------------
1 | -- How to get all City collections by user_id:
2 | SELECT City.*
3 | FROM City c
4 | JOIN Creator cr ON c.id = cr.city_id
5 | WHERE cr.user_id = ;
--------------------------------------------------------------------------------
/lab8/docs/report.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/docs/report.docx
--------------------------------------------------------------------------------
/lab8/docs/report.pdf:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:a48b65fae0f748c3968c7a847ad84afda08abeedb65a0db7dc7a5942c47ce0d0
3 | size 207408
4 |
--------------------------------------------------------------------------------
/lab8/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worthant/Java-labs/643fbd8d986c170938ffc2da053bb40436675771/lab8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/lab8/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/lab8/server/src/collectionStorageManager/DatabaseManager.java:
--------------------------------------------------------------------------------
1 | package collectionStorageManager;
2 |
3 | import models.City;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Map;
7 |
8 | public interface DatabaseManager {
9 | ArrayList getCollectionFromDatabase();
10 |
11 | void writeCollectionToDatabase();
12 |
13 | Map getOwnerShipMap();
14 | }
15 |
--------------------------------------------------------------------------------
/lab8/server/src/commandManager/commands/ArgumentConsumer.java:
--------------------------------------------------------------------------------
1 | package commandManager.commands;
2 |
3 | /**
4 | * Provides Argument Consumer
5 | *
6 | * @param Argument param
7 | * @author worthant
8 | * @since 2.0
9 | */
10 | public interface ArgumentConsumer {
11 | void setObj(T obj);
12 | }
13 |
--------------------------------------------------------------------------------
/lab8/server/src/exceptions/InvalidRequestException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class InvalidRequestException extends Exception {
4 | public InvalidRequestException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/server/src/exceptions/NotAvailableException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 |
7 | public class NotAvailableException extends Exception {
8 |
9 | private static final Logger logger = LogManager.getLogger("com.github.zerumi.lab6");
10 | private final CallerBack deniedClient;
11 |
12 | public NotAvailableException(CallerBack deniedClient) {
13 | this.deniedClient = deniedClient;
14 | logger.info("Denied connection: " + deniedClient);
15 | }
16 |
17 | public CallerBack getDeniedClient() {
18 | return deniedClient;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab8/server/src/exceptions/UnknownCommandException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | /**
4 | * Provides a simple exception, indicates that command isn't found in manager
5 | */
6 | public class UnknownCommandException extends Exception {
7 | /**
8 | * Constructor with message.
9 | *
10 | * @param message Message to show
11 | */
12 | public UnknownCommandException(String message) {
13 | super(message);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab8/server/src/exceptions/UnsupportedRequestException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UnsupportedRequestException extends Exception {
4 | public UnsupportedRequestException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/server/src/exceptions/UserNotAuthenticatedException.java:
--------------------------------------------------------------------------------
1 | package exceptions;
2 |
3 | public class UserNotAuthenticatedException extends Exception {
4 | public UserNotAuthenticatedException(String msg) {
5 | super(msg);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/server/src/main/resources/db.cfg:
--------------------------------------------------------------------------------
1 | user = postgres
2 | password = b3514132
3 |
--------------------------------------------------------------------------------
/lab8/server/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lab8/server/src/multithreading/MultithreadingManager.java:
--------------------------------------------------------------------------------
1 | package multithreading;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 |
6 | public class MultithreadingManager {
7 | private static final ExecutorService requestThreadPool = Executors.newFixedThreadPool(4);
8 | private static final ExecutorService responseThreadPool = Executors.newCachedThreadPool();
9 |
10 | public static ExecutorService getRequestThreadPool() {
11 | return requestThreadPool;
12 | }
13 |
14 | public static ExecutorService getResponseThreadPool() {
15 | return responseThreadPool;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/server/src/requestLogic/RequestReader.java:
--------------------------------------------------------------------------------
1 | package requestLogic;
2 |
3 | import requests.BaseRequest;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.ObjectInputStream;
8 |
9 | public class RequestReader {
10 | final InputStream in;
11 |
12 | public RequestReader(InputStream in) {
13 | this.in = in;
14 | }
15 |
16 | public BaseRequest readObject() throws IOException, ClassNotFoundException {
17 | ObjectInputStream ois = new ObjectInputStream(in);
18 | return (BaseRequest) ois.readObject();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/lab8/server/src/requestLogic/StatusRequest.java:
--------------------------------------------------------------------------------
1 | package requestLogic;
2 |
3 | import java.io.InputStream;
4 |
5 | public class StatusRequest {
6 | private InputStream inputStream;
7 | private CallerBack callerBack;
8 | private int code;
9 |
10 | public InputStream getInputStream() {
11 | return inputStream;
12 | }
13 |
14 | public void setInputStream(InputStream inputStream) {
15 | this.inputStream = inputStream;
16 | }
17 |
18 | public CallerBack getCallerBack() {
19 | return callerBack;
20 | }
21 |
22 | public void setCallerBack(CallerBack callerBack) {
23 | this.callerBack = callerBack;
24 | }
25 |
26 | public int getCode() {
27 | return code;
28 | }
29 |
30 | public void setCode(int code) {
31 | this.code = code;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/lab8/server/src/requestLogic/requestWorkers/BaseRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.requests.ServerRequest;
6 |
7 | public class BaseRequestWorker implements RequestWorker {
8 |
9 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
10 |
11 | @Override
12 | public void workWithRequest(ServerRequest request) {
13 | logger.info("we've got base request wow");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lab8/server/src/requestLogic/requestWorkers/CommandConfigureRequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandManager.CommandExporter;
5 | import requestLogic.requests.ServerRequest;
6 | import responseLogic.responseSenders.CommandConfigureResponseSender;
7 | import responses.CommandDescriptionsResponse;
8 |
9 | import java.util.ArrayList;
10 |
11 | public class CommandConfigureRequestWorker implements RequestWorker {
12 | @Override
13 | public void workWithRequest(ServerRequest request) {
14 | ArrayList commands = CommandExporter.getCommandsToExport();
15 | CommandDescriptionsResponse response = new CommandDescriptionsResponse(commands);
16 | CommandConfigureResponseSender.sendResponse(response, request.getConnection(), request.getFrom());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab8/server/src/requestLogic/requestWorkers/RequestWorker.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requestWorkers;
2 |
3 | import requestLogic.requests.ServerRequest;
4 |
5 | public interface RequestWorker {
6 | void workWithRequest(ServerRequest request);
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/server/src/requestLogic/requests/ServerRequest.java:
--------------------------------------------------------------------------------
1 | package requestLogic.requests;
2 |
3 | import requestLogic.CallerBack;
4 | import requests.BaseRequest;
5 | import serverLogic.ServerConnection;
6 |
7 | public class ServerRequest {
8 | private final BaseRequest request;
9 | private final CallerBack from;
10 | private final ServerConnection connection;
11 |
12 | public ServerRequest(BaseRequest request, CallerBack from, ServerConnection connection) {
13 | this.request = request;
14 | this.from = from;
15 | this.connection = connection;
16 | }
17 |
18 | public BaseRequest getUserRequest() {
19 | return request;
20 | }
21 |
22 | public ServerConnection getConnection() {
23 | return connection;
24 | }
25 |
26 | public CallerBack getFrom() {
27 | return from;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/lab8/server/src/responseLogic/responseSenders/CommandConfigureResponseSender.java:
--------------------------------------------------------------------------------
1 | package responseLogic.responseSenders;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 | import responses.CommandDescriptionsResponse;
7 | import serverLogic.ServerConnection;
8 |
9 | import java.io.IOException;
10 |
11 | public class CommandConfigureResponseSender {
12 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
13 |
14 | public static void sendResponse(CommandDescriptionsResponse response, ServerConnection connection, CallerBack to) {
15 | if (response != null) {
16 | ResponseSender.sendResponse(response, connection, to);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab8/server/src/responseLogic/responseSenders/CommandResponseSender.java:
--------------------------------------------------------------------------------
1 | package responseLogic.responseSenders;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import requestLogic.CallerBack;
6 | import responses.CommandStatusResponse;
7 | import serverLogic.ServerConnection;
8 |
9 | import java.io.IOException;
10 |
11 | public class CommandResponseSender {
12 | private static final Logger logger = LogManager.getLogger("io.github.worthant.lab6");
13 |
14 | public static void sendResponse(CommandStatusResponse response, ServerConnection connection, CallerBack to) {
15 | if (response != null) {
16 | ResponseSender.sendResponse(response, connection, to);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lab8/server/src/serverLogic/ServerConnection.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | import requestLogic.StatusRequest;
4 |
5 | import java.io.IOException;
6 | import java.net.InetAddress;
7 | import java.net.SocketTimeoutException;
8 |
9 | public interface ServerConnection {
10 | StatusRequest listenAndGetData() throws SocketTimeoutException, IOException;
11 |
12 | void sendData(byte[] data, InetAddress addr, int port);
13 | }
14 |
--------------------------------------------------------------------------------
/lab8/server/src/serverLogic/ServerConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package serverLogic;
2 |
3 | public interface ServerConnectionFactory {
4 | ServerConnection initializeServer(int port);
5 |
6 | ServerConnection initializeServer(int port, int timeout);
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'server'
2 | include 'client'
3 | include 'shared'
4 |
5 |
--------------------------------------------------------------------------------
/lab8/shared/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | version '1.2'
4 |
5 | sourceSets.main.java.srcDirs = ['src']
6 |
7 | repositories {
8 | mavenCentral()
9 | }
10 |
11 | dependencies {
12 | implementation 'org.modelmapper:modelmapper:3.1.1'
13 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
14 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
15 | }
16 |
17 | test {
18 | useJUnitPlatform()
19 | }
20 |
21 | jar {
22 | manifest {
23 | attributes(
24 | 'Main-Class': 'main.Main',
25 | 'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
26 | )
27 | }
28 | }
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/CommandDescription.java:
--------------------------------------------------------------------------------
1 | package commandLogic;
2 |
3 | import commandLogic.commandReceiverLogic.callers.ExternalCaller;
4 |
5 | import java.io.Serializable;
6 |
7 | public class CommandDescription implements Serializable {
8 | private final String name;
9 | private final ExternalCaller caller;
10 |
11 | public CommandDescription(String name, ExternalCaller caller) {
12 | this.name = name;
13 | this.caller = caller;
14 | }
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public ExternalCaller getReceiver() {
21 | return caller;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/callers/ExternalBaseReceiverCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 | import commandLogic.commandReceiverLogic.enums.ReceiverType;
6 |
7 | public class ExternalBaseReceiverCaller extends ExternalCaller {
8 | @Override
9 | public void callReceivers(String name, char[] passwd, ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception {
10 | var receiver = manager.getReceivers(ReceiverType.NoArgs);
11 | boolean commandCompleted = true;
12 | for (int i = 0; i < receiver.size() && commandCompleted; i++) {
13 | commandCompleted = receiver.get(i).receiveCommand(name, passwd, description, lineArgs);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/callers/ExternalCaller.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.callers;
2 |
3 | import commandLogic.CommandDescription;
4 | import commandLogic.commandReceiverLogic.ReceiverManager;
5 |
6 | import java.io.Serializable;
7 |
8 | public abstract class ExternalCaller implements Serializable {
9 | public abstract void callReceivers(String name, char[] passwd, ReceiverManager manager, CommandDescription description, String[] lineArgs) throws Exception;
10 | }
11 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/enums/ReceiverType.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.enums;
2 |
3 | public enum ReceiverType {
4 | NoArgs,
5 | ArgumentRoute
6 | }
7 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/handlers/NonArgReceiversHandler.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.handlers;
2 |
3 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class NonArgReceiversHandler extends ReceiverHandler {
8 |
9 | private final ArrayList receivers;
10 |
11 | {
12 | receivers = new ArrayList<>();
13 | }
14 |
15 | @Override
16 | public void addReceiver(ExternalBaseReceiver receiver) {
17 | receivers.add(receiver);
18 | }
19 |
20 | @Override
21 | public ArrayList getReceivers() {
22 | return receivers;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/handlers/ReceiverHandler.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.handlers;
2 |
3 | import commandLogic.commandReceiverLogic.receivers.ExternalBaseReceiver;
4 |
5 | import java.util.ArrayList;
6 |
7 | public abstract class ReceiverHandler {
8 | public abstract void addReceiver(ExternalBaseReceiver receiver);
9 |
10 | public abstract ArrayList extends ExternalBaseReceiver> getReceivers();
11 | }
12 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/receivers/ExternalArgumentReceiver.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.receivers;
2 |
3 | public interface ExternalArgumentReceiver extends ExternalBaseReceiver {
4 | T getArguemnt();
5 | }
6 |
--------------------------------------------------------------------------------
/lab8/shared/src/commandLogic/commandReceiverLogic/receivers/ExternalBaseReceiver.java:
--------------------------------------------------------------------------------
1 | package commandLogic.commandReceiverLogic.receivers;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public interface ExternalBaseReceiver {
6 | boolean receiveCommand(String name, char[] passwd, CommandDescription command, String[] args) throws Exception;
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/shared/src/main/Main.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | System.out.println("""
6 | Однажды Вася спросил у своего старшего брата-сеньора Пети:
7 | "Петя, зачем вообще нам нужно запускать общую библиотеку классов?"
8 | На что Петя ответил: "Братиш, для того, чтобы практик на защите прочитал этот текст.\"""");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/lab8/shared/src/models/Climate.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different climate types
7 | */
8 | public enum Climate implements Serializable {
9 | TROPICAL_SAVANNA,
10 | OCEANIC,
11 | STEPPE,
12 | MEDITERRANEAN,
13 | SUBARCTIC,
14 | TUNDRA,
15 | DESERT,
16 | RAINFOREST,
17 | CONTINENTAL,
18 | MARINE_WEST_COAST,
19 | HIGHLAND
20 | }
21 |
--------------------------------------------------------------------------------
/lab8/shared/src/models/Government.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different government types
7 | */
8 | public enum Government implements Serializable {
9 | ANARCHY,
10 | GERONTOCRACY,
11 | DEMARCHY,
12 | COMMUNISM,
13 | NOOCRACY,
14 | DEMOCRACY,
15 | MONARCHY,
16 | OLIGARCHY,
17 | PLUTOCRACY,
18 | THEOCRACY,
19 | TECHNOCRACY,
20 | FEDERAL_REPUBLIC,
21 | PARLIAMENTARY_SYSTEM,
22 | AUTOCRACY
23 | }
24 |
--------------------------------------------------------------------------------
/lab8/shared/src/models/StandardOfLiving.java:
--------------------------------------------------------------------------------
1 | package models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Enum for different StandardOfLiving types
7 | */
8 | public enum StandardOfLiving implements Serializable {
9 | ULTRA_HIGH,
10 | VERY_HIGH,
11 | HIGH,
12 | MEDIUM,
13 | AVERAGE,
14 | LOW,
15 | VERY_LOW,
16 | ULTRA_LOW,
17 | NIGHTMARE,
18 | DISASTROUS,
19 | CATASTROPHIC
20 | }
--------------------------------------------------------------------------------
/lab8/shared/src/requests/ArgumentCommandClientRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | public class ArgumentCommandClientRequest extends CommandClientRequest {
6 | private final T argument;
7 |
8 | public ArgumentCommandClientRequest(String name, char[] passwd, CommandDescription command, String[] lineArgs, T argument) {
9 | super(name, passwd, command, lineArgs);
10 | this.argument = argument;
11 | }
12 |
13 | public T getArgument() {
14 | return argument;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lab8/shared/src/requests/AuthRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class AuthRequest extends BaseRequest {
4 | private final String name;
5 | private final char[] passwd;
6 | public AuthRequest(String name, char[] passwd) {
7 | this.name = name;
8 | this.passwd = passwd;
9 | }
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public char[] getPasswd() {
16 | return passwd;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab8/shared/src/requests/BaseRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class BaseRequest implements Serializable {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/lab8/shared/src/requests/CommandDescriptionsRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class CommandDescriptionsRequest extends BaseRequest {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/lab8/shared/src/requests/RegRequest.java:
--------------------------------------------------------------------------------
1 | package requests;
2 |
3 | public class RegRequest extends BaseRequest {
4 | private final String name;
5 | private final char[] passwd;
6 | public RegRequest(String name, char[] passwd) {
7 | this.name = name;
8 | this.passwd = passwd;
9 | }
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public char[] getPasswd() {
16 | return passwd;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/AuthResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class AuthResponse extends BaseResponse {
4 | boolean auth;
5 | public AuthResponse(boolean auth) {
6 | this.auth = auth;
7 | }
8 |
9 | public boolean isAuth() {
10 | return auth;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/BaseResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class BaseResponse implements Serializable {
6 | }
7 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/CommandDescriptionsResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import commandLogic.CommandDescription;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class CommandDescriptionsResponse extends BaseResponse {
8 | private final ArrayList commands;
9 |
10 | public CommandDescriptionsResponse(ArrayList commands) {
11 | this.commands = commands;
12 | }
13 |
14 | public ArrayList getCommands() {
15 | return commands;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/CommandStatusResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class CommandStatusResponse extends BaseResponse {
4 |
5 | private final String response;
6 | private final int statusCode;
7 |
8 | public CommandStatusResponse(String response, int statusCode) {
9 | this.response = response;
10 | this.statusCode = statusCode;
11 | }
12 |
13 | public static CommandStatusResponse ofString(String s) {
14 | return new CommandStatusResponse(s, 0);
15 | }
16 |
17 | public String getResponse() {
18 | return response;
19 | }
20 |
21 | public int getStatusCode() {
22 | return statusCode;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class ErrorResponse extends BaseResponse {
4 |
5 | private final String msg;
6 |
7 | public ErrorResponse(String msg) {
8 | this.msg = msg;
9 | }
10 |
11 | public String getMsg() {
12 | return msg;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/GetOwnershipResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import java.util.Map;
4 |
5 | public class GetOwnershipResponse extends CommandStatusResponse {
6 | /**
7 | * Map (city_id, client_name)
8 | * Used for coloring city by different colors
9 | */
10 | private Map response;
11 |
12 | public GetOwnershipResponse(String oldResponse, int statusCode, Map response) {
13 | super(oldResponse, statusCode);
14 | this.response = response;
15 | }
16 |
17 | public static GetOwnershipResponse of(String s, Map ownershipMap) {
18 | return new GetOwnershipResponse(s, 0, ownershipMap);
19 | }
20 |
21 | public Map getOwnershipMap() {
22 | return response;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/RegResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | public class RegResponse extends BaseResponse{
4 | boolean reg;
5 | public RegResponse(boolean reg) {
6 | this.reg = reg;
7 | }
8 |
9 | public boolean isReg() {
10 | return reg;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/lab8/shared/src/responses/ShowResponse.java:
--------------------------------------------------------------------------------
1 | package responses;
2 |
3 | import models.City;
4 |
5 | import java.util.TreeSet;
6 |
7 | public class ShowResponse extends CommandStatusResponse {
8 | private TreeSet response;
9 |
10 | public ShowResponse(String oldResponse, int statusCode, TreeSet response) {
11 | super(oldResponse, statusCode);
12 | this.response = response;
13 | }
14 |
15 | public static ShowResponse of(String s, TreeSet cityTreeSet) {
16 | return new ShowResponse(s, 0, cityTreeSet);
17 | }
18 |
19 | public TreeSet getCityTreeSet() {
20 | return response;
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/plan.txt:
--------------------------------------------------------------------------------
1 | 1) Прочитать мануал к лабе: https://docs.google.com/document/d/1ZV8LvnAlaZj17FwegsXJwbwSMUkyRLKhDj3FfvMCWbM/edit
2 | 2) Прочитать про шаблоны проектирования: https://se.ifmo.ru/documents/10180/1422934/patterns_notes.pdf/f3975b88-e287-a663-91f4-61be1c0fb739
3 | 3) Прочитать про многопоточность: https://se.ifmo.ru/documents/10180/1422934/prog-concurrency.pdf/da25f4c8-02fc-506d-79da-7ea9a2186dac
4 | .
5 | .
6 | .
7 | 4) Разобраться, сотавить структуру своей программы на примере варианта 4. Попробовать сделать UML и написать код, чтобы показать потом практику.
--------------------------------------------------------------------------------