├── 2022 ├── .gitignore ├── 01-enum-advanced │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── App.java │ │ │ ├── function │ │ │ ├── Operation.java │ │ │ └── OperationLambda.java │ │ │ ├── singleton │ │ │ └── TextAnalysis.java │ │ │ ├── strategy │ │ │ ├── Cook.java │ │ │ └── Cooks.java │ │ │ └── vo │ │ │ ├── Colors.java │ │ │ └── Currencies.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ ├── AppTest.java │ │ └── singleton │ │ └── TextAnalysisTest.java ├── 02-three-states │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── App.java │ │ │ ├── Document.java │ │ │ └── DocumentType.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ └── DocumentTest.java ├── 03-optimizing-optional │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── DriveLicense.java │ │ │ ├── Person.java │ │ │ ├── PersonBuilder.java │ │ │ ├── PersonService.java │ │ │ └── client │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ └── PersonServiceTest.java ├── 04-encapsulation │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── Player.java │ │ │ └── Team.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ └── TeamTest.java ├── 05-builder-fluent-api │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── Person.java │ │ │ ├── PersonBuilder.java │ │ │ ├── PersonDSL.java │ │ │ └── PersonFluent.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ ├── PersonBuilderTest.java │ │ ├── PersonDSLTest.java │ │ └── PersonTest.java ├── 06-functions-composite │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ ├── App.java │ │ ├── AppConsumer.java │ │ ├── AppPredicate.java │ │ ├── AppSupplier.java │ │ ├── HelloFunction.java │ │ └── Person.java ├── 07-interface │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── Bike.java │ │ │ ├── Transport.java │ │ │ └── TransportType.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ ├── TransportTest.java │ │ └── client │ │ └── Person.java ├── 08-money-api │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── Order.java │ │ │ └── Product.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ └── OrderTest.java ├── 09-intro-rich-model │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── Player.java │ │ │ ├── PlayerBuilder.java │ │ │ ├── Position.java │ │ │ ├── Team.java │ │ │ └── client │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ └── TeamTest.java ├── 10-collector │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ ├── Player.java │ │ │ ├── PlayerBuilder.java │ │ │ ├── PlayerSummary.java │ │ │ ├── Position.java │ │ │ ├── Team.java │ │ │ └── client │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── com │ │ └── osachitech │ │ └── examples │ │ └── TeamTest.java ├── 11-cdi-introduction │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── osachitech │ │ │ └── examples │ │ │ └── cdi │ │ │ ├── App.java │ │ │ ├── App2.java │ │ │ ├── App3.java │ │ │ ├── App4.java │ │ │ ├── App5.java │ │ │ ├── cars │ │ │ ├── Brand.java │ │ │ ├── Car.java │ │ │ ├── CarType.java │ │ │ ├── Ferrari.java │ │ │ ├── Fiat.java │ │ │ └── Garage.java │ │ │ ├── music │ │ │ ├── CurrencySupplier.java │ │ │ ├── LoggerProducer.java │ │ │ ├── Music.java │ │ │ ├── MusicService.java │ │ │ └── MusicSupplier.java │ │ │ ├── news │ │ │ ├── Journalist.java │ │ │ ├── Magazine.java │ │ │ ├── News.java │ │ │ ├── NewsPaper.java │ │ │ ├── PremiumCategory.java │ │ │ ├── PremiumMagazine.java │ │ │ ├── Press.java │ │ │ ├── SocialMedia.java │ │ │ └── Twitter.java │ │ │ ├── start │ │ │ ├── EagerBean.java │ │ │ ├── LazyBean.java │ │ │ ├── Startup.java │ │ │ └── StartupBeanExtension.java │ │ │ └── worker │ │ │ ├── Manager.java │ │ │ ├── Programmer.java │ │ │ ├── TextSupplier.java │ │ │ ├── Timed.java │ │ │ ├── TimedInterceptor.java │ │ │ └── Worker.java │ │ └── resources │ │ └── META-INF │ │ ├── beans.xml │ │ └── services │ │ └── jakarta.enterprise.inject.spi.Extension ├── 12-microstream │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── a4j │ │ │ └── workshop │ │ │ └── helidon │ │ │ └── microstream │ │ │ ├── App.java │ │ │ ├── Book.java │ │ │ ├── BookBuilder.java │ │ │ ├── BookService.java │ │ │ └── Library.java │ │ └── resources │ │ └── META-INF │ │ ├── beans.xml │ │ └── microprofile-config.properties ├── README.adoc └── pom.xml ├── 2023 ├── 01-documentation │ ├── .gitignore │ ├── CHANGELOG.adoc │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── App.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── AppTest.java ├── 02-record │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── App.java │ │ │ ├── Book.java │ │ │ ├── BookBuilder.java │ │ │ ├── Delivered.java │ │ │ ├── Email.java │ │ │ ├── Money.java │ │ │ ├── OldPerson.java │ │ │ ├── Order.java │ │ │ ├── Ordered.java │ │ │ ├── Person.java │ │ │ ├── Received.java │ │ │ └── Team.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ ├── AppTest.java │ │ ├── BookTest.java │ │ └── OrderTest.java ├── 03-java-doc-test │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── videos │ │ │ └── demo │ │ │ ├── Animal.java │ │ │ ├── ChampionRepository.java │ │ │ ├── ChampionshipService.java │ │ │ ├── OverTeamException.java │ │ │ ├── Player.java │ │ │ ├── Team.java │ │ │ └── package-info.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── videos │ │ └── demo │ │ ├── ChampionshipServiceTest.java │ │ ├── PlayerProvider.java │ │ └── TeamTest.java ├── 04-jupiter-cdi │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── expert │ │ │ │ └── os │ │ │ │ └── examples │ │ │ │ ├── Inventory.java │ │ │ │ ├── PayPalPayment.java │ │ │ │ ├── Payment.java │ │ │ │ └── Product.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── beans.xml │ │ └── test │ │ ├── java │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── InventoryTest.java │ │ │ └── PaymentMock.java │ │ └── resources │ │ └── META-INF │ │ └── beans.xml ├── 05-reflections │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ └── mapping │ │ │ ├── Append.java │ │ │ ├── Appends.java │ │ │ ├── Column.java │ │ │ ├── Entity.java │ │ │ ├── Mapper.java │ │ │ ├── MapperInvocationHandler.java │ │ │ ├── MapperRepository.java │ │ │ └── ReflectionMapper.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ └── mapping │ │ ├── Fruit.java │ │ ├── MapperRepositoryTest.java │ │ ├── MapperTest.java │ │ └── Pet.java ├── 06-java-functions │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── videos │ │ │ └── demo │ │ │ └── Player.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── videos │ │ └── demo │ │ ├── ConsumerTest.java │ │ ├── FunctionTest.java │ │ ├── PlayerTest.java │ │ ├── PredicateTest.java │ │ └── SupplierTest.java ├── 07-archi-unit │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── videos │ │ │ └── demo │ │ │ ├── Book.java │ │ │ └── infrastructure │ │ │ └── Magazine.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── videos │ │ └── demo │ │ └── MyArchTest.java ├── 08-java-design │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── videos │ │ │ └── demo │ │ │ └── sample │ │ │ ├── drive │ │ │ ├── DriverLicense.java │ │ │ ├── Inventory.java │ │ │ └── Person.java │ │ │ ├── tips │ │ │ ├── Email.java │ │ │ ├── Event.java │ │ │ └── Money.java │ │ │ └── worker │ │ │ ├── Chef.java │ │ │ ├── Doctor.java │ │ │ ├── Driver.java │ │ │ ├── DriverLicense.java │ │ │ ├── Person.java │ │ │ └── Worker.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── videos │ │ └── demo │ │ └── sample │ │ └── drive │ │ ├── InventoryTest.java │ │ └── PersonTest.java ├── 09-mapstruct │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── Delivery.java │ │ │ ├── DeliveryDTO.java │ │ │ └── DeliveryMapper.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ └── DeliveryMapperTest.java ├── 10-modelmapper │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── Delivery.java │ │ │ └── DeliveryDTO.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ └── DeliveryMapperTest.java ├── 11-lombok │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ └── entity │ │ │ ├── Book.java │ │ │ └── Person.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ ├── AppTest.java │ │ └── entity │ │ ├── BookTest.java │ │ └── PersonTest.java ├── 12-java-21 │ ├── .gitignore │ ├── README.adoc │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── CreditCard.java │ │ │ ├── Payment.java │ │ │ ├── Person.java │ │ │ ├── PersonFacade.java │ │ │ ├── PersonRepository.java │ │ │ ├── PersonService.java │ │ │ ├── User.java │ │ │ ├── UserCreatedEvent.java │ │ │ └── UserDeletedEvent.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ ├── PersonTest.java │ │ ├── RecordTest.java │ │ ├── SequenceCollectionTest.java │ │ └── VirtualThreadTest.java └── pom.xml ├── 2024 ├── 01-refactoring-2024 │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── CreditCardPaymentService.java │ │ │ ├── DebitCardPaymentService.java │ │ │ ├── Money.java │ │ │ ├── PaymentService.java │ │ │ └── User.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ └── PaymentServiceTest.java ├── 02-exception-log │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── CreditCard.java │ │ │ ├── CreditCardException.java │ │ │ ├── CreditCardNotFoundException.java │ │ │ ├── CreditCardService.java │ │ │ ├── MyCompanyException.java │ │ │ └── Product.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ └── CreditCardServiceTest.java ├── 03-microservices-tips │ ├── .dockerignore │ ├── .gitignore │ ├── .helidon │ ├── Dockerfile │ ├── Dockerfile.jlink │ ├── Dockerfile.native │ ├── README.adoc │ ├── app.yaml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── os │ │ │ │ └── expert │ │ │ │ └── demo │ │ │ │ └── helidon │ │ │ │ ├── Expedition.java │ │ │ │ ├── ExpeditionResource.java │ │ │ │ ├── FieldAccessStrategy.java │ │ │ │ ├── GreetResource.java │ │ │ │ ├── GreetingProvider.java │ │ │ │ ├── Message.java │ │ │ │ ├── SimpleGreetResource.java │ │ │ │ └── package-info.java │ │ └── resources │ │ │ ├── META-INF │ │ │ ├── beans.xml │ │ │ ├── microprofile-config.properties │ │ │ └── native-image │ │ │ │ └── os │ │ │ │ └── expert │ │ │ │ └── demo │ │ │ │ └── helidon │ │ │ │ └── native-image.properties │ │ │ └── logging.properties │ │ └── test │ │ ├── java │ │ └── os │ │ │ └── expert │ │ │ └── demo │ │ │ └── helidon │ │ │ └── MainTest.java │ │ └── resources │ │ ├── META-INF │ │ └── microprofile-config.properties │ │ └── application-test.yaml ├── 04-pmd-checkstyle │ ├── .gitignore │ ├── pmd │ │ ├── bestpractices.xml │ │ └── codestyle.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ ├── Animal.java │ │ ├── Guest.java │ │ ├── Hotel.java │ │ ├── Room.java │ │ └── RoomDAO.java ├── 05-jmolecules │ ├── .dockerignore │ ├── .gitignore │ ├── .helidon │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ └── CreditCard.java │ │ └── test │ │ └── java │ │ └── expert │ │ └── os │ │ └── examples │ │ ├── IntegrationSampleTest.java │ │ └── JMoleculesDddUnitTest.java └── pom.xml ├── 2025 ├── 01-quarkus-fast-rest │ ├── .gitignore │ ├── README.md │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── docker │ │ ├── Dockerfile.jvm │ │ ├── Dockerfile.legacy-jar │ │ ├── Dockerfile.native │ │ └── Dockerfile.native-micro │ │ ├── java │ │ └── expert │ │ │ └── os │ │ │ └── videos │ │ │ └── quarkus │ │ │ ├── Developer.java │ │ │ └── DevelopersResource.java │ │ └── resources │ │ └── application.properties ├── 02-polymorphism-cdi │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── expert │ │ │ └── os │ │ │ └── examples │ │ │ ├── App.java │ │ │ ├── Instrument.java │ │ │ ├── InstrumentType.java │ │ │ ├── MusicInstrument.java │ │ │ ├── MusicInstrumentLiteral.java │ │ │ ├── Orchestra.java │ │ │ ├── Piano.java │ │ │ ├── Violin.java │ │ │ └── Xylophone.java │ │ └── resources │ │ └── META-INF │ │ └── beans.xml └── pom.xml ├── .github └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.adoc └── pom.xml /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Set up JDK 21 20 | uses: actions/setup-java@v3 21 | with: 22 | java-version: '21' 23 | distribution: 'temurin' 24 | cache: maven 25 | - name: Build with Maven 26 | run: mvn -B package --file pom.xml 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/01-enum-advanced/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/function/Operation.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.function; 2 | 3 | public enum Operation { 4 | 5 | PLUS{ 6 | @Override 7 | public double operate(double valueA, double valueB) { 8 | return valueA + valueB; 9 | } 10 | }, MINUS{ 11 | @Override 12 | public double operate(double valueA, double valueB) { 13 | return valueA - valueB; 14 | } 15 | }, TIMES{ 16 | @Override 17 | public double operate(double valueA, double valueB) { 18 | return valueA * valueB; 19 | } 20 | }; 21 | 22 | public abstract double operate(double valueA, double valueB); 23 | } 24 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/function/OperationLambda.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.function; 2 | 3 | import java.util.function.BiFunction; 4 | 5 | public enum OperationLambda { 6 | PLUS(Double::sum), MINUS((a, b) -> a - b), TIMES((a, b) -> a * b); 7 | 8 | private final BiFunction operation; 9 | 10 | OperationLambda(BiFunction operation) { 11 | this.operation = operation; 12 | } 13 | 14 | public double operate(double valueA, double valueB) { 15 | return this.operation.apply(valueA, valueB); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/singleton/TextAnalysis.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.singleton; 2 | 3 | import java.util.Objects; 4 | 5 | public enum TextAnalysis { 6 | 7 | INSTANCE; 8 | 9 | public String prepare(String text) { 10 | Objects.requireNonNull(text, "text is required"); 11 | return text.toUpperCase(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/strategy/Cook.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.strategy; 2 | 3 | public interface Cook { 4 | 5 | String prepare(); 6 | } 7 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/strategy/Cooks.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.strategy; 2 | 3 | public enum Cooks implements Cook { 4 | 5 | ITALIAN{ 6 | @Override 7 | public String prepare() { 8 | return "Making Pizza"; 9 | } 10 | }, BRAZILIAN{ 11 | @Override 12 | public String prepare() { 13 | return "Making Feijoada"; 14 | } 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/vo/Colors.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.vo; 2 | 3 | import java.util.function.Supplier; 4 | 5 | public enum Colors implements Supplier { 6 | 7 | 8 | BLUE("#00FFFF"), WHITE("#FFFFFF"), 9 | BLACK("#000000"), GREEN("#008000"); 10 | 11 | private final String value; 12 | 13 | Colors(String value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public String get() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/main/java/com/osachitech/examples/vo/Currencies.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.vo; 2 | 3 | import javax.money.CurrencyUnit; 4 | import javax.money.Monetary; 5 | import java.util.function.Supplier; 6 | 7 | public enum Currencies implements Supplier { 8 | EURO("EUR"), DOLLAR("USD"); 9 | 10 | private final CurrencyUnit currency; 11 | 12 | Currencies(String currencyCode) { 13 | this.currency = Monetary.getCurrency(currencyCode); 14 | } 15 | 16 | @Override 17 | public CurrencyUnit get() { 18 | return currency; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/test/java/com/osachitech/examples/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | 4 | import com.osachitech.examples.function.Operation; 5 | import com.osachitech.examples.strategy.Cook; 6 | import com.osachitech.examples.strategy.Cooks; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.Test; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertTrue; 11 | 12 | /** 13 | * Unit test for simple App. 14 | */ 15 | public class AppTest 16 | { 17 | /** 18 | * Rigorous Test :-) 19 | */ 20 | @Test 21 | public void shouldAnswerWithTrue() 22 | { 23 | Operation operation = Operation.MINUS; 24 | double operate = operation.operate(10, 4); 25 | Assertions.assertEquals(6D, operate); 26 | } 27 | 28 | @Test 29 | public void shouldReturnADish() { 30 | Cook cook = Cooks.ITALIAN; 31 | Assertions.assertNotNull(cook.prepare()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /2022/01-enum-advanced/src/test/java/com/osachitech/examples/singleton/TextAnalysisTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.singleton; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class TextAnalysisTest { 9 | 10 | @Test 11 | public void shouldPrepare() { 12 | TextAnalysis instance = TextAnalysis.INSTANCE; 13 | Assertions.assertNotNull(instance); 14 | String text = instance.prepare("hello poliana"); 15 | Assertions.assertNotNull(instance); 16 | Assertions.assertEquals("hello poliana".toUpperCase(), text); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /2022/02-three-states/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/02-three-states/src/main/java/com/osachitech/examples/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2022/02-three-states/src/main/java/com/osachitech/examples/Document.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.time.Duration; 4 | import java.util.concurrent.ThreadLocalRandom; 5 | 6 | public class Document { 7 | 8 | private String name; 9 | 10 | private String description; 11 | 12 | private DocumentType type = DocumentType.UNPROCESSED; 13 | 14 | public Document(String name, String description) { 15 | this.name = name; 16 | this.description = description; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public String getDescription() { 24 | return description; 25 | } 26 | 27 | public Duration getDays() { 28 | if (type.isUnprocessed()) { 29 | //load 30 | this.type = DocumentType.PERSON; 31 | } 32 | return type.getDays(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /2022/02-three-states/src/main/java/com/osachitech/examples/DocumentType.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.time.Duration; 4 | 5 | public enum DocumentType { 6 | PERSON { 7 | @Override 8 | Duration getDays() { 9 | return Duration.ofDays(10); 10 | } 11 | }, COMPANY { 12 | @Override 13 | Duration getDays() { 14 | return Duration.ofDays(20); 15 | } 16 | }, UNPROCESSED { 17 | @Override 18 | Duration getDays() { 19 | throw new IllegalStateException(""); 20 | } 21 | }; 22 | 23 | abstract Duration getDays(); 24 | 25 | public boolean isUnprocessed() { 26 | return this == UNPROCESSED; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2022/02-three-states/src/test/java/com/osachitech/examples/DocumentTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.time.Duration; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class DocumentTest { 11 | 12 | @Test 13 | public void shouldCreateDocument() { 14 | Document document = new Document("Otavio", "Description"); 15 | Duration days = document.getDays(); 16 | Assertions.assertEquals(Duration.ofDays(10), days); 17 | } 18 | } -------------------------------------------------------------------------------- /2022/03-optimizing-optional/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/03-optimizing-optional/src/main/java/com/osachitech/examples/DriveLicense.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Objects; 4 | 5 | public class DriveLicense { 6 | 7 | private final String license; 8 | 9 | public DriveLicense(String license) { 10 | this.license = license; 11 | } 12 | 13 | public String getLicense() { 14 | return license; 15 | } 16 | 17 | 18 | @Override 19 | public boolean equals(Object o) { 20 | if (this == o) { 21 | return true; 22 | } 23 | if (o == null || getClass() != o.getClass()) { 24 | return false; 25 | } 26 | DriveLicense that = (DriveLicense) o; 27 | return Objects.equals(license, that.license); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return Objects.hashCode(license); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /2022/03-optimizing-optional/src/main/java/com/osachitech/examples/Person.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Objects; 4 | import java.util.Optional; 5 | 6 | public class Person { 7 | 8 | private String name; 9 | 10 | private String city; 11 | 12 | private DriveLicense license; 13 | 14 | public Person(String name, String city, DriveLicense license) { 15 | this.name = Objects.requireNonNull(name, "name is required"); 16 | this.city = Objects.requireNonNull(city, "city is required"); 17 | this.license = license; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public String getCity() { 25 | return city; 26 | } 27 | 28 | public Optional getDriveLicense() { 29 | return Optional.ofNullable(this.license); 30 | } 31 | public static PersonBuilder builder() { 32 | return new PersonBuilder(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /2022/03-optimizing-optional/src/main/java/com/osachitech/examples/PersonBuilder.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public class PersonBuilder { 4 | private String name; 5 | private String city; 6 | private DriveLicense license; 7 | 8 | PersonBuilder() { 9 | } 10 | 11 | public PersonBuilder name(String name) { 12 | this.name = name; 13 | return this; 14 | } 15 | 16 | public PersonBuilder city(String city) { 17 | this.city = city; 18 | return this; 19 | } 20 | 21 | public PersonBuilder license(DriveLicense license) { 22 | this.license = license; 23 | return this; 24 | } 25 | 26 | public Person build() { 27 | return new Person(name, city, license); 28 | } 29 | } -------------------------------------------------------------------------------- /2022/03-optimizing-optional/src/main/java/com/osachitech/examples/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Objects; 4 | import java.util.Optional; 5 | 6 | public class PersonService { 7 | 8 | public Optional findByName(String name){ 9 | Objects.requireNonNull(name, "name is required"); 10 | if("Helber".equals(name)) { 11 | return Optional.of(new PersonBuilder() 12 | .name("Helber") 13 | .city("Porto Alegre") 14 | .license(new DriveLicense("123")) 15 | .build()); 16 | } 17 | return Optional.empty(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2022/03-optimizing-optional/src/main/java/com/osachitech/examples/client/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.client; 2 | 3 | import com.osachitech.examples.Person; 4 | import com.osachitech.examples.PersonBuilder; 5 | import com.osachitech.examples.PersonService; 6 | 7 | import java.util.Optional; 8 | 9 | /** 10 | * Hello world! 11 | */ 12 | public class App { 13 | public static void main(String[] args) { 14 | PersonService service = new PersonService(); 15 | PersonBuilder builder = Person.builder(); 16 | System.out.println("Hello World!"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2022/03-optimizing-optional/src/test/java/com/osachitech/examples/PersonServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.Optional; 8 | 9 | class PersonServiceTest { 10 | 11 | private PersonService service; 12 | 13 | @BeforeEach 14 | public void setUp() { 15 | this.service = new PersonService(); 16 | } 17 | 18 | @Test 19 | public void shouldReturnHelder() { 20 | Optional helber = service.findByName("Helber"); 21 | Assertions.assertNotNull(helber); 22 | String name = helber.map(Person::getName) 23 | .orElse("not know person"); 24 | Assertions.assertEquals("Helber", name); 25 | } 26 | 27 | @Test 28 | public void shouldReturnNotHelber() { 29 | Optional helder = service.findByName("Helder"); 30 | Person person = helder 31 | .orElseGet(() -> new PersonBuilder().name("Helder").city("Sao Paulo").build()); 32 | 33 | helder.ifPresent(p -> p.getName()); 34 | Assertions.assertNotNull(person.getName()); 35 | Assertions.assertEquals("Helder", person.getName()); 36 | } 37 | } -------------------------------------------------------------------------------- /2022/04-encapsulation/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/04-encapsulation/src/main/java/com/osachitech/examples/Player.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public class Player { 4 | 5 | private final String name; 6 | 7 | public Player(String name) { 8 | this.name = name; 9 | } 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2022/04-encapsulation/src/main/java/com/osachitech/examples/Team.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | public class Team { 9 | 10 | private List players = new ArrayList<>(); 11 | 12 | public void add(Player player) { 13 | Objects.requireNonNull(player, "player is required"); 14 | this.players.add(player); 15 | } 16 | public List getPlayers() { 17 | return Collections.unmodifiableList(players); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2022/04-encapsulation/src/test/java/com/osachitech/examples/TeamTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class TeamTest { 9 | 10 | @Test 11 | public void shouldAddPlayerTeam() { 12 | Team team = new Team(); 13 | team.add(new Player("Bruno")); 14 | Assertions.assertThrows(UnsupportedOperationException.class, 15 | () -> team.getPlayers().clear()); 16 | Assertions.assertFalse(team.getPlayers().isEmpty()); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/main/java/com/osachitech/examples/Person.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Optional; 4 | 5 | public class Person { 6 | 7 | private String name; 8 | 9 | private String city; 10 | 11 | private String occupation; 12 | 13 | 14 | 15 | @Deprecated 16 | Person() { 17 | } 18 | 19 | Person(String name, String city, String occupation) { 20 | this.name = name; 21 | this.city = city; 22 | this.occupation = occupation; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public String getCity() { 30 | return city; 31 | } 32 | 33 | public Optional getOccupation() { 34 | return Optional.ofNullable(occupation); 35 | } 36 | 37 | public static PersonBuilder builder() { 38 | return new PersonBuilder(); 39 | } 40 | 41 | public static PersonFluent.PersonCity name(String name) { 42 | return PersonFluent.name(name); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/main/java/com/osachitech/examples/PersonBuilder.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Objects; 4 | 5 | public class PersonBuilder { 6 | private String name; 7 | private String city; 8 | private String occupation; 9 | 10 | PersonBuilder() { 11 | } 12 | 13 | public PersonBuilder name(String name) { 14 | this.name = Objects.requireNonNull(name, "name is required"); 15 | return this; 16 | } 17 | 18 | public PersonBuilder city(String city) { 19 | this.city = Objects.requireNonNull(city, "city is required"); 20 | return this; 21 | } 22 | 23 | public PersonBuilder occupation(String occupation) { 24 | this.occupation = Objects.requireNonNull(occupation, "occupation is required"); 25 | return this; 26 | } 27 | 28 | public Person build() { 29 | if(Objects.isNull(name) || Objects.isNull(city)) { 30 | throw new IllegalStateException("You cannot create a person without name or city"); 31 | } 32 | return new Person(name, city, occupation); 33 | } 34 | } -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/main/java/com/osachitech/examples/PersonDSL.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Objects; 4 | 5 | public class PersonDSL implements PersonFluent, PersonFluent.PersonCity, PersonFluent.PersonBuild { 6 | 7 | private final String name; 8 | 9 | private String city; 10 | 11 | private String occupation; 12 | 13 | public PersonDSL(String name) { 14 | this.name = name; 15 | } 16 | 17 | 18 | @Override 19 | public PersonBuild city(String city) { 20 | this.city = Objects.requireNonNull(city, "city is required"); 21 | return this; 22 | } 23 | 24 | @Override 25 | public Person build() { 26 | return new Person(name, city, occupation); 27 | } 28 | 29 | @Override 30 | public Person occupation(String occupation) { 31 | this.occupation = Objects.requireNonNull(city, "occupation is required"); 32 | return build(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/main/java/com/osachitech/examples/PersonFluent.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Objects; 4 | 5 | public interface PersonFluent { 6 | 7 | static PersonCity name(String name) { 8 | Objects.requireNonNull(name, "name is required"); 9 | return new PersonDSL(name); 10 | } 11 | 12 | interface PersonCity { 13 | PersonBuild city(String city); 14 | } 15 | 16 | interface PersonBuild { 17 | 18 | Person build(); 19 | 20 | Person occupation(String occupation); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/test/java/com/osachitech/examples/PersonBuilderTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class PersonBuilderTest { 9 | 10 | @Test 11 | public void shouldCreatePerson() { 12 | Person person = Person.builder().name("Otavio").occupation("Developer").city("Salvador").build(); 13 | Assertions.assertNotNull(person); 14 | } 15 | 16 | @Test 17 | public void shouldReturnErrorWhenParametersIsNull() { 18 | Assertions.assertThrows(NullPointerException.class, () -> 19 | Person.builder().name(null) 20 | ); 21 | Assertions.assertThrows(NullPointerException.class, () -> 22 | Person.builder().city(null) 23 | ); 24 | 25 | Assertions.assertThrows(NullPointerException.class, () -> 26 | Person.builder().occupation(null) 27 | ); 28 | } 29 | 30 | @Test 31 | public void shouldNotCreateInstanceWhenPersonIsInvalid() { 32 | 33 | Assertions.assertThrows(IllegalStateException.class, () -> 34 | Person.builder().city("Salvador").build() 35 | ); 36 | 37 | Assertions.assertThrows(IllegalStateException.class, () -> 38 | Person.builder().name("Otavio").build() 39 | ); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/test/java/com/osachitech/examples/PersonDSLTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class PersonDSLTest { 7 | 8 | @Test 9 | public void shouldCreateInstance() { 10 | Person edson = Person.name("Yanaga").city("Salvador").occupation("DevRel"); 11 | Assertions.assertNotNull(edson); 12 | } 13 | } -------------------------------------------------------------------------------- /2022/05-builder-fluent-api/src/test/java/com/osachitech/examples/PersonTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class PersonTest { 7 | 8 | @Test 9 | public void shouldCreatePersonWithOccupation() { 10 | String name = "Ada"; 11 | String occupation = "Engineer"; 12 | String city = "London"; 13 | Person person = Person.builder().name(name).city(city).occupation(occupation).build(); 14 | Assertions.assertEquals(name, person.getName()); 15 | Assertions.assertEquals(occupation, person.getOccupation().orElse("")); 16 | Assertions.assertEquals(city, person.getCity()); 17 | } 18 | 19 | @Test 20 | public void shouldCreatePersonWithNoOccupation() { 21 | String name = "Ada"; 22 | String city = "London"; 23 | Person person = Person.builder().name(name).city(city).build(); 24 | Assertions.assertEquals(name, person.getName()); 25 | Assertions.assertTrue(person.getOccupation().isEmpty()); 26 | Assertions.assertEquals(city, person.getCity()); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /2022/06-functions-composite/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/06-functions-composite/src/main/java/com/osachitech/examples/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.function.Function; 4 | import java.util.function.UnaryOperator; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args) { 9 | 10 | String text = " 10 "; 11 | Function convertString =Integer::valueOf; 12 | UnaryOperator trim = String::trim; 13 | Function smartConverter = trim.andThen(convertString); 14 | Integer value = smartConverter.apply(text); 15 | 16 | System.out.println("the integer value is: " + value); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2022/06-functions-composite/src/main/java/com/osachitech/examples/AppConsumer.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.function.Consumer; 4 | 5 | public class AppConsumer { 6 | public static void main(String[] args) { 7 | Person bruno = new Person("Bruno"); 8 | Consumer log = p -> System.out.println("Log 1" + p); 9 | Consumer log2 = p -> System.out.println("Log 2" + p); 10 | Consumer consumer = log.andThen(log2); 11 | consumer.accept(bruno); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2022/06-functions-composite/src/main/java/com/osachitech/examples/AppPredicate.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.function.Predicate; 4 | 5 | public class AppPredicate { 6 | 7 | public static void main(String[] args) { 8 | Person otavio = new Person("Otavio"); 9 | Predicate question = p -> p.getName().startsWith("O"); 10 | Predicate size = p -> p.getName().length() > 3; 11 | Predicate validName = size.and(question); 12 | Predicate notStartWithO = question.negate(); 13 | System.out.println("Is the predicate true: " + validName.test(otavio)); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2022/06-functions-composite/src/main/java/com/osachitech/examples/AppSupplier.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.Optional; 4 | import java.util.function.Consumer; 5 | import java.util.function.Supplier; 6 | 7 | public class AppSupplier { 8 | 9 | public static void main(String[] args) { 10 | Supplier database = () -> new Person("Otavio"); 11 | 12 | Optional person = Optional.empty(); 13 | Person person1 = person.orElseGet(database); 14 | System.out.println("The value result is: " + person1); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2022/06-functions-composite/src/main/java/com/osachitech/examples/HelloFunction.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | @FunctionalInterface 4 | public interface HelloFunction { 5 | 6 | String value(String value); 7 | } 8 | -------------------------------------------------------------------------------- /2022/06-functions-composite/src/main/java/com/osachitech/examples/Person.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public class Person { 4 | 5 | private final String name; 6 | 7 | public Person(String name) { 8 | this.name = name; 9 | } 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return "Person{" + 18 | "name='" + name + '\'' + 19 | '}'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2022/07-interface/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/07-interface/src/main/java/com/osachitech/examples/Bike.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public class Bike implements Transport { 4 | 5 | @Override 6 | public String getName() { 7 | return "Bike"; 8 | } 9 | 10 | @Override 11 | public void move() { 12 | System.out.println("Ride a bike"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2022/07-interface/src/main/java/com/osachitech/examples/Transport.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public interface Transport { 4 | 5 | String getName(); 6 | 7 | void move(); 8 | 9 | static Transport get(TransportType type) { 10 | return type.get(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2022/07-interface/src/main/java/com/osachitech/examples/TransportType.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.function.Supplier; 4 | 5 | public enum TransportType { 6 | 7 | CAR("Car"),BOAT("Boat"),PLANE("Plane"); 8 | 9 | private final String name; 10 | 11 | TransportType(String name) { 12 | this.name = name; 13 | } 14 | 15 | Transport get() { 16 | return new Transport() { 17 | @Override 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | @Override 23 | public void move() { 24 | System.out.println("moving by " + name); 25 | } 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2022/07-interface/src/test/java/com/osachitech/examples/TransportTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class TransportTest { 9 | 10 | @Test 11 | public void shouldCreateTransport() { 12 | Transport transport = Transport.get(TransportType.BOAT); 13 | Assertions.assertNotNull(transport); 14 | Assertions.assertEquals("Boat", transport.getName()); 15 | transport.move(); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /2022/07-interface/src/test/java/com/osachitech/examples/client/Person.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.client; 2 | 3 | import com.osachitech.examples.Transport; 4 | import com.osachitech.examples.TransportType; 5 | 6 | public class Person { 7 | 8 | public void bla() { 9 | Transport transport = Transport.get(TransportType.BOAT); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022/08-money-api/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/08-money-api/src/main/java/com/osachitech/examples/Order.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import javax.money.MonetaryAmount; 4 | import java.math.BigDecimal; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Objects; 8 | import java.util.Optional; 9 | 10 | public class Order { 11 | 12 | private final List products; 13 | 14 | public Order() { 15 | this.products = new ArrayList<>(); 16 | } 17 | 18 | public void add(Product product) { 19 | Objects.requireNonNull(product, "product is required"); 20 | this.products.add(product); 21 | } 22 | 23 | public Optional getTotal() { 24 | return this.products 25 | .stream() 26 | .map(Product::getPrice) 27 | .reduce(MonetaryAmount::add); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2022/08-money-api/src/main/java/com/osachitech/examples/Product.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import javax.money.MonetaryAmount; 4 | import java.math.BigDecimal; 5 | import java.util.Currency; 6 | import java.util.Objects; 7 | 8 | public class Product { 9 | 10 | private final String name; 11 | 12 | private final MonetaryAmount price; 13 | 14 | 15 | private Product(String name, MonetaryAmount price) { 16 | this.name = name; 17 | this.price = price; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public MonetaryAmount getPrice() { 25 | return price; 26 | } 27 | 28 | 29 | public static Product of(String name, MonetaryAmount price) { 30 | Objects.requireNonNull(name, "name is required"); 31 | Objects.requireNonNull(price, "price is required"); 32 | if(price.isNegative()) { 33 | throw new IllegalArgumentException("we not work with negative price"); 34 | } 35 | return new Product(name, price); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /2022/08-money-api/src/test/java/com/osachitech/examples/OrderTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.javamoney.moneta.Money; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import javax.money.CurrencyUnit; 8 | import javax.money.Monetary; 9 | import javax.money.MonetaryAmount; 10 | import java.math.BigDecimal; 11 | import java.util.Currency; 12 | import java.util.Optional; 13 | 14 | import static org.junit.jupiter.api.Assertions.*; 15 | 16 | class OrderTest { 17 | 18 | @Test 19 | public void shouldReturnTotal() { 20 | Order order = new Order(); 21 | CurrencyUnit dollar = Monetary.getCurrency("USD"); 22 | Money money = Money.of(BigDecimal.valueOf(2.8), dollar); 23 | Money moneyB = Money.of(BigDecimal.valueOf(0.17), dollar); 24 | order.add(Product.of("Banana", money)); 25 | order.add(Product.of("Pen", moneyB)); 26 | Optional total = order.getTotal(); 27 | Money result = Money.of(2.97, dollar); 28 | Assertions.assertEquals(result, total.get()); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /2022/09-intro-rich-model/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/09-intro-rich-model/src/main/java/com/osachitech/examples/Player.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import javax.money.MonetaryAmount; 4 | 5 | public class Player { 6 | 7 | private String name; 8 | 9 | private String city; 10 | 11 | private MonetaryAmount salary; 12 | 13 | private int score; 14 | 15 | private Position position; 16 | 17 | Player(String name, String city, 18 | MonetaryAmount salary, int score, 19 | Position position) { 20 | this.name = name; 21 | this.city = city; 22 | this.salary = salary; 23 | this.score = score; 24 | this.position = position; 25 | } 26 | 27 | /** 28 | * Please use the builder method instead, it is to framework only. 29 | * {@link Player#builder()} 30 | */ 31 | @Deprecated 32 | Player() { 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public String getCity() { 40 | return city; 41 | } 42 | 43 | public MonetaryAmount getSalary() { 44 | return salary; 45 | } 46 | 47 | public int getScore() { 48 | return score; 49 | } 50 | 51 | public Position getPosition() { 52 | return position; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "Player{" + 58 | "name='" + name + '\'' + 59 | ", city='" + city + '\'' + 60 | ", salary=" + salary + 61 | ", score=" + score + 62 | ", position=" + position + 63 | '}'; 64 | } 65 | 66 | public static PlayerBuilder builder() { 67 | return new PlayerBuilder(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /2022/09-intro-rich-model/src/main/java/com/osachitech/examples/PlayerBuilder.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import javax.money.MonetaryAmount; 4 | 5 | public class PlayerBuilder { 6 | private String name; 7 | private String city; 8 | private MonetaryAmount salary; 9 | private int score; 10 | private Position position; 11 | 12 | PlayerBuilder() { 13 | } 14 | 15 | public PlayerBuilder name(String name) { 16 | this.name = name; 17 | return this; 18 | } 19 | 20 | public PlayerBuilder city(String city) { 21 | this.city = city; 22 | return this; 23 | } 24 | 25 | public PlayerBuilder salary(MonetaryAmount salary) { 26 | this.salary = salary; 27 | return this; 28 | } 29 | 30 | public PlayerBuilder score(int score) { 31 | this.score = score; 32 | return this; 33 | } 34 | 35 | public PlayerBuilder position(Position position) { 36 | this.position = position; 37 | return this; 38 | } 39 | 40 | public Player build() { 41 | 42 | return new Player(name, city, salary, score, position); 43 | } 44 | } -------------------------------------------------------------------------------- /2022/09-intro-rich-model/src/main/java/com/osachitech/examples/Position.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public enum Position { 4 | GOALKEEPER,DEFENDER,ATTACKER; 5 | } 6 | -------------------------------------------------------------------------------- /2022/09-intro-rich-model/src/main/java/com/osachitech/examples/Team.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.IntSummaryStatistics; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Objects; 9 | import java.util.stream.Collectors; 10 | 11 | public class Team { 12 | 13 | private String name; 14 | 15 | private List players; 16 | 17 | private Team(String name) { 18 | this.name = name; 19 | this.players = new ArrayList<>(); 20 | } 21 | 22 | Team() { 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public List getPlayers() { 30 | return Collections.unmodifiableList(players); 31 | } 32 | 33 | public void add(Player player) { 34 | this.players.add(Objects.requireNonNull(player, "player is required")); 35 | } 36 | 37 | public Map> getPlayerGroupByPosition() { 38 | return players.stream() 39 | .collect(Collectors.groupingBy(Player::getPosition)); 40 | } 41 | 42 | public IntSummaryStatistics getScoreSummary() { 43 | return this.players 44 | .stream() 45 | .mapToInt(Player::getScore) 46 | .summaryStatistics(); 47 | } 48 | 49 | public static Team of(String name) { 50 | Objects.requireNonNull(name, "name is required"); 51 | return new Team(name); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /2022/09-intro-rich-model/src/main/java/com/osachitech/examples/client/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.client; 2 | 3 | import com.osachitech.examples.Player; 4 | import com.osachitech.examples.PlayerBuilder; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args) { 9 | PlayerBuilder builder = Player.builder(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022/09-intro-rich-model/src/test/java/com/osachitech/examples/TeamTest.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import org.hamcrest.MatcherAssert; 4 | import org.hamcrest.Matchers; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.util.IntSummaryStatistics; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | class TeamTest { 13 | 14 | @Test 15 | public void shouldCreateTeam() { 16 | Team team = Team.of("Mario Soccer"); 17 | Player mario = Player.builder().name("Mario") 18 | .position(Position.ATTACKER).build(); 19 | team.add(mario); 20 | 21 | team.add(Player.builder().name("Mario") 22 | .position(Position.DEFENDER).build()); 23 | 24 | Map> byPosition = team.getPlayerGroupByPosition(); 25 | Assertions.assertNotNull(byPosition); 26 | List players = byPosition.get(Position.ATTACKER); 27 | MatcherAssert.assertThat(players, Matchers.contains(mario)); 28 | } 29 | 30 | @Test 31 | public void shouldCreateSummary() { 32 | Team team = Team.of("Mario Soccer"); 33 | Player mario = Player.builder().name("Mario") 34 | .position(Position.ATTACKER).score(2).build(); 35 | team.add(mario); 36 | 37 | team.add(Player.builder().name("Luigi") 38 | .position(Position.DEFENDER).score(1).build()); 39 | 40 | IntSummaryStatistics summary = team.getScoreSummary(); 41 | Assertions.assertEquals(3, summary.getSum()); 42 | } 43 | } -------------------------------------------------------------------------------- /2022/10-collector/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/10-collector/src/main/java/com/osachitech/examples/Player.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import javax.money.MonetaryAmount; 4 | 5 | public class Player { 6 | 7 | private String name; 8 | 9 | private String city; 10 | 11 | private MonetaryAmount salary; 12 | 13 | private int score; 14 | 15 | private Position position; 16 | 17 | Player(String name, String city, 18 | MonetaryAmount salary, int score, 19 | Position position) { 20 | this.name = name; 21 | this.city = city; 22 | this.salary = salary; 23 | this.score = score; 24 | this.position = position; 25 | } 26 | 27 | /** 28 | * Please use the builder method instead, it is to framework only. 29 | * {@link Player#builder()} 30 | */ 31 | @Deprecated 32 | Player() { 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public String getCity() { 40 | return city; 41 | } 42 | 43 | public MonetaryAmount getSalary() { 44 | return salary; 45 | } 46 | 47 | public int getScore() { 48 | return score; 49 | } 50 | 51 | public Position getPosition() { 52 | return position; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "Player{" + 58 | "name='" + name + '\'' + 59 | ", city='" + city + '\'' + 60 | ", salary=" + salary + 61 | ", score=" + score + 62 | ", position=" + position + 63 | '}'; 64 | } 65 | 66 | public static PlayerBuilder builder() { 67 | return new PlayerBuilder(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /2022/10-collector/src/main/java/com/osachitech/examples/PlayerBuilder.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | import javax.money.MonetaryAmount; 4 | 5 | public class PlayerBuilder { 6 | private String name; 7 | private String city; 8 | private MonetaryAmount salary; 9 | private int score; 10 | private Position position; 11 | 12 | PlayerBuilder() { 13 | } 14 | 15 | public PlayerBuilder name(String name) { 16 | this.name = name; 17 | return this; 18 | } 19 | 20 | public PlayerBuilder city(String city) { 21 | this.city = city; 22 | return this; 23 | } 24 | 25 | public PlayerBuilder salary(MonetaryAmount salary) { 26 | this.salary = salary; 27 | return this; 28 | } 29 | 30 | public PlayerBuilder score(int score) { 31 | this.score = score; 32 | return this; 33 | } 34 | 35 | public PlayerBuilder position(Position position) { 36 | this.position = position; 37 | return this; 38 | } 39 | 40 | public Player build() { 41 | 42 | return new Player(name, city, salary, score, position); 43 | } 44 | } -------------------------------------------------------------------------------- /2022/10-collector/src/main/java/com/osachitech/examples/Position.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples; 2 | 3 | public enum Position { 4 | GOALKEEPER,DEFENDER,ATTACKER; 5 | } 6 | -------------------------------------------------------------------------------- /2022/10-collector/src/main/java/com/osachitech/examples/client/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.client; 2 | 3 | import com.osachitech.examples.Player; 4 | import com.osachitech.examples.PlayerBuilder; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args) { 9 | PlayerBuilder builder = Player.builder(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/App.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi; 2 | 3 | import com.osachitech.examples.cdi.cars.Garage; 4 | import jakarta.enterprise.inject.se.SeContainer; 5 | import jakarta.enterprise.inject.se.SeContainerInitializer; 6 | 7 | public class App { 8 | public static void main(String[] args) { 9 | 10 | try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { 11 | Garage garage = container.select(Garage.class).get(); 12 | garage.moves(); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/App2.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi; 2 | 3 | import com.osachitech.examples.cdi.music.Music; 4 | import com.osachitech.examples.cdi.music.MusicService; 5 | import jakarta.enterprise.inject.se.SeContainer; 6 | import jakarta.enterprise.inject.se.SeContainerInitializer; 7 | import org.javamoney.moneta.Money; 8 | 9 | import javax.money.CurrencyUnit; 10 | import javax.money.MonetaryAmount; 11 | 12 | public class App2 { 13 | 14 | public static void main(String[] args) { 15 | 16 | try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { 17 | Music music = container.select(Music.class).get(); 18 | music.play(); 19 | 20 | CurrencyUnit currency = container.select(CurrencyUnit.class).get(); 21 | MonetaryAmount money = Money.of(10, currency); 22 | 23 | System.out.println("The money value: " + money); 24 | 25 | MusicService service = container.select(MusicService.class).get(); 26 | service.sing(); 27 | 28 | 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/App3.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi; 2 | 3 | import com.osachitech.examples.cdi.news.Journalist; 4 | import com.osachitech.examples.cdi.news.News; 5 | import com.osachitech.examples.cdi.news.SocialMedia; 6 | import jakarta.enterprise.inject.se.SeContainer; 7 | import jakarta.enterprise.inject.se.SeContainerInitializer; 8 | 9 | public class App3 { 10 | 11 | public static void main(String[] args) { 12 | 13 | try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { 14 | 15 | Journalist journalist = container.select(Journalist.class).get(); 16 | journalist.publish(new News("Java version has arrived")); 17 | System.out.println("The premium news"); 18 | journalist.premiumNews(new News("Jakarta EE has arrived")); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/App4.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi; 2 | 3 | import com.osachitech.examples.cdi.worker.TextSupplier; 4 | import com.osachitech.examples.cdi.worker.Worker; 5 | import jakarta.enterprise.inject.se.SeContainer; 6 | import jakarta.enterprise.inject.se.SeContainerInitializer; 7 | 8 | public class App4 { 9 | 10 | public static void main(String[] args) { 11 | 12 | try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { 13 | Worker worker = container.select(Worker.class).get(); 14 | String result = worker.work("A single button."); 15 | System.out.println("The result job is: " + result); 16 | TextSupplier supplier = container.select(TextSupplier.class).get(); 17 | String value = supplier.get(); 18 | System.out.println("the value is " + value); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/App5.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi; 2 | 3 | import com.osachitech.examples.cdi.start.EagerBean; 4 | import com.osachitech.examples.cdi.start.LazyBean; 5 | import jakarta.enterprise.inject.se.SeContainer; 6 | import jakarta.enterprise.inject.se.SeContainerInitializer; 7 | 8 | public class App5 { 9 | 10 | public static void main(String[] args) { 11 | 12 | try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { 13 | LazyBean bean = container.select(LazyBean.class).get(); 14 | bean.action(); 15 | EagerBean eagerBean = container.select(EagerBean.class).get(); 16 | eagerBean.action(); 17 | 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/cars/Brand.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.cars; 2 | 3 | import jakarta.enterprise.util.Nonbinding; 4 | import jakarta.inject.Qualifier; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Qualifier 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) 14 | public @interface Brand { 15 | CarType value(); 16 | } 17 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/cars/Car.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.cars; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | 5 | public interface Car { 6 | 7 | void move(); 8 | } 9 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/cars/CarType.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.cars; 2 | 3 | public enum CarType { 4 | SPORT, REGULAR; 5 | } 6 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/cars/Ferrari.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.cars; 2 | 3 | import jakarta.inject.Named; 4 | 5 | @Brand(CarType.SPORT) 6 | public class Ferrari implements Car { 7 | @Override 8 | public void move() { 9 | System.out.println("Moving my ferrari"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/cars/Fiat.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.cars; 2 | 3 | import jakarta.inject.Named; 4 | 5 | @Brand(CarType.REGULAR) 6 | public class Fiat implements Car{ 7 | @Override 8 | public void move() { 9 | System.out.println("Moving my fiat 500"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/cars/Garage.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.cars; 2 | 3 | import jakarta.enterprise.inject.Any; 4 | import jakarta.enterprise.inject.Instance; 5 | import jakarta.inject.Inject; 6 | 7 | public class Garage { 8 | 9 | @Inject 10 | @Brand(CarType.SPORT) 11 | private Car sport; 12 | 13 | @Inject 14 | @Brand(CarType.REGULAR) 15 | private Car regular; 16 | 17 | @Inject 18 | @Any 19 | private Instance cars; 20 | 21 | public void moveSport() { 22 | this.sport.move(); 23 | } 24 | 25 | public void moveRegular() { 26 | this.regular.move(); 27 | } 28 | 29 | public void moves() { 30 | this.cars.forEach(c -> c.move()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/music/CurrencySupplier.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.music; 2 | 3 | import jakarta.annotation.PostConstruct; 4 | import jakarta.enterprise.context.ApplicationScoped; 5 | import jakarta.enterprise.inject.Disposes; 6 | import jakarta.enterprise.inject.Produces; 7 | 8 | import javax.money.CurrencyUnit; 9 | import javax.money.Monetary; 10 | 11 | @ApplicationScoped 12 | class CurrencySupplier { 13 | 14 | private CurrencyUnit currency; 15 | 16 | @PostConstruct 17 | public void setUp() { 18 | this.currency = Monetary.getCurrency("EUR"); 19 | } 20 | 21 | @Produces 22 | CurrencyUnit getCurrency() { 23 | return currency; 24 | } 25 | 26 | void close(@Disposes CurrencyUnit currency) { 27 | System.out.println("We don't need this currency: " + currency); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/music/LoggerProducer.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.music; 2 | 3 | import jakarta.enterprise.inject.Produces; 4 | import jakarta.enterprise.inject.spi.InjectionPoint; 5 | 6 | import java.util.logging.Logger; 7 | 8 | class LoggerProducer { 9 | 10 | private static final Logger LOGGER = Logger.getLogger(LoggerProducer.class.getName()); 11 | 12 | @Produces 13 | public Logger getLog(InjectionPoint ip) { 14 | String declaringClass = ip.getMember().getDeclaringClass().getName(); 15 | LOGGER.info("creating the log for "+ declaringClass); 16 | return Logger.getLogger(declaringClass); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/music/Music.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.music; 2 | 3 | import jakarta.enterprise.inject.Vetoed; 4 | 5 | @Vetoed 6 | public class Music { 7 | 8 | private String sing; 9 | 10 | Music() { 11 | } 12 | 13 | public Music(String sing) { 14 | this.sing = sing; 15 | } 16 | 17 | public void play() { 18 | System.out.println("Playing the music: " + sing); 19 | } 20 | 21 | public void stop() { 22 | System.out.println("Stop sinning the music: " + sing); 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "Music{" + 28 | "sing='" + sing + '\'' + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/music/MusicService.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.music; 2 | 3 | import jakarta.inject.Inject; 4 | 5 | import java.util.logging.Logger; 6 | 7 | public class MusicService { 8 | 9 | @Inject 10 | private Music music; 11 | 12 | @Inject 13 | private Logger logger; 14 | 15 | 16 | public void sing() { 17 | logger.info("Start to singing this music here: " + music); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/music/MusicSupplier.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.music; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | import jakarta.enterprise.inject.Disposes; 5 | import jakarta.enterprise.inject.Produces; 6 | 7 | import java.util.function.Supplier; 8 | 9 | class MusicSupplier implements Supplier { 10 | 11 | @Override 12 | @Produces 13 | @ApplicationScoped 14 | public Music get() { 15 | return new Music("Don't stop me now"); 16 | } 17 | 18 | public void stopSinning(@Disposes Music music) { 19 | music.stop(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/Journalist.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | import jakarta.enterprise.event.Event; 5 | import jakarta.inject.Inject; 6 | 7 | @ApplicationScoped 8 | public class Journalist { 9 | 10 | @Inject 11 | private Event event; 12 | 13 | @Inject 14 | @PremiumCategory 15 | private Event eventQualifier; 16 | public void publish(News news) { 17 | this.event.fire(news); 18 | this.event.fireAsync(news); 19 | } 20 | 21 | public void premiumNews(News news) { 22 | this.eventQualifier.fire(news); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/Magazine.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.event.Observes; 4 | 5 | public class Magazine { 6 | 7 | public void receive(@Observes News news) { 8 | System.out.println("Publishing the news on magazine: " + news); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/News.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import java.util.function.Supplier; 4 | 5 | public class News implements Supplier { 6 | 7 | private final String value; 8 | 9 | public News(String value) { 10 | this.value = value; 11 | } 12 | 13 | @Override 14 | public String get() { 15 | return value; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "News{" + 21 | "value='" + value + '\'' + 22 | '}'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/NewsPaper.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.event.Observes; 4 | 5 | public class NewsPaper { 6 | 7 | public void receive(@Observes News news) { 8 | System.out.println("Publishing the newspaper: " + news); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/PremiumCategory.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | 4 | import jakarta.inject.Qualifier; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Qualifier 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) 14 | public @interface PremiumCategory { 15 | } 16 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/PremiumMagazine.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.event.Observes; 4 | 5 | public class PremiumMagazine { 6 | 7 | public void receive(@Observes @PremiumCategory News news) { 8 | System.out.println("Publishing the news on the premium magazine: " + news); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/Press.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.event.Observes; 4 | 5 | public class Press { 6 | 7 | public void receive(@Observes News news) { 8 | System.out.println("Publishing the news on the TV: " + news); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/SocialMedia.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.event.Observes; 4 | 5 | public class SocialMedia { 6 | 7 | public void receive(@Observes News news) { 8 | System.out.println("Publishing the news on social media: " + news + " " 9 | + Thread.currentThread().getName()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/news/Twitter.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.news; 2 | 3 | import jakarta.enterprise.event.Observes; 4 | import jakarta.enterprise.event.ObservesAsync; 5 | 6 | public class Twitter { 7 | 8 | public void receive(@ObservesAsync News news) { 9 | System.out.println("Publishing the news on twitter: " + news + " " 10 | + Thread.currentThread().getName()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/start/EagerBean.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.start; 2 | 3 | 4 | import jakarta.annotation.PostConstruct; 5 | import jakarta.enterprise.context.ApplicationScoped; 6 | 7 | @ApplicationScoped 8 | @Startup 9 | public class EagerBean { 10 | 11 | @PostConstruct 12 | public void setUp() { 13 | System.out.println("Application starting up on the eager way"); 14 | } 15 | 16 | public void action() { 17 | System.out.println("Let me do something"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/start/LazyBean.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.start; 2 | 3 | 4 | import jakarta.annotation.PostConstruct; 5 | import jakarta.enterprise.context.ApplicationScoped; 6 | 7 | @ApplicationScoped 8 | public class LazyBean { 9 | @PostConstruct 10 | public void setUp() { 11 | System.out.println("Application starting up on the lazy way"); 12 | } 13 | public void action() { 14 | System.out.println("Let me do something"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/start/Startup.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.start; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) 10 | public @interface Startup { 11 | } 12 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/start/StartupBeanExtension.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.start; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | import jakarta.enterprise.event.Observes; 5 | import jakarta.enterprise.inject.spi.*; 6 | 7 | import java.util.LinkedHashSet; 8 | import java.util.Set; 9 | 10 | public class StartupBeanExtension implements Extension { 11 | 12 | private final Set> startupBeans = new LinkedHashSet<>(); 13 | 14 | void processBean(@Observes ProcessBean event) { 15 | if (event.getAnnotated().isAnnotationPresent(Startup.class) 16 | && event.getAnnotated().isAnnotationPresent(ApplicationScoped.class)) { 17 | this.startupBeans.add(event.getBean()); 18 | } 19 | } 20 | 21 | void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager manager) { 22 | for (Bean bean : startupBeans) { 23 | 24 | manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean)).toString(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/worker/Manager.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.worker; 2 | 3 | import jakarta.annotation.Priority; 4 | import jakarta.decorator.Decorator; 5 | import jakarta.decorator.Delegate; 6 | import jakarta.enterprise.inject.Any; 7 | import jakarta.inject.Inject; 8 | import jakarta.interceptor.Interceptor; 9 | 10 | @Decorator 11 | @Priority(Interceptor.Priority.APPLICATION) 12 | public class Manager implements Worker{ 13 | 14 | @Inject 15 | @Delegate 16 | @Any 17 | private Worker worker; 18 | 19 | @Override 20 | public String work(String job) { 21 | return "A manager has received the job, and it will delegate to a programmer -> " 22 | + worker.work(job); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/worker/Programmer.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.worker; 2 | 3 | public class Programmer implements Worker { 4 | @Override 5 | public String work(String job) { 6 | return "converting coffee into code, the job: " + job; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/worker/TextSupplier.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.worker; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.function.Supplier; 5 | 6 | public class TextSupplier implements Supplier { 7 | 8 | @Override 9 | @Timed 10 | public String get() { 11 | try { 12 | TimeUnit.SECONDS.sleep(2L); 13 | } catch (InterruptedException e) { 14 | throw new RuntimeException(e); 15 | } 16 | return "Using my text"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/worker/Timed.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.worker; 2 | 3 | import jakarta.interceptor.InterceptorBinding; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @InterceptorBinding 11 | @Target({ElementType.METHOD, ElementType.TYPE}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface Timed { 14 | } 15 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/worker/TimedInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.worker; 2 | 3 | 4 | import jakarta.annotation.Priority; 5 | import jakarta.interceptor.AroundInvoke; 6 | import jakarta.interceptor.Interceptor; 7 | import jakarta.interceptor.InvocationContext; 8 | 9 | import java.util.logging.Logger; 10 | 11 | @Timed 12 | @Interceptor 13 | @Priority(Interceptor.Priority.APPLICATION) 14 | class TimedInterceptor { 15 | private static final Logger LOGGER = Logger.getLogger(TimedInterceptor.class.getName()); 16 | 17 | @AroundInvoke 18 | public Object timed(InvocationContext context) throws Exception { 19 | long start = System.currentTimeMillis(); 20 | Object result = context.proceed(); 21 | long end = System.currentTimeMillis() -start; 22 | String message = String.format("Time to execute the class %s the method %s " + 23 | " is of %d milliseconds", context.getTarget(), context.getMethod(), end); 24 | LOGGER.info(message); 25 | return result; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/java/com/osachitech/examples/cdi/worker/Worker.java: -------------------------------------------------------------------------------- 1 | package com.osachitech.examples.cdi.worker; 2 | 3 | public interface Worker { 4 | 5 | String work(String job); 6 | } 7 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /2022/11-cdi-introduction/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | com.osachitech.examples.cdi.start.StartupBeanExtension -------------------------------------------------------------------------------- /2022/12-microstream/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 4.0.0 8 | 9 | 10 | com.osachitech.examples 11 | 12-microstream 12 | 1.0-SNAPSHOT 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | 21 | 22 | one.microstream 23 | microstream-integrations-cdi 24 | 07.00.00-MS-GA 25 | 26 | 27 | org.jboss.weld.se 28 | weld-se-shaded 29 | 3.1.9.Final 30 | 31 | 32 | io.smallrye.config 33 | smallrye-config 34 | 2.13.0 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /2022/12-microstream/src/main/java/org/a4j/workshop/helidon/microstream/BookBuilder.java: -------------------------------------------------------------------------------- 1 | package org.a4j.workshop.helidon.microstream; 2 | 3 | import java.time.Year; 4 | 5 | public class BookBuilder { 6 | private String id; 7 | private String title; 8 | private String author; 9 | private Year release; 10 | 11 | BookBuilder() { 12 | } 13 | 14 | public BookBuilder id(String id) { 15 | this.id = id; 16 | return this; 17 | } 18 | 19 | public BookBuilder title(String title) { 20 | this.title = title; 21 | return this; 22 | } 23 | 24 | public BookBuilder author(String author) { 25 | this.author = author; 26 | return this; 27 | } 28 | 29 | public BookBuilder release(Year release) { 30 | this.release = release; 31 | return this; 32 | } 33 | 34 | public Book build() { 35 | return new Book(id, title, author, release); 36 | } 37 | } -------------------------------------------------------------------------------- /2022/12-microstream/src/main/java/org/a4j/workshop/helidon/microstream/BookService.java: -------------------------------------------------------------------------------- 1 | package org.a4j.workshop.helidon.microstream; 2 | 3 | import one.microstream.integrations.cdi.types.Store; 4 | 5 | import javax.enterprise.context.ApplicationScoped; 6 | import javax.inject.Inject; 7 | import java.util.List; 8 | import java.util.Objects; 9 | 10 | @ApplicationScoped 11 | public class BookService { 12 | 13 | @Inject 14 | private Library library; 15 | 16 | @Store 17 | public void add(Book book) { 18 | Objects.requireNonNull(book, "book is required"); 19 | this.library.add(book); 20 | } 21 | 22 | public List getBooks() { 23 | return this.library.getBooks(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2022/12-microstream/src/main/java/org/a4j/workshop/helidon/microstream/Library.java: -------------------------------------------------------------------------------- 1 | package org.a4j.workshop.helidon.microstream; 2 | 3 | import one.microstream.integrations.cdi.types.Storage; 4 | 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.stream.Collectors; 9 | 10 | @Storage 11 | public class Library { 12 | 13 | private final Set books; 14 | 15 | public Library() { 16 | books = new HashSet<>(); 17 | } 18 | 19 | public void add(Book book){ 20 | this.books.add(book); 21 | } 22 | 23 | public List getBooks() { 24 | return this.books.stream().collect(Collectors.toUnmodifiableList()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2022/12-microstream/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /2022/12-microstream/src/main/resources/META-INF/microprofile-config.properties: -------------------------------------------------------------------------------- 1 | 2 | one.microstream.storage.directory=target/data 3 | one.microstream.channel.count=4 4 | one.microstream.store=true -------------------------------------------------------------------------------- /2022/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.osachitech.examples 6 | java-videos-code-2022 7 | 1.0-SNAPSHOT 8 | pom 9 | 10 | java-videos-code-2022 11 | http://www.osachitech.com 12 | The code result from the youtube channel on 2022 13 | 14 | 15 | 01-enum-advanced 16 | 02-three-states 17 | 03-optimizing-optional 18 | 04-encapsulation 19 | 05-builder-fluent-api 20 | 06-functions-composite 21 | 07-interface 22 | 08-money-api 23 | 09-intro-rich-model 24 | 10-collector 25 | 11-cdi-introduction 26 | 12-microstream 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /2023/01-documentation/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/01-documentation/CHANGELOG.adoc: -------------------------------------------------------------------------------- 1 | = Changelog 2 | :toc: auto 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | The format is based on https://keepachangelog.com/en/1.0.0/[Keep a Changelog], 7 | and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Versioning]. 8 | 9 | == [Unreleased] 10 | 11 | === Added 12 | - Create 13 | 14 | === Changed 15 | 16 | - Changed 17 | 18 | === Removed 19 | 20 | - Remove 21 | 22 | === Fixed 23 | - Ops, fixed 24 | 25 | == [old-version] - 2022-08-04 -------------------------------------------------------------------------------- /2023/01-documentation/README.adoc: -------------------------------------------------------------------------------- 1 | = Project Name 2 | :toc: auto 3 | 4 | == Introduction 5 | 6 | A paragraph that explains the "why" or reason for this project exists. 7 | 8 | == Goals 9 | 10 | * The goals on bullets 11 | * The second goal 12 | 13 | == Getting Started 14 | 15 | Your reader gets into here; they need to know how to use and install it. 16 | 17 | == The API overview 18 | 19 | The coolest features here 20 | 21 | == To know more 22 | 23 | More references such as books, articles, videos, and so on. 24 | 25 | 26 | == Samples 27 | 28 | * https://github.com/spring-projects/spring-data-commons[Spring data commons] 29 | * https://github.com/eclipse/jnosql[JNoSQL] 30 | * https://github.com/xmolecules/jmolecules[jmolecules] -------------------------------------------------------------------------------- /2023/01-documentation/src/main/java/expert/os/App.java: -------------------------------------------------------------------------------- 1 | package expert.os; 2 | 3 | /** 4 | * Hello world! 5 | */ 6 | public class App { 7 | public static void main(String[] args) { 8 | System.out.println("Hello World!"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2023/01-documentation/src/test/java/expert/os/AppTest.java: -------------------------------------------------------------------------------- 1 | package expert.os; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * Unit test for simple App. 8 | */ 9 | public class AppTest { 10 | /** 11 | * Rigorous Test :-) 12 | */ 13 | @Test 14 | public void shouldTest() { 15 | } 16 | 17 | @Test 18 | public void shouldTestB() { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2023/02-record/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/02-record/README.adoc: -------------------------------------------------------------------------------- 1 | = Project Name 2 | :toc: auto 3 | 4 | == Record beyond Record 5 | 6 | * What is record? 7 | * Why record? 8 | * DTO 9 | * Immutable entities 10 | * State -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/App.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.LocalDate; 4 | import java.time.Month; 5 | 6 | /** 7 | * Hello world! 8 | */ 9 | public class App { 10 | public static void main(String[] args) { 11 | Person person = new Person("Otavio", LocalDate.of(1988, 12 | Month.JANUARY, 9), "Salvador"); 13 | 14 | System.out.println("The person: " + person); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Book.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.Year; 4 | import java.util.Objects; 5 | 6 | public record Book(String id, String title, Year release, int edition) { 7 | 8 | 9 | public Book { 10 | Objects.requireNonNull(id, "id is required"); 11 | Objects.requireNonNull(title, "title is required"); 12 | Objects.requireNonNull(release, "release is required"); 13 | if (edition < 1) { 14 | throw new IllegalArgumentException("Edition cannot be negative"); 15 | } 16 | } 17 | 18 | public Book newEdition(String id, Year year) { 19 | Objects.requireNonNull(id, "id is required"); 20 | Objects.requireNonNull(year, "year is required"); 21 | return new Book(id, this.title, year, (edition + 1)); 22 | } 23 | 24 | @Override 25 | public boolean equals(Object o) { 26 | if (this == o) { 27 | return true; 28 | } 29 | if (o == null || getClass() != o.getClass()) { 30 | return false; 31 | } 32 | Book book = (Book) o; 33 | return Objects.equals(id, book.id); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | return Objects.hashCode(id); 39 | } 40 | 41 | public static BookBuilder builder() { 42 | return new BookBuilder(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/BookBuilder.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.Year; 4 | 5 | public class BookBuilder { 6 | 7 | private String id; 8 | private String title; 9 | private Year release; 10 | private int edition = 1; 11 | 12 | public BookBuilder id(String id) { 13 | this.id = id; 14 | return this; 15 | } 16 | 17 | public BookBuilder title(String title) { 18 | this.title = title; 19 | return this; 20 | } 21 | 22 | public BookBuilder release(Year release) { 23 | this.release = release; 24 | return this; 25 | } 26 | 27 | public BookBuilder edition(int edition) { 28 | this.edition = edition; 29 | return this; 30 | } 31 | 32 | public Book builder() { 33 | return new Book(id, title, release, edition); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Delivered.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Objects; 6 | 7 | public record Delivered(List products) implements Order { 8 | 9 | public Delivered { 10 | Objects.requireNonNull(products, "products is required"); 11 | } 12 | @Override 13 | public Order next() { 14 | return new Received(products); 15 | } 16 | 17 | @Override 18 | public List products() { 19 | return Collections.unmodifiableList(products); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Email.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public record Email (String value) { 4 | } 5 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Money.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Currency; 5 | import java.util.Objects; 6 | 7 | public record Money(Currency currency, BigDecimal value) { 8 | 9 | Money add(Money money) { 10 | Objects.requireNonNull(money, "Money is required"); 11 | if (currency.equals(money.currency)) { 12 | BigDecimal result = this.value.add(money.value); 13 | return new Money(currency, result); 14 | } 15 | throw new IllegalStateException("You cannot sum money with different currencies"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/OldPerson.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Objects; 5 | 6 | public class OldPerson { 7 | 8 | private final String name; 9 | 10 | private final LocalDate birthday; 11 | 12 | private final String city; 13 | 14 | public OldPerson(String name, LocalDate birthday, String city) { 15 | this.name = name; 16 | this.birthday = birthday; 17 | this.city = city; 18 | } 19 | 20 | 21 | public String name() { 22 | return name; 23 | } 24 | 25 | public LocalDate birthday() { 26 | return birthday; 27 | } 28 | 29 | public String city() { 30 | return city; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object o) { 35 | if (this == o) { 36 | return true; 37 | } 38 | if (o == null || getClass() != o.getClass()) { 39 | return false; 40 | } 41 | OldPerson person = (OldPerson) o; 42 | return Objects.equals(name, person.name) 43 | && Objects.equals(birthday, person.birthday) 44 | && Objects.equals(city, person.city); 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | return Objects.hash(name, birthday, city); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "OldPerson{" + 55 | "name='" + name + '\'' + 56 | ", birthday=" + birthday + 57 | ", city='" + city + '\'' + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Order.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.List; 4 | 5 | public sealed interface Order permits Ordered, Delivered, Received { 6 | 7 | static Order newOrder(List products) { 8 | return new Ordered(products); 9 | } 10 | 11 | Order next(); 12 | List products(); 13 | } 14 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Ordered.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Objects; 6 | 7 | public record Ordered(List products) implements Order { 8 | 9 | public Ordered { 10 | Objects.requireNonNull(products, "products is required"); 11 | } 12 | @Override 13 | public Order next() { 14 | return new Delivered(products); 15 | } 16 | 17 | @Override 18 | public List products() { 19 | return Collections.unmodifiableList(products); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Person.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.LocalDate; 4 | 5 | public record Person(String name, LocalDate birthday, String city) { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Received.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Objects; 6 | 7 | public record Received(List products) implements Order { 8 | 9 | public Received { 10 | Objects.requireNonNull(products, "products is required"); 11 | } 12 | 13 | @Override 14 | public Order next() { 15 | throw new IllegalStateException("We finished our journey here"); 16 | } 17 | 18 | @Override 19 | public List products() { 20 | return Collections.unmodifiableList(products); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2023/02-record/src/main/java/expert/os/examples/Team.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.Objects; 4 | 5 | public class Team { 6 | 7 | private String id; 8 | 9 | @Override 10 | public boolean equals(Object o) { 11 | if (this == o) return true; 12 | if (o == null || getClass() != o.getClass()) return false; 13 | Team team = (Team) o; 14 | return Objects.equals(id, team.id); 15 | } 16 | 17 | @Override 18 | public int hashCode() { 19 | return Objects.hash(id); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2023/02-record/src/test/java/expert/os/examples/AppTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * Unit test for simple App. 8 | */ 9 | public class AppTest { 10 | /** 11 | * Rigorous Test :-) 12 | */ 13 | @Test 14 | public void shouldTest() { 15 | } 16 | 17 | @Test 18 | public void shouldTestB() { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2023/02-record/src/test/java/expert/os/examples/BookTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.time.Year; 7 | 8 | class BookTest { 9 | 10 | 11 | @Test 12 | public void shouldReturnInvalid() { 13 | Assertions.assertThrows(NullPointerException.class, () -> 14 | new Book(null, null, null, -1)); 15 | } 16 | 17 | @Test 18 | public void shouldReturnError() { 19 | Assertions.assertThrows(IllegalArgumentException.class, () -> new Book("id", "Effective Java", 20 | Year.of(2001), 0)); 21 | 22 | Assertions.assertThrows(IllegalArgumentException.class, () -> new Book("id", "Effective Java", 23 | Year.of(2001), -1)); 24 | } 25 | 26 | @Test 27 | public void shouldTitle() { 28 | Book book = new Book("id", "Effective Java", Year.of(2001), 1); 29 | System.out.println(book.title()); 30 | } 31 | 32 | @Test 33 | public void shouldCreateFromBuilder() { 34 | Book book = Book.builder().id("id").title("Effective Java").release(Year.of(2001)).builder(); 35 | } 36 | 37 | @Test 38 | public void shouldCreateNewEdition() { 39 | Book first = Book.builder().id("id").title("Effective Java").release(Year.of(2001)).builder(); 40 | Book second = first.newEdition("id-2", Year.of(2009)); 41 | Assertions.assertNotNull(second); 42 | Assertions.assertEquals(first.title(), second.title()); 43 | Assertions.assertNotEquals(first.id(), second.id()); 44 | Assertions.assertNotEquals(first.release(), second.release()); 45 | Assertions.assertEquals(2, second.edition()); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /2023/02-record/src/test/java/expert/os/examples/OrderTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.List; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | public class OrderTest { 11 | 12 | @Test 13 | public void shouldShouldOrder() { 14 | List products = List.of("Banana"); 15 | Order order = Order.newOrder(products); 16 | assertThat(order).isInstanceOfAny(Ordered.class); 17 | Order delivered = order.next(); 18 | assertThat(delivered).isInstanceOfAny(Delivered.class); 19 | Order received = delivered.next(); 20 | assertThat(received).isInstanceOfAny(Received.class); 21 | 22 | Assertions.assertThrows(IllegalStateException.class, () -> received.next()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2023/03-java-doc-test/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/03-java-doc-test/README.adoc: -------------------------------------------------------------------------------- 1 | = Documentation and test 2 | :toc: auto 3 | 4 | == Java Docs 5 | 6 | - @param 7 | - @throws 8 | - @version 9 | - @author 10 | 11 | 12 | === References 13 | 14 | - https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/main/java/expert/os/videos/demo/Animal.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | 4 | /** 5 | * Don't do this 6 | * This is a class 7 | */ 8 | public class Animal { 9 | 10 | /** 11 | * This is a field 12 | */ 13 | private String name; 14 | 15 | /** 16 | * This is aconstructor 17 | * @param name 18 | */ 19 | public Animal(String name) { 20 | this.name = name; 21 | } 22 | 23 | 24 | /** 25 | * This is a getter 26 | * @return 27 | */ 28 | public String name() { 29 | return name; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/main/java/expert/os/videos/demo/ChampionRepository.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | public interface ChampionRepository { 4 | boolean existByName(String name); 5 | 6 | void save(Team team); 7 | } 8 | -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/main/java/expert/os/videos/demo/ChampionshipService.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | public class ChampionshipService { 4 | 5 | private ChampionRepository repository; 6 | 7 | public void register(Team team) { 8 | if(repository.existByName(team.name())) { 9 | throw new IllegalArgumentException("The champion league has a team with this name"); 10 | } 11 | this.repository.save(team); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/main/java/expert/os/videos/demo/OverTeamException.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | public class OverTeamException extends RuntimeException{ 4 | public OverTeamException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/main/java/expert/os/videos/demo/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The soccer team domain. 3 | * Where we have a team that has eleven players. 4 | * @author otaviojava 5 | * @version 0.0.1 6 | * @since 7 | */ 8 | package expert.os.videos.demo; -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/test/java/expert/os/videos/demo/ChampionshipServiceTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.DisplayName; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | import org.mockito.InjectMocks; 8 | import org.mockito.Mock; 9 | import org.mockito.Mockito; 10 | import org.mockito.junit.jupiter.MockitoExtension; 11 | 12 | @ExtendWith(MockitoExtension.class) 13 | class ChampionshipServiceTest { 14 | 15 | @Mock 16 | private ChampionRepository repository; 17 | 18 | @InjectMocks 19 | private ChampionshipService service; 20 | 21 | @Test 22 | public void shouldRegister() { 23 | Mockito.when(repository.existByName("Bahia")).thenReturn(false); 24 | Team bahia = Team.of("Bahia"); 25 | service.register(bahia); 26 | 27 | Mockito.verify(repository).existByName("Bahia"); 28 | } 29 | @Test 30 | @DisplayName("should return an exception when there is a team with a name") 31 | public void shouldThrownAnExceptionWhenTeamNameExists() { 32 | Mockito.when(repository.existByName("Bahia")).thenReturn(true); 33 | Team bahia = Team.of("Bahia"); 34 | Assertions.assertThrows(IllegalArgumentException.class, () -> 35 | service.register(bahia)); 36 | 37 | Mockito.verify(repository).existByName("Bahia"); 38 | } 39 | } -------------------------------------------------------------------------------- /2023/03-java-doc-test/src/test/java/expert/os/videos/demo/PlayerProvider.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.junit.jupiter.api.extension.ExtensionContext; 4 | import org.junit.jupiter.params.provider.Arguments; 5 | import org.junit.jupiter.params.provider.ArgumentsProvider; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.stream.Stream; 10 | 11 | public class PlayerProvider implements ArgumentsProvider { 12 | @Override 13 | public Stream provideArguments(ExtensionContext extensionContext) throws Exception { 14 | List players = new ArrayList<>(); 15 | players.add(Player.of("Poliana", "Salvador", 20)); 16 | players.add(Player.of("Otavio", "Salvador", 0)); 17 | return Stream.of(Arguments.of(players)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/main/java/expert/os/examples/Inventory.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | import jakarta.inject.Inject; 5 | 6 | @ApplicationScoped 7 | public class Inventory { 8 | 9 | @Inject 10 | private Payment payment; 11 | 12 | 13 | public void buy(Product product) { 14 | this.payment.buy(product); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/main/java/expert/os/examples/PayPalPayment.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | 5 | @ApplicationScoped 6 | public class PayPalPayment implements Payment { 7 | @Override 8 | public void buy(Product product) { 9 | System.out.println("Using payment from external service " + product); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/main/java/expert/os/examples/Payment.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public interface Payment { 4 | void buy(Product product); 5 | } 6 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/main/java/expert/os/examples/Product.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public record Product(String name) { 4 | } 5 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/test/java/expert/os/examples/InventoryTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.inject.Inject; 4 | import org.jboss.weld.junit5.auto.AddPackages; 5 | import org.jboss.weld.junit5.auto.EnableAutoWeld; 6 | import org.junit.jupiter.api.Test; 7 | 8 | @EnableAutoWeld 9 | @AddPackages(Inventory.class) 10 | @AddPackages(PaymentMock.class) 11 | class InventoryTest { 12 | 13 | @Inject 14 | private Inventory inventory; 15 | 16 | @Test 17 | public void shouldBy() { 18 | Product product = new Product("Banana"); 19 | inventory.buy(product); 20 | } 21 | } -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/test/java/expert/os/examples/PaymentMock.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.annotation.Priority; 4 | import jakarta.enterprise.context.ApplicationScoped; 5 | import jakarta.enterprise.inject.Alternative; 6 | import jakarta.interceptor.Interceptor; 7 | 8 | @ApplicationScoped 9 | @Alternative 10 | @Priority(Interceptor.Priority.APPLICATION) 11 | public class PaymentMock implements Payment { 12 | @Override 13 | public void buy(Product product) { 14 | System.out.println("Overwriting on the test scope" + product); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /2023/04-jupiter-cdi/src/test/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /2023/05-reflections/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/Append.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Repeatable; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target(ElementType.TYPE) 12 | @Repeatable(Appends.class) 13 | public @interface Append { 14 | 15 | String key(); 16 | String value(); 17 | } 18 | -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/Appends.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.TYPE) 11 | public @interface Appends { 12 | 13 | Append[] value(); 14 | } 15 | -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/Column.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.FIELD) 11 | public @interface Column { 12 | String value() default ""; 13 | } 14 | -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/Entity.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.TYPE) 11 | public @interface Entity { 12 | } 13 | -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/Mapper.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | import java.util.Map; 4 | 5 | public interface Mapper { 6 | 7 | /** 8 | * 9 | * @param entity 10 | * @param 11 | * @return 12 | * @throws NullPointerException when the entity is null 13 | */ 14 | Map toMap(T entity); 15 | 16 | T toEntity(Map map); 17 | } 18 | -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/MapperInvocationHandler.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.util.Map; 6 | import java.util.Objects; 7 | 8 | public class MapperInvocationHandler implements InvocationHandler { 9 | 10 | private Mapper mapper = new ReflectionMapper(); 11 | @Override 12 | public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { 13 | String name = method.getName(); 14 | switch (name) { 15 | case "entity": 16 | Map map = (Map) params[0]; 17 | Objects.requireNonNull(map, "map is required"); 18 | return mapper.toEntity(map); 19 | case "map": 20 | Object entity = params[0]; 21 | Objects.requireNonNull(entity, "entity is required"); 22 | return mapper.toMap(entity); 23 | } 24 | if(method.isDefault()) { 25 | return InvocationHandler.invokeDefault(proxy, method, params); 26 | } 27 | throw new UnsupportedOperationException("The proxy is not supported to the method: " + method); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2023/05-reflections/src/main/java/expert/os/examples/mapping/MapperRepository.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | import java.lang.reflect.Proxy; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.Objects; 7 | 8 | public interface MapperRepository { 9 | 10 | T entity(Map map); 11 | 12 | Map map(T entity); 13 | 14 | default T incrementAge(Map map) { 15 | Objects.requireNonNull(map, "map is required"); 16 | if (map.containsKey("age")) { 17 | Map entity = new HashMap<>(map); 18 | entity.computeIfPresent("age", (k, v) -> { 19 | Integer age = (Integer) v; 20 | return ++age; 21 | }); 22 | return this.entity(entity); 23 | } 24 | return this.entity(map); 25 | } 26 | 27 | static MapperRepository repository() { 28 | return (MapperRepository) Proxy.newProxyInstance(MapperRepository.class.getClassLoader(), 29 | new Class[]{MapperRepository.class}, new MapperInvocationHandler()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2023/05-reflections/src/test/java/expert/os/examples/mapping/Fruit.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | @Entity 4 | @Append(key = "type", value = "Fruit") 5 | @Append(key = "category", value = "Natural") 6 | public class Fruit { 7 | 8 | @Column 9 | private String name; 10 | 11 | 12 | public Fruit(String name) { 13 | this.name = name; 14 | } 15 | 16 | @Deprecated 17 | public Fruit() { 18 | } 19 | 20 | public String name() { 21 | return name; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /2023/05-reflections/src/test/java/expert/os/examples/mapping/Pet.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.mapping; 2 | 3 | @Entity 4 | public class Pet { 5 | 6 | @Column 7 | private String name; 8 | 9 | @Column 10 | private int age; 11 | 12 | @Deprecated 13 | public Pet() { 14 | } 15 | 16 | private Pet(String name, int age) { 17 | this.name = name; 18 | this.age = age; 19 | } 20 | 21 | public String name() { 22 | return name; 23 | } 24 | 25 | public int age() { 26 | return age; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Pet{" + 32 | "name='" + name + '\'' + 33 | ", age=" + age + 34 | '}'; 35 | } 36 | 37 | public static Pet of(String name, int age) { 38 | //TODO validations 39 | return new Pet(name, age); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /2023/06-java-functions/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/06-java-functions/README.adoc: -------------------------------------------------------------------------------- 1 | = Documentation and test 2 | :toc: auto 3 | 4 | == Java Docs 5 | 6 | - @param 7 | - @throws 8 | - @version 9 | - @author 10 | 11 | 12 | === References 13 | 14 | - https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html -------------------------------------------------------------------------------- /2023/06-java-functions/src/main/java/expert/os/videos/demo/Player.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | public record Player(String name, String city, int score) implements Comparable { 4 | 5 | @Override 6 | public int compareTo(Player player) { 7 | return this.name.compareTo(player.name); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /2023/06-java-functions/src/test/java/expert/os/videos/demo/ConsumerTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.junit.jupiter.api.Tag; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.function.Consumer; 7 | 8 | public class ConsumerTest { 9 | 10 | @Test 11 | @Tag("consumer") 12 | public void shouldCreateConsumer() { 13 | Consumer log = (s) -> System.out.println("my log: " + s); 14 | log.accept("Ada is my dog"); 15 | } 16 | 17 | @Test 18 | @Tag("consumer") 19 | public void shouldCombineConsumer() { 20 | Consumer logA = (s) -> System.out.println("[A] my log: " + s); 21 | Consumer logB = (s) -> System.out.println("[B] my log: " + s); 22 | 23 | logA.andThen(logB).accept("My log message"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2023/06-java-functions/src/test/java/expert/os/videos/demo/FunctionTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.assertj.core.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.function.BiFunction; 7 | import java.util.function.Function; 8 | import java.util.function.UnaryOperator; 9 | 10 | public class FunctionTest { 11 | 12 | @Test 13 | public void shouldCreateFunction() { 14 | Function converter = Integer::valueOf; 15 | Integer result = converter.apply("123"); 16 | Assertions.assertThat(result).isEqualTo(123); 17 | } 18 | 19 | @Test 20 | public void shouldCreateSpeciliazations() { 21 | UnaryOperator trim = String::trim; 22 | BiFunction operation = (a, b) -> a * b; 23 | 24 | Assertions.assertThat(operation.apply(1, 2)).isEqualTo(2); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /2023/06-java-functions/src/test/java/expert/os/videos/demo/PredicateTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.assertj.core.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.function.Predicate; 7 | 8 | public class PredicateTest { 9 | 10 | @Test 11 | public void shouldUsePredicate() { 12 | Predicate higherTen = i -> i > 10; 13 | 14 | Assertions.assertThat(higherTen.test(12)).isTrue(); 15 | Assertions.assertThat(higherTen.test(5)).isFalse(); 16 | } 17 | 18 | @Test 19 | public void shouldDecoratePredicate() { 20 | Predicate higherTen = i -> i > 10; 21 | Predicate lesserOneHundraded = i -> i < 100; 22 | 23 | Assertions.assertThat(higherTen.or(lesserOneHundraded).test(35)) 24 | .isTrue(); 25 | Assertions.assertThat(higherTen.and(lesserOneHundraded).test(200)) 26 | .isFalse(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2023/06-java-functions/src/test/java/expert/os/videos/demo/SupplierTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.assertj.core.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.condition.EnabledIfSystemProperty; 6 | 7 | import java.util.Optional; 8 | import java.util.function.Supplier; 9 | 10 | @EnabledIfSystemProperty(named = "os.exepert.test",matches = "true") 11 | public class SupplierTest { 12 | 13 | @Test 14 | public void shouldUseSupplier() { 15 | Supplier db = () -> "Ada"; 16 | 17 | Optional cache = Optional.empty(); 18 | 19 | String name = cache.orElseGet(db); 20 | Assertions.assertThat(name).isEqualTo("Ada"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2023/07-archi-unit/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/07-archi-unit/README.adoc: -------------------------------------------------------------------------------- 1 | = Documentation and test 2 | :toc: auto 3 | 4 | == Java Docs 5 | 6 | - @param 7 | - @throws 8 | - @version 9 | - @author 10 | 11 | 12 | === References 13 | 14 | - https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html -------------------------------------------------------------------------------- /2023/07-archi-unit/src/main/java/expert/os/videos/demo/Book.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import org.jmolecules.ddd.annotation.Entity; 4 | import org.jmolecules.ddd.annotation.Identity; 5 | 6 | @Entity 7 | public class Book { 8 | @Identity 9 | 10 | private String isbn; 11 | 12 | private String title; 13 | 14 | 15 | private String description; 16 | } 17 | -------------------------------------------------------------------------------- /2023/07-archi-unit/src/main/java/expert/os/videos/demo/infrastructure/Magazine.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.infrastructure; 2 | 3 | import org.jmolecules.ddd.annotation.Entity; 4 | 5 | import java.time.Year; 6 | 7 | 8 | public record Magazine (String id, String name, int edition, Year year){ 9 | } 10 | -------------------------------------------------------------------------------- /2023/07-archi-unit/src/test/java/expert/os/videos/demo/MyArchTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo; 2 | 3 | import com.tngtech.archunit.core.domain.JavaClasses; 4 | import com.tngtech.archunit.core.importer.ClassFileImporter; 5 | import com.tngtech.archunit.lang.ArchRule; 6 | import com.tngtech.archunit.lang.syntax.ArchRuleDefinition; 7 | import org.jmolecules.ddd.annotation.Entity; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class MyArchTest { 11 | 12 | @Test 13 | public void shouldNotHaveRecordEntity() { 14 | 15 | JavaClasses importedClasses = new ClassFileImporter() 16 | .importPackages(MyArchTest.class.getPackageName()); 17 | 18 | ArchRule rule = ArchRuleDefinition 19 | .classes() 20 | .that().areAnnotatedWith(Entity.class) 21 | .should().notBeRecords(); 22 | 23 | rule.check(importedClasses); 24 | } 25 | 26 | @Test 27 | public void shouldNotHaveEntityInfrastructure() { 28 | JavaClasses importedClasses = new ClassFileImporter() 29 | .importPackages(MyArchTest.class.getPackageName()); 30 | 31 | 32 | ArchRule rule = ArchRuleDefinition 33 | .noClasses() 34 | .that().areAnnotatedWith(Entity.class) 35 | .should().resideInAPackage("..infrastructure.."); 36 | 37 | rule.check(importedClasses); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /2023/08-java-design/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/08-java-design/README.adoc: -------------------------------------------------------------------------------- 1 | = Documentation and test 2 | :toc: auto 3 | 4 | == Java Docs 5 | 6 | - @param 7 | - @throws 8 | - @version 9 | - @author 10 | 11 | 12 | === References 13 | 14 | - https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/drive/DriverLicense.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.drive; 2 | 3 | public class DriverLicense { 4 | } 5 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/drive/Inventory.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.drive; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | public class Inventory { 9 | 10 | private List items = new ArrayList<>(); 11 | 12 | public void add(String item) { 13 | //validation 14 | Objects.requireNonNull(item, "item is required"); 15 | this.items.add(item); 16 | } 17 | 18 | public List getItems() { 19 | return Collections.unmodifiableList(items); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/drive/Person.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.drive; 2 | 3 | import java.util.Optional; 4 | 5 | public class Person { 6 | 7 | private String name; 8 | 9 | private String city; 10 | 11 | private DriverLicense license; 12 | 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public String getCity() { 19 | return city; 20 | } 21 | 22 | public Optional getLicense() { 23 | return Optional.ofNullable(license); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/tips/Email.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.tips;public enum Email { 2 | } 3 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/tips/Event.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.tips;public record Event() { 2 | } 3 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/tips/Money.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.tips;public record Money() { 2 | } 3 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/worker/Chef.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.worker; 2 | 3 | public interface Chef extends Worker{ 4 | } 5 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/worker/Doctor.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.worker; 2 | 3 | public interface Doctor extends Worker{ 4 | 5 | /** 6 | * it works only with a Doctor 7 | * @param person 8 | * @throws UnsupportedOperationException if you are not a doctor 9 | */ 10 | void care(Person person); 11 | } 12 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/worker/Driver.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.worker; 2 | 3 | public interface Driver extends Worker { 4 | /** 5 | * It works only with a Driver 6 | * @return 7 | * @throws UnsupportedOperationException if you are not a driver 8 | */ 9 | DriverLicense license(); 10 | } 11 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/worker/DriverLicense.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.worker; 2 | 3 | public interface DriverLicense { 4 | } 5 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/worker/Person.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.worker; 2 | 3 | public class Person { 4 | } 5 | -------------------------------------------------------------------------------- /2023/08-java-design/src/main/java/expert/os/videos/demo/sample/worker/Worker.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.worker; 2 | 3 | public interface Worker { 4 | 5 | 6 | /** 7 | * everyone work 8 | */ 9 | void work(); 10 | } 11 | -------------------------------------------------------------------------------- /2023/08-java-design/src/test/java/expert/os/videos/demo/sample/drive/InventoryTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.drive; 2 | 3 | import expert.os.videos.demo.sample.drive.Inventory; 4 | import org.assertj.core.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | 7 | class InventoryTest { 8 | 9 | 10 | @Test 11 | public void shouldNotReturnNullCollection() { 12 | Inventory inventory = new Inventory(); 13 | Assertions.assertThat(inventory.getItems()) 14 | .isNotNull(); 15 | } 16 | 17 | 18 | 19 | } -------------------------------------------------------------------------------- /2023/08-java-design/src/test/java/expert/os/videos/demo/sample/drive/PersonTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.demo.sample.drive; 2 | 3 | import expert.os.videos.demo.sample.drive.DriverLicense; 4 | import expert.os.videos.demo.sample.drive.Person; 5 | import org.junit.jupiter.api.Disabled; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.util.Optional; 9 | 10 | public class PersonTest { 11 | 12 | private Person person; 13 | 14 | @Test 15 | @Disabled 16 | public void shouldReturnDriverLicense() { 17 | Optional license = person.getLicense(); 18 | license.ifPresent(d -> System.out.println("my license : " + d)); 19 | DriverLicense driver = license 20 | .orElseThrow( 21 | () -> new RuntimeException("It should have a license for driver")) 22 | ; 23 | 24 | if(license != null) { 25 | // 26 | } 27 | if(license.isPresent()) { 28 | // 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2023/09-mapstruct/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/09-mapstruct/README.adoc: -------------------------------------------------------------------------------- 1 | = Project Name 2 | :toc: auto 3 | 4 | == Record beyond Record 5 | 6 | * What is record? 7 | * Why record? 8 | * DTO 9 | * Immutable entities 10 | * State -------------------------------------------------------------------------------- /2023/09-mapstruct/src/main/java/expert/os/examples/DeliveryDTO.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public record DeliveryDTO(String id, String when, String city, String country) { 4 | } 5 | -------------------------------------------------------------------------------- /2023/09-mapstruct/src/main/java/expert/os/examples/DeliveryMapper.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import org.mapstruct.Mapper; 5 | import org.mapstruct.Mapping; 6 | 7 | @Mapper 8 | public interface DeliveryMapper { 9 | 10 | @Mapping(target = "trackId", source = "id") 11 | Delivery toEntity(DeliveryDTO dto); 12 | 13 | @Mapping(target = "id", source = "trackId") 14 | DeliveryDTO toDTO(Delivery entity); 15 | } 16 | -------------------------------------------------------------------------------- /2023/10-modelmapper/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/10-modelmapper/README.adoc: -------------------------------------------------------------------------------- 1 | = Project Name 2 | :toc: auto 3 | 4 | == Record beyond Record 5 | 6 | * What is record? 7 | * Why record? 8 | * DTO 9 | * Immutable entities 10 | * State -------------------------------------------------------------------------------- /2023/11-lombok/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/11-lombok/README.adoc: -------------------------------------------------------------------------------- 1 | = Project Name 2 | :toc: auto 3 | 4 | == Record beyond Record 5 | 6 | * What is record? 7 | * Why record? 8 | * DTO 9 | * Immutable entities 10 | * State -------------------------------------------------------------------------------- /2023/11-lombok/src/main/java/expert/os/examples/entity/Book.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.entity; 2 | 3 | public record Book(String id, String title, String author) { 4 | 5 | public Book setId(String newId) { 6 | return new Book(newId, title, author); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2023/11-lombok/src/main/java/expert/os/examples/entity/Person.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.entity; 2 | 3 | 4 | import lombok.Builder; 5 | import lombok.Data; 6 | 7 | import java.util.Objects; 8 | 9 | @Builder 10 | @Data 11 | public class Person { 12 | 13 | private Long id; 14 | 15 | private String name; 16 | 17 | private String email; 18 | 19 | public Person(Long id, String name, String email) { 20 | this.id = Objects.requireNonNull(id); 21 | this.name = name; 22 | this.email = email; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /2023/11-lombok/src/test/java/expert/os/examples/AppTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * Unit test for simple App. 8 | */ 9 | public class AppTest { 10 | /** 11 | * Rigorous Test :-) 12 | */ 13 | @Test 14 | public void shouldTest() { 15 | } 16 | 17 | @Test 18 | public void shouldTestB() { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /2023/11-lombok/src/test/java/expert/os/examples/entity/BookTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.entity; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class BookTest { 8 | 9 | 10 | @Test 11 | public void shouldCreateBook() { 12 | Book book = new Book("1", "The Lord of the Rings", "J. R. R. Tolkien"); 13 | 14 | assertEquals("1", book.id()); 15 | assertEquals("The Lord of the Rings", book.title()); 16 | assertEquals("J. R. R. Tolkien", book.author()); 17 | 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /2023/11-lombok/src/test/java/expert/os/examples/entity/PersonTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples.entity; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class PersonTest { 8 | 9 | @Test 10 | public void shouldCreatePerson() { 11 | Person person = Person.builder() 12 | .id(1L) 13 | .name("John Doe") 14 | .email("jonh@test.com").build(); 15 | 16 | assertEquals(1L, person.getId()); 17 | person.setId(2L); 18 | assertEquals(2L, person.getId()); 19 | } 20 | } -------------------------------------------------------------------------------- /2023/12-java-21/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2023/12-java-21/README.adoc: -------------------------------------------------------------------------------- 1 | = Project Name 2 | :toc: auto 3 | 4 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/CreditCard.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class CreditCard { 4 | 5 | public String payment() { 6 | return "Payment done!"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/Payment.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public interface Payment { 4 | 5 | String payment(); 6 | } 7 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/Person.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class Person { 4 | 5 | private String name; 6 | 7 | public Person(String name) { 8 | this.name = name; 9 | } 10 | 11 | 12 | public String speakEnglish() { 13 | return "Hello, my name is " + name; 14 | } 15 | 16 | public String speakPortuguese() { 17 | return "Olá, me chamo " + name; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/PersonFacade.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class PersonFacade { 4 | 5 | private final PersonService service; 6 | 7 | public PersonFacade(PersonService service) { 8 | this.service = service; 9 | } 10 | 11 | public String payment() { 12 | return service.payment(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public interface PersonRepository { 4 | } 5 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/PersonService.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class PersonService { 4 | 5 | private final PersonRepository repository; 6 | 7 | public PersonService(PersonRepository repository) { 8 | this.repository = repository; 9 | } 10 | 11 | public String payment() { 12 | //logic 13 | return "return"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/User.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public record User(String username) { 4 | } 5 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/UserCreatedEvent.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.Instant; 4 | import java.util.function.Supplier; 5 | 6 | public record UserCreatedEvent(User user, Instant when) implements Supplier { 7 | @Override 8 | public User get() { 9 | return user; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2023/12-java-21/src/main/java/expert/os/examples/UserDeletedEvent.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.time.Instant; 4 | import java.util.function.Supplier; 5 | 6 | public record UserDeletedEvent(User user, Instant when, String reason) implements Supplier { 7 | @Override 8 | public User get() { 9 | return user; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2023/12-java-21/src/test/java/expert/os/examples/PersonTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class PersonTest { 8 | 9 | 10 | @Test 11 | public void shouldSpeakEnglish(){ 12 | Person person = new Person("John"); 13 | assertEquals("Hello, my name is John", person.speakEnglish()); 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /2023/12-java-21/src/test/java/expert/os/examples/SequenceCollectionTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.assertj.core.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.LinkedHashSet; 7 | import java.util.SequencedCollection; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | public class SequenceCollectionTest { 12 | 13 | @Test 14 | public void shouldCreateSequenceCollection() { 15 | SequencedCollection languages = LinkedHashSet.newLinkedHashSet(10); 16 | languages.add("English"); 17 | languages.add("Spanish"); 18 | languages.add("French"); 19 | languages.add("Italian"); 20 | languages.addFirst("Portuguese"); 21 | 22 | assertThat(languages.getFirst()).isEqualTo("Portuguese"); 23 | assertThat(languages.getLast()).isEqualTo("Italian"); 24 | 25 | assertThat(languages) 26 | .containsExactly("Portuguese", "English", "Spanish", "French", "Italian"); 27 | 28 | SequencedCollection reversed = languages.reversed(); 29 | assertThat(reversed) 30 | .containsExactly("Italian", "French", "Spanish", "English", "Portuguese"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /2023/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.osachitech.examples 6 | java-videos-code-2023 7 | 1.0-SNAPSHOT 8 | pom 9 | 10 | java-videos-code-2023 11 | http://www.osachitech.com 12 | The code result from the youtube channel on 2022 13 | 14 | 15 | 01-documentation 16 | 02-record 17 | 03-java-doc-test 18 | 04-jupiter-cdi 19 | 05-reflections 20 | 06-java-functions 21 | 07-archi-unit 22 | 08-java-design 23 | 09-mapstruct 24 | 10-modelmapper 25 | 11-lombok 26 | 12-java-21 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /2024/01-refactoring-2024/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2024/01-refactoring-2024/src/main/java/expert/os/examples/CreditCardPaymentService.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class CreditCardPaymentService implements PaymentService { 4 | 5 | 6 | @Override 7 | public String pay(User user, Money amount){ 8 | // payment logic 9 | return "The credit Card Payment Successful"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2024/01-refactoring-2024/src/main/java/expert/os/examples/DebitCardPaymentService.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class DebitCardPaymentService implements PaymentService { 4 | 5 | 6 | @Override 7 | public String pay(User user, Money amount){ 8 | // payment logic 9 | return "The debit Card Payment Successful"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /2024/01-refactoring-2024/src/main/java/expert/os/examples/Money.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class Money { 4 | } 5 | -------------------------------------------------------------------------------- /2024/01-refactoring-2024/src/main/java/expert/os/examples/PaymentService.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public interface PaymentService { 4 | String pay(User user, Money amount); 5 | } 6 | -------------------------------------------------------------------------------- /2024/01-refactoring-2024/src/main/java/expert/os/examples/User.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class User { 4 | } 5 | -------------------------------------------------------------------------------- /2024/01-refactoring-2024/src/test/java/expert/os/examples/PaymentServiceTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class PaymentServiceTest { 8 | 9 | 10 | @Test 11 | void pay() { 12 | User user = new User(); 13 | Money amount = new Money(); 14 | PaymentService paymentService = new CreditCardPaymentService(); 15 | String result = paymentService.pay(user, amount); 16 | assertEquals("The credit Card Payment Successful", result); 17 | } 18 | } -------------------------------------------------------------------------------- /2024/02-exception-log/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2024/02-exception-log/src/main/java/expert/os/examples/CreditCard.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.UUID; 4 | 5 | public class CreditCard { 6 | 7 | private UUID id; 8 | //only the last four digits of the credit card number are stored 9 | private String number; 10 | 11 | private String password; 12 | 13 | public UUID getId() { 14 | return id; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "CreditCard{" + 20 | "id=" + id + 21 | ", number='" + number + '\'' + 22 | ", password= *****" + 23 | '}'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2024/02-exception-log/src/main/java/expert/os/examples/CreditCardException.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class CreditCardException extends MyCompanyException { 4 | 5 | public CreditCardException(String message) { 6 | super(message); 7 | } 8 | 9 | public CreditCardException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2024/02-exception-log/src/main/java/expert/os/examples/CreditCardNotFoundException.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class CreditCardNotFoundException extends CreditCardException { 4 | 5 | public CreditCardNotFoundException(String message) { 6 | super(message); 7 | } 8 | 9 | public CreditCardNotFoundException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2024/02-exception-log/src/main/java/expert/os/examples/MyCompanyException.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class MyCompanyException extends RuntimeException { 4 | 5 | public MyCompanyException(String message) { 6 | super(message); 7 | } 8 | 9 | public MyCompanyException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2024/02-exception-log/src/main/java/expert/os/examples/Product.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.UUID; 4 | 5 | public class Product { 6 | 7 | private UUID id; 8 | 9 | private String name; 10 | 11 | public UUID getId() { 12 | return id; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "Product{" + 22 | "id=" + id + 23 | ", name='" + name + '\'' + 24 | '}'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2024/02-exception-log/src/test/java/expert/os/examples/CreditCardServiceTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class CreditCardServiceTest { 8 | 9 | private CreditCardService creditCardService = new CreditCardService(); 10 | @Test 11 | void shouldPay() { 12 | CreditCard creditCard = new CreditCard(); 13 | Product product = new Product(); 14 | creditCardService.pay(creditCard, product); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /2024/03-microservices-tips/.dockerignore: -------------------------------------------------------------------------------- 1 | target/* 2 | .idea -------------------------------------------------------------------------------- /2024/03-microservices-tips/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | test-output/ 7 | /doc 8 | *.iml 9 | *.idea 10 | *.log 11 | .classpath 12 | -project 13 | /.resourceCache 14 | /.project 15 | /.idea 16 | .settings/ 17 | .checkstyle 18 | 19 | # Eclipse metadata 20 | .project 21 | .factorypath 22 | 23 | **/.DS_Store 24 | # Annotation processor metadata 25 | .apt_generated/ 26 | .apt_generated_tests/ 27 | 28 | # Quarkus Plugin dir 29 | 30 | .quarkus/ -------------------------------------------------------------------------------- /2024/03-microservices-tips/.helidon: -------------------------------------------------------------------------------- 1 | #Helidon Project Configuration 2 | #Fri Feb 16 15:18:48 UTC 2024 3 | schema.version=1.1.0 4 | helidon.version=4.0.5 5 | project.flavor=mp 6 | project.archetype=quickstart 7 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | # 1st stage, build the app 3 | FROM container-registry.oracle.com/java/openjdk:21 as build 4 | 5 | # Install maven 6 | WORKDIR /usr/share 7 | RUN set -x && \ 8 | curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \ 9 | tar -xvf apache-maven-*-bin.tar.gz && \ 10 | rm apache-maven-*-bin.tar.gz && \ 11 | mv apache-maven-* maven && \ 12 | ln -s /usr/share/maven/bin/mvn /bin/ 13 | 14 | WORKDIR /helidon 15 | 16 | # Create a first layer to cache the "Maven World" in the local repository. 17 | # Incremental docker builds will always resume after that, unless you update 18 | # the pom 19 | ADD pom.xml . 20 | RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -Declipselink.weave.skip -DskipOpenApiGenerate 21 | 22 | # Do the Maven build! 23 | # Incremental docker builds will resume here when you change sources 24 | ADD src src 25 | RUN mvn package -DskipTests 26 | 27 | RUN echo "done!" 28 | 29 | # 2nd stage, build the runtime image 30 | FROM container-registry.oracle.com/java/openjdk:21 31 | WORKDIR /helidon 32 | 33 | # Copy the binary built in the 1st stage 34 | COPY --from=build /helidon/target/helidon.jar ./ 35 | COPY --from=build /helidon/target/libs ./libs 36 | 37 | CMD ["java", "-jar", "helidon.jar"] 38 | 39 | EXPOSE 8080 40 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/Dockerfile.jlink: -------------------------------------------------------------------------------- 1 | 2 | # 1st stage, build the app 3 | FROM container-registry.oracle.com/java/openjdk:21 as build 4 | 5 | WORKDIR /usr/share 6 | 7 | # Install maven 8 | RUN set -x && \ 9 | curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \ 10 | tar -xvf apache-maven-*-bin.tar.gz && \ 11 | rm apache-maven-*-bin.tar.gz && \ 12 | mv apache-maven-* maven && \ 13 | ln -s /usr/share/maven/bin/mvn /bin/ 14 | 15 | WORKDIR /helidon 16 | 17 | # Create a first layer to cache the "Maven World" in the local repository. 18 | # Incremental docker builds will always resume after that, unless you update 19 | # the pom 20 | ADD pom.xml . 21 | RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip 22 | 23 | # Do the Maven build to create the custom Java Runtime Image 24 | # Incremental docker builds will resume here when you change sources 25 | ADD src src 26 | RUN mvn package -Pjlink-image -DskipTests 27 | RUN echo "done!" 28 | 29 | # 2nd stage, build the final image with the JRI built in the 1st stage 30 | 31 | FROM debian:stretch-slim 32 | WORKDIR /helidon 33 | COPY --from=build /helidon/target/helidon-jri ./ 34 | ENTRYPOINT ["/bin/bash", "/helidon/bin/start"] 35 | EXPOSE 8080 36 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/Dockerfile.native: -------------------------------------------------------------------------------- 1 | 2 | # 1st stage, build the app 3 | FROM ghcr.io/graalvm/graalvm-community:21.0.0-ol9 as build 4 | 5 | WORKDIR /usr/share 6 | 7 | # Install maven 8 | RUN set -x && \ 9 | curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \ 10 | tar -xvf apache-maven-*-bin.tar.gz && \ 11 | rm apache-maven-*-bin.tar.gz && \ 12 | mv apache-maven-* maven && \ 13 | ln -s /usr/share/maven/bin/mvn /bin/ 14 | 15 | WORKDIR /helidon 16 | 17 | # Create a first layer to cache the "Maven World" in the local repository. 18 | # Incremental docker builds will always resume after that, unless you update 19 | # the pom 20 | ADD pom.xml . 21 | RUN mvn package -Pnative-image -Dnative.image.skip -Dmaven.test.skip -Declipselink.weave.skip 22 | 23 | # Do the Maven build! 24 | # Incremental docker builds will resume here when you change sources 25 | ADD src src 26 | RUN mvn package -Pnative-image -Dnative.image.buildStatic -DskipTests 27 | 28 | RUN echo "done!" 29 | 30 | # 2nd stage, build the runtime image 31 | FROM scratch 32 | WORKDIR /helidon 33 | 34 | # Copy the binary built in the 1st stage 35 | COPY --from=build /helidon/target/helidon . 36 | 37 | ENTRYPOINT ["./helidon"] 38 | 39 | EXPOSE 8080 40 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/app.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: helidon 5 | labels: 6 | app: helidon 7 | spec: 8 | type: NodePort 9 | selector: 10 | app: helidon 11 | ports: 12 | - port: 8080 13 | targetPort: 8080 14 | name: http 15 | --- 16 | kind: Deployment 17 | apiVersion: apps/v1 18 | metadata: 19 | name: helidon 20 | spec: 21 | replicas: 1 22 | selector: 23 | matchLabels: 24 | app: helidon 25 | template: 26 | metadata: 27 | labels: 28 | app: helidon 29 | version: v1 30 | spec: 31 | containers: 32 | - name: helidon 33 | image: helidon 34 | imagePullPolicy: IfNotPresent 35 | ports: 36 | - containerPort: 8080 37 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/java/os/expert/demo/helidon/Expedition.java: -------------------------------------------------------------------------------- 1 | package os.expert.demo.helidon; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class Expedition { 6 | private String name; 7 | private String location; 8 | private LocalDate date; 9 | 10 | public Expedition(String name, String location, LocalDate date) { 11 | this.name = name; 12 | this.location = location; 13 | this.date = date; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public String getLocation() { 21 | return location; 22 | } 23 | 24 | public LocalDate getDate() { 25 | return date; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/java/os/expert/demo/helidon/ExpeditionResource.java: -------------------------------------------------------------------------------- 1 | package os.expert.demo.helidon; 2 | 3 | import jakarta.ws.rs.GET; 4 | import jakarta.ws.rs.Path; 5 | import jakarta.ws.rs.PathParam; 6 | 7 | import java.time.LocalDate; 8 | import java.util.List; 9 | 10 | @Path("/api/v1/expeditions") 11 | public class ExpeditionResource { 12 | 13 | 14 | //pagination 15 | @GET 16 | public List list() { 17 | return List.of( 18 | new Expedition("Everest", "Nepal", LocalDate.parse("2022-03-01")), 19 | new Expedition("K2", "Pakistan", LocalDate.parse("2022-06-01")), 20 | new Expedition("Kangchenjunga", "Nepal", LocalDate.parse("2022-04-01")), 21 | new Expedition("Lhotse", "Nepal", LocalDate.parse("2022-05-01")), 22 | new Expedition("Makalu", "Nepal", LocalDate.parse("2022-07-01")), 23 | new Expedition("Cho Oyu", "Nepal", LocalDate.parse("2022-08-01")), 24 | new Expedition("Dhaulagiri", "Nepal", LocalDate.parse("2022-09-01"))); 25 | } 26 | 27 | @GET 28 | @Path("/{id}") 29 | public Expedition get(@PathParam("id") String id) { 30 | 31 | return null; 32 | } 33 | 34 | @GET 35 | @Path("/my-expeditions") 36 | public List myExpeditions() { 37 | // 38 | return List.of(); 39 | } 40 | } -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/java/os/expert/demo/helidon/FieldAccessStrategy.java: -------------------------------------------------------------------------------- 1 | package os.expert.demo.helidon; 2 | 3 | import jakarta.json.bind.config.PropertyVisibilityStrategy; 4 | 5 | import java.lang.reflect.Field; 6 | import java.lang.reflect.Method; 7 | 8 | public class FieldAccessStrategy implements PropertyVisibilityStrategy { 9 | @Override 10 | public boolean isVisible(Field field) { 11 | return true; 12 | } 13 | 14 | @Override 15 | public boolean isVisible(Method method) { 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/java/os/expert/demo/helidon/GreetingProvider.java: -------------------------------------------------------------------------------- 1 | 2 | package os.expert.demo.helidon; 3 | 4 | import java.util.concurrent.atomic.AtomicReference; 5 | 6 | import jakarta.enterprise.context.ApplicationScoped; 7 | import jakarta.inject.Inject; 8 | 9 | import org.eclipse.microprofile.config.inject.ConfigProperty; 10 | 11 | /** 12 | * Provider for greeting message. 13 | */ 14 | @ApplicationScoped 15 | public class GreetingProvider { 16 | private final AtomicReference message = new AtomicReference<>(); 17 | 18 | /** 19 | * Create a new greeting provider, reading the message from configuration. 20 | * 21 | * @param message greeting to use 22 | */ 23 | @Inject 24 | public GreetingProvider(@ConfigProperty(name = "app.greeting") String message) { 25 | this.message.set(message); 26 | } 27 | 28 | String getMessage() { 29 | return message.get(); 30 | } 31 | 32 | void setMessage(String message) { 33 | this.message.set(message); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/java/os/expert/demo/helidon/Message.java: -------------------------------------------------------------------------------- 1 | package os.expert.demo.helidon; 2 | 3 | public class Message { 4 | 5 | private String message; 6 | 7 | private String greeting; 8 | 9 | public Message() { 10 | } 11 | 12 | public Message(String message) { 13 | this.message = message; 14 | } 15 | 16 | public void setMessage(String message) { 17 | this.message = message; 18 | } 19 | 20 | public String getMessage() { 21 | return this.message; 22 | } 23 | 24 | public void setGreeting(String greeting) { 25 | this.greeting = greeting; 26 | } 27 | 28 | public String getGreeting() { 29 | return this.greeting; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/java/os/expert/demo/helidon/package-info.java: -------------------------------------------------------------------------------- 1 | 2 | package os.expert.demo.helidon; 3 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/resources/META-INF/microprofile-config.properties: -------------------------------------------------------------------------------- 1 | # Microprofile server properties 2 | server.port=8181 3 | server.host=0.0.0.0 4 | 5 | # Change the following to true to enable the optional MicroProfile Metrics REST.request metrics 6 | metrics.rest-request.enabled=false 7 | 8 | # Application properties. This is the default greeting 9 | app.greeting=Hello 10 | 11 | 12 | jnosql.keyvalue.database=machines 13 | jnosql.document.database=machines 14 | jnosql.oracle.nosql.host=http://localhost:8080 -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/resources/META-INF/native-image/os/expert/demo/helidon/native-image.properties: -------------------------------------------------------------------------------- 1 | Args=--initialize-at-build-time=os.expert.demo.helidon -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/main/resources/logging.properties: -------------------------------------------------------------------------------- 1 | 2 | # Example Logging Configuration File 3 | # For more information see $JAVA_HOME/jre/lib/logging.properties 4 | 5 | # Send messages to the console 6 | handlers=io.helidon.logging.jul.HelidonConsoleHandler 7 | 8 | # HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread 9 | java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n 10 | 11 | # Global logging level. Can be overridden by specific loggers 12 | .level=INFO 13 | 14 | # Quiet Weld 15 | org.jboss.level=WARNING 16 | 17 | # Component specific log levels 18 | #io.helidon.config.level=INFO 19 | #io.helidon.security.level=INFO 20 | #io.helidon.common.level=INFO 21 | #io.netty.level=INFO 22 | -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/test/resources/META-INF/microprofile-config.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o-s-expert/java-videos-code/bc762661b61caa28a406f33a0922dd63dde531ee/2024/03-microservices-tips/src/test/resources/META-INF/microprofile-config.properties -------------------------------------------------------------------------------- /2024/03-microservices-tips/src/test/resources/application-test.yaml: -------------------------------------------------------------------------------- 1 | security: 2 | enabled: false -------------------------------------------------------------------------------- /2024/04-pmd-checkstyle/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2024/04-pmd-checkstyle/src/main/java/expert/os/examples/Animal.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import java.util.logging.Logger; 4 | 5 | public class Animal { 6 | 7 | private static final Logger LOGGER = Logger.getLogger(Animal.class.getName()); 8 | 9 | public void eat(String food) { 10 | if("meat".equals(food)){ 11 | LOGGER.info("Animal is eating meat"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2024/04-pmd-checkstyle/src/main/java/expert/os/examples/Guest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public record Guest(String name, String document) { 4 | } 5 | -------------------------------------------------------------------------------- /2024/04-pmd-checkstyle/src/main/java/expert/os/examples/Hotel.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import java.util.Optional; 5 | 6 | public interface Hotel { 7 | 8 | void checkIn(Room room); 9 | 10 | void checkOut(Room room); 11 | 12 | Optional checkReservation(int number); 13 | } 14 | -------------------------------------------------------------------------------- /2024/04-pmd-checkstyle/src/main/java/expert/os/examples/Room.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public class Room { 4 | 5 | private int number; 6 | 7 | private boolean available; 8 | 9 | private boolean cleaned; 10 | 11 | private Guest guest; 12 | } 13 | -------------------------------------------------------------------------------- /2024/04-pmd-checkstyle/src/main/java/expert/os/examples/RoomDAO.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import java.util.Optional; 5 | 6 | public interface RoomDAO { 7 | 8 | void insert(Room room); 9 | 10 | void update(Room room); 11 | 12 | void delete(Room room); 13 | 14 | Optional findById(int number); 15 | } 16 | -------------------------------------------------------------------------------- /2024/05-jmolecules/.dockerignore: -------------------------------------------------------------------------------- 1 | target/* 2 | .idea -------------------------------------------------------------------------------- /2024/05-jmolecules/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | test-output/ 7 | /doc 8 | *.iml 9 | *.idea 10 | *.log 11 | .classpath 12 | -project 13 | /.resourceCache 14 | /.project 15 | /.idea 16 | .settings/ 17 | .checkstyle 18 | 19 | # Eclipse metadata 20 | .project 21 | .factorypath 22 | 23 | **/.DS_Store 24 | # Annotation processor metadata 25 | .apt_generated/ 26 | .apt_generated_tests/ 27 | 28 | # Quarkus Plugin dir 29 | 30 | .quarkus/ -------------------------------------------------------------------------------- /2024/05-jmolecules/.helidon: -------------------------------------------------------------------------------- 1 | #Helidon Project Configuration 2 | #Fri Feb 16 15:18:48 UTC 2024 3 | schema.version=1.1.0 4 | helidon.version=4.0.5 5 | project.flavor=mp 6 | project.archetype=quickstart 7 | -------------------------------------------------------------------------------- /2024/05-jmolecules/src/main/java/expert/os/examples/CreditCard.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import org.jmolecules.ddd.annotation.Entity; 4 | import org.jmolecules.ddd.annotation.Identity; 5 | 6 | import java.math.BigInteger; 7 | import java.time.YearMonth; 8 | 9 | @Entity 10 | public class CreditCard { 11 | 12 | @Identity 13 | private BigInteger id; 14 | 15 | private String number; 16 | 17 | private String name; 18 | 19 | private YearMonth expiry; 20 | } 21 | -------------------------------------------------------------------------------- /2024/05-jmolecules/src/test/java/expert/os/examples/IntegrationSampleTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import com.tngtech.archunit.core.domain.JavaClasses; 4 | import com.tngtech.archunit.junit.AnalyzeClasses; 5 | import com.tngtech.archunit.junit.ArchTest; 6 | import com.tngtech.archunit.lang.ArchRule; 7 | import com.tngtech.archunit.lang.EvaluationResult; 8 | import org.jmolecules.archunit.JMoleculesArchitectureRules; 9 | import org.jmolecules.archunit.JMoleculesDddRules; 10 | 11 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; 12 | 13 | @AnalyzeClasses(packages = "expert.os.examples") 14 | public class IntegrationSampleTest { 15 | 16 | @ArchTest 17 | private ArchRule dddRules = JMoleculesDddRules.all(); 18 | @ArchTest 19 | private ArchRule layering = JMoleculesArchitectureRules.ensureLayering(); 20 | 21 | @ArchTest 22 | void detectsViolations(JavaClasses classes) { 23 | 24 | EvaluationResult result = JMoleculesDddRules.all().evaluate(classes); 25 | assertThat(result.hasViolation()).isFalse(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2024/05-jmolecules/src/test/java/expert/os/examples/JMoleculesDddUnitTest.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import com.tngtech.archunit.core.domain.JavaClasses; 5 | import com.tngtech.archunit.core.importer.ClassFileImporter; 6 | import org.jmolecules.archunit.JMoleculesArchitectureRules; 7 | import org.jmolecules.archunit.JMoleculesDddRules; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class JMoleculesDddUnitTest { 11 | 12 | @Test 13 | void checkTheLayerIntegration() { 14 | String packageName = "expert.os.examples"; 15 | JavaClasses classes = new ClassFileImporter().importPackages(packageName); 16 | JMoleculesArchitectureRules.ensureLayering().check(classes); 17 | 18 | } 19 | 20 | @Test 21 | void checkDDDIntegration() { 22 | String packageName = "expert.os.examples"; 23 | JavaClasses classes = new ClassFileImporter().importPackages(packageName); 24 | JMoleculesDddRules.all().check(classes); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2024/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.osachitech.examples 6 | java-videos-code-2024 7 | 1.0-SNAPSHOT 8 | pom 9 | 10 | java-videos-code-2024 11 | http://www.osachitech.com 12 | The code result from the youtube channel on 2024 13 | 14 | 15 | 01-refactoring-2024 16 | 02-exception-log 17 | 03-microservices-tips 18 | 04-pmd-checkstyle 19 | 05-jmolecules 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /2025/01-quarkus-fast-rest/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2025/01-quarkus-fast-rest/src/main/docker/Dockerfile.native: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. 3 | # 4 | # Before building the container image run: 5 | # 6 | # ./mvnw package -Dnative 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.native -t quarkus/chapter-11 . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/chapter-11 15 | # 16 | # The ` registry.access.redhat.com/ubi9/ubi-minimal:9.5` base image is based on UBI 9. 17 | # To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. 18 | ### 19 | FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5 20 | WORKDIR /work/ 21 | RUN chown 1001 /work \ 22 | && chmod "g+rwX" /work \ 23 | && chown 1001:root /work 24 | COPY --chown=1001:root --chmod=0755 target/*-runner /work/application 25 | 26 | EXPOSE 8080 27 | USER 1001 28 | 29 | ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] 30 | -------------------------------------------------------------------------------- /2025/01-quarkus-fast-rest/src/main/docker/Dockerfile.native-micro: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. 3 | # It uses a micro base image, tuned for Quarkus native executables. 4 | # It reduces the size of the resulting container image. 5 | # Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. 6 | # 7 | # Before building the container image run: 8 | # 9 | # ./mvnw package -Dnative 10 | # 11 | # Then, build the image with: 12 | # 13 | # docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/chapter-11 . 14 | # 15 | # Then run the container using: 16 | # 17 | # docker run -i --rm -p 8080:8080 quarkus/chapter-11 18 | # 19 | # The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on UBI 9. 20 | # To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. 21 | ### 22 | FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0 23 | WORKDIR /work/ 24 | RUN chown 1001 /work \ 25 | && chmod "g+rwX" /work \ 26 | && chown 1001:root /work 27 | COPY --chown=1001:root --chmod=0755 target/*-runner /work/application 28 | 29 | EXPOSE 8080 30 | USER 1001 31 | 32 | ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] 33 | -------------------------------------------------------------------------------- /2025/01-quarkus-fast-rest/src/main/java/expert/os/videos/quarkus/Developer.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.quarkus; 2 | 3 | import io.quarkus.hibernate.orm.panache.PanacheEntity; 4 | import jakarta.persistence.Column; 5 | import jakarta.persistence.Entity; 6 | 7 | @Entity 8 | public class Developer extends PanacheEntity { 9 | 10 | @Column 11 | public String name; 12 | 13 | @Column 14 | public String email; 15 | 16 | @Column 17 | public String language; 18 | 19 | @Column 20 | public String city; 21 | } 22 | -------------------------------------------------------------------------------- /2025/01-quarkus-fast-rest/src/main/java/expert/os/videos/quarkus/DevelopersResource.java: -------------------------------------------------------------------------------- 1 | package expert.os.videos.quarkus; 2 | 3 | import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource; 4 | 5 | public interface DevelopersResource extends PanacheEntityResource { 6 | } 7 | -------------------------------------------------------------------------------- /2025/01-quarkus-fast-rest/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | quarkus.datasource.db-kind=h2 2 | quarkus.datasource.jdbc.url=jdbc:h2:file:../src/main/resources/data/database;AUTO_SERVER=true;DB_CLOSE_DELAY=-1 3 | 4 | quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect 5 | quarkus.hibernate-orm.database.generation=drop-and-create 6 | quarkus.hibernate-orm.log.sql=true -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | ~* 4 | 5 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 6 | hs_err_pid* 7 | LICENSE 8 | 9 | # Maven 10 | target/ 11 | .m2/ 12 | .mvn/timing.properties 13 | .mvn/wrapper/maven-wrapper.jar 14 | pom.xml.tag 15 | pom.xml.releaseBackup 16 | pom.xml.versionsBackup 17 | pom.xml.next 18 | dependency-reduced-pom.xml 19 | release.properties 20 | buildNumber.properties 21 | settings.xml 22 | .flattened-pom.xml 23 | 24 | # Gradle 25 | .gradle/ 26 | build/ 27 | 28 | # Package Files 29 | *.jar 30 | *.war 31 | *.nar 32 | *.ear 33 | *.zip 34 | *.tar.gz 35 | *.rar 36 | 37 | # JetBrains 38 | .idea/ 39 | *.ipr 40 | *.iws 41 | *.iml 42 | *.releaseBackup 43 | out/ 44 | .idea_modules/ 45 | atlassian-ide-plugin.xml 46 | 47 | # Eclipse 48 | .settings/ 49 | .settings 50 | .project 51 | .classpath 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .settings/ 61 | .loadpath 62 | .recommenders 63 | .externalToolBuilders/ 64 | *.launch 65 | .factorypath 66 | .target 67 | .springBeans 68 | .recommenders/ 69 | .apt_generated/ 70 | .apt_generated_test/ 71 | .cache-main 72 | .scala_dependencies 73 | .worksheet 74 | 75 | # NetBeans 76 | nbproject/private/ 77 | build/ 78 | nbbuild/ 79 | dist/ 80 | nbdist/ 81 | nbactions.xml 82 | nb-configuration.xml 83 | .nb-gradle/ 84 | 85 | # MacOS 86 | .DS_Store 87 | profile 88 | 89 | # Asciidoctor 90 | .asciidoctor/ 91 | 92 | # Vim 93 | *.swp -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/App.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.enterprise.inject.se.SeContainer; 4 | import jakarta.enterprise.inject.se.SeContainerInitializer; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args) { 9 | try(SeContainer container = SeContainerInitializer.newInstance().initialize()) { 10 | Orchestra orchestra = container.select(Orchestra.class).get(); 11 | Instrument keyboard = orchestra.select(InstrumentType.KEYBOARD); 12 | Instrument string = orchestra.select(InstrumentType.STRING); 13 | Instrument percurssion = orchestra.select(InstrumentType.PERCURSSION); 14 | 15 | System.out.println("Playing the orchestra"); 16 | System.out.println("Keyboard: " + keyboard.play()); 17 | System.out.println("string: " + string.play()); 18 | System.out.println("percurssion: " + percurssion.play()); 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/Instrument.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public interface Instrument { 4 | 5 | String play(); 6 | } 7 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/InstrumentType.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | public enum InstrumentType { 4 | STRING, PERCURSSION, KEYBOARD; 5 | } 6 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/MusicInstrument.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | import jakarta.inject.Qualifier; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Qualifier 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) 14 | public @interface MusicInstrument { 15 | 16 | InstrumentType value(); 17 | } 18 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/MusicInstrumentLiteral.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.enterprise.util.AnnotationLiteral; 4 | 5 | public class MusicInstrumentLiteral extends AnnotationLiteral implements MusicInstrument { 6 | 7 | private final InstrumentType type; 8 | 9 | private MusicInstrumentLiteral(InstrumentType type) { 10 | this.type = type; 11 | } 12 | 13 | @Override 14 | public InstrumentType value() { 15 | return type; 16 | } 17 | 18 | public static MusicInstrumentLiteral of(InstrumentType instrumentType) { 19 | return new MusicInstrumentLiteral(instrumentType); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/Orchestra.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | import jakarta.enterprise.context.ApplicationScoped; 4 | import jakarta.enterprise.inject.Any; 5 | import jakarta.enterprise.inject.Instance; 6 | import jakarta.inject.Inject; 7 | 8 | @ApplicationScoped 9 | public class Orchestra { 10 | 11 | @Inject 12 | @Any 13 | private Instance instruments; 14 | 15 | public Instrument select(InstrumentType type) { 16 | return instruments.select(MusicInstrumentLiteral.of(type)).get(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/Piano.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | @MusicInstrument(InstrumentType.KEYBOARD) 4 | public class Piano implements Instrument { 5 | 6 | @Override 7 | public String play() { 8 | return "Piano Sound"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/Violin.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | @MusicInstrument(InstrumentType.STRING) 4 | public class Violin implements Instrument { 5 | @Override 6 | public String play() { 7 | return "Violin Sound"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/java/expert/os/examples/Xylophone.java: -------------------------------------------------------------------------------- 1 | package expert.os.examples; 2 | 3 | 4 | @MusicInstrument(InstrumentType.PERCURSSION) 5 | public class Xylophone implements Instrument { 6 | @Override 7 | public String play() { 8 | return "Xylophone Sound"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2025/02-polymorphism-cdi/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /2025/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.osachitech.examples 6 | java-videos-code-2025 7 | 1.0-SNAPSHOT 8 | pom 9 | 10 | java-videos-code-2025 11 | http://www.osachitech.com 12 | The code result from the youtube channel on 2025 13 | 14 | 15 | 01-quarkus-fast-rest 16 | 02-polymorphism-cdi 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.osachitech.examples 6 | java-videos-code 7 | 1.0-SNAPSHOT 8 | pom 9 | 10 | java-videos-code 11 | http://www.osachitech.com 12 | The code result from the youtube channel 13 | 14 | 15 | 2022 16 | 2023 17 | 2024 18 | 2025 19 | 20 | 21 | 22 | --------------------------------------------------------------------------------