From 42f64f0e57b1c0c499c2ed988c67698ef8b8a8d2 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Sun, 25 Feb 2024 15:51:38 +0100 Subject: [PATCH] Add initial files Co-authored-by: LucasCatolino Co-authored-by: KuJo7 --- .gitignore | 194 ++++++++++++++++++ test/pom.xml | 17 ++ test/src/main/java/edu/uastw/Book.java | 20 ++ .../uastw/DecreaseBooksCapacityDecorator.java | 21 ++ .../uastw/IncreaseBooksCapacityDecorator.java | 16 ++ test/src/main/java/edu/uastw/Library.java | 43 ++++ .../main/java/edu/uastw/LibraryBuilder.java | 18 ++ .../main/java/edu/uastw/LibraryDecorator.java | 11 + test/src/main/java/edu/uastw/LibraryItem.java | 6 + test/src/main/java/edu/uastw/Magazine.java | 20 ++ test/src/main/java/edu/uastw/Test.java | 29 +++ 11 files changed, 395 insertions(+) create mode 100644 .gitignore create mode 100644 test/pom.xml create mode 100644 test/src/main/java/edu/uastw/Book.java create mode 100644 test/src/main/java/edu/uastw/DecreaseBooksCapacityDecorator.java create mode 100644 test/src/main/java/edu/uastw/IncreaseBooksCapacityDecorator.java create mode 100644 test/src/main/java/edu/uastw/Library.java create mode 100644 test/src/main/java/edu/uastw/LibraryBuilder.java create mode 100644 test/src/main/java/edu/uastw/LibraryDecorator.java create mode 100644 test/src/main/java/edu/uastw/LibraryItem.java create mode 100644 test/src/main/java/edu/uastw/Magazine.java create mode 100644 test/src/main/java/edu/uastw/Test.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6746c8d --- /dev/null +++ b/.gitignore @@ -0,0 +1,194 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +*/.idea/ + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +############################## +## Java +############################## +.mtj.tmp/ +*.class +*.jar +*.war +*.ear +*.nar +hs_err_pid* +replay_pid* + +############################## +## Maven +############################## +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +pom.xml.bak +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + +############################## +## Gradle +############################## +bin/ +build/ +.gradle +.gradletasknamecache +gradle-app.setting +!gradle-wrapper.jar + +############################## +## IntelliJ +############################## +out/ +.idea/ +.idea_modules/ +*.iml +*.ipr +*.iws + +############################## +## Eclipse +############################## +.settings/ +bin/ +tmp/ +.metadata +.classpath +.project +*.tmp +*.bak +*.swp +*~.nib +local.properties +.loadpath +.factorypath + +############################## +## NetBeans +############################## +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml + +############################## +## Visual Studio Code +############################## +.vscode/ +.code-workspace + +############################## +## OS X +############################## +.DS_Store + +############################## +## Miscellaneous +############################## +*.log diff --git a/test/pom.xml b/test/pom.xml new file mode 100644 index 0000000..f3c4aa3 --- /dev/null +++ b/test/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + edu.uastw + test + 1.0-SNAPSHOT + + + 11 + 11 + UTF-8 + + + \ No newline at end of file diff --git a/test/src/main/java/edu/uastw/Book.java b/test/src/main/java/edu/uastw/Book.java new file mode 100644 index 0000000..e95852d --- /dev/null +++ b/test/src/main/java/edu/uastw/Book.java @@ -0,0 +1,20 @@ +package edu.uastw; + +public class Book implements LibraryItem { + private final String title; + private final String author; + + public Book(String title, String author) { + this.title = title; + this.author = author; + } + + public String getTitle() { + return title; + } + + @Override + public String getOwner() { + return author; + } +} diff --git a/test/src/main/java/edu/uastw/DecreaseBooksCapacityDecorator.java b/test/src/main/java/edu/uastw/DecreaseBooksCapacityDecorator.java new file mode 100644 index 0000000..4974b6a --- /dev/null +++ b/test/src/main/java/edu/uastw/DecreaseBooksCapacityDecorator.java @@ -0,0 +1,21 @@ +package edu.uastw; + +class DecreaseBooksCapacityDecorator extends LibraryDecorator { + private final int reducedCapacity; + + public DecreaseBooksCapacityDecorator(Library library, int reducedCapacity) { + super(library); + this.reducedCapacity = reducedCapacity; + } + + @Override + public void extendedFunctionality() { + int newCapacity = library.getBooksCapacity() - reducedCapacity; + if (newCapacity >= 0) { + library.setBooksCapacity(newCapacity); + System.out.println("Books capacity decreased by " + reducedCapacity); + } else { + System.out.println("Cannot decrease capacity. New capacity would be negative."); + } + } +} diff --git a/test/src/main/java/edu/uastw/IncreaseBooksCapacityDecorator.java b/test/src/main/java/edu/uastw/IncreaseBooksCapacityDecorator.java new file mode 100644 index 0000000..3f07165 --- /dev/null +++ b/test/src/main/java/edu/uastw/IncreaseBooksCapacityDecorator.java @@ -0,0 +1,16 @@ +package edu.uastw; + +class IncreaseBooksCapacityDecorator extends LibraryDecorator { + private final int additionalCapacity; + + public IncreaseBooksCapacityDecorator(Library library, int additionalCapacity) { + super(library); + this.additionalCapacity = additionalCapacity; + } + + @Override + public void extendedFunctionality() { + library.setBooksCapacity(library.getBooksCapacity() + additionalCapacity); + System.out.println("Books capacity increased by " + additionalCapacity); + } +} diff --git a/test/src/main/java/edu/uastw/Library.java b/test/src/main/java/edu/uastw/Library.java new file mode 100644 index 0000000..29f98fe --- /dev/null +++ b/test/src/main/java/edu/uastw/Library.java @@ -0,0 +1,43 @@ +package edu.uastw; + +import java.util.ArrayList; +import java.util.List; + +public class Library { + private static Library instance; + private final List libraryItems; + private int booksCapacity = 100; + + public Library() { + this.libraryItems = new ArrayList<>(); + } + + public static Library getInstance() { + if (instance == null) { + instance = new Library(); + } + return instance; + } + public void setBooksCapacity(int capacity) { + this.booksCapacity = capacity; + } + + public int getBooksCapacity() { + return booksCapacity; + } + + public void addLibraryItem(LibraryItem libraryItem) { + if (libraryItems.size() < booksCapacity) { + libraryItems.add(libraryItem); + } else { + System.out.println("Library capacity reached. Cannot add more items."); + } + } + + public void displayLibraryItems() { + System.out.println("Items available in the library:"); + libraryItems.forEach(libraryItem -> + System.out.println(libraryItem.getTitle() + " by " + libraryItem.getOwner()) + ); + } +} diff --git a/test/src/main/java/edu/uastw/LibraryBuilder.java b/test/src/main/java/edu/uastw/LibraryBuilder.java new file mode 100644 index 0000000..03e2827 --- /dev/null +++ b/test/src/main/java/edu/uastw/LibraryBuilder.java @@ -0,0 +1,18 @@ +package edu.uastw; + +public class LibraryBuilder { + private final Library library; + + public LibraryBuilder() { + library = Library.getInstance(); + } + + public LibraryBuilder addLibraryItem(LibraryItem libraryItem) { + library.addLibraryItem(libraryItem); + return this; + } + + public Library build() { + return library; + } +} diff --git a/test/src/main/java/edu/uastw/LibraryDecorator.java b/test/src/main/java/edu/uastw/LibraryDecorator.java new file mode 100644 index 0000000..e42a9b1 --- /dev/null +++ b/test/src/main/java/edu/uastw/LibraryDecorator.java @@ -0,0 +1,11 @@ +package edu.uastw; + +abstract class LibraryDecorator extends Library { + protected Library library; + + public LibraryDecorator(Library library) { + this.library = library; + } + + public abstract void extendedFunctionality(); +} diff --git a/test/src/main/java/edu/uastw/LibraryItem.java b/test/src/main/java/edu/uastw/LibraryItem.java new file mode 100644 index 0000000..c946ed9 --- /dev/null +++ b/test/src/main/java/edu/uastw/LibraryItem.java @@ -0,0 +1,6 @@ +package edu.uastw; + +interface LibraryItem { + String getTitle(); + String getOwner(); +} diff --git a/test/src/main/java/edu/uastw/Magazine.java b/test/src/main/java/edu/uastw/Magazine.java new file mode 100644 index 0000000..dfd40ff --- /dev/null +++ b/test/src/main/java/edu/uastw/Magazine.java @@ -0,0 +1,20 @@ +package edu.uastw; + +public class Magazine implements LibraryItem { + private final String title; + private final String publisher; + + public Magazine(String title, String publisher) { + this.title = title; + this.publisher = publisher; + } + + public String getTitle() { + return title; + } + + @Override + public String getOwner() { + return publisher; + } +} diff --git a/test/src/main/java/edu/uastw/Test.java b/test/src/main/java/edu/uastw/Test.java new file mode 100644 index 0000000..af5eb88 --- /dev/null +++ b/test/src/main/java/edu/uastw/Test.java @@ -0,0 +1,29 @@ +package edu.uastw; + +public class Test { + public static void main(String[] args) { + LibraryItem book1 = new Book("The Great Gatsby", "F. Scott Fitzgerald"); + LibraryItem book2 = new Book("To Kill a Mockingbird", "Harper Lee"); + LibraryItem book3 = new Book("1984", "George Orwell"); + LibraryItem magazine1 = new Magazine("National Geographic", "National Geographic Society"); + + Library library = new LibraryBuilder() + .addLibraryItem(book1) + .addLibraryItem(book2) + .addLibraryItem(book3) + .addLibraryItem(magazine1) + .build(); + + library.displayLibraryItems(); + + LibraryDecorator increasedCapacityLibrary = new IncreaseBooksCapacityDecorator(library, 50); + increasedCapacityLibrary.extendedFunctionality(); + + System.out.println("Modified books capacity: " + library.getBooksCapacity()); + + LibraryDecorator decreasedCapacityLibrary = new DecreaseBooksCapacityDecorator(library, 30); + decreasedCapacityLibrary.extendedFunctionality(); + + System.out.println("Modified books capacity: " + library.getBooksCapacity()); + } +} \ No newline at end of file