diff --git a/CHANGELOG.md b/CHANGELOG.md index d450e69..956f043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ ADDED: CHANGED: - update of jdk to version 17 +- moved state design pattern to its own repository and deleted from this repository +- moved observer design pattern to its own repository and deleted from this repository +- moved eventbus design pattern to its own repository and deleted from this repository +- moved visitor design pattern to its own repository and deleted from this repository Version 6 ------------- diff --git a/eventbus/.gitignore b/eventbus/.gitignore deleted file mode 100644 index f5f878b..0000000 --- a/eventbus/.gitignore +++ /dev/null @@ -1,59 +0,0 @@ -################## -# Compiled files # -################## -*.class - -################## -# intellij files # -################## -*.iml -.idea -*/.idea - -################# -# eclipse files # -################# -/.project -/.classpath -/.settings - -######################### -# maven generated files # -######################### -/target - -############# -# Zip files # -############# -*.tar -*.zip -*.7z -*.dmg -*.gz -*.iso -*.jar -*.rar - -############## -# Logs files # -############## -*.log - -################# -# test-ng files # -################# -/test-output - -############################ -# Binaries generated files # -############################ -/bin - -################ -# gradle files # -################ -/build -/.gradle -/gradle -/reports -/pom.xml.bak diff --git a/eventbus/LICENSE b/eventbus/LICENSE deleted file mode 100644 index 1bab125..0000000 --- a/eventbus/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (C) 2015 Asterios Raptis - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/eventbus/README.md b/eventbus/README.md deleted file mode 100644 index ebcec09..0000000 --- a/eventbus/README.md +++ /dev/null @@ -1 +0,0 @@ -# design-pattern eventbus diff --git a/eventbus/build.gradle b/eventbus/build.gradle deleted file mode 100644 index 847c4b0..0000000 --- a/eventbus/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "../gradle/dependencies-eventbus.gradle" -apply from: "../gradle/licensing.gradle" -apply from: "../gradle/publishing-eventbus.gradle" diff --git a/eventbus/src/main/java/io/github/astrapi69/design/pattern/eventbus/GenericEventBus.java b/eventbus/src/main/java/io/github/astrapi69/design/pattern/eventbus/GenericEventBus.java deleted file mode 100644 index 0242d53..0000000 --- a/eventbus/src/main/java/io/github/astrapi69/design/pattern/eventbus/GenericEventBus.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import lombok.NonNull; -import io.github.astrapi69.design.pattern.observer.event.EventObject; -import io.github.astrapi69.design.pattern.observer.event.EventSource; -import io.github.astrapi69.design.pattern.observer.event.EventSubject; - -/** - * The {@code GenericEventBus} is a final utility class that provides a centralized event bus - * mechanism for managing and dispatching events using {@code EventSource} objects. It maintains a - * registry of event sources keyed by strings or class types, enabling efficient event dispatching - * and management. - */ -public final class GenericEventBus -{ - // A static map holding event sources keyed by their string representation - private static final Map> eventSources = new HashMap<>(); - - // Private constructor to prevent instantiation - private GenericEventBus() - { - } - - /** - * Retrieves the event source associated with the specified key - * - * @param key - * the key associated with the event source - * @return the event source associated with the given key or null if none is found - */ - public static EventSource get(final String key) - { - return eventSources.get(key); - } - - /** - * Checks if the event bus contains an event source associated with the specified key - * - * @param key - * the key to check - * @return {@code true} if the event source is present, {@code false} otherwise - */ - public static boolean containsKey(final String key) - { - return eventSources.containsKey(key); - } - - /** - * Checks if the event bus contains an event source associated with the specified class type - * - * @param - * the type of the event source - * @param eventSourceTypeClass - * the class type of the event source to check - * @return {@code true} if the event source is present, {@code false} otherwise - */ - public static boolean containsKey(@NonNull final Class eventSourceTypeClass) - { - return eventSources.containsKey(eventSourceTypeClass.getSimpleName()); - } - - /** - * Retrieves the event source associated with the specified class type. If it does not exist, a - * new {@code EventSubject} is created and associated with the class type. - * - * @param - * the type of the event source - * @param eventSourceTypeClass - * the class type of the event source - * @return the event source associated with the specified class type - */ - @SuppressWarnings("unchecked") - public static EventSource> getEventSource( - @NonNull final Class eventSourceTypeClass) - { - if (!containsKey(eventSourceTypeClass)) - { - put(eventSourceTypeClass.getSimpleName(), new EventSubject>()); - } - return (EventSource>)get(eventSourceTypeClass.getSimpleName()); - } - - /** - * Removes the event source associated with the specified class type - * - * @param - * the type of the event source - * @param eventSourceTypeClass - * the class type of the event source to be removed - * @return an {@code Optional} containing the removed event source, or {@code Optional.empty()} - * if none existed - */ - public static Optional>> remove( - @NonNull final Class eventSourceTypeClass) - { - if (containsKey(eventSourceTypeClass)) - { - EventSource> removedEventSource = (EventSource>)eventSources - .remove(eventSourceTypeClass.getSimpleName()); - return Optional.of(removedEventSource); - } - return Optional.empty(); - } - - /** - * Associates the specified event source with the specified key - * - * @param key - * the key with which the event source is to be associated - * @param value - * the event source to be associated with the key - * @return the previous event source associated with the key, or {@code null} if there was no - * mapping for the key - */ - public static synchronized EventSource put(final String key, final EventSource value) - { - return eventSources.put(key, value); - } - -} diff --git a/eventbus/src/main/java/module-info.java b/eventbus/src/main/java/module-info.java deleted file mode 100644 index 4ccb048..0000000 --- a/eventbus/src/main/java/module-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -module design.patterns.eventbus -{ - requires lombok; - requires design.patterns.observer; - - exports io.github.astrapi69.design.pattern.eventbus; -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/ApplicationEventBus.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/ApplicationEventBus.java deleted file mode 100644 index 99ea896..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/ApplicationEventBus.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus; - -import lombok.Getter; - -import com.google.common.eventbus.EventBus; - -import io.github.astrapi69.design.pattern.eventbus.eventobject.ImportWizardModel; -import io.github.astrapi69.design.pattern.observer.event.EventObject; -import io.github.astrapi69.design.pattern.observer.event.EventSource; - -/** - * The class {@link ApplicationEventBus} serves as the central event bus for the application It - * provides access to various event sources, including those related to navigation and the import - * wizard model, and it uses an instance of {@link EventBus} from the Guava library to manage and - * dispatch events - */ -public class ApplicationEventBus -{ - - /** The singleton instance of the {@link ApplicationEventBus} */ - private static final ApplicationEventBus instance = new ApplicationEventBus(); - - /** The underlying Guava {@link EventBus} for managing events */ - @Getter - private final EventBus applicationEventBus = new EventBus(); - - /** - * Private constructor to enforce singleton pattern - */ - private ApplicationEventBus() - { - } - - /** - * Retrieves an event source by its key - * - * @param key - * the key associated with the event source - * @return the event source associated with the given key, or {@code null} if none is found - */ - public static EventSource get(final String key) - { - return GenericEventBus.get(key); - } - - /** - * Retrieves the event source for navigation state events - * - * @return the event source associated with {@link NavigationEventState} events - */ - public static EventSource> getImportNavigationState() - { - return GenericEventBus.getEventSource(NavigationEventState.class); - } - - /** - * Retrieves the event source for import wizard model events - * - * @return the event source associated with {@link ImportWizardModel} events - */ - public static EventSource> getImportWizardModel() - { - return GenericEventBus.getEventSource(ImportWizardModel.class); - } - - /** - * Retrieves the singleton instance of the {@link ApplicationEventBus} - * - * @return the singleton instance of the {@link ApplicationEventBus} - */ - public static ApplicationEventBus getInstance() - { - return instance; - } -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/GenericEventBusTest.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/GenericEventBusTest.java deleted file mode 100644 index 67cfcbd..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/GenericEventBusTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus; - -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -/** - * The class {@link GenericEventBusTest} provides unit tests for the integration of the - * {@link GenericEventBus} with the {@link ApplicationEventBus} using the Guava {@link EventBus} The - * tests verify the registration, event posting, and unregistration of event listeners, ensuring - * correct behavior of the event bus system - */ -public class GenericEventBusTest -{ - /** Counter to track the number of events processed */ - private static long counter; - - /** Stores the current state of the {@link NavigationEventState} as set by the event handler */ - private static NavigationEventState navigationEventState; - - /** - * Test method for verifying the functionality of the {@link ApplicationEventBus} using the - * Guava {@link EventBus} It checks the correct registration and unregistration of listeners, - * the proper handling of different types of events, and the integrity of event-driven state - * changes - */ - @Test - public void testApplicationEventBus() - { - // ApplicationEventBus from guava - EventBus guavaEventBus = ApplicationEventBus.getInstance().getApplicationEventBus(); - // Register this instance as listener - guavaEventBus.register(this); - // Post an event - guavaEventBus.post("increment"); - // Verify that the counter is incremented - assertEquals(1, counter); - // Post an event - guavaEventBus.post(NavigationEventState.UPDATE); - // Verify that the navigationEventState is set to NavigationEventState.UPDATE - assertEquals(NavigationEventState.UPDATE, navigationEventState); - // Verify that the counter is not incremented - assertEquals(1, counter); - // Unregister this instance as listener - guavaEventBus.unregister(this); - // Post an event - guavaEventBus.post("increment"); - // Verify that the counter is not incremented - assertEquals(1, counter); - // Register again this instance as listener - guavaEventBus.register(this); - // Post an event - guavaEventBus.post("increment"); - // Verify that the counter is incremented - assertEquals(2, counter); - // Post an event - guavaEventBus.post(NavigationEventState.RESET); - // Verify that the navigationEventState is set to NavigationEventState.RESET - assertEquals(NavigationEventState.RESET, navigationEventState); - // Post an event - guavaEventBus.post(NavigationEventState.VALIDATE); - // Verify that the navigationEventState is set to NavigationEventState.VALIDATE - assertEquals(NavigationEventState.VALIDATE, navigationEventState); - // Unregister this instance as listener - guavaEventBus.unregister(this); - } - - /** - * Event handler method for string-based events This method increments the counter each time it - * is called - * - * @param event - * the event string, typically a command or action indicator - */ - @Subscribe - public void onAddition(String event) - { - counter++; - } - - /** - * Event handler method for {@link NavigationEventState} events This method updates the - * {@code navigationEventState} field to reflect the state passed in the event - * - * @param navigationEventState - * the event containing the new navigation state - */ - @Subscribe - public void onAdditionWithObject(NavigationEventState navigationEventState) - { - GenericEventBusTest.navigationEventState = navigationEventState; - } -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/ImportWizardPanelTest.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/ImportWizardPanelTest.java deleted file mode 100644 index efbbaa4..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/ImportWizardPanelTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus; - -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import io.github.astrapi69.design.pattern.observer.event.EventListener; -import io.github.astrapi69.design.pattern.observer.event.EventObject; -import io.github.astrapi69.design.pattern.observer.event.EventSource; - -/** - * The class {@link ImportWizardPanelTest} provides unit tests for the {@link ImportWizardPanel} - * class It implements the {@link EventListener} interface to listen for - * {@link NavigationEventState} events and verify the correct behavior of the event handling and - * state update logic - */ -public class ImportWizardPanelTest implements EventListener> -{ - - /** The current state of the navigation event, set by the event listener */ - private NavigationEventState navigationEventState; - - /** - * Handles the given event by updating the navigation state of the panel - * - * @param event - * the event containing the new {@link NavigationEventState} - */ - @Override - public void onEvent(EventObject event) - { - updateButtonState(event.getSource()); - } - - /** - * Updates the button state based on the given navigation state - * - * @param navigationState - * the new navigation state to be applied - */ - protected void updateButtonState(NavigationEventState navigationState) - { - this.navigationEventState = navigationState; - } - - /** - * Test method for verifying the event handling functionality of the {@link ImportWizardPanel} - * It registers the test class as a listener for {@link NavigationEventState} events, fires - * events, and verifies that the {@code navigationEventState} is updated correctly - */ - @Test - public void testApplicationEventBus() - { - // Register as listener... - final EventSource> eventSource = ApplicationEventBus - .getImportNavigationState(); - eventSource.add(this); - // Create an event source object - final EventSource> navigationEventStateEventSource = ApplicationEventBus - .getImportNavigationState(); - // Fire a new event - navigationEventStateEventSource.fireEvent(new EventObject<>(NavigationEventState.UPDATE)); - // Verify that the navigationEventState is set to NavigationEventState.UPDATE - assertEquals(NavigationEventState.UPDATE, this.navigationEventState); - // Fire a new event - navigationEventStateEventSource.fireEvent(new EventObject<>(NavigationEventState.VALIDATE)); - // Verify that the navigationEventState is set to NavigationEventState.VALIDATE - assertEquals(NavigationEventState.VALIDATE, this.navigationEventState); - // Fire a new event - navigationEventStateEventSource.fireEvent(new EventObject<>(NavigationEventState.RESET)); - // Verify that the navigationEventState is set to NavigationEventState.RESET - assertEquals(NavigationEventState.RESET, this.navigationEventState); - } -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/NavigationEventState.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/NavigationEventState.java deleted file mode 100644 index cac3d5e..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/NavigationEventState.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus; - -/** - * The enum {@link NavigationEventState} represents different states of navigation events that can - * occur in a wizard navigation process - */ -public enum NavigationEventState -{ - - /** - * The RESET state indicates that the navigation should reset to its initial state - */ - RESET, - - /** - * The UPDATE state indicates that the navigation should update its current state - */ - UPDATE, - - /** - * The VALIDATE state indicates that the navigation should validate its current state - */ - VALIDATE -} \ No newline at end of file diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportProgressPanel.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportProgressPanel.java deleted file mode 100644 index b382a1f..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportProgressPanel.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus.eventobject; - -import lombok.Getter; -import io.github.astrapi69.design.pattern.eventbus.ApplicationEventBus; -import io.github.astrapi69.design.pattern.observer.event.EventListener; -import io.github.astrapi69.design.pattern.observer.event.EventObject; -import io.github.astrapi69.design.pattern.observer.event.EventSource; - -/** - * The {@code ImportProgressPanel} class is responsible for handling events related to the - * {@code ImportWizardModel}. It listens for events on the {@code ApplicationEventBus} and updates - * its internal state when an event occurs. - */ -public class ImportProgressPanel implements EventListener> -{ - - /** The model that this panel is monitoring */ - @Getter - ImportWizardModel importWizardModel; - - /** - * Constructs a new {@code ImportProgressPanel} and registers it as a listener for - * {@code ImportWizardModel} events on the {@code ApplicationEventBus} - */ - ImportProgressPanel() - { - // Register as listener... - final EventSource> eventSource = ApplicationEventBus - .getImportWizardModel(); - eventSource.add(this); - } - - /** - * Handles the event when an {@code ImportWizardModel} event is fired. This method updates the - * internal {@code importWizardModel} with the event's source. - * - * @param event - * the event object containing the updated {@code ImportWizardModel} - */ - @Override - public void onEvent(EventObject event) - { - this.importWizardModel = event.getSource(); - } -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportProgressPanelTest.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportProgressPanelTest.java deleted file mode 100644 index 9bfde3b..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportProgressPanelTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus.eventobject; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import org.testng.annotations.Test; - -import io.github.astrapi69.design.pattern.eventbus.ApplicationEventBus; - -/** - * The class {@link ImportProgressPanelTest} provides unit tests for the {@link ImportProgressPanel} - * class It verifies the functionality of event handling and state synchronization between - * {@link ImportProgressPanel} and {@link ImportWizardPanel} - */ -public class ImportProgressPanelTest -{ - - /** - * Test method for the interaction between {@link ImportProgressPanel} and - * {@link ImportWizardPanel} through the {@link ApplicationEventBus} It validates that events - * are correctly fired, received, and processed, ensuring that the model state is synchronized - * across the panels - */ - @Test - public void testApplicationEventBus() - { - ImportProgressPanel importProgressPanel = new ImportProgressPanel(); - ImportWizardModel importWizardModel = importProgressPanel.getImportWizardModel(); - assertNull(importWizardModel); - - ImportWizardPanel importWizardPanel = new ImportWizardPanel(); - importWizardPanel.fireNewEvent(); - importWizardModel = importProgressPanel.getImportWizardModel(); - assertNotNull(importWizardModel); - - ImportWizardModel model = importWizardPanel.getModel(); - assertEquals(importWizardModel, model); - - importWizardPanel.setModel(ImportWizardModel.builder().bundleAppName("blabla").build()); - model = importWizardPanel.getModel(); - assertNotEquals(importWizardModel, model); - - importWizardPanel.fireNewEvent(); - importWizardModel = importProgressPanel.getImportWizardModel(); - assertEquals(importWizardModel, model); - } -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportWizardModel.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportWizardModel.java deleted file mode 100644 index d0b885d..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportWizardModel.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus.eventobject; - -import java.io.File; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class {@link ImportWizardModel} acts as a model for the import wizard It contains data - * related to the import process, such as the application name, whether a database import is - * required, and the root directory for the import - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class ImportWizardModel -{ - - /** The name of the application bundle */ - private String bundleAppName; - - /** Flag indicating whether the database import is required */ - private boolean dbImport; - - /** The root directory for the import process */ - private File rootDir; - -} diff --git a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportWizardPanel.java b/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportWizardPanel.java deleted file mode 100644 index cdbf8ae..0000000 --- a/eventbus/src/test/java/io/github/astrapi69/design/pattern/eventbus/eventobject/ImportWizardPanel.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.eventbus.eventobject; - -import lombok.Getter; -import lombok.Setter; -import io.github.astrapi69.design.pattern.eventbus.ApplicationEventBus; -import io.github.astrapi69.design.pattern.observer.event.EventObject; - -/** - * The class {@link ImportWizardPanel} represents a panel in the import wizard It holds an instance - * of {@link ImportWizardModel} and can fire events related to the model - */ -public class ImportWizardPanel -{ - /** The model associated with this panel */ - @Getter - @Setter - ImportWizardModel model; - - /** - * Constructs a new {@code ImportWizardPanel} with a default model The default model is - * initialized with a bundle application name "foobar" - */ - ImportWizardPanel() - { - this.model = ImportWizardModel.builder().bundleAppName("foobar").build(); - } - - /** - * Fires a new event to the {@link ApplicationEventBus} with the current model The event is - * created using the current state of the {@code ImportWizardModel} - */ - public void fireNewEvent() - { - ApplicationEventBus.getImportWizardModel().fireEvent(EventObject.of(this.model)); - } -} diff --git a/gradle/dependencies-eventbus.gradle b/gradle/dependencies-eventbus.gradle deleted file mode 100644 index 2d4c9d0..0000000 --- a/gradle/dependencies-eventbus.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - implementation project(":observer") - - testImplementation libs.guava -} diff --git a/gradle/dependencies-observer.gradle b/gradle/dependencies-observer.gradle deleted file mode 100644 index 0f5f773..0000000 --- a/gradle/dependencies-observer.gradle +++ /dev/null @@ -1,4 +0,0 @@ -dependencies { - testImplementation libs.auth - testImplementation libs.auth.api -} diff --git a/gradle/dependencies-state.gradle b/gradle/dependencies-state.gradle deleted file mode 100644 index 4372159..0000000 --- a/gradle/dependencies-state.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - testImplementation libs.crypt.api - testImplementation libs.crypt.data - testImplementation libs.file.worker -} diff --git a/gradle/dependencies-visitor.gradle b/gradle/dependencies-visitor.gradle deleted file mode 100644 index 8bf332a..0000000 --- a/gradle/dependencies-visitor.gradle +++ /dev/null @@ -1,4 +0,0 @@ -dependencies { - testImplementation libs.file.worker - testImplementation libs.jobj.core -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b0c2698..6d22939 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,5 @@ [versions] -auth-api-version = "6" -auth-version = "6" commons-lang3-version = "3.14.0" -crypt-api-version = "9" -crypt-data-version = "9" file-worker-version = "17.2" gradle-plugin-grgit-version = "5.2.2" gradle-plugin-license-version = "0.16.1" @@ -11,8 +7,6 @@ gradle-plugin-lombok-version = "8.6" gradle-plugin-spotless-version = "7.0.0.BETA1" gradle-plugin-version-catalog-update-version = "0.8.4" gradle-plugin-versions-version = "0.51.0" -guava-version = "33.2.1-jre" -jobj-core-version = "8.2" lombok-version = "1.18.32" meanbean-version = "2.0.3" test-object-version = "8.2" @@ -23,14 +17,8 @@ xml-jackson-extensions-version = "2.1" xstream-extensions-version = "1.1" [libraries] -auth = { module = "io.github.astrapi69:auth", version.ref = "auth-version" } -auth-api = { module = "io.github.astrapi69:auth-api", version.ref = "auth-api-version" } commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang3-version" } -crypt-api = { module = "io.github.astrapi69:crypt-api", version.ref = "crypt-api-version" } -crypt-data = { module = "io.github.astrapi69:crypt-data", version.ref = "crypt-data-version" } file-worker = { module = "io.github.astrapi69:file-worker", version.ref = "file-worker-version" } -guava = { module = "com.google.guava:guava", version.ref = "guava-version" } -jobj-core = { module = "io.github.astrapi69:jobj-core", version.ref = "jobj-core-version" } lombok = { module = "org.projectlombok:lombok", version.ref = "lombok-version" } meanbean = { module = "org.meanbean:meanbean", version.ref = "meanbean-version" } test-object = { module = "io.github.astrapi69:test-object", version.ref = "test-object-version" } diff --git a/gradle/publishing-eventbus.gradle b/gradle/publishing-eventbus.gradle deleted file mode 100644 index 7bdda0e..0000000 --- a/gradle/publishing-eventbus.gradle +++ /dev/null @@ -1,62 +0,0 @@ -apply from: "../gradle/pre-publishing-tasks.gradle" - -def releaseVersion = !version.endsWith("SNAPSHOT") - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId = "$project.name" - from components.java - artifact sourcesJar - artifact javadocJar - pom { - name = "$project.name" - description = "$projectEventbusDescription" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" - organization { - name = "$projectOrganizationName" - url = "$projectOrganizationUrl" - } - issueManagement { - system = "$projectIssueManagementSystem" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$issuesPath" - } - licenses { - license { - name = "$projectLicenseName" - url = "$projectLicenseUrl" - distribution = "$projectLicenseDistribution" - } - } - developers { - developer { - id = "$projectHolderUsername" - name = "$projectLeaderName" - } - } - scm { - connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - } - } - } - } - repositories { - maven { - credentials { - username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey") - password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey") - } - def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl" - def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl" - url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl - } - } -} - -signing { - if (releaseVersion) { - sign publishing.publications.mavenJava - } -} diff --git a/gradle/publishing-observer.gradle b/gradle/publishing-observer.gradle deleted file mode 100644 index 7153829..0000000 --- a/gradle/publishing-observer.gradle +++ /dev/null @@ -1,62 +0,0 @@ -apply from: "../gradle/pre-publishing-tasks.gradle" - -def releaseVersion = !version.endsWith("SNAPSHOT") - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId = "$project.name" - from components.java - artifact sourcesJar - artifact javadocJar - pom { - name = "$project.name" - description = "$projectObserverDescription" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" - organization { - name = "$projectOrganizationName" - url = "$projectOrganizationUrl" - } - issueManagement { - system = "$projectIssueManagementSystem" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$issuesPath" - } - licenses { - license { - name = "$projectLicenseName" - url = "$projectLicenseUrl" - distribution = "$projectLicenseDistribution" - } - } - developers { - developer { - id = "$projectHolderUsername" - name = "$projectLeaderName" - } - } - scm { - connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - } - } - } - } - repositories { - maven { - credentials { - username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey") - password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey") - } - def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl" - def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl" - url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl - } - } -} - -signing { - if (releaseVersion) { - sign publishing.publications.mavenJava - } -} diff --git a/gradle/publishing-state.gradle b/gradle/publishing-state.gradle deleted file mode 100644 index dd5cb52..0000000 --- a/gradle/publishing-state.gradle +++ /dev/null @@ -1,62 +0,0 @@ -apply from: "../gradle/pre-publishing-tasks.gradle" - -def releaseVersion = !version.endsWith("SNAPSHOT") - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId = "$project.name" - from components.java - artifact sourcesJar - artifact javadocJar - pom { - name = "$project.name" - description = "$projectStateDescription" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" - organization { - name = "$projectOrganizationName" - url = "$projectOrganizationUrl" - } - issueManagement { - system = "$projectIssueManagementSystem" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$issuesPath" - } - licenses { - license { - name = "$projectLicenseName" - url = "$projectLicenseUrl" - distribution = "$projectLicenseDistribution" - } - } - developers { - developer { - id = "$projectHolderUsername" - name = "$projectLeaderName" - } - } - scm { - connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - } - } - } - } - repositories { - maven { - credentials { - username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey") - password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey") - } - def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl" - def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl" - url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl - } - } -} - -signing { - if (releaseVersion) { - sign publishing.publications.mavenJava - } -} diff --git a/gradle/publishing-visitor.gradle b/gradle/publishing-visitor.gradle deleted file mode 100644 index aaadd17..0000000 --- a/gradle/publishing-visitor.gradle +++ /dev/null @@ -1,62 +0,0 @@ -apply from: "../gradle/pre-publishing-tasks.gradle" - -def releaseVersion = !version.endsWith("SNAPSHOT") - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId = "$project.name" - from components.java - artifact sourcesJar - artifact javadocJar - pom { - name = "$project.name" - description = "$projectVisitorDescription" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" - organization { - name = "$projectOrganizationName" - url = "$projectOrganizationUrl" - } - issueManagement { - system = "$projectIssueManagementSystem" - url = "$projectScmProviderUrl" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$issuesPath" - } - licenses { - license { - name = "$projectLicenseName" - url = "$projectLicenseUrl" - distribution = "$projectLicenseDistribution" - } - } - developers { - developer { - id = "$projectHolderUsername" - name = "$projectLeaderName" - } - } - scm { - connection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - developerConnection = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - url = "$projectScmGitUrlPrefix" + "$projectScmProviderDomain" + "$colon" + "$projectHolderUsername" + "$slash" + "$rootProject.name" + "$projectScmGitUrlSuffix" - } - } - } - } - repositories { - maven { - credentials { - username System.getenv("$projectRepositoriesUserNameKey") ?: project.property("$projectRepositoriesUserNameKey") - password System.getenv("$projectRepositoriesPasswordKey") ?: project.property("$projectRepositoriesPasswordKey") - } - def releasesRepoUrl = "$projectRepositoriesReleasesRepoUrl" - def snapshotsRepoUrl = "$projectRepositoriesSnapshotsRepoUrl" - url = releaseVersion ? releasesRepoUrl : snapshotsRepoUrl - } - } -} - -signing { - if (releaseVersion) { - sign publishing.publications.mavenJava - } -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0d18421..e1adfb4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/observer/.gitignore b/observer/.gitignore deleted file mode 100644 index 9111d6a..0000000 --- a/observer/.gitignore +++ /dev/null @@ -1,58 +0,0 @@ -################## -# Compiled files # -################## -*.class - -################## -# intellij files # -################## -*.iml -.idea -*/.idea - -################# -# eclipse files # -################# -/.project -/.classpath -/.settings - -######################### -# maven generated files # -######################### -/target - -############# -# Zip files # -############# -*.tar -*.zip -*.7z -*.dmg -*.gz -*.iso -*.jar -*.rar - -############## -# Logs files # -############## -*.log - -################# -# test-ng files # -################# -/test-output - -############################ -# Binaries generated files # -############################ -/bin - -################ -# gradle files # -################ -/build -/.gradle -/gradle -/pom.xml.bak diff --git a/observer/LICENSE b/observer/LICENSE deleted file mode 100644 index 1bab125..0000000 --- a/observer/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (C) 2015 Asterios Raptis - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/observer/README.md b/observer/README.md deleted file mode 100644 index f1a0f6e..0000000 --- a/observer/README.md +++ /dev/null @@ -1 +0,0 @@ -# design-pattern observer diff --git a/observer/build.gradle b/observer/build.gradle deleted file mode 100644 index 79e8c71..0000000 --- a/observer/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "../gradle/dependencies-observer.gradle" -apply from: "../gradle/licensing.gradle" -apply from: "../gradle/publishing-observer.gradle" diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/AbstractObserver.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/AbstractObserver.java deleted file mode 100644 index 7de80c9..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/AbstractObserver.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import io.github.astrapi69.design.pattern.observer.api.ActionCommand; -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; - -/** - * A generic implementation of the Observer pattern This abstract class implements the - * {@link Observer} and {@link ActionCommand} interfaces, providing a basic framework for observers - * in the Observer design pattern - * - * @param - * the generic type of the observable object - */ -public abstract class AbstractObserver implements Observer, ActionCommand -{ - - /** The subject being observed */ - protected Subject> subject; - - /** The current observable object */ - private T observable; - - /** - * Constructor for a new observer object - * - * @param subject - * the subject to observe - */ - public AbstractObserver(final Subject> subject) - { - this.subject = subject; - this.observable = subject.getObservable(); - this.subject.add(this); - } - - /** - * Gets the current observable object - * - * @return the observable object - */ - public synchronized T getObservable() - { - return observable; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void update(final T observable) - { - this.observable = observable; - execute(); - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/AbstractSubject.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/AbstractSubject.java deleted file mode 100644 index e42b9d6..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/AbstractSubject.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import lombok.Getter; -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; - -/** - * The class {@link AbstractSubject} is an implementation of the {@link Subject} interface This - * class encapsulates the observable object and notifies all registered observers when the - * observable changes - * - * @param - * the generic type of the observable object - * @param - * the generic type of the observer - */ -public abstract class AbstractSubject> implements Subject -{ - - /** The list of registered observers */ - @Getter - private final List observers; - - /** The current observable object */ - @Getter - private T observable; - - /** - * Initialization block to create the list of observers - **/ - { - observers = new ArrayList<>(); - } - - /** - * Default constructor for a new subject with no initial observable - */ - public AbstractSubject() - { - } - - /** - * Constructor for a new subject with an initial observable - * - * @param observable - * the initial observable object - */ - public AbstractSubject(final T observable) - { - this.observable = observable; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void add(final O observer) - { - getObservers().add(observer); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void addAll(final Collection observers) - { - getObservers().addAll(observers); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void remove(final O observer) - { - final int index = getObservers().indexOf(observer); - if (0 <= index) - { - getObservers().remove(observer); - } - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void removeAll(final Collection observers) - { - getObservers().removeAll(observers); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void setObservable(final T observable) - { - this.observable = observable; - updateObservers(); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void updateObservers() - { - for (final O observer : getObservers()) - { - observer.update(getObservable()); - } - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/ActionCommand.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/ActionCommand.java deleted file mode 100644 index a80f652..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/ActionCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.api; - -/** - * The interface {@link ActionCommand} represents a command that can be executed Implementations of - * this interface encapsulate a specific action that can be triggered - */ -public interface ActionCommand -{ - - /** - * Executes the command Implementing classes should define the specific action to be performed - * when this method is called - */ - void execute(); -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/Observer.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/Observer.java deleted file mode 100644 index 0b82b04..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/Observer.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.api; - -/** - * The Interface {@link Observer} represents an observer in the Observer design pattern It defines a - * contract for objects that should be notified of changes in an observable subject - * - * @param - * the generic type of the observable object that the observer is interested in - */ -public interface Observer -{ - - /** - * This method is called to notify the observer of changes in the observable object Implementing - * classes should define the specific behavior that occurs when the observable object changes - * - * @param observable - * the observable object that has changed - */ - void update(final T observable); -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/Subject.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/Subject.java deleted file mode 100644 index 2bc2a44..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/Subject.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.api; - -import java.util.Collection; -import java.util.List; - -/** - * The interface {@link Subject} represents the "subject" in the Observer design pattern The subject - * is the object whose state changes are being observed by one or more observers When the state of - * the subject changes, the observers are notified of the change - * - * @param - * the generic type of the observable object whose state is being observed - * @param - * the generic type of the observer that is observing the subject - */ -public interface Subject> -{ - - /** - * Adds the given observer to the list of observers - * - * @param observer - * the observer to be added - */ - default void add(final O observer) - { - getObservers().add(observer); - } - - /** - * Adds the given observers to the list of observers - * - * @param observers - * the observers to be added - */ - default void addAll(final Collection observers) - { - getObservers().addAll(observers); - } - - /** - * Gets the observable object, which is the object being observed for state changes - * - * @return the observable object - */ - T getObservable(); - - /** - * Sets the observable object, which is the object being observed for state changes - * - * @param observable - * the new observable object - */ - void setObservable(final T observable); - - /** - * Gets the list of observers that wish to be notified of changes to the observable object - * - * @return the list of observers - */ - List getObservers(); - - /** - * Removes the given observer from the list of observers - * - * @param observer - * the observer to be removed - */ - default void remove(final O observer) - { - final int index = getObservers().indexOf(observer); - if (0 <= index) - { - getObservers().remove(observer); - } - } - - /** - * Removes the given observers from the list of observers - * - * @param observers - * the observers to be removed - */ - default void removeAll(final Collection observers) - { - getObservers().removeAll(observers); - } - - /** - * Notifies all observers of a change in the state of the observable object Each observer's - * {@code update} method is called with the current state of the observable - */ - default void updateObservers() - { - for (final O observer : getObservers()) - { - observer.update(getObservable()); - } - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/package-info.java deleted file mode 100644 index 6ce534e..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/api/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Provides interfaces that define the core components of the observer design pattern - * - *

- * The observer pattern is a behavioral design pattern that allows an object, known as the subject, to maintain a list of its dependents, called observers, - * and notify them automatically of any state changes, usually by calling one of their methods - * This package contains the fundamental interfaces that are essential for implementing the observer pattern. - *

- * - *

- * The key interfaces in this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.api.Observer} - Represents the observer that watches the subject for changes
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.api.Subject} - Represents the subject being observed
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.api.ActionCommand} - Represents a command that can be executed, typically used by observers to respond to subject changes
  • - *
- * - *

- * These interfaces provide a flexible and extensible framework for implementing the observer pattern in various contexts - * By adhering to these interfaces, developers can create systems where objects can be notified of changes in other objects' states, promoting loose coupling and dynamic behavior. - *

- */ -package io.github.astrapi69.design.pattern.observer.api; diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatMessage.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatMessage.java deleted file mode 100644 index 444514c..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatMessage.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; - -/** - * The class {@link ChatMessage} represents a message in a chat application It implements the - * {@link Message} interface and is serializable - * - * @param - * the type of the value held by the message, which in this case is a - * {@link MessageRoomModelBean} - */ -public class ChatMessage implements Message, Serializable -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The value of the message, typically containing the chat room details */ - private MessageRoomModelBean value; - - /** - * {@inheritDoc} - */ - @Override - public MessageRoomModelBean getValue() - { - return value; - } - - /** - * {@inheritDoc} - */ - @Override - public ChatMessage setValue(final MessageRoomModelBean value) - { - this.value = value; - return this; - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoom.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoom.java deleted file mode 100644 index 9bb849a..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoom.java +++ /dev/null @@ -1,231 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import io.github.astrapi69.design.pattern.observer.AbstractSubject; -import io.github.astrapi69.design.pattern.observer.api.Subject; - -/** - * The class {@link ChatRoom} represents a chat room where users can send and receive messages It - * extends {@link AbstractSubject} and implements {@link Subject}, {@link Room}, and - * {@link Serializable} - * - * @param - * the generic type of the message that will be sent in this chat room - */ -public class ChatRoom> extends AbstractSubject> - implements - Subject>, - Room, - Serializable -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The list of observers (chat room users) */ - private final List> observers; - - /** The message history of the chat room */ - private final List messageHistory = new ArrayList<>(); - - /** The name of the chat room */ - private final String name; - - /** The observable message object */ - private M observable; - - /** - * Initialization block to create the list of observers - **/ - { - observers = new ArrayList<>(); - } - - /** - * Constructor for a new chat room with an initial observable message and a name - * - * @param observable - * the initial observable message - * @param name - * the name of the chat room - */ - public ChatRoom(final M observable, final String name) - { - this.observable = observable; - this.name = name; - } - - /** - * Constructor for a new chat room with the given name - * - * @param name - * the name of the chat room - */ - public ChatRoom(final String name) - { - this.name = name; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void add(final ChatRoomUser observer) - { - observers.add(observer); - } - - /** - * {@inheritDoc} - */ - @Override - public void addAll(final Collection> observers) - { - for (final ChatRoomUser chatUser : observers) - { - add(chatUser); - } - } - - /** - * Gets the chat room users as a list of {@link IUser} objects - * - * @return the list of chat room users - */ - @Override - public List> getChatRoomUsers() - { - final List> chatRoomUsers = new ArrayList<>(); - for (final ChatRoomUser chatUser : observers) - { - chatRoomUsers.add(chatUser.getUser()); - } - return chatRoomUsers; - } - - /** - * Gets the message history of the chat room - * - * @return the list of messages sent in the chat room - */ - @Override - public List getMessageHistory() - { - return messageHistory; - } - - /** - * Gets the name of the chat room - * - * @return the name of the chat room - */ - public String getName() - { - return name; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized M getObservable() - { - return observable; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void setObservable(final M observable) - { - this.observable = observable; - messageHistory.add(observable); - updateObservers(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSecure() - { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void remove(final ChatRoomUser observer) - { - final int index = this.observers.indexOf(observer); - if (0 <= index) - { - this.observers.remove(observer); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void removeAll(final Collection> observers) - { - for (final ChatRoomUser chatUser : observers) - { - remove(chatUser); - } - } - - /** - * Returns the number of users in this chat room - * - * @return the number of users in this chat room - */ - public int size() - { - return this.observers.size(); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void updateObservers() - { - for (final ChatRoomUser observer : this.observers) - { - observer.update(observable); - } - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoomService.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoomService.java deleted file mode 100644 index d576cea..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoomService.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -/** - * The class {@link ChatRoomService} manages the creation and retrieval of chat rooms It provides a - * way to obtain a {@link ChatRoom} based on an observable message and a room name - * - * @param - * the generic type of the message that will be sent in the chat rooms - */ -public class ChatRoomService> implements Serializable -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** A map of chat room names to their corresponding {@link ChatRoom} instances */ - private final Map> chatRooms = new HashMap<>(); - - /** - * Gets the chat room with the specified name If the chat room does not exist, a new one is - * created with the given observable message and name - * - * @param observable - * the observable message for the chat room - * @param name - * the name of the chat room - * @return the chat room associated with the given name - */ - public ChatRoom getChatRoom(final M observable, final String name) - { - ChatRoom room = chatRooms.get(name); - if (room == null) - { - room = new ChatRoom<>(observable, name); - chatRooms.put(name, room); - } - return room; - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoomUser.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoomUser.java deleted file mode 100644 index 6b816e5..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/ChatRoomUser.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; - -import io.github.astrapi69.design.pattern.observer.api.ActionCommand; -import io.github.astrapi69.design.pattern.observer.api.Observer; - -/** - * The class {@link ChatRoomUser} represents a user in a chat room who can send and receive messages - * This class implements {@link Observer} to observe messages in the chat room, - * {@link ActionCommand} to define actions when a message is received, and {@link Serializable} for - * serialization support - * - * @param - * the generic type of the message that will be sent and observed in the chat room - */ -public abstract class ChatRoomUser> - implements - Observer, - ActionCommand, - Serializable -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The user associated with this chat room user */ - private final IUser user; - - /** The chat room (subject) that this user is part of */ - protected ChatRoom subject; - - /** The observable message currently observed by this user */ - private M observable; - - /** - * Instantiates a new chat room user - * - * @param room - * the chat room (subject) that this user is part of - * @param user - * the user associated with this chat room user - */ - public ChatRoomUser(final ChatRoom room, final IUser user) - { - this.subject = room; - this.observable = this.subject.getObservable(); - this.user = user; - this.subject.add(this); - } - - /** - * Gets the observable message currently observed by this user - * - * @return the observable message - */ - public synchronized M getObservable() - { - return observable; - } - - /** - * Gets the user associated with this chat room user - * - * @return the user - */ - public IUser getUser() - { - return user; - } - - /** - * Sends the given message to the chat room - * - * @param message - * the message to be sent - */ - public void send(final M message) - { - subject.setObservable(message); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void update(final M observable) - { - this.observable = observable; - execute(); - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/IUser.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/IUser.java deleted file mode 100644 index 544948a..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/IUser.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; - -/** - * The interface {@link IUser} represents a user in a chat application It provides methods to manage - * the user's identity, including getting and setting the application user, retrieving the user's - * unique identifier, and obtaining the user's name - * - * @param - * the generic type representing the application user - */ -public interface IUser extends Serializable -{ - - /** - * Gets the application user associated with this {@link IUser} - * - * @return the application user - */ - U getApplicationUser(); - - /** - * Sets the application user associated with this {@link IUser} - * - * @param user - * the new application user - */ - void setApplicationUser(final U user); - - /** - * Gets the unique identifier for this {@link IUser} - * - * @return the unique identifier - */ - Serializable getId(); - - /** - * Gets the name of this {@link IUser} - * - * @return the name of the user - */ - String getName(); -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Invitation.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Invitation.java deleted file mode 100644 index 5a9db27..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Invitation.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; - -/** - * The Interface {@link Invitation} represents an invitation to join a chat room It defines the - * methods to retrieve the sender, recipient, and the room associated with the invitation, as well - * as methods to check if the invitation has been accepted and if the denial is visible to the - * sender - * - * @param - * the generic type of the message associated with the chat room - */ -public interface Invitation> extends Serializable -{ - - /** - * Gets the recipient of this invitation - * - * @return the recipient of this invitation - */ - IUser getRecipient(); - - /** - * Gets the room associated with this invitation - * - * @return the room for this invitation - */ - Room getRoom(); - - /** - * Gets the sender of this invitation - * - * @return the sender of this invitation - */ - IUser getSender(); - - /** - * Checks if this invitation has been accepted by the recipient - * - * @return true if the invitation is accepted, otherwise false - */ - boolean isAccepted(); - - /** - * Checks if the recipient wants the sender to see that the invitation was denied - * - * @return true if the recipient wants the sender to see the denial, otherwise false - */ - boolean isDeniedVisible(); -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Message.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Message.java deleted file mode 100644 index 5fc0b81..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Message.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; - -/** - * The interface {@link Message} represents a message that can be sent in a chat application It - * provides methods for getting and setting the value of the message - * - * @param - * the generic type of the value contained in the message - */ -public interface Message extends Serializable -{ - - /** - * Gets the value of the message - * - * @return the value of the message - */ - T getValue(); - - /** - * Sets the value of the message - * - * @param value - * the value to set - * @return the updated message - */ - Message setValue(final T value); - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/MessageRoomModelBean.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/MessageRoomModelBean.java deleted file mode 100644 index 76a4b91..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/MessageRoomModelBean.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; -import java.util.Date; - -/** - * The class {@link MessageRoomModelBean} represents a model for a message in a chat room It - * includes details such as the chat room name, the user who sent the message, the message content, - * and any associated data, as well as the date the message was created - */ -public class MessageRoomModelBean implements Serializable -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The name of the chat room */ - private final String chatRoomName; - - /** The date the message was created */ - private final Date date = new Date(); - - /** The user who sent the message */ - private final IUser user; - - /** Any additional data associated with the message */ - private Byte[] data; - - /** The content of the message */ - private String message; - - /** - * Instantiates a new {@code MessageRoomModelBean} with the specified details - * - * @param chatRoomName - * the name of the chat room - * @param user - * the user who sent the message - * @param message - * the content of the message - * @param data - * any additional data associated with the message - */ - public MessageRoomModelBean(final String chatRoomName, final IUser user, - final String message, final Byte[] data) - { - super(); - this.chatRoomName = chatRoomName; - this.user = user; - this.message = message; - this.data = data; - } - - /** - * Gets the name of the chat room - * - * @return the chat room name - */ - public String getChatRoomName() - { - return chatRoomName; - } - - /** - * Gets the additional data associated with the message - * - * @return the data - */ - public Byte[] getData() - { - return data; - } - - /** - * Sets the additional data associated with the message - * - * @param data - * the new data - */ - public void setData(final Byte[] data) - { - this.data = data; - } - - /** - * Gets the date the message was created - * - * @return the creation date of the message - */ - public Date getDate() - { - return date; - } - - /** - * Gets the content of the message - * - * @return the message content - */ - public String getMessage() - { - return message; - } - - /** - * Sets the content of the message - * - * @param message - * the new message content - */ - public void setMessage(final String message) - { - this.message = message; - } - - /** - * Gets the user who sent the message - * - * @return the user who sent the message - */ - public IUser getUser() - { - return user; - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Room.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Room.java deleted file mode 100644 index 67f8815..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/Room.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; -import java.util.List; - -/** - * The interface {@link Room} represents a chat room in which users can participate It provides - * methods to retrieve the list of users in the chat room, the history of messages sent in the room, - * and to check whether the room is secure - * - * @param - * the generic type representing the messages that can be sent in the room - */ -public interface Room> extends Serializable -{ - - /** - * Gets the list of users in the chat room - * - * @return the list of users in the chat room - */ - List> getChatRoomUsers(); - - /** - * Gets the history of messages sent in the chat room - * - * @return the list of messages sent in the chat room - */ - List getMessageHistory(); - - /** - * Checks if the chat room is secure - * - * @return true if the chat room is secure, otherwise false - */ - boolean isSecure(); -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/StringMessage.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/StringMessage.java deleted file mode 100644 index 444fb0d..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/StringMessage.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -/** - * The class {@link StringMessage} represents a message that contains a string value It implements - * the {@link Message} interface and provides methods to get and set the string value - */ -public class StringMessage implements Message -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The value of the string message */ - private String value; - - /** - * Instantiates a new {@code StringMessage} with no initial value - */ - public StringMessage() - { - } - - /** - * Instantiates a new {@code StringMessage} with the given value - * - * @param value - * the value of the message - */ - public StringMessage(final String value) - { - this.value = value; - } - - /** - * {@inheritDoc} - */ - @Override - public String getValue() - { - return value; - } - - /** - * {@inheritDoc} - */ - @Override - public StringMessage setValue(final String value) - { - this.value = value; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return "StringMessage [value=" + value + "]"; - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/User.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/User.java deleted file mode 100644 index 930d5a7..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/User.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -/** - * The class {@link User} represents a user in a chat application It implements the {@link IUser} - * interface and provides methods to manage the user's identity, including their name and ID - */ -public class User implements IUser -{ - - /** The Constant serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The name of the user */ - private String name; - - /** The ID number of the user */ - private Integer id; - - /** - * Instantiates a new user with the given name and ID - * - * @param name - * the name of the user - * @param id - * the ID number of the user - */ - public User(final String name, final Integer id) - { - super(); - this.name = name; - this.id = id; - } - - /** - * {@inheritDoc} - */ - @Override - public User getApplicationUser() - { - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public void setApplicationUser(final User user) - { - // This method is intentionally left blank as this class represents the application user - // itself - } - - /** - * {@inheritDoc} - */ - @Override - public Integer getId() - { - return id; - } - - /** - * Sets the ID number of the user - * - * @param id - * the new ID number - */ - public void setId(final Integer id) - { - this.id = id; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() - { - return name; - } - - /** - * Sets the name of the user - * - * @param name - * the new name of the user - */ - public void setName(final String name) - { - this.name = name; - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageListener.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageListener.java deleted file mode 100644 index 9306044..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat.listener; - -/** - * The listener interface for receiving message events The class that is interested in processing a - * message implements this interface, and the object created with that class is registered with a - * component using the component's addMessageListener method When the message event - * occurs, the appropriate method of that object is invoked - * - * @param - * the generic type of the message event - */ -public interface MessageListener -{ - - /** - * Handles the given message event - * - * @param event - * the event containing the message to be processed - */ - void onMessage(final T event); -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageObject.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageObject.java deleted file mode 100644 index af1fb8e..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageObject.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat.listener; - -/** - * The Class {@link MessageObject} represents an object that contains a message event It - * encapsulates the source object on which the message event initially occurred - * - * @param - * the generic type of the source object - */ -public class MessageObject -{ - - /** - * The object on which the message event initially occurred - */ - protected transient T source; - - /** - * Instantiates a new {@code MessageObject} with the given source - * - * @param source - * the source object on which the message event occurred - * @throws IllegalArgumentException - * if the source is {@code null} - */ - public MessageObject(final T source) - { - if (source == null) - { - throw new IllegalArgumentException("null source"); - } - - this.source = source; - } - - /** - * Gets the source object on which the message event initially occurred - * - * @return the source object - */ - public T getSource() - { - return source; - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageSource.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageSource.java deleted file mode 100644 index 0f45579..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageSource.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat.listener; - -import java.util.Collection; - -/** - * The Interface {@link MessageSource} represents a source that can send messages to registered - * listeners It provides methods for adding, removing, and notifying {@link MessageListener} objects - * - * @param - * the generic type of the message object - */ -public interface MessageSource -{ - - /** - * Adds the given {@link MessageListener} to the list of listeners that will receive messages - * - * @param messageListener - * the {@link MessageListener} to be added - */ - void add(final MessageListener messageListener); - - /** - * Adds all the given {@link MessageListener} objects to the list of listeners that will receive - * messages - * - * @param messageListeners - * the collection of {@link MessageListener} objects to be added - */ - void addAll(final Collection> messageListeners); - - /** - * Fires a message to all registered listeners with the given source object - * - * @param source - * the message source object to be sent to listeners - */ - void fireMessage(final T source); - - /** - * Removes the given {@link MessageListener} from the list of listeners that receive messages - * - * @param messageListener - * the {@link MessageListener} to be removed - */ - void remove(final MessageListener messageListener); - - /** - * Removes all the given {@link MessageListener} objects from the list of listeners that receive - * messages - * - * @param messageListeners - * the collection of {@link MessageListener} objects to be removed - */ - void removeAll(final Collection> messageListeners); - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageSubject.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageSubject.java deleted file mode 100644 index 27485be..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/MessageSubject.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat.listener; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * The class {@link MessageSubject} represents a subject in the Observer design pattern for handling - * messages It maintains a list of {@link MessageListener} objects that are notified when a message - * is fired - * - * @param - * the generic type of the message object - */ -public class MessageSubject implements MessageSource -{ - /** The list of registered message listeners */ - private final List> messageListeners; - - /** The current message source */ - private T source; - - /** - * Initialization block to create the list of message listeners - **/ - { - messageListeners = new ArrayList<>(); - } - - /** - * Instantiates a new {@code MessageSubject} with no initial source - */ - public MessageSubject() - { - } - - /** - * Instantiates a new {@code MessageSubject} with the given initial source - * - * @param source - * the initial message source - */ - public MessageSubject(final T source) - { - this.source = source; - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void add(final MessageListener messageListener) - { - messageListeners.add(messageListener); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void addAll(final Collection> messageListeners) - { - this.messageListeners.addAll(messageListeners); - } - - /** - * Fires a message to all registered listeners with the current source - */ - private synchronized void fireMessage() - { - for (final MessageListener messageListener : messageListeners) - { - messageListener.onMessage(source); - } - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void fireMessage(final T source) - { - this.source = source; - fireMessage(); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void remove(final MessageListener messageListener) - { - messageListeners.remove(messageListener); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void removeAll(final Collection> messageListeners) - { - this.messageListeners.removeAll(messageListeners); - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/package-info.java deleted file mode 100644 index d09394e..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/listener/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Provides interfaces and classes for implementing listeners in a chat application using the observer design pattern - * - *

- * This package is focused on defining the components necessary for handling events in a chat system, specifically through the use of listeners - * Listeners are essential in the observer pattern as they allow objects to be notified of events, such as incoming messages or changes in chat state. - *

- * - *

- * The key interfaces and classes in this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.listener.MessageListener} - Represents a listener that reacts to message events in the chat system
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.listener.MessageObject} - Encapsulates the message event that is passed to listeners when a message is received
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.listener.MessageSource} - Represents the source of messages, managing the registration of listeners and the firing of message events
  • - *
- * - *

- * This package plays a crucial role in enabling dynamic communication between components in the chat application by allowing objects to react to specific events - * It demonstrates how to use the observer pattern to create responsive and interactive chat systems. - *

- */ -package io.github.astrapi69.design.pattern.observer.chat.listener; diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/package-info.java deleted file mode 100644 index 29c8722..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/chat/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Provides classes and interfaces for implementing a chat application using the observer design pattern - * - *

- * The chat package includes implementations of chat rooms, users, and messages, all of which interact through the observer pattern - * This package demonstrates how to structure a chat system where users can send and receive messages, and how those messages - * are propagated to all participants in the chat room. - *

- * - *

- * The key components of this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.ChatRoom} - Represents a chat room where users can exchange messages
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.ChatRoomUser} - Represents a user participating in a chat room
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.Message} - An interface for messages sent within the chat room
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.StringMessage} - A concrete implementation of {@link io.github.astrapi69.design.pattern.observer.chat.Message} for text-based messages
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.chat.User} - Represents a user entity in the chat system
  • - *
- * - *

- * The observer design pattern allows the chat application to notify all users in a chat room when a new message is received - * This package demonstrates a flexible and extensible way to implement such functionality using Java. - *

- */ -package io.github.astrapi69.design.pattern.observer.chat; diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventListener.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventListener.java deleted file mode 100644 index 7813a80..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -/** - * The {@link EventListener} interface is for receiving events The class that is interested in - * processing an event implements this interface, and the object created with that class is - * registered with a component using the component's addEventListener method When the - * event occurs, that object's appropriate method is invoked - * - * @param - * the generic type of the event to be processed - */ -public interface EventListener -{ - - /** - * Handles the given event - * - * @param event - * the event to be handled - */ - void onEvent(final T event); - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventObject.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventObject.java deleted file mode 100644 index ee62314..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventObject.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NonNull; -import lombok.ToString; -import lombok.experimental.SuperBuilder; - -/** - * The class {@link EventObject} serves, as its name suggests, as an event object It encapsulates - * the source object on which an event initially occurred - * - * @param - * the generic type of the source object - */ -@Getter -@EqualsAndHashCode -@ToString -@SuperBuilder -public class EventObject -{ - - /** - * The object on which the Event initially occurred - */ - protected transient T source; - - /** - * Instantiates a new {@link EventObject} object - * - * @param source - * the source object on which the event occurred - */ - public EventObject(final @NonNull T source) - { - this.source = source; - } - - /** - * Factory method to create a new {@link EventObject} object - * - * @param - * the generic type of the source object - * @param source - * the source object on which the event occurred - * @return the newly created {@link EventObject} object - */ - public static EventObject of(final @NonNull T source) - { - return EventObject. builder().source(source).build(); - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventSource.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventSource.java deleted file mode 100644 index e90334b..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventSource.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import java.util.Collection; - -/** - * The interface {@link EventSource} represents a source of events It provides methods to manage - * event listeners and to fire events to those listeners - * - * @param - * the generic type of the source object - */ -public interface EventSource -{ - - /** - * Adds the given event listener to the list of event listeners - * - * @param eventListener - * the event listener to be added - */ - void add(final EventListener eventListener); - - /** - * Adds all the given event listeners to the list of event listeners - * - * @param eventListeners - * the collection of event listeners to be added - */ - void addAll(final Collection> eventListeners); - - /** - * Fires an event to all registered listeners with the given source object - * - * @param source - * the source object that the event relates to - */ - void fireEvent(final T source); - - /** - * Removes the given event listener from the list of event listeners - * - * @param eventListener - * the event listener to be removed - */ - void remove(final EventListener eventListener); - - /** - * Removes all the given event listeners from the list of event listeners - * - * @param eventListeners - * the collection of event listeners to be removed - */ - void removeAll(final Collection> eventListeners); - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventSubject.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventSubject.java deleted file mode 100644 index 0414421..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/EventSubject.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import java.util.ArrayList; -import java.util.Collection; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NonNull; -import lombok.ToString; - -/** - * The class {@link EventSubject} is an implementation of the {@link EventSource} interface It - * represents a subject that can have multiple event listeners and can fire events to them - * - * @param - * the generic type of the source object - */ -@Getter -@EqualsAndHashCode -@ToString -public class EventSubject implements EventSource -{ - - /** The collection of registered event listeners */ - private final Collection> eventListeners; - - /** The source object associated with the event */ - private T source; - - /* Initialization block to initialize the eventListeners collection */ - { - eventListeners = new ArrayList<>(); - } - - /** - * Instantiates a new {@code EventSubject} with no initial source - */ - public EventSubject() - { - } - - /** - * Instantiates a new {@code EventSubject} with the specified source - * - * @param source - * the source object associated with the event - */ - public EventSubject(final T source) - { - this.source = source; - } - - /** - * Factory method to create a new {@link EventSubject} object - * - * @param - * the generic type of the source object - * @param source - * the source object associated with the event - * @return the newly created {@link EventSubject} object - */ - public static EventSubject of(final @NonNull T source) - { - return new EventSubject<>(source); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void add(final EventListener eventListener) - { - eventListeners.add(eventListener); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void addAll(final Collection> eventListeners) - { - this.eventListeners.addAll(eventListeners); - } - - /** - * Fires the event to all registered listeners - */ - private synchronized void fireEvent() - { - for (final EventListener eventListener : eventListeners) - { - eventListener.onEvent(source); - } - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void fireEvent(final T source) - { - this.source = source; - fireEvent(); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void remove(final EventListener eventListener) - { - eventListeners.remove(eventListener); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void removeAll(final Collection> eventListeners) - { - this.eventListeners.removeAll(eventListeners); - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/package-info.java deleted file mode 100644 index 6ea7374..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/event/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Provides classes and interfaces for implementing event handling in the observer design pattern - * - *

- * This package is designed to manage events and event sources within the observer pattern framework - * It includes the necessary components for creating, firing, and handling events, allowing objects to respond dynamically to changes in other objects' states. - *

- * - *

- * The key interfaces and classes in this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.event.EventListener} - Represents an interface for handling events that occur within the system
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.event.EventObject} - Encapsulates the event data, acting as a carrier of the information related to the event
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.event.EventSource} - Represents the source of events, managing event listeners and the firing of events
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.event.EventSubject} - A concrete implementation of {@link io.github.astrapi69.design.pattern.observer.event.EventSource}, which manages a collection of event listeners and notifies them when an event occurs
  • - *
- * - *

- * This package is essential for building a robust event-driven architecture within an application, enabling objects to communicate changes efficiently and effectively - * It demonstrates how to use the observer pattern to manage and propagate events throughout a system. - *

- */ -package io.github.astrapi69.design.pattern.observer.event; diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionEvent.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionEvent.java deleted file mode 100644 index 8124607..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionEvent.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class {@link ExceptionEvent} represents an event that encapsulates a {@link Throwable} object - * It acts as an observable event that can be passed to listeners interested in handling exceptions - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class ExceptionEvent -{ - /** The {@link Throwable} object associated with this event */ - private Throwable value; - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionListener.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionListener.java deleted file mode 100644 index 5b96740..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception; - -import java.util.EventListener; - -/** - * The listener interface for receiving exception events The class that is interested in processing - * an exception event implements this interface, and the object created with that class is - * registered with a component using the component's addExceptionListener method When - * the exception event occurs, that object's appropriate method is invoked - * - * @see ExceptionEvent - */ -public interface ExceptionListener extends EventListener -{ - - /** - * Invoked when an exception event occurs - * - * @param event - * the exception event to be processed - */ - void onException(final ExceptionEvent event); - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionMessage.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionMessage.java deleted file mode 100644 index 3acc12c..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionMessage.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception; - -import java.io.Serializable; -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class {@link ExceptionMessage} represents a message object used in exception handling It - * encapsulates information such as a properties key and value, an ID, and additional data that may - * be related to the exception - * - * @version 1.0 - * @param - * the generic type of the additional data - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class ExceptionMessage implements Serializable -{ - - /** The serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The key reference for a property in the resource bundle */ - private String propertiesKey; - - /** The value reference for a property in the resource bundle */ - private String propertiesValue; - - /** The unique identifier in the database */ - private String id; - - /** A list of additional data related to the exception */ - private List additions; - - /** - * Constructor for creating an {@code ExceptionMessage} with specified key, value, and ID - * - * @param propertiesKey - * the key reference for a property in the resource bundle - * @param propertiesValue - * the value reference for a property in the resource bundle - * @param id - * the unique identifier in the database - */ - public ExceptionMessage(final String propertiesKey, final String propertiesValue, - final String id) - { - this(propertiesKey, propertiesValue, id, null); - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionMessages.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionMessages.java deleted file mode 100644 index 7cc6d4c..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionMessages.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * The class {@link ExceptionMessages} manages a collection of exception messages organized by keys - * It allows adding, retrieving, and removing exception messages based on specific keys - * - * @param - * the generic type of the additional data contained in the exception messages - */ -public class ExceptionMessages -{ - - /** A map that contains all exception messages, organized by keys */ - private final Map>> exceptions = new HashMap<>(); - - /** - * Adds a map of exception messages to the existing collection - * - * @param keyListMap - * the map of keys and corresponding sets of exception messages to be added - */ - public void add(final Map>> keyListMap) - { - this.exceptions.putAll(keyListMap); - } - - /** - * Adds an exception message to the collection under the specified key - * - * @param key - * the key under which the exception message should be stored - * @param value - * the exception message to be added - */ - public void add(final String key, final ExceptionMessage value) - { - Set> values = this.exceptions.get(key); - if (values == null) - { - values = new HashSet<>(); - this.exceptions.put(key, values); - } - values.add(value); - } - - /** - * Checks if the collection contains exception messages associated with the specified key - * - * @param key - * the key to be checked - * @return true if the key exists in the collection, otherwise false - */ - public boolean containsKey(final String key) - { - return this.exceptions.containsKey(key); - } - - /** - * Retrieves the set of exception messages associated with the specified key - * - * @param key - * the key whose associated exception messages are to be returned - * @return the set of exception messages associated with the specified key, or null if no - * messages are found - */ - public Set> get(final String key) - { - return this.exceptions.get(key); - } - - /** - * Retrieves the set of all keys used in the collection - * - * @return the set of all keys - */ - public Set getKeys() - { - return this.exceptions.keySet(); - } - - /** - * Gets the number of unique keys in the collection - * - * @return the number of unique keys - */ - public int getSize() - { - return this.exceptions.size(); - } - - /** - * Checks if the collection is empty - * - * @return true if the collection contains no entries, otherwise false - */ - public boolean isEmpty() - { - return this.exceptions.isEmpty(); - } - - /** - * Removes all exception messages associated with the specified key - * - * @param key - * the key whose associated exception messages are to be removed - * @return the set of exception messages that were removed, or null if the key was not found - */ - public Set> remove(final String key) - { - return this.exceptions.remove(key); - } - - /** - * Removes all exception messages associated with the specified collection of keys - * - * @param keys - * the collection of keys whose associated exception messages are to be removed - */ - public void removeAll(final Collection keys) - { - for (final String key : keys) - { - this.remove(key); - } - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionObservers.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionObservers.java deleted file mode 100644 index d3d1298..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/ExceptionObservers.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception; - -import java.util.ArrayList; -import java.util.List; - -/** - * The class {@link ExceptionObservers} is a singleton that manages a list of - * {@link ExceptionListener} objects It allows classes to register and unregister for exception - * events, and notifies registered listeners when an exception event occurs - */ -public class ExceptionObservers -{ - - /** The single instance of this class */ - private static ExceptionObservers instance = null; - - /** The list of registered exception listeners */ - protected List exceptionListeners = new ArrayList<>(); - - /** - * Instantiates a new {@code ExceptionObservers} object This constructor is private to enforce - * the singleton pattern - */ - private ExceptionObservers() - { - } - - /** - * Gets the single instance of {@code ExceptionObservers} - * - * @return the single instance of {@code ExceptionObservers} - */ - public static synchronized ExceptionObservers getInstance() - { - synchronized (ExceptionObservers.class) - { - if (instance == null) - { - instance = new ExceptionObservers(); - } - } - return instance; - } - - /** - * Adds the specified exception listener to the list of listeners This method allows classes to - * register for exception events - * - * @param listener - * the exception listener to be added - */ - public void addExceptionListener(final ExceptionListener listener) - { - exceptionListeners.add(listener); - } - - /** - * Fires an exception event to all registered listeners - * - * @param event - * the exception event to be fired - */ - void fireExceptionEvent(final ExceptionEvent event) - { - final int listenerSize = exceptionListeners.size(); - for (int i = 0; i < listenerSize; i++) - { - final ExceptionListener lis = exceptionListeners.get(i); - lis.onException(event); - } - } - - /** - * Removes the specified exception listener from the list of listeners This method allows - * classes to unregister for exception events - * - * @param listener - * the exception listener to be removed - */ - public void removeExceptionListener(final ExceptionListener listener) - { - exceptionListeners.remove(listener); - } -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/AbstractExceptionHandler.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/AbstractExceptionHandler.java deleted file mode 100644 index 290e754..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/AbstractExceptionHandler.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception.handlers; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionListener; - -/** - * The abstract class {@link AbstractExceptionHandler} handles all exceptions by managing a list of - * {@link ExceptionListener} objects and updating them when an exception event occurs - * - * @version 1.0 - * @author Asterios Raptis - */ -public abstract class AbstractExceptionHandler implements Serializable -{ - - /** The serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = 1L; - - /** The list of registered {@link ExceptionListener} objects */ - private final List listeners = new ArrayList<>(); - - /** - * Adds an {@link ExceptionListener} object to the list of listeners - * - * @param listener - * the listener to be added - */ - void addExceptionListener(final ExceptionListener listener) - { - listeners.add(listener); - } - - /** - * Removes an {@link ExceptionListener} object from the list of listeners - * - * @param listener - * the listener to be removed - */ - void removeExceptionListener(final ExceptionListener listener) - { - listeners.remove(listener); - } - - /** - * Updates all registered listeners with the given exception event - * - * @param event - * the exception event to be propagated to the listeners - */ - void update(final ExceptionEvent event) - { - for (final ExceptionListener listener : listeners) - { - updateEvent(listener, event); - } - } - - /** - * Updates the specified listener with the given exception event This method must be implemented - * by subclasses to define how the event is propagated to the listener - * - * @param listener - * the listener to be updated - * @param event - * the exception event to be propagated to the listener - */ - public abstract void updateEvent(final ExceptionListener listener, final ExceptionEvent event); - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/DefaultExceptionHandler.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/DefaultExceptionHandler.java deleted file mode 100644 index 88c1518..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/DefaultExceptionHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.exception.handlers; - -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionListener; - -/** - * The class {@link DefaultExceptionHandler} provides a default implementation for handling - * exception events It extends {@link AbstractExceptionHandler} and propagates exception events to - * the registered listeners - */ -public class DefaultExceptionHandler extends AbstractExceptionHandler -{ - - /** The serialVersionUID for serialization compatibility */ - private static final long serialVersionUID = -7194471234913656513L; - - /** - * {@inheritDoc} - */ - @Override - public void updateEvent(final ExceptionListener listener, final ExceptionEvent event) - { - listener.onException(event); - } - - /** - * Updates all registered listeners with the given exception event - * - * @param event - * the exception event to be propagated to the listeners - */ - public void updateOnException(final ExceptionEvent event) - { - super.update(event); - } - -} diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/package-info.java deleted file mode 100644 index f5cfa01..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/handlers/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Provides classes for handling exceptions using the observer design pattern - * - *

- * This package is focused on managing exception events and notifying registered listeners when exceptions occur - * By utilizing the observer pattern, it allows for a flexible and decoupled approach to exception handling, where multiple components can respond to exceptions in a coordinated manner. - *

- * - *

- * The key classes in this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.handlers.AbstractExceptionHandler} - An abstract base class that provides common functionality for managing exception listeners and propagating exception events
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.handlers.DefaultExceptionHandler} - A concrete implementation of {@link io.github.astrapi69.design.pattern.observer.exception.handlers.AbstractExceptionHandler} that provides default behavior for handling exceptions and notifying listeners
  • - *
- * - *

- * This package is essential for building a robust exception handling mechanism within an application, allowing for centralized and consistent management of exception events - * It demonstrates how the observer pattern can be applied to exception handling to ensure that exceptions are effectively communicated and managed across the system. - *

- */ -package io.github.astrapi69.design.pattern.observer.exception.handlers; diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/package-info.java deleted file mode 100644 index 6fff172..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/exception/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Provides classes and interfaces for handling exceptions using the observer design pattern - * - *

- * This package is designed to facilitate the management and communication of exceptions within an application - * By using the observer pattern, it allows multiple components to listen for and respond to exception events, enabling a decoupled and flexible approach to exception handling. - *

- * - *

- * The key interfaces and classes in this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent} - Encapsulates an exception event, carrying information about an exception that has occurred
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.ExceptionListener} - Represents a listener that reacts to exception events, allowing components to respond when exceptions occur
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.ExceptionMessage} - Represents a structured message related to an exception, containing details such as a properties key, value, and additional data
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.ExceptionObservers} - Manages a collection of exception listeners and notifies them when an exception event occurs, following the singleton pattern
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.exception.ExceptionMessages} - Manages a collection of exception messages organized by keys, providing methods to add, retrieve, and remove messages
  • - *
- * - *

- * This package is crucial for implementing a centralized and consistent approach to exception handling in an application - * It demonstrates how the observer pattern can be applied to ensure that exceptions are effectively communicated and managed across different components in the system. - *

- */ -package io.github.astrapi69.design.pattern.observer.exception; diff --git a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/package-info.java b/observer/src/main/java/io/github/astrapi69/design/pattern/observer/package-info.java deleted file mode 100644 index cb8a5df..0000000 --- a/observer/src/main/java/io/github/astrapi69/design/pattern/observer/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Provides core classes and interfaces for implementing the observer design pattern - * - *

- * The observer design pattern is a behavioral design pattern where an object, known as the subject, maintains a list of its dependents, called observers, - * and notifies them automatically of any state changes, usually by calling one of their methods - * This package contains the foundational components necessary for building systems based on the observer pattern, enabling objects to be notified of changes in other objects' states. - *

- * - *

- * The key interfaces and classes in this package include: - *

- *
    - *
  • {@link io.github.astrapi69.design.pattern.observer.AbstractObserver} - A base class that provides a concrete implementation of the observer interface, handling updates and executing commands
  • - *
  • {@link io.github.astrapi69.design.pattern.observer.AbstractSubject} - A base class that provides a concrete implementation of the subject interface, managing observers and updating them when changes occur
  • - *
- * - *

- * This package is essential for creating systems where objects need to be informed of state changes in other objects, promoting loose coupling and dynamic behavior - * It demonstrates the flexibility and power of the observer design pattern in a wide range of application scenarios. - *

- */ -package io.github.astrapi69.design.pattern.observer; diff --git a/observer/src/main/java/module-info.java b/observer/src/main/java/module-info.java deleted file mode 100644 index 0be17e3..0000000 --- a/observer/src/main/java/module-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -module design.patterns.observer -{ - requires lombok; - - exports io.github.astrapi69.design.pattern.observer.api; - exports io.github.astrapi69.design.pattern.observer.chat; - exports io.github.astrapi69.design.pattern.observer.chat.listener; - exports io.github.astrapi69.design.pattern.observer.event; - exports io.github.astrapi69.design.pattern.observer.exception; - exports io.github.astrapi69.design.pattern.observer.exception.handlers; -} diff --git a/observer/src/main/resources/LICENSE.txt b/observer/src/main/resources/LICENSE.txt deleted file mode 100644 index 9160e17..0000000 --- a/observer/src/main/resources/LICENSE.txt +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (C) ${year} ${owner} - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/observer/src/main/resources/META-INF/MANIFEST.MF b/observer/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 348f1bd..0000000 --- a/observer/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1 +0,0 @@ -Manifest-Version: 1.0 \ No newline at end of file diff --git a/observer/src/main/resources/log4j.properties b/observer/src/main/resources/log4j.properties deleted file mode 100644 index e07168e..0000000 --- a/observer/src/main/resources/log4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.appender.Stdout=org.apache.log4j.ConsoleAppender -log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n - -log4j.rootLogger=INFO,Stdout - -log4j.logger.org.apache.wicket=INFO -log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO -log4j.logger.org.apache.wicket.version=INFO -log4j.logger.org.apache.wicket.RequestCycle=INFO \ No newline at end of file diff --git a/observer/src/main/resources/log4j2.xml b/observer/src/main/resources/log4j2.xml deleted file mode 100644 index e43e1b9..0000000 --- a/observer/src/main/resources/log4j2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/DemonstrateObserverPattern.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/DemonstrateObserverPattern.java deleted file mode 100644 index 48d2c0c..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/DemonstrateObserverPattern.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; - -/** - * The Class DemonstrateObserverPattern. - */ -public class DemonstrateObserverPattern -{ - - /** - * The main method. - * - * @param args - * the args - * @throws InterruptedException - */ - public static void main(final String[] args) throws InterruptedException - { - // Create a Subject... - System.out.println("Create a Subject..."); - final Subject> eventSubject = new ExceptionEventSubject(); - // and three Observer... - System.out.println("and three Observer..."); - new ExceptionEventObserver(eventSubject); - new ShowExceptionView(eventSubject); - new GetStacktraceDisplayView(eventSubject); - // Create the first ExceptionEvent as Observable... - System.out.println("Create the first ExceptionEvent as Observable..."); - ExceptionEvent exceptionEvent = new ExceptionEvent( - new Exception("the first ExceptionEvent")); - // Set the first Observable... - System.out.println("Set the first Observable..."); - eventSubject.setObservable(exceptionEvent); - System.out.println("wait 2 seconds..."); - // wait 2 seconds... - Thread.sleep(2000); - // Set the second ExceptionEvent as Observable... - System.out.println("Set the second ExceptionEvent as Observable..."); - exceptionEvent = new ExceptionEvent(new Exception("the second ExceptionEvent")); - // Set the second Observable... - System.out.println("Set the second Observable..."); - eventSubject.setObservable(exceptionEvent); - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ExceptionEventObserver.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ExceptionEventObserver.java deleted file mode 100644 index fe1c95d..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ExceptionEventObserver.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; - -/** - * The Class ExceptionEventDisplayView. - */ -public class ExceptionEventObserver extends AbstractObserver -{ - - /** - * Instantiates a new exception event display view. - * - * @param subject - * the subject - */ - public ExceptionEventObserver(final Subject> subject) - { - super(subject); - } - - /** - * (non-Javadoc) - * - * @see io.github.astrapi69.design.pattern.observer.api.ActionCommand#execute() - */ - @Override - public void execute() - { - System.out - .println("From ExceptionEventDisplayView:::" + getObservable().toString() + ":::"); - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ExceptionEventSubject.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ExceptionEventSubject.java deleted file mode 100644 index fb528ec..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ExceptionEventSubject.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; - -/** - * The Class EventSubject. - */ -public class ExceptionEventSubject extends AbstractSubject> - implements - Subject> -{ -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/GetStacktraceDisplayView.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/GetStacktraceDisplayView.java deleted file mode 100644 index fb6a8e9..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/GetStacktraceDisplayView.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; - -/** - * The Class GetStacktraceDisplayView. - */ -public class GetStacktraceDisplayView extends AbstractObserver -{ - - /** - * Instantiates a new gets the stacktrace display view. - * - * @param subject - * the subject - */ - public GetStacktraceDisplayView(final Subject> subject) - { - super(subject); - } - - /** - * (non-Javadoc) - * - * @see io.github.astrapi69.design.pattern.observer.api.ActionCommand#execute() - */ - @Override - public void execute() - { - - System.out.print("From GetStacktraceView:"); - getObservable().getValue().printStackTrace(); - - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ShowExceptionView.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ShowExceptionView.java deleted file mode 100644 index 8671ab9..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/ShowExceptionView.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer; - -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; -import io.github.astrapi69.design.pattern.observer.exception.ExceptionEvent; - -/** - * The Class ShowExceptionView. - */ -public class ShowExceptionView extends AbstractObserver -{ - - /** - * Instantiates a new show exception view. - * - * @param subject - * the subject - */ - public ShowExceptionView(final Subject> subject) - { - super(subject); - } - - /** - * (non-Javadoc). - * - * @see io.github.astrapi69.design.pattern.observer.api.ActionCommand#execute() - */ - @Override - public void execute() - { - System.out.println("From ShowExceptionView:::" + getObservable().getValue() + ":::"); - - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/ApplicationUser.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/ApplicationUser.java deleted file mode 100644 index e4bec50..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/ApplicationUser.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import java.io.Serializable; - -import io.github.astrapi69.auth.SimpleUser; - -/** - * The class {@link ApplicationUser} represents a user in the chat application It implements the - * {@link IUser} interface, providing methods to manage the application user's identity - */ -public class ApplicationUser implements IUser -{ - - private static final long serialVersionUID = 1L; - private SimpleUser applicationUser; - - /** - * {@inheritDoc} - */ - @Override - public SimpleUser getApplicationUser() - { - return this.applicationUser; - } - - /** - * {@inheritDoc} - */ - @Override - public void setApplicationUser(final SimpleUser user) - { - this.applicationUser = user; - } - - /** - * {@inheritDoc} - */ - @Override - public Serializable getId() - { - return this.applicationUser.getId(); - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() - { - return this.applicationUser.getUsername(); - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/DataChatRoomUser.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/DataChatRoomUser.java deleted file mode 100644 index e5568ef..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/DataChatRoomUser.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -/** - * The class {@link DataChatRoomUser} represents a user in a chat room who can send and receive - * {@link ChatMessage} objects It extends {@link ChatRoomUser} and provides specific behavior for - * handling {@link ChatMessage} objects - */ -public class DataChatRoomUser extends ChatRoomUser -{ - - private static final long serialVersionUID = 1L; - - /** - * Instantiates a new {@code DataChatRoomUser} with the specified chat room and user - * - * @param room - * the chat room - * @param user - * the user associated with this chat room user - */ - public DataChatRoomUser(final ChatRoom room, final IUser user) - { - super(room, user); - } - - /** - * {@inheritDoc} - */ - @Override - public void execute() - { - final String display = "----------------------------------------------\n" - + getUser().getName() + " sees the Message:\n" + getObservable().getValue().getMessage() - + "\n----------------------------------------------"; - System.out.println(display); - } - - /** - * {@inheritDoc} - */ - @Override - public void send(final ChatMessage message) - { - System.out.println("In chat room '" + subject.getName() + "' the user:\n" - + getUser().getName() + " tells:" + message.getValue().getMessage()); - super.send(message); - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/DemonstrateChatObserver.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/DemonstrateChatObserver.java deleted file mode 100644 index 071843b..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/DemonstrateChatObserver.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -import io.github.astrapi69.design.pattern.observer.api.Subject; - -/** - * The class {@link DemonstrateChatObserver} demonstrates the usage of the chat observer pattern - * with various chat rooms and users This class contains a main method that simulates a chat session - * between multiple users in different chat rooms - */ -public class DemonstrateChatObserver -{ - - /** - * The main method that simulates a chat session between multiple users in different chat rooms - * - * @param args - * the command line arguments - */ - public static void main(final String[] args) - { - - final ChatRoomService chatRoomService = new ChatRoomService<>(); - final Subject> firstRoom = chatRoomService - .getChatRoom(new StringMessage().setValue("Welcome in this chat room"), - "First chat room"); - final Subject> secondRoom = chatRoomService - .getChatRoom(new StringMessage().setValue("Welcome in this chat room"), - "Second chat room"); - final User antonUser = new User("anton", 1); - final User johnUser = new User("john", 2); - final User alfredUser = new User("alfred", 3); - final ChatRoomUser antonFirstRoom = new SimpleChatRoomUser( - (ChatRoom)firstRoom, antonUser); - final ChatRoomUser johnFirstRoom = new SimpleChatRoomUser( - (ChatRoom)firstRoom, johnUser); - final ChatRoomUser alfredFirstRoom = new ChatRoomUser( - (ChatRoom)firstRoom, alfredUser) - { - - private static final long serialVersionUID = 1L; - - @Override - public void execute() - { - final String display = "----------------------------------------------\n" - + alfredUser.getName() + " sees the Message:\n" + getObservable().getValue() - + "\n----------------------------------------------"; - System.out.println(display); - } - - @Override - public void send(final StringMessage message) - { - System.out.println("In chat room '" + subject.getName() + "' the user:\n" - + getUser().getName() + " tells:" + message.getValue()); - super.send(message); - } - - }; - - final ChatRoomUser antonSecondRoom = new SimpleChatRoomUser( - (ChatRoom)secondRoom, antonUser); - final ChatRoomUser johnSecondRoom = new SimpleChatRoomUser( - (ChatRoom)secondRoom, johnUser); - StringMessage message = new StringMessage("Hello everybody"); - System.out.println("########## New message ##############"); - antonFirstRoom.send(message); - antonSecondRoom.send(message); - message = new StringMessage("Hello anton"); - System.out.println("########## New message ##############"); - johnFirstRoom.send(message); - johnSecondRoom.send(message); - message = new StringMessage("Hello anton and john. Im alfred."); - System.out.println("########## New message ##############"); - alfredFirstRoom.send(message); - message = new StringMessage("Im leafing this room"); - System.out.println("########## New message ##############"); - antonFirstRoom.send(message); - firstRoom.remove(antonFirstRoom); - message = new StringMessage("how old are you John"); - System.out.println("########## New message ##############"); - alfredFirstRoom.send(message); - message = new StringMessage("Im leafing this room"); - System.out.println("########## New message ##############"); - johnFirstRoom.send(message); - firstRoom.remove(johnFirstRoom); - message = new StringMessage("im alone now :-(("); - System.out.println("########## New message ##############"); - alfredFirstRoom.send(message); - message = new StringMessage("Im leaving this room too..."); - System.out.println("########## New message ##############"); - alfredFirstRoom.send(message); - firstRoom.remove(alfredFirstRoom); - - System.out.println("########## Data message service ##############"); - final ChatRoomService chatRoomSeriveExtended = new ChatRoomService<>(); - final User rootUser = new User("root", 0); - MessageRoomModelBean messageRoomModel = new MessageRoomModelBean("", rootUser, "", null); - ChatMessage chatMessage = new ChatMessage().setValue(messageRoomModel); - final ChatRoom firstFileRoom = chatRoomSeriveExtended.getChatRoom(chatMessage, - "file chat room 1"); - - final ChatRoomUser antonFirstFileRoom = new DataChatRoomUser(firstFileRoom, - antonUser); - final ChatRoomUser johnFirstFileRoom = new DataChatRoomUser(firstFileRoom, - johnUser); - messageRoomModel = new MessageRoomModelBean(firstFileRoom.getName(), antonUser, "Foo bar", - null); - chatMessage = new ChatMessage().setValue(messageRoomModel); - System.out.println("########## New message ##############"); - antonFirstFileRoom.send(chatMessage); - messageRoomModel = new MessageRoomModelBean(firstFileRoom.getName(), johnUser, "Bar foo", - null); - chatMessage = new ChatMessage().setValue(messageRoomModel); - johnFirstFileRoom.send(chatMessage); - - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/SimpleChatRoomUser.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/SimpleChatRoomUser.java deleted file mode 100644 index 7889b4f..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/SimpleChatRoomUser.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.chat; - -/** - * The class {@link SimpleChatRoomUser} represents a user in a chat room who can send and receive - * string messages It extends {@link ChatRoomUser} and provides specific behavior for handling - * {@link StringMessage} objects - */ -public class SimpleChatRoomUser extends ChatRoomUser -{ - - private static final long serialVersionUID = 1L; - - /** - * Instantiates a new {@code SimpleChatRoomUser} with the specified chat room and user - * - * @param room - * the chat room - * @param user - * the user associated with this chat room user - */ - public SimpleChatRoomUser(final ChatRoom room, final IUser user) - { - super(room, user); - } - - /** - * {@inheritDoc} - */ - @Override - public void execute() - { - final String display = "----------------------------------------------\n" - + getUser().getName() + " sees the Message:\n" + getObservable().getValue() - + "\n----------------------------------------------"; - System.out.println(display); - } - - /** - * {@inheritDoc} - */ - @Override - public void send(final StringMessage message) - { - System.out.println("In chat room '" + subject.getName() + "' the user:\n" - + getUser().getName() + " tells:" + message.getValue()); - super.send(message); - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatApp.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatApp.java deleted file mode 100644 index fea8473..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatApp.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.github.astrapi69.design.pattern.observer.chat.example; - -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.*; - -import io.github.astrapi69.design.pattern.observer.chat.IUser; - -public class ChatApp -{ - - private JFrame frame; - private JTextArea chatArea; - private JTextField inputField; - private ChatRoom chatRoom; - - public static void main(String[] args) - { - SwingUtilities.invokeLater(ChatApp::new); - } - - public ChatApp() - { - initialize(); - } - - private void initialize() - { - // Create the chat room - chatRoom = new ChatRoom<>("General"); - - // Create some users - User user1 = new User("Alice", 1); - User user2 = new User("Bob", 2); - - // Register the users in the chat room - ChatRoomUser chatUser1 = new ChatRoomUserImpl(chatRoom, user1); - ChatRoomUser chatUser2 = new ChatRoomUserImpl(chatRoom, user2); - - // Set up the frame - frame = new JFrame("Chat Room"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(400, 300); - frame.setLayout(new BorderLayout()); - - // Create chat area - chatArea = new JTextArea(); - chatArea.setEditable(false); - frame.add(new JScrollPane(chatArea), BorderLayout.CENTER); - - // Create input field - inputField = new JTextField(); - inputField.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - String text = inputField.getText(); - if (!text.isEmpty()) - { - StringMessage message = new StringMessage(text); - chatUser1.send(message); - inputField.setText(""); - } - } - }); - frame.add(inputField, BorderLayout.SOUTH); - - // Show the frame - frame.setVisible(true); - - // Simulate a message from another user - Timer timer = new Timer(5000, new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - StringMessage message = new StringMessage("Hello from " + user2.getName() + "!"); - chatUser2.send(message); - } - }); - timer.setRepeats(false); - timer.start(); - } - - // Implementation of a simple ChatRoomUser that updates the chat area when a message is received - private class ChatRoomUserImpl extends ChatRoomUser - { - - public ChatRoomUserImpl(ChatRoom room, IUser user) - { - super(room, user); - } - - @Override - public void execute() - { - SwingUtilities.invokeLater(() -> chatArea - .append(getUser().getName() + ": " + getObservable().getValue() + "\n")); - } - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatRoom.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatRoom.java deleted file mode 100644 index 32b273d..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatRoom.java +++ /dev/null @@ -1,115 +0,0 @@ -package io.github.astrapi69.design.pattern.observer.chat.example; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import io.github.astrapi69.design.pattern.observer.AbstractSubject; -import io.github.astrapi69.design.pattern.observer.chat.IUser; -import io.github.astrapi69.design.pattern.observer.chat.Message; -import io.github.astrapi69.design.pattern.observer.chat.Room; - -public class ChatRoom> extends AbstractSubject> - implements - Room, - Serializable -{ - - private static final long serialVersionUID = 1L; - private final List> observers = new ArrayList<>(); - private final List messageHistory = new ArrayList<>(); - private final String name; - private M observable; - - public ChatRoom(String name) - { - this.name = name; - } - - public ChatRoom(M observable, String name) - { - this.observable = observable; - this.name = name; - } - - @Override - public synchronized void add(ChatRoomUser observer) - { - observers.add(observer); - } - - @Override - public void addAll(Collection> observers) - { - this.observers.addAll(observers); - } - - @Override - public List> getChatRoomUsers() - { - List> chatRoomUsers = new ArrayList<>(); - for (ChatRoomUser chatUser : observers) - { - chatRoomUsers.add(chatUser.getUser()); - } - return chatRoomUsers; - } - - @Override - public List getMessageHistory() - { - return messageHistory; - } - - @Override - public synchronized M getObservable() - { - return observable; - } - - @Override - public synchronized void setObservable(M observable) - { - this.observable = observable; - messageHistory.add(observable); - updateObservers(); - } - - @Override - public boolean isSecure() - { - return false; - } - - @Override - public synchronized void remove(ChatRoomUser observer) - { - observers.remove(observer); - } - - @Override - public void removeAll(Collection> observers) - { - this.observers.removeAll(observers); - } - - public int size() - { - return observers.size(); - } - - @Override - public synchronized void updateObservers() - { - for (ChatRoomUser observer : observers) - { - observer.update(observable); - } - } - - public String getName() - { - return name; - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatRoomUser.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatRoomUser.java deleted file mode 100644 index 6a512c1..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/ChatRoomUser.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.github.astrapi69.design.pattern.observer.chat.example; - -import java.io.Serializable; - -import io.github.astrapi69.design.pattern.observer.api.ActionCommand; -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.chat.IUser; -import io.github.astrapi69.design.pattern.observer.chat.Message; - -public abstract class ChatRoomUser> - implements - Observer, - ActionCommand, - Serializable -{ - - private static final long serialVersionUID = 1L; - private final IUser user; - protected ChatRoom subject; - private M observable; - - public ChatRoomUser(ChatRoom room, IUser user) - { - this.subject = room; - this.observable = this.subject.getObservable(); - this.user = user; - this.subject.add(this); - } - - @Override - public synchronized void update(M observable) - { - this.observable = observable; - execute(); - } - - public synchronized M getObservable() - { - return observable; - } - - public IUser getUser() - { - return user; - } - - public void send(M message) - { - subject.setObservable(message); - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/StringMessage.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/StringMessage.java deleted file mode 100644 index eae6310..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/StringMessage.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.astrapi69.design.pattern.observer.chat.example; - -import io.github.astrapi69.design.pattern.observer.chat.Message; - -public class StringMessage implements Message -{ - - private static final long serialVersionUID = 1L; - private String value; - - public StringMessage() - { - } - - public StringMessage(String value) - { - this.value = value; - } - - @Override - public String getValue() - { - return value; - } - - @Override - public StringMessage setValue(String value) - { - this.value = value; - return this; - } - - @Override - public String toString() - { - return "StringMessage [value=" + value + "]"; - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/User.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/User.java deleted file mode 100644 index 242940c..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/chat/example/User.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.github.astrapi69.design.pattern.observer.chat.example; - -import io.github.astrapi69.design.pattern.observer.chat.IUser; - -public class User implements IUser -{ - - private static final long serialVersionUID = 1L; - private String name; - private Integer id; - - public User(String name, Integer id) - { - this.name = name; - this.id = id; - } - - @Override - public User getApplicationUser() - { - return this; - } - - @Override - public void setApplicationUser(User user) - { - } - - @Override - public Integer getId() - { - return id; - } - - public void setId(Integer id) - { - this.id = id; - } - - @Override - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/DemonstrateEventListener.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/DemonstrateEventListener.java deleted file mode 100644 index aa8e40c..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/DemonstrateEventListener.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import javax.swing.JTextField; - -/** - * This class is to demonstrate the Event Listener interface. - */ -public class DemonstrateEventListener -{ - - /** - * The main method. - * - * @param args - * the arguments - */ - public static void main(final String[] args) - { - - withoutEventObject(); - - withEventObject(); - } - - private static void withEventObject() - { - final EventListener> printString = new EventListener>() - { - - @Override - public void onEvent(final EventObject event) - { - System.out.println(event.getSource().getText()); - - } - }; - final EventListener> printStringReverse = new EventListener>() - { - - @Override - public void onEvent(final EventObject event) - { - System.out.println(new StringBuffer(event.getSource().getText()).reverse()); - - } - }; - final JTextField tx = new JTextField("Hello"); - final EventObject eventObject = new EventObject<>(tx); - final EventSource> eventSource = new EventSubject<>(); - eventSource.add(printString); - eventSource.add(printStringReverse); - eventSource.fireEvent(eventObject); - tx.setText("good bye..."); - eventSource.fireEvent(eventObject); - } - - private static void withoutEventObject() - { - final EventListener printString = new EventListener() - { - - @Override - public void onEvent(final String event) - { - System.out.println(event); - - } - }; - final EventListener printStringReverse = new EventListener() - { - - @Override - public void onEvent(final String event) - { - System.out.println(new StringBuffer(event).reverse()); - - } - }; - final EventSource eventSource = new EventSubject<>(); - eventSource.add(printString); - eventSource.add(printStringReverse); - eventSource.fireEvent("Hallo"); - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/DemonstrateEventObserver.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/DemonstrateEventObserver.java deleted file mode 100644 index 0062cf8..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/DemonstrateEventObserver.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; - -public class DemonstrateEventObserver -{ - - public static void main(final String[] args) throws InterruptedException - { - System.out.println("Create a Subject..."); - final Subject> stateSubject = new StateSubject(); - new EventObserver(stateSubject); - stateSubject.setObservable(State.stop); - Thread.sleep(2000); - stateSubject.setObservable(State.spinning); - } -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/EventObserver.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/EventObserver.java deleted file mode 100644 index 126b19c..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/EventObserver.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import io.github.astrapi69.design.pattern.observer.AbstractObserver; -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; - -public class EventObserver extends AbstractObserver -{ - - public EventObserver(final Subject> subject) - { - super(subject); - } - - @Override - public void execute() - { - System.out.println("State of cylinder have changed and is " + getObservable().name()); - } - -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/State.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/State.java deleted file mode 100644 index 513c686..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/State.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -public enum State -{ - stop, spinning -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/StateSubject.java b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/StateSubject.java deleted file mode 100644 index 612c47f..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/event/StateSubject.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.observer.event; - -import io.github.astrapi69.design.pattern.observer.AbstractSubject; -import io.github.astrapi69.design.pattern.observer.api.Observer; -import io.github.astrapi69.design.pattern.observer.api.Subject; - -/** - * The Class StateSubject. - */ -public class StateSubject extends AbstractSubject> - implements - Subject> -{ -} diff --git a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/package.html b/observer/src/test/java/io/github/astrapi69/design/pattern/observer/package.html deleted file mode 100644 index 9bd6910..0000000 --- a/observer/src/test/java/io/github/astrapi69/design/pattern/observer/package.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - io.github.astrapi69.design.pattern.observer - - - - Provides test classes for the package 'io.github.astrapi69.design.pattern.observer'. - - diff --git a/observer/src/test/resources/log4j2-test.xml b/observer/src/test/resources/log4j2-test.xml deleted file mode 100644 index 7d76608..0000000 --- a/observer/src/test/resources/log4j2-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index abcb110..b06cc7d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,9 +2,5 @@ rootProject.name = 'design-patterns' include(':builder') include(':command') include(':decorator') -include(':eventbus') -include(':observer') -include(':state') include(':strategy') -include(':visitor') diff --git a/state/.gitignore b/state/.gitignore deleted file mode 100644 index 95ac387..0000000 --- a/state/.gitignore +++ /dev/null @@ -1,59 +0,0 @@ -################## -# Compiled files # -################## -*.class - -################## -# intellij files # -################## -*.iml -.idea -*/.idea - -################# -# eclipse files # -################# -/.project -/.classpath -/.settings -/.tern-project - -######################### -# maven generated files # -######################### -/target - -############# -# Zip files # -############# -*.tar -*.zip -*.7z -*.dmg -*.gz -*.iso -*.jar -*.rar - -############## -# Logs files # -############## -*.log - -################# -# test-ng files # -################# -/test-output - -############################ -# Binaries generated files # -############################ -/bin - -################ -# gradle files # -################ -/build -/.gradle -/gradle -/pom.xml.bak diff --git a/state/LICENSE b/state/LICENSE deleted file mode 100644 index 1bab125..0000000 --- a/state/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (C) 2015 Asterios Raptis - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/state/README.md b/state/README.md deleted file mode 100644 index 976c14e..0000000 --- a/state/README.md +++ /dev/null @@ -1 +0,0 @@ -# design-pattern state diff --git a/state/build.gradle b/state/build.gradle deleted file mode 100644 index ce67bf7..0000000 --- a/state/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "../gradle/dependencies-state.gradle" -apply from: "../gradle/licensing.gradle" -apply from: "../gradle/publishing-state.gradle" diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/button/ButtonState.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/button/ButtonState.java deleted file mode 100644 index 3b99ac5..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/button/ButtonState.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -/** - * The interface {@link ButtonState} represents a state in a button state machine. - * - * @param - * the generic type of the state machine object - */ -public interface ButtonState -{ -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/button/ButtonStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/button/ButtonStateMachine.java deleted file mode 100644 index 239db7c..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/button/ButtonStateMachine.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.SuperBuilder; - -/** - * The abstract class {@link ButtonStateMachine} can provide states on buttons. It manages the - * current state of a button and defines abstract methods for updating the button state and - * enabling/disabling the button. For an example, see the unit tests. - * - * @param - * the type parameter for the button - * @param - * the type parameter for the state - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -public abstract class ButtonStateMachine implements ButtonState -{ - /** - * The current state of the button. - */ - ButtonState current; - - /** - * The button associated with this state machine. - */ - @NonNull - T button; - - /** - * Updates the state of the button. - */ - protected abstract void updateButtonState(); - - /** - * Sets the enabled state of the button. - * - * @param enabled - * the new enabled state - */ - protected abstract void setEnabled(final boolean enabled); -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/component/AbstractJComponentStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/component/AbstractJComponentStateMachine.java deleted file mode 100644 index 80f0e5d..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/component/AbstractJComponentStateMachine.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.component; - -import javax.swing.JComponent; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.SuperBuilder; - -/** - * The abstract class {@link AbstractJComponentStateMachine} provides a state machine for - * JComponents. - * - * @param - * the type parameter for the JComponent - * @param - * the type parameter for the state - */ -@Getter -@Setter -@EqualsAndHashCode(callSuper = true) -@ToString -@NoArgsConstructor -@SuperBuilder -public abstract class AbstractJComponentStateMachine - extends - ComponentStateMachine -{ - - /** - * Sets the enabled state of the JComponent. - * - * @param b - * the new enabled state - */ - public void setEnabled(boolean b) - { - component.setEnabled(b); - } -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/component/ComponentStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/component/ComponentStateMachine.java deleted file mode 100644 index a284df8..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/component/ComponentStateMachine.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.component; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.SuperBuilder; - -/** - * The abstract class {@link ComponentStateMachine} can provide states on components. It manages the - * current state of a component and defines abstract methods for updating the component state and - * enabling/disabling the component. For an example, see the unit tests. - * - * @param - * the generic type of the component - * @param - * the generic type of the current state - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -public abstract class ComponentStateMachine -{ - - /** - * The component associated with this state machine. - */ - @NonNull - C component; - - /** - * The current state of the component, can be a model object or a bean. - */ - S currentState; - - /** - * Updates the state of the component. - */ - protected abstract void updateComponentState(); - - /** - * Sets the enabled flag for the component. - * - * @param enabled - * the enabled flag for the component - */ - protected abstract void setEnabled(boolean enabled); -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/BaseWizardState.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/BaseWizardState.java deleted file mode 100644 index 9aeb199..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/BaseWizardState.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard; - -/** - * The interface {@link BaseWizardState} represents a wizard state. - * - * @param - * the type parameter for the state machine - */ -public interface BaseWizardState extends WizardState -{ - - /** - * Gets the simple name of this {@link WizardState} object. - * - * @return the simple name of this {@link WizardState} object - */ - default String getName() - { - return this.getClass().getSimpleName(); - } - - /** - * Go to the next {@link WizardState} object. - * - * @param input - * the {@link WizardStateMachine} object - */ - void goNext(ST input); - - /** - * Go to the previous {@link WizardState} object. - * - * @param input - * the {@link WizardStateMachine} object - */ - void goPrevious(ST input); - - /** - * Checks if this {@link WizardState} object has a next {@link WizardState} object. - * - * @return true, if this {@link WizardState} object has a next {@link WizardState} object - * otherwise false - */ - default boolean hasNext() - { - return true; - } - - /** - * Checks if this {@link WizardState} object has a previous {@link WizardState} object. - * - * @return true, if this {@link WizardState} object has a previous {@link WizardState} object - * otherwise false - */ - default boolean hasPrevious() - { - return true; - } - - /** - * Checks if this {@link WizardState} object is the first {@link WizardState} object. - * - * @return true, if this {@link WizardState} object is the first {@link WizardState} object - * otherwise false - */ - default boolean isFirst() - { - return false; - } - - /** - * Checks if this {@link WizardState} object is the last {@link WizardState} object. - * - * @return true, if this {@link WizardState} object is the last {@link WizardState} object - * otherwise false - */ - default boolean isLast() - { - return false; - } - - /** - * Cancel the {@link BaseWizardState}. - * - * @param input - * the {@link BaseWizardStateMachine} object - */ - void cancel(ST input); - - /** - * Finish the {@link BaseWizardState}. - * - * @param input - * the {@link BaseWizardStateMachine} object - */ - void finish(ST input); -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/BaseWizardStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/BaseWizardStateMachine.java deleted file mode 100644 index 28c57b4..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/BaseWizardStateMachine.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class {@link BaseWizardStateMachine} implements {@link IBaseWizardStateMachine} and manages - * the state transitions for a wizard. - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class BaseWizardStateMachine - implements - IBaseWizardStateMachine> -{ - - /** - * The current state of the wizard. - */ - private BaseWizardState currentState; - - /** - * Cancels the wizard by transitioning to the cancel state. - */ - @Override - public void cancel() - { - getCurrentState().cancel(this); - } - - /** - * Finishes the wizard by transitioning to the finish state. - */ - @Override - public void finish() - { - getCurrentState().finish(this); - } - - /** - * {@inheritDoc} - */ - @Override - public void next() - { - getCurrentState().goNext(this); - } - - /** - * {@inheritDoc} - */ - @Override - public void previous() - { - getCurrentState().goPrevious(this); - } -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/IBaseWizardStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/IBaseWizardStateMachine.java deleted file mode 100644 index cc52c94..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/IBaseWizardStateMachine.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard; - -/** - * The interface {@link IBaseWizardStateMachine} extends {@link IWizardStateMachine} and adds - * methods for canceling and finishing the wizard. - * - * @param - * the type parameter for the state - */ -public interface IBaseWizardStateMachine extends IWizardStateMachine -{ - - /** - * Cancels the wizard. - */ - void cancel(); - - /** - * Finishes the wizard. - */ - void finish(); -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/IWizardStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/IWizardStateMachine.java deleted file mode 100644 index 2bb09f9..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/IWizardStateMachine.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard; - -/** - * The interface {@link IWizardStateMachine} represents a state machine for a wizard. - * - * @param - * the generic type of the state object - */ -public interface IWizardStateMachine -{ - - /** - * Gets the current state. - * - * @return the current state - */ - S getCurrentState(); - - /** - * Sets the current state. - * - * @param currentState - * the new current state - */ - void setCurrentState(S currentState); - - /** - * Go to the next {@link WizardState} object. - */ - void next(); - - /** - * Go to the previous {@link WizardState} object. - */ - void previous(); -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/WizardState.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/WizardState.java deleted file mode 100644 index 22b2231..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/WizardState.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard; - -/** - * The interface {@link WizardState} represents a state in a wizard. - * - * @param - * the generic type of the state machine - */ -public interface WizardState -{ - - /** - * Gets the simple name of this {@link WizardState} object. - * - * @return the simple name of this {@link WizardState} object - */ - default String getName() - { - return this.getClass().getSimpleName(); - } - - /** - * Go to the next {@link WizardState} object. - * - * @param input - * the {@link WizardStateMachine} object - */ - void goNext(ST input); - - /** - * Go to the previous {@link WizardState} object. - * - * @param input - * the {@link WizardStateMachine} object - */ - void goPrevious(ST input); - - /** - * Checks if this {@link WizardState} object has a next {@link WizardState} object. - * - * @return true if this {@link WizardState} object has a next {@link WizardState} object, - * otherwise false - */ - default boolean hasNext() - { - return true; - } - - /** - * Checks if this {@link WizardState} object has a previous {@link WizardState} object. - * - * @return true if this {@link WizardState} object has a previous {@link WizardState} object, - * otherwise false - */ - default boolean hasPrevious() - { - return true; - } - - /** - * Checks if this {@link WizardState} object is the first {@link WizardState} object. - * - * @return true if this {@link WizardState} object is the first {@link WizardState} object, - * otherwise false - */ - default boolean isFirst() - { - return false; - } - - /** - * Checks if this {@link WizardState} object is the last {@link WizardState} object. - * - * @return true if this {@link WizardState} object is the last {@link WizardState} object, - * otherwise false - */ - default boolean isLast() - { - return false; - } -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/WizardStateMachine.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/WizardStateMachine.java deleted file mode 100644 index 5886d59..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/WizardStateMachine.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class {@link WizardStateMachine} implements {@link IWizardStateMachine} and manages the state - * transitions for a wizard. - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class WizardStateMachine implements IWizardStateMachine> -{ - - /** The current {@link WizardState} object. */ - private WizardState currentState; - - /** - * {@inheritDoc} - */ - @Override - public void next() - { - getCurrentState().goNext(this); - } - - /** - * {@inheritDoc} - */ - @Override - public void previous() - { - getCurrentState().goPrevious(this); - } -} diff --git a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateMachineModel.java b/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateMachineModel.java deleted file mode 100644 index f1d1301..0000000 --- a/state/src/main/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateMachineModel.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardState; -import io.github.astrapi69.design.pattern.state.wizard.IBaseWizardStateMachine; - -/** - * The class {@link BaseWizardStateMachineModel} implements {@link IBaseWizardStateMachine} and - * manages the state transitions for a wizard with a model object. - * - * @param - * the type parameter for the model object - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class BaseWizardStateMachineModel - implements - IBaseWizardStateMachine>> -{ - - /** - * The current state of the wizard. - */ - private BaseWizardState> currentState; - - /** - * The model object associated with the wizard. - */ - private T modelObject; - - /** - * Cancels the wizard by transitioning to the cancel state. - */ - @Override - public void cancel() - { - getCurrentState().cancel(this); - } - - /** - * Finishes the wizard by transitioning to the finish state. - */ - @Override - public void finish() - { - getCurrentState().finish(this); - } - - /** - * {@inheritDoc} - */ - @Override - public void next() - { - getCurrentState().goNext(this); - } - - /** - * {@inheritDoc} - */ - @Override - public void previous() - { - getCurrentState().goPrevious(this); - } - -} diff --git a/state/src/main/java/module-info.java b/state/src/main/java/module-info.java deleted file mode 100644 index 87568ee..0000000 --- a/state/src/main/java/module-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -module design.patterns.state -{ - requires lombok; - requires java.desktop; - - exports io.github.astrapi69.design.pattern.state.button; - exports io.github.astrapi69.design.pattern.state.component; - exports io.github.astrapi69.design.pattern.state.wizard.model; - exports io.github.astrapi69.design.pattern.state.wizard; -} diff --git a/state/src/main/resources/log4j2.xml b/state/src/main/resources/log4j2.xml deleted file mode 100644 index e43e1b9..0000000 --- a/state/src/main/resources/log4j2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/state/src/test/java/io/github/astrapi69/constructorcallorder/ConstructorCallOrderExample.java b/state/src/test/java/io/github/astrapi69/constructorcallorder/ConstructorCallOrderExample.java deleted file mode 100644 index b2ca364..0000000 --- a/state/src/test/java/io/github/astrapi69/constructorcallorder/ConstructorCallOrderExample.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.constructorcallorder; - -class Child extends Parent -{ - // Static init block - static - { - System.out.println("static block - child"); - } - Printer printer = new Printer() - { - @Override - void print() - { - System.out.println("instance variable substitution from child"); - } - }; - // Instance init block - { - System.out.println("instance init block - child"); - } - - // Constructor - public Child() - { - System.out.println("constructor - child"); - } -} - -/** - * The Class ConstructorCallOrderExample demonstrates the call hierarchy from classes. - */ -public class ConstructorCallOrderExample -{ - - /** - * The main method. - * - * @param args - * the arguments - */ - public static void main(final String[] args) - { - System.out.println("START"); - new Child(); - System.out.println("END"); - } -} - -class Grandparent -{ - // Static init block - static - { - System.out.println("static block - grandparent"); - } - Printer substitution = new Printer() - { - @Override - void print() - { - System.out.println("instance variable substitution from grandparent"); - } - }; - // Instance init block - { - System.out.println("instance init block - grandparent"); - } - - // Constructor - public Grandparent() - { - System.out.println("constructor - grandparent"); - } -} - -class Parent extends Grandparent -{ - // Static init block - static - { - System.out.println("static block - parent"); - } - Printer substitution = new Printer() - { - @Override - void print() - { - System.out.println("instance variable substitution from parent"); - } - }; - // Instance init block - { - System.out.println("instance init block - parent"); - } - - // Constructor - public Parent() - { - System.out.println("constructor - parent"); - } -} - -class Printer -{ - Printer() - { - print(); - } - - void print() - { - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/MyButton.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/button/MyButton.java deleted file mode 100644 index fe1bbf8..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/MyButton.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class MyButton -{ - String text; - boolean enabled; -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonCurrentState.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonCurrentState.java deleted file mode 100644 index 3770e6a..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonCurrentState.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -public enum SigninButtonCurrentState implements ButtonState -{ - ENABLED, DISABLED -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonState.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonState.java deleted file mode 100644 index 0ee2c19..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonState.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -public interface SigninButtonState extends ButtonState -{ - void onApplicationFileAdded(); - - void onChangeWithMasterPassword(); - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonStateMachine.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonStateMachine.java deleted file mode 100644 index c31e269..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/SigninButtonStateMachine.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.SuperBuilder; - -@Getter -@Setter -@EqualsAndHashCode(callSuper = true) -@ToString -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -public class SigninButtonStateMachine extends ButtonStateMachine - implements - SigninButtonState -{ - boolean withMasterPassword; - boolean applicationFilePresent; - - @Override - public void onApplicationFileAdded() - { - boolean applicationFilePresent = !isApplicationFilePresent(); - setApplicationFilePresent(applicationFilePresent); - updateButtonState(); - } - - @Override - public void onChangeWithMasterPassword() - { - boolean withMasterPassword = !isWithMasterPassword(); - setWithMasterPassword(withMasterPassword); - updateButtonState(); - } - - protected void updateButtonState() - { - if (isApplicationFilePresent() && isWithMasterPassword()) - { - current = SigninButtonCurrentState.ENABLED; - setEnabled(true); - } - else - { - current = SigninButtonCurrentState.DISABLED; - setEnabled(false); - } - } - - public void setEnabled(final boolean enabled) - { - getButton().setEnabled(enabled); - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/TestSigninButtonStateMachine.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/button/TestSigninButtonStateMachine.java deleted file mode 100644 index faa15b2..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/button/TestSigninButtonStateMachine.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.button; - -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; - -import org.testng.annotations.Test; - -/** - * Test class for class {@link SigninButtonStateMachine} - */ -public class TestSigninButtonStateMachine -{ - - @Test - public void testState() - { - SigninButtonCurrentState expected; - ButtonState actual; - SigninButtonStateMachine buttonStateMachine = SigninButtonStateMachine.builder() - .button(MyButton.builder().text("OK").enabled(false).build()) - .current(SigninButtonCurrentState.DISABLED).build(); - // test case that no operation the current state is initial ButtonStateEnum.DISABLED - expected = SigninButtonCurrentState.DISABLED; - actual = buttonStateMachine.getCurrent(); - assertEquals(expected, actual); - assertFalse(buttonStateMachine.getButton().isEnabled()); - // test case that add application file the current state is still ButtonStateEnum.DISABLED - // because both application file and password should be true for get enabled state - buttonStateMachine.onApplicationFileAdded(); - expected = SigninButtonCurrentState.DISABLED; - actual = buttonStateMachine.getCurrent(); - assertEquals(expected, actual); - assertFalse(buttonStateMachine.getButton().isEnabled()); - // test case both application file and password are true so the current state is - // ButtonStateEnum.ENABLED - buttonStateMachine.onChangeWithMasterPassword(); - expected = SigninButtonCurrentState.ENABLED; - actual = buttonStateMachine.getCurrent(); - assertEquals(expected, actual); - assertTrue(buttonStateMachine.getButton().isEnabled()); - // toggle password to false will cause the disable state transition - buttonStateMachine.onChangeWithMasterPassword(); - expected = SigninButtonCurrentState.DISABLED; - actual = buttonStateMachine.getCurrent(); - assertEquals(expected, actual); - assertFalse(buttonStateMachine.getButton().isEnabled()); - // toggle password to true will cause the enable state transition - buttonStateMachine.onChangeWithMasterPassword(); - expected = SigninButtonCurrentState.ENABLED; - actual = buttonStateMachine.getCurrent(); - assertEquals(expected, actual); - assertTrue(buttonStateMachine.getButton().isEnabled()); - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveComponentState.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveComponentState.java deleted file mode 100644 index 6a3677e..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveComponentState.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.component; - -public interface BtnSaveComponentState -{ - void onInitialize(); - - void onGenerate(); - - void onClear(); - - void onChangeFilename(); - - void onChangeDirectory(); - - void onChangeKeySize(); -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveStateMachine.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveStateMachine.java deleted file mode 100644 index 0e32037..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveStateMachine.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.component; - -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; - -import javax.swing.JButton; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.SuperBuilder; - -@Getter -@Setter -@EqualsAndHashCode(callSuper = true) -@ToString -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -public class BtnSaveStateMachine - extends - AbstractJComponentStateMachine - implements - BtnSaveComponentState -{ - NewPrivateKeyModelBean modelObject; - - @Override - protected void updateComponentState() - { - if (modelObject == null) - { - setEnabled(false); - return; - } - boolean filenameOfPrivateKeyPresent = modelObject.getFilenameOfPrivateKey() != null; - boolean privateKeyDirectoryPresent = modelObject.getPrivateKeyDirectory() != null; - boolean privateKeyObjectPresent = modelObject.getPrivateKey() != null; - boolean keySizePresent = modelObject.getKeySize() != null; - if (filenameOfPrivateKeyPresent && privateKeyDirectoryPresent && privateKeyObjectPresent - && keySizePresent) - { - setEnabled(true); - return; - } - setEnabled(false); - } - - - @Override - public void onInitialize() - { - updateComponentState(); - } - - @Override - public void onGenerate() - { - updateComponentState(); - } - - @Override - public void onClear() - { - updateComponentState(); - } - - @Override - public void onChangeFilename() - { - updateComponentState(); - } - - @Override - public void onChangeDirectory() - { - updateComponentState(); - } - - @Override - public void onChangeKeySize() - { - updateComponentState(); - } - - public boolean isEmpty(Object obj) - { - if (obj == null) - { - return true; - } - - if (obj instanceof Optional) - { - return !((Optional)obj).isPresent(); - } - if (obj instanceof CharSequence) - { - return ((CharSequence)obj).length() == 0; - } - if (obj.getClass().isArray()) - { - return Array.getLength(obj) == 0; - } - if (obj instanceof Collection) - { - return ((Collection)obj).isEmpty(); - } - if (obj instanceof Map) - { - return ((Map)obj).isEmpty(); - } - - // else - return false; - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveStateMachineTest.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveStateMachineTest.java deleted file mode 100644 index ef79ca7..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/BtnSaveStateMachineTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.component; - -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; - -import java.security.KeyPair; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.PrivateKey; - -import javax.swing.JButton; - -import org.testng.annotations.Test; - -import io.github.astrapi69.crypt.api.algorithm.key.KeyPairGeneratorAlgorithm; -import io.github.astrapi69.crypt.api.key.KeySize; -import io.github.astrapi69.crypt.data.factory.KeyPairFactory; -import io.github.astrapi69.file.search.PathFinder; - -public class BtnSaveStateMachineTest -{ - - @Test - public void testState() throws NoSuchAlgorithmException, NoSuchProviderException - { - boolean enabled; - JButton btnSave; - PrivateKey expected; - KeyPair keyPair; - - btnSave = new JButton(); - NewPrivateKeyModelBean modelObject = NewPrivateKeyModelBean.builder().build(); - BtnSaveStateMachine btnSaveStateMachine = BtnSaveStateMachine.builder().component(btnSave) - .modelObject(modelObject).build(); - btnSaveStateMachine.onInitialize(); - enabled = btnSave.isEnabled(); - assertFalse(enabled); - - modelObject.setFilenameOfPrivateKey("master.key"); - btnSaveStateMachine.onChangeFilename(); - enabled = btnSave.isEnabled(); - assertFalse(enabled); - - modelObject.setPrivateKeyDirectory(PathFinder.getSrcMainResourcesDir()); - btnSaveStateMachine.onChangeDirectory(); - enabled = btnSave.isEnabled(); - assertFalse(enabled); - - keyPair = KeyPairFactory.newKeyPair(KeyPairGeneratorAlgorithm.RSA, KeySize.KEYSIZE_2048); - expected = keyPair.getPrivate(); - modelObject.setPrivateKey(expected); - btnSaveStateMachine.onGenerate(); - enabled = btnSave.isEnabled(); - assertTrue(enabled); - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/NewPrivateKeyModelBean.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/component/NewPrivateKeyModelBean.java deleted file mode 100644 index d705a71..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/component/NewPrivateKeyModelBean.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.component; - -import java.io.File; -import java.security.PrivateKey; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.FieldDefaults; -import lombok.experimental.SuperBuilder; -import io.github.astrapi69.crypt.api.key.KeySize; - -/** - * The class {@link NewPrivateKeyModelBean} - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder(toBuilder = true) -@FieldDefaults(level = AccessLevel.PRIVATE) -public class NewPrivateKeyModelBean -{ - int keyLength; - - @Builder.Default - KeySize keySize = KeySize.KEYSIZE_2048; - - PrivateKey privateKey; - - /** The private key directory */ - File privateKeyDirectory; - - String filenameOfPrivateKey; - - /** The private key file */ - File privateKeyFile; -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatch.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatch.java deleted file mode 100644 index 84091c2..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatch.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.stopwatch; - -/** - * The Class StopWatch. - */ -public class StopWatch -{ - - /** The start time. */ - private long startTime = 0; - - /** The stop time. */ - private long stopTime = 0; - - /** The elapsed milliseconds. */ - private long elapsedMilliseconds = 0; - - /** The running. */ - private boolean running = false; - - /** - * Gets the elapsed milliseconds. - * - * @return the elapsed milliseconds - */ - public long getElapsedMilliseconds() - { - return elapsedMilliseconds; - } - - - /** - * Gets the elapsed time in milliseconds. - * - * @return the elapsed time in milliseconds - */ - public long getElapsedTimeInMilliseconds() - { - if (running) - { - elapsedMilliseconds = elapsedMilliseconds + System.currentTimeMillis() - startTime; - } - else - { - elapsedMilliseconds = elapsedMilliseconds + stopTime - startTime; - } - return elapsedMilliseconds; - } - - /** - * Gets the elapsed time in seconds. - * - * @return the elapsed time in seconds - */ - public long getElapsedTimeInSeconds() - { - if (running) - { - elapsedMilliseconds = elapsedMilliseconds + System.currentTimeMillis() - startTime; - } - else - { - elapsedMilliseconds = elapsedMilliseconds + stopTime - startTime; - } - return elapsedMilliseconds / 1000; - } - - /** - * Start. - */ - public void start() - { - this.startTime = System.currentTimeMillis(); - this.running = true; - } - - - /** - * Stop. - */ - public void stop() - { - this.stopTime = System.currentTimeMillis(); - this.running = false; - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchState.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchState.java deleted file mode 100644 index 2f3df94..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchState.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.stopwatch; - -/** - * The class WizardState. - */ -public enum StopWatchState implements StopWatchTransition -{ - - /** The READY state. */ - READY { - @Override - public void pause(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void reset(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void start(final StopWatchStateContextMachine context) - { - System.out.println("started time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.getStopWatch().start(); - context.setCurrent(RUNNING); - } - - @Override - public void stop(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - }, - - /** The RUNNING state. */ - RUNNING { - @Override - public void pause(final StopWatchStateContextMachine context) - { - System.out.println("paused time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.getStopWatch().stop(); - context.setCurrent(PAUSED); - } - - @Override - public void reset(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void start(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void stop(final StopWatchStateContextMachine context) - { - System.out.println("stopped time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.getStopWatch().stop(); - context.setCurrent(STOPPED); - } - }, - - /** The PAUSED state. */ - PAUSED { - @Override - public void pause(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void reset(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void start(final StopWatchStateContextMachine context) - { - System.out.println("started time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.getStopWatch().start(); - context.setCurrent(RUNNING); - } - - @Override - public void stop(final StopWatchStateContextMachine context) - { - System.out.println("stopped time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.getStopWatch().stop(); - context.setCurrent(STOPPED); - } - }, - - /** The STOPPED state. */ - STOPPED { - @Override - public void pause(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - - @Override - public void reset(final StopWatchStateContextMachine context) - { - System.out.println("reset time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.setStopWatch(new StopWatch()); - context.setCurrent(READY); - } - - @Override - public void start(final StopWatchStateContextMachine context) - { - System.out.println("started time in milliseconds: " - + context.getStopWatch().getElapsedTimeInMilliseconds()); - context.getStopWatch().start(); - context.setCurrent(RUNNING); - } - - @Override - public void stop(final StopWatchStateContextMachine context) - { - context.setCurrent(this); - } - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchStateContextMachine.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchStateContextMachine.java deleted file mode 100644 index 699a447..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchStateContextMachine.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.stopwatch; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class StopWatchStateContextMachine. - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class StopWatchStateContextMachine -{ - - /** The stop watch. */ - @Builder.Default - private StopWatch stopWatch = new StopWatch(); - - /** The current. */ - @Builder.Default - private StopWatchState current = StopWatchState.READY; - - - /** - * Pause. - */ - public void pause() - { - getCurrent().pause(this); - } - - /** - * Reset. - */ - public void reset() - { - getCurrent().reset(this); - } - - /** - * Start. - */ - public void start() - { - getCurrent().start(this); - } - - /** - * Stop. - */ - public void stop() - { - getCurrent().stop(this); - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchStateContextMachineTest.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchStateContextMachineTest.java deleted file mode 100644 index c44881a..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchStateContextMachineTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.stopwatch; - -import org.testng.annotations.Test; - -public class StopWatchStateContextMachineTest -{ - - @Test - public void testStart() throws InterruptedException - { - final StopWatchStateContextMachine context = new StopWatchStateContextMachine(); - context.start(); - Thread.sleep(1000); - context.pause(); - Thread.sleep(2000); - context.start(); - Thread.sleep(3000); - context.stop(); - context.reset(); - context.start(); - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchTransition.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchTransition.java deleted file mode 100644 index aff8d48..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/stopwatch/StopWatchTransition.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.stopwatch; - -/** - * The interface transition. - */ -public interface StopWatchTransition -{ - - /** - * Stop. - * - * @param context - * the state context - */ - void stop(final StopWatchStateContextMachine context); - - /** - * Start. - * - * @param context - * the state context - */ - void start(final StopWatchStateContextMachine context); - - /** - * Reset. - * - * @param context - * the state context - */ - void reset(final StopWatchStateContextMachine context); - - /** - * Pause. - * - * @param context - * the state context - */ - void pause(final StopWatchStateContextMachine context); -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateMachineModelTest.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateMachineModelTest.java deleted file mode 100644 index 4c0afb0..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateMachineModelTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.model; - -import static org.testng.AssertJUnit.assertEquals; - -import org.testng.annotations.Test; - -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardState; -import io.github.astrapi69.design.pattern.state.wizard.WizardStateMachine; - -public class BaseWizardStateMachineModelTest -{ - - /** - * Test method for the methods previous and next of the {@link WizardStateMachine}. - */ - @Test - public void testWizardStateMachine() - { - BaseWizardStateModel expected; - BaseWizardState> actual; - final BaseWizardStateMachineModel stateMachine = BaseWizardStateMachineModel - . builder().currentState(BaseWizardStateModel.FIRST) - .modelObject(WizardModel.builder().build()).build(); - - expected = BaseWizardStateModel.FIRST; - stateMachine.previous(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // next not valid - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // set next to valid - stateMachine.getModelObject().setValidNext(true); - expected = BaseWizardStateModel.SECOND; - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // set next to valid - stateMachine.getModelObject().setValidNext(true); - expected = BaseWizardStateModel.THIRD; - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // cancel not valid - stateMachine.cancel(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // set cancel to valid - stateMachine.getModelObject().setValidCancel(true); - expected = BaseWizardStateModel.CANCELED; - stateMachine.cancel(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // finish not valid - stateMachine.finish(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - // set cancel to valid - stateMachine.getModelObject().setValidFinish(true); - - expected = BaseWizardStateModel.FINISHED; - stateMachine.finish(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateModel.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateModel.java deleted file mode 100644 index da0e6ea..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/BaseWizardStateModel.java +++ /dev/null @@ -1,276 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.model; - -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardState; - -/** - * The enum {@link BaseWizardStateModel} represents three wizard states and the cancel with the - * finish states. The state is only changing if the wizard model is valid. - */ -public enum BaseWizardStateModel - implements BaseWizardState> -{ - - /** The first {@link BaseWizardStateModel} object. */ - FIRST { - - @Override - public void cancel(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidCancel()) - { - stateMachine.setCurrentState(BaseWizardStateModel.CANCELED); - } - } - - @Override - public void finish(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidFinish()) - { - stateMachine.setCurrentState(BaseWizardStateModel.FINISHED); - } - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidNext()) - { - stateMachine.setCurrentState(BaseWizardStateModel.SECOND); - stateMachine.getModelObject().reset(); - } - } - - @Override - public void goPrevious(final BaseWizardStateMachineModel input) - { - } - - @Override - public boolean hasPrevious() - { - return false; - } - - @Override - public boolean isFirst() - { - return true; - } - - }, - - /** The second {@link BaseWizardStateModel} object. */ - SECOND { - - @Override - public void cancel(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidCancel()) - { - stateMachine.setCurrentState(BaseWizardStateModel.CANCELED); - } - } - - @Override - public void finish(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidFinish()) - { - stateMachine.setCurrentState(BaseWizardStateModel.FINISHED); - } - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidNext()) - { - stateMachine.setCurrentState(BaseWizardStateModel.THIRD); - stateMachine.getModelObject().reset(); - } - } - - @Override - public void goPrevious(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidPrevious()) - { - stateMachine.setCurrentState(BaseWizardStateModel.FIRST); - stateMachine.getModelObject().reset(); - } - } - - }, - - /** The third {@link BaseWizardStateModel} object. */ - THIRD { - - @Override - public void cancel(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidCancel()) - { - stateMachine.setCurrentState(BaseWizardStateModel.CANCELED); - } - } - - @Override - public void finish(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidFinish()) - { - stateMachine.setCurrentState(BaseWizardStateModel.FINISHED); - } - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachineModel stateMachine) - { - } - - @Override - public void goPrevious(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidPrevious()) - { - stateMachine.setCurrentState(SECOND); - stateMachine.getModelObject().reset(); - } - } - - @Override - public boolean hasNext() - { - return false; - } - - @Override - public boolean isLast() - { - return true; - } - - }, - - /** The cancel {@link BaseWizardStateModel} object. */ - CANCELED { - - - @Override - public void cancel(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidCancel()) - { - stateMachine.setCurrentState(BaseWizardStateModel.CANCELED); - } - } - - @Override - public void finish(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidFinish()) - { - stateMachine.setCurrentState(BaseWizardStateModel.FINISHED); - } - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachineModel stateMachine) - { - } - - @Override - public void goPrevious(final BaseWizardStateMachineModel stateMachine) - { - } - - }, - - /** The finish {@link BaseWizardStateModel} object. */ - FINISHED { - - @Override - public void cancel(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidCancel()) - { - stateMachine.setCurrentState(BaseWizardStateModel.CANCELED); - } - } - - @Override - public void finish(final BaseWizardStateMachineModel stateMachine) - { - if (stateMachine.getModelObject().isValidFinish()) - { - stateMachine.setCurrentState(BaseWizardStateModel.FINISHED); - } - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachineModel stateMachine) - { - } - - @Override - public void goPrevious(final BaseWizardStateMachineModel stateMachine) - { - } - - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/WizardModel.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/WizardModel.java deleted file mode 100644 index 3db60a8..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/model/WizardModel.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -/** - * The class {@link WizardModel} act as a model for a wizard.
- * This wizard model serves only as an example.
- * You can create a specific wizard model to your requirements. - */ -@Getter -@Setter -@EqualsAndHashCode -@ToString -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -public class WizardModel -{ - - /** The flag that signals if next is valid or not. */ - private boolean validNext; - - /** The flag that signals if previous is valid or not. */ - private boolean validPrevious; - - /** The flag that signals if cancel is valid or not. */ - private boolean validCancel; - - /** The flag that signals if finish is valid or not. */ - private boolean validFinish; - - /** - * Reset all flags to false. - */ - public void reset() - { - validNext = false; - validPrevious = false; - validCancel = false; - validFinish = false; - } -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/step/WizardStateMachineTest.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/step/WizardStateMachineTest.java deleted file mode 100644 index a0452b0..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/step/WizardStateMachineTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.step; - -import static org.testng.AssertJUnit.assertEquals; - -import org.testng.annotations.Test; - -import io.github.astrapi69.design.pattern.state.wizard.WizardState; -import io.github.astrapi69.design.pattern.state.wizard.WizardStateMachine; - -/** - * Test class for class {@link WizardStateMachine}. - */ -public class WizardStateMachineTest -{ - - /** - * Test method for the methods previous and next of the {@link WizardStateMachine}. - */ - @Test - public void testStateMachine() - { - WizardState expected; - WizardState actual; - WizardStateMachine wizardStateMachine = WizardStateMachine.builder() - .currentState(WizardStep.FIRST).build(); - // test case that no operation the current state is WizardStep.FIRST - expected = WizardStep.FIRST; - actual = wizardStateMachine.getCurrentState(); - assertEquals(expected, actual); - // test case that previous operation the current state is still WizardStep.FIRST - expected = WizardStep.FIRST; - wizardStateMachine.previous(); - actual = wizardStateMachine.getCurrentState(); - assertEquals(expected, actual); - // test case that next operation the current state goes from WizardStep.FIRST to - // WizardStep.SECOND - expected = WizardStep.SECOND; - wizardStateMachine.next(); - actual = wizardStateMachine.getCurrentState(); - assertEquals(expected, actual); - // test case that next operation the current state goes from WizardStep.SECOND to - // WizardStep.THIRD - expected = WizardStep.THIRD; - wizardStateMachine.next(); - actual = wizardStateMachine.getCurrentState(); - assertEquals(expected, actual); - // test case that next operation the current state is still WizardStep.THIRD because it is - // the last step - wizardStateMachine.next(); - actual = wizardStateMachine.getCurrentState(); - assertEquals(expected, actual); - - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/step/WizardStep.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/step/WizardStep.java deleted file mode 100644 index 2fc5709..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/step/WizardStep.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.step; - -import io.github.astrapi69.design.pattern.state.wizard.WizardState; -import io.github.astrapi69.design.pattern.state.wizard.WizardStateMachine; - -/** - * The enum {@link WizardStep} represents three steps. - */ -public enum WizardStep implements WizardState -{ - - /** The first {@link WizardStep} object. */ - FIRST { - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final WizardStateMachine stateMachine) - { - stateMachine.setCurrentState(SECOND); - } - - @Override - public void goPrevious(final WizardStateMachine stateMachine) - { - } - - @Override - public boolean hasPrevious() - { - return false; - } - - @Override - public boolean isFirst() - { - return true; - } - }, - - /** The second {@link WizardStep} object. */ - SECOND { - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final WizardStateMachine stateMachine) - { - stateMachine.setCurrentState(THIRD); - } - - @Override - public void goPrevious(final WizardStateMachine stateMachine) - { - stateMachine.setCurrentState(FIRST); - } - }, - - /** The third {@link WizardStep} object. */ - THIRD { - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final WizardStateMachine stateMachine) - { - } - - @Override - public void goPrevious(final WizardStateMachine stateMachine) - { - stateMachine.setCurrentState(SECOND); - } - - @Override - public boolean hasNext() - { - return false; - } - - @Override - public boolean isLast() - { - return true; - } - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/withenum/BaseWizardStateMachineTest.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/withenum/BaseWizardStateMachineTest.java deleted file mode 100644 index 8ee796b..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/withenum/BaseWizardStateMachineTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.withenum; - -import static org.testng.AssertJUnit.assertEquals; - -import org.testng.annotations.Test; - -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardState; -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardStateMachine; -import io.github.astrapi69.design.pattern.state.wizard.WizardStateMachine; - -public class BaseWizardStateMachineTest -{ - - - /** - * Test method for the methods previous and next of the {@link WizardStateMachine}. - */ - @Test - public void testWizardStateMachine() - { - EnumBaseWizardWizardState expected; - BaseWizardState actual; - final BaseWizardStateMachine stateMachine = BaseWizardStateMachine.builder() - .currentState(EnumBaseWizardWizardState.FIRST).build(); - - expected = EnumBaseWizardWizardState.FIRST; - stateMachine.previous(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - expected = EnumBaseWizardWizardState.SECOND; - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - expected = EnumBaseWizardWizardState.THIRD; - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - stateMachine.next(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - expected = EnumBaseWizardWizardState.CANCELED; - stateMachine.cancel(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - expected = EnumBaseWizardWizardState.FINISHED; - stateMachine.finish(); - actual = stateMachine.getCurrentState(); - assertEquals(expected, actual); - - } - -} diff --git a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/withenum/EnumBaseWizardWizardState.java b/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/withenum/EnumBaseWizardWizardState.java deleted file mode 100644 index 4cab867..0000000 --- a/state/src/test/java/io/github/astrapi69/design/pattern/state/wizard/withenum/EnumBaseWizardWizardState.java +++ /dev/null @@ -1,230 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.state.wizard.withenum; - -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardState; -import io.github.astrapi69.design.pattern.state.wizard.BaseWizardStateMachine; - -/** - * The enum {@link EnumBaseWizardWizardState} represents three wizard states and the cancel with the - * finish states. - */ -public enum EnumBaseWizardWizardState implements BaseWizardState -{ - - /** The first {@link EnumBaseWizardWizardState} object. */ - FIRST { - - @Override - public void cancel(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.CANCELED); - } - - @Override - public void finish(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.FINISHED); - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.SECOND); - } - - @Override - public void goPrevious(final BaseWizardStateMachine input) - { - } - - @Override - public boolean hasPrevious() - { - return false; - } - - @Override - public boolean isFirst() - { - return true; - } - - }, - - /** The second {@link EnumBaseWizardWizardState} object. */ - SECOND { - - @Override - public void cancel(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.CANCELED); - } - - @Override - public void finish(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.FINISHED); - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.THIRD); - } - - @Override - public void goPrevious(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.FIRST); - } - - }, - - /** The third {@link EnumBaseWizardWizardState} object. */ - THIRD { - - @Override - public void cancel(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.CANCELED); - } - - @Override - public void finish(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.FINISHED); - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachine stateMachine) - { - } - - @Override - public void goPrevious(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(SECOND); - } - - @Override - public boolean hasNext() - { - return false; - } - - @Override - public boolean isLast() - { - return true; - } - - }, - - /** The cancel {@link EnumBaseWizardWizardState} object. */ - CANCELED { - - - @Override - public void cancel(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.CANCELED); - } - - @Override - public void finish(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.FINISHED); - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachine stateMachine) - { - } - - @Override - public void goPrevious(final BaseWizardStateMachine stateMachine) - { - } - - }, - - /** The finish {@link EnumBaseWizardWizardState} object. */ - FINISHED { - - @Override - public void cancel(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.CANCELED); - } - - @Override - public void finish(final BaseWizardStateMachine stateMachine) - { - stateMachine.setCurrentState(EnumBaseWizardWizardState.FINISHED); - } - - @Override - public String getName() - { - return name(); - } - - @Override - public void goNext(final BaseWizardStateMachine stateMachine) - { - } - - @Override - public void goPrevious(final BaseWizardStateMachine stateMachine) - { - } - - } -} diff --git a/state/src/test/resources/log4j2-test.xml b/state/src/test/resources/log4j2-test.xml deleted file mode 100644 index 7d76608..0000000 --- a/state/src/test/resources/log4j2-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/state/src/test/resources/master.key b/state/src/test/resources/master.key deleted file mode 100644 index e69de29..0000000 diff --git a/visitor/.gitignore b/visitor/.gitignore deleted file mode 100644 index 9111d6a..0000000 --- a/visitor/.gitignore +++ /dev/null @@ -1,58 +0,0 @@ -################## -# Compiled files # -################## -*.class - -################## -# intellij files # -################## -*.iml -.idea -*/.idea - -################# -# eclipse files # -################# -/.project -/.classpath -/.settings - -######################### -# maven generated files # -######################### -/target - -############# -# Zip files # -############# -*.tar -*.zip -*.7z -*.dmg -*.gz -*.iso -*.jar -*.rar - -############## -# Logs files # -############## -*.log - -################# -# test-ng files # -################# -/test-output - -############################ -# Binaries generated files # -############################ -/bin - -################ -# gradle files # -################ -/build -/.gradle -/gradle -/pom.xml.bak diff --git a/visitor/README.md b/visitor/README.md deleted file mode 100644 index cf2e663..0000000 --- a/visitor/README.md +++ /dev/null @@ -1 +0,0 @@ -# design-pattern visitor diff --git a/visitor/build.gradle b/visitor/build.gradle deleted file mode 100644 index 057f19e..0000000 --- a/visitor/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -apply from: "../gradle/dependencies-visitor.gradle" -apply from: "../gradle/licensing.gradle" -apply from: "../gradle/publishing-visitor.gradle" diff --git a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/Acceptable.java b/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/Acceptable.java deleted file mode 100644 index 0a1fbe4..0000000 --- a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/Acceptable.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor; - -/** - * The interface {@link Acceptable} have to be implemented from all classes that wants to accept - * visitor objects. This interface is the counterpart of the {@link Acceptable} interface - * - * @param - * the generic type from the visitor object - */ -public interface Acceptable -{ - - /** - * Accepts the given visitor that provides a custom algorithm for processing all elements - * - * @param visitor - * the visitor - */ - void accept(final V visitor); -} diff --git a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/GenericAcceptable.java b/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/GenericAcceptable.java deleted file mode 100644 index b275062..0000000 --- a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/GenericAcceptable.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor; - -/** - * The interface {@link GenericAcceptable} have to be implemented from all classes that wants to - * accept visitor objects, and is the counterpart of the interface {@link GenericVisitor}. This - * interface is restrictive for the visitor and * the acceptable objects, if this is not required - * then use the less restrictive interface {@link Acceptable} and is the counterpart of the - * interface {@link Visitor} - * - * @param - * the generic type from the visitor - * @param - * the generic type from the object to visit also called 'visitable' or 'acceptable' - */ -public interface GenericAcceptable, ACCEPTABLE extends GenericAcceptable> -{ - - /** - * Accepts the given visitor that provides a custom algorithm for processing all elements - * - * @param visitor - * the visitor - */ - void accept(final VISITOR visitor); - -} diff --git a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/GenericVisitor.java b/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/GenericVisitor.java deleted file mode 100644 index 15db213..0000000 --- a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/GenericVisitor.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor; - -/** - * The interface {@link GenericVisitor} have to be implemented from all classes that wants to be - * visitor objects and provide a custom algorithm. This interface is restrictive for the visitor and - * the acceptable objects, if this is not wanted or required then use the less restrictive - * interfaces {@link Visitor} and is the counterpart of the interface {@link Acceptable} - * - * @param - * the generic type from the visitor - * @param - * the generic type from the object to visit also called 'visitable' or 'acceptable' - */ -public interface GenericVisitor, ACCEPTABLE extends GenericAcceptable> -{ - - /** - * Visits the given acceptable object - * - * @param visitable - * the acceptable object to visit - */ - void visit(final ACCEPTABLE visitable); - -} diff --git a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/Visitor.java b/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/Visitor.java deleted file mode 100644 index f1c599b..0000000 --- a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/Visitor.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor; - -/** - * The interface {@link Visitor} have to be implemented from all classes that wants to be visitor - * objects and provide a custom algorithm. This interface is the counterpart of the - * {@link Acceptable} interface - * - * @param - * the generic type from the object to visit - */ -public interface Visitor -{ - - /** - * Visits the given acceptable object - * - * @param acceptable - * the acceptable object to visit - */ - void visit(final T acceptable); -} diff --git a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/package.html b/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/package.html deleted file mode 100644 index 2e886fc..0000000 --- a/visitor/src/main/java/io/github/astrapi69/design/pattern/visitor/package.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - io.github.astrapi69.design.pattern.visitor - - - - Provides abstract classes for the generic implementation from the visitor pattern. - - diff --git a/visitor/src/main/java/module-info.java b/visitor/src/main/java/module-info.java deleted file mode 100644 index 0770a99..0000000 --- a/visitor/src/main/java/module-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -module design.patterns.visitor -{ - exports io.github.astrapi69.design.pattern.visitor; -} diff --git a/visitor/src/main/resources/log4j2.xml b/visitor/src/main/resources/log4j2.xml deleted file mode 100644 index e43e1b9..0000000 --- a/visitor/src/main/resources/log4j2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/DemonstrateVisitorPattern.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/DemonstrateVisitorPattern.java deleted file mode 100644 index a9c2ccb..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/DemonstrateVisitorPattern.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.first; - -import java.util.ArrayList; - -/** - * The Class DemonstrateVisitorPattern. - */ -public class DemonstrateVisitorPattern -{ - - /** - * The main method. - * - * @param args - * the arguments - */ - public static void main(final String[] args) - { - // The main menu. - final Menu mainMenu = new Menu("Main", new ArrayList()); - // Sub menu 'new' from main menu. - final Menu mainMenuNew = new Menu("New", new ArrayList()); - // Sub menuitems from the sub menu 'new'. - mainMenuNew.getChildren().add(new MenuItem("File", "File action")); - mainMenuNew.getChildren().add(new MenuItem("Folder", "Folder action")); - // Sub menuitems from the main menu. - mainMenu.getChildren().add(mainMenuNew); - mainMenu.getChildren().add(new MenuItem("Open", "Open action")); - mainMenu.getChildren().add(new MenuItem("Save", "Save action")); - mainMenu.getChildren().add(new MenuItem("Print", "Print action")); - - // Test the PrintActionCommandsMenuVisitor... - final MenuVisitor menuVisitor = new PrintActionCommandsMenuVisitor(); - menuVisitor.visit(mainMenu); - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/Menu.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/Menu.java deleted file mode 100644 index 0d803de..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/Menu.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.first; - -import java.util.Collection; - -/** - * The Class Menu. - */ -public class Menu implements MenuAcceptableObject -{ - - /** The name. */ - private final String name; - - /** The children. */ - private final Collection children; - - /** - * Instantiates a new menu. - * - * @param name - * the name - * @param children - * the children - */ - public Menu(final String name, final Collection children) - { - super(); - this.name = name; - this.children = children; - } - - /** - * {@inheritDoc} - */ - @Override - public void accept(final MenuVisitor visitor) - { - visitor.visit(this); - } - - /** - * Gets the children. - * - * @return the children - */ - public Collection getChildren() - { - return children; - } - - /** - * Gets the name. - * - * @return the name - */ - @Override - public String getName() - { - return name; - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuAcceptableObject.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuAcceptableObject.java deleted file mode 100644 index 3059a5f..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuAcceptableObject.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.first; - -import io.github.astrapi69.design.pattern.visitor.GenericAcceptable; - -/** - * The Interface MenuAcceptableObject. - */ -public interface MenuAcceptableObject extends GenericAcceptable -{ - String getName(); -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuItem.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuItem.java deleted file mode 100644 index 4c1d4da..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuItem.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.first; - -/** - * The Class MenuItem. - */ -public class MenuItem implements MenuAcceptableObject -{ - - /** The name. */ - private final String name; - - /** The action command. */ - private final String actionCommand; - - /** - * Instantiates a new menu item. - * - * @param name - * the name - * @param actionCommand - * the action command - */ - public MenuItem(final String name, final String actionCommand) - { - super(); - this.name = name; - this.actionCommand = actionCommand; - } - - /** - * {@inheritDoc} - */ - @Override - public void accept(final MenuVisitor visitor) - { - visitor.visit(this); - } - - /** - * Gets the action command. - * - * @return the action command - */ - public String getActionCommand() - { - return actionCommand; - } - - /** - * Gets the name. - * - * @return the name - */ - @Override - public String getName() - { - return name; - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuVisitor.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuVisitor.java deleted file mode 100644 index cdf77e2..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/MenuVisitor.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.first; - -import io.github.astrapi69.design.pattern.visitor.GenericVisitor; - -/** - * The Interface MenuVisitor. - */ -public interface MenuVisitor extends GenericVisitor -{ - - /** - * Visit. - * - * @param menu - * the menu - */ - void visit(final Menu menu); - - /** - * Visit. - * - * @param menuItem - * the menu item - */ - void visit(final MenuItem menuItem); - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/PrintActionCommandsMenuVisitor.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/PrintActionCommandsMenuVisitor.java deleted file mode 100644 index 4ce3617..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/PrintActionCommandsMenuVisitor.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.first; - -import java.util.Iterator; - -/** - * The Class PrintActionCommandsMenuVisitor. - */ -public class PrintActionCommandsMenuVisitor implements MenuVisitor -{ - - /** - * {@inheritDoc} - */ - @Override - public void visit(final Menu menu) - { - System.out.println(menu.getName()); - final Iterator iterator = menu.getChildren().iterator(); - while (iterator.hasNext()) - { - final MenuAcceptableObject menuVisitableObject = iterator.next(); - menuVisitableObject.accept(this); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void visit(final MenuItem menuItem) - { - System.out.println(menuItem.getActionCommand()); - } - - /** - * {@inheritDoc} - */ - @Override - public void visit(final MenuAcceptableObject visitable) - { - visitable.accept(this); - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/package.html b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/package.html deleted file mode 100644 index 71b0675..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/first/package.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - io.github.astrapi69.design.pattern.visitor.example.first - - - - Provides test classes for the package 'io.github.astrapi69.design.pattern.visitor.example.first'. - - diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/DemonstrateVisitorPattern.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/DemonstrateVisitorPattern.java deleted file mode 100644 index a27c083..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/DemonstrateVisitorPattern.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.second; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; - -import io.github.astrapi69.file.search.PathFinder; -import io.github.astrapi69.lang.ClassExtensions; - -/** - * The Class DemonstrateVisitorPattern. - */ -public class DemonstrateVisitorPattern -{ - - /** - * The main method. - * - * @param args - * the arguments - * @throws URISyntaxException - * occurs by creation of the file with an uri. - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public static void main(final String[] args) throws URISyntaxException, IOException - { - - final FileVisitor visitor = new FileVisitor(); - - // File directory = new File("."); - File directory = ClassExtensions.getResourceAsFile("DemonstrateVisitorPattern.class", - new DemonstrateVisitorPattern()); - directory = directory.getParentFile(); - directory = PathFinder.getProjectDirectory(); - final FileAcceptable visitable = new FileAcceptable(directory); - visitor.visit(visitable); - System.out.println(visitor.getFilesCounted()); - - - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileAcceptable.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileAcceptable.java deleted file mode 100644 index cfb6a60..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileAcceptable.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.second; - -import java.io.File; -import java.util.Collection; -import java.util.LinkedHashSet; - -import io.github.astrapi69.design.pattern.visitor.GenericAcceptable; -import io.github.astrapi69.design.pattern.visitor.GenericVisitor; - -/** - * The Class FileAcceptable. - */ -public class FileAcceptable implements GenericAcceptable -{ - - /** The file. */ - private final File file; - /** The children. */ - private Collection children; - - /** - * Instantiates a new file visitable. - * - * @param file - * the file - */ - public FileAcceptable(final File file) - { - super(); - this.file = file; - if (this.file.isDirectory()) - { - children = new LinkedHashSet<>(); - final File[] files = file.listFiles(); - for (final File childrenFile : files) - { - children.add(new FileAcceptable(childrenFile)); - } - } - } - - /** - * (non-Javadoc). - * - * @param visitor - * the visitor - * @see GenericAcceptable#accept(GenericVisitor) - */ - @Override - public void accept(final FileVisitor visitor) - { - visitor.visit(this); - } - - /** - * Gets the absolute path. - * - * @return the absolute path - */ - public String getAbsolutePath() - { - return this.file.getAbsolutePath(); - } - - /** - * Gets the children. - * - * @return the children - */ - public Collection getChildren() - { - return children; - } - - /** - * Checks if is directory. - * - * @return true, if is directory - */ - public boolean isDirectory() - { - return this.file.isDirectory(); - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileVisitor.cld b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileVisitor.cld deleted file mode 100644 index 2b6e1a1..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileVisitor.cld +++ /dev/null @@ -1,608 +0,0 @@ - - - - - - - - - _stereo_type - Stereo Type - false - - - _simpleEntityName - Simple Name - false - - - _entityName - Name - false - - - _background - Background Color - false - - - _attrs - Attributes... - false - - - _operations - Operations... - false - - - - io.github.astrapi69.designpattern.visitor.GenericVisitable - - 917 - 96 - -1 - -1 - - - - - - false - - - _stereo_type - Stereo Type - false - - - _simpleEntityName - Simple Name - false - - - _entityName - Name - false - - - _background - Background Color - false - - - _attrs - Attributes... - false - - - _operations - Operations... - false - - - _abstract - abstract - false - - - - io.github.astrapi69.designpattern.visitor.example.second.FileVisitable - - 886 - 288 - -1 - -1 - - - - - - - - - children - Collection<FileVisitable> - false - - 255 - 255 - 206 - - - 0 - 0 - 0 - - true - - - - - 2 - - - - - - - - - file - File - false - - - true - - - - - 2 - - - - - - - - - getChildren - Collection<FileVisitable> - - false - false - - - true - - - - - 2 - - - - - - - - - FileVisitable - void - - - file - File - - - false - false - - - true - - - - - 2 - - - - - - - - - accept - void - - - visitor - FileVisitor - - - false - false - - - true - - - - - 2 - - - - - - - - - getAbsolutePath - String - - false - false - - - true - - - - - 2 - - - - - - - - - isDirectory - boolean - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - true - - - - 2 - - - - - - - - - - - accept - void - - - visitor - GV - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - - _stereo_type - Stereo Type - false - - - _simpleEntityName - Simple Name - false - - - _entityName - Name - false - - - _background - Background Color - false - - - _attrs - Attributes... - false - - - _operations - Operations... - false - - - - io.github.astrapi69.designpattern.visitor.GenericVisitor - - 370 - 94 - -1 - -1 - - - - - - false - - - _stereo_type - Stereo Type - false - - - _simpleEntityName - Simple Name - false - - - _entityName - Name - false - - - _background - Background Color - false - - - _attrs - Attributes... - false - - - _operations - Operations... - false - - - _abstract - abstract - false - - - - io.github.astrapi69.designpattern.visitor.example.second.FileVisitor - - 341 - 300 - -1 - -1 - - - - - - - - - filesCounted - int - false - - - true - - - - - 2 - - - - - - - - - getFilesCounted - int - - false - false - - - true - - - - - 2 - - - - - - - - - FileVisitor - void - - false - false - - - true - - - - - 2 - - - - - - - - - visit - void - - - visitable - FileVisitable - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - true - - - - 2 - - - - - - - - - - - visit - void - - - visitable - GVSTABLE - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - - - - - true - - - - 2 - - - - - - diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileVisitor.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileVisitor.java deleted file mode 100644 index 7968454..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/FileVisitor.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.second; - -import java.util.Collection; - -import io.github.astrapi69.design.pattern.visitor.GenericVisitor; - - -/** - * The Class FileVisitor. - */ -public class FileVisitor implements GenericVisitor -{ - - /** The files counted. */ - private int filesCounted; - - /** - * Instantiates a new file visitor. - */ - public FileVisitor() - { - super(); - } - - /** - * Gets the files counted. - * - * @return the files counted - */ - public int getFilesCounted() - { - return filesCounted; - } - - @Override - public void visit(final FileAcceptable visitable) - { - filesCounted++; - System.out.println(visitable.getAbsolutePath()); - if (visitable.isDirectory()) - { - final Collection children = visitable.getChildren(); - for (final FileAcceptable fileVisitable : children) - { - fileVisitable.accept(this); - } - } - } - - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/package.html b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/package.html deleted file mode 100644 index 1584210..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/second/package.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - io.github.astrapi69.designpattern.visitor.example.second - - - - Provides test classes for the package 'io.github.astrapi69.designpattern.visitor.example.second'. - - diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/DisplayValueOfSimpleTreeNodeVisitor.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/DisplayValueOfSimpleTreeNodeVisitor.java deleted file mode 100644 index 1cef01e..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/DisplayValueOfSimpleTreeNodeVisitor.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.tree; - -import io.github.astrapi69.design.pattern.visitor.Visitor; - -public class DisplayValueOfSimpleTreeNodeVisitor implements Visitor> -{ - - @Override - public void visit(SimpleTreeNode simpleTreeNode) - { - System.out.println(simpleTreeNode.getValue()); - } -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/SimpleTreeNode.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/SimpleTreeNode.java deleted file mode 100644 index 317a5d8..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/SimpleTreeNode.java +++ /dev/null @@ -1,239 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.tree; - - -import java.util.LinkedHashSet; -import java.util.Set; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.FieldDefaults; -import lombok.experimental.SuperBuilder; -import io.github.astrapi69.design.pattern.visitor.Acceptable; -import io.github.astrapi69.design.pattern.visitor.Visitor; - -@NoArgsConstructor -@ToString(exclude = { "parent" }) -@SuperBuilder(toBuilder = true) -@FieldDefaults(level = AccessLevel.PRIVATE) -public class SimpleTreeNode implements Acceptable>> -{ - - @Getter - @Setter - /** The left most child */ - SimpleTreeNode parent; - /** The left most child */ - @Getter - @Setter - SimpleTreeNode leftMostChild; - /** The right sibling */ - @Getter - @Setter - SimpleTreeNode rightSibling; - /** The value */ - @Getter - @Setter - T value; - /** The flag that indicates if this tree node is a leaf or a node */ - @Getter - @Setter - boolean leaf; - - public SimpleTreeNode(T value) - { - this.value = value; - } - - public SimpleTreeNode getRoot() - { - SimpleTreeNode root = this; - if (isRoot()) - { - return root; - } - do - { - root = root.getParent(); - } - while (!isRoot()); - return root; - } - - /** - * Checks if this {@link SimpleTreeNode} is the root {@link SimpleTreeNode} object - * - * @return true, if this {@link SimpleTreeNode} is the root {@link SimpleTreeNode} object - */ - public boolean isRoot() - { - return !hasParent(); - } - - /** - * Checks if this {@link SimpleTreeNode} object is a node - * - * @return true, if this {@link SimpleTreeNode} object is a node otherwise false - */ - boolean isNode() - { - return !isLeaf(); - } - - public Set> getAllSiblings() - { - Set> allSiblings = new LinkedHashSet<>(); - if (hasParent()) - { - SimpleTreeNode parent = getParent(); - SimpleTreeNode leftMostChild = parent.getLeftMostChild(); - allSiblings.add(leftMostChild); - if (leftMostChild.hasRightSibling()) - { - SimpleTreeNode currentRightSibling = leftMostChild.getRightSibling(); - allSiblings.add(currentRightSibling); - do - { - currentRightSibling = currentRightSibling.getRightSibling(); - allSiblings.add(currentRightSibling); - } - while (currentRightSibling.hasRightSibling()); - } - } - return allSiblings; - } - - public Set> getAllLeftSiblings() - { - Set> allSiblings = new LinkedHashSet<>(); - if (hasParent()) - { - SimpleTreeNode parent = getParent(); - SimpleTreeNode leftMostChild = parent.getLeftMostChild(); - if (leftMostChild.equals(this)) - { - return allSiblings; - } - allSiblings.add(leftMostChild); - if (leftMostChild.hasRightSibling()) - { - SimpleTreeNode currentRightSibling = leftMostChild.getRightSibling(); - if (currentRightSibling.equals(this)) - { - return allSiblings; - } - allSiblings.add(currentRightSibling); - do - { - currentRightSibling = currentRightSibling.getRightSibling(); - if (currentRightSibling.equals(this)) - { - return allSiblings; - } - allSiblings.add(currentRightSibling); - } - while (currentRightSibling.hasRightSibling()); - } - } - return allSiblings; - } - - public Set> getAllRightSiblings() - { - Set> allRightSiblings = new LinkedHashSet<>(); - if (hasRightSibling()) - { - SimpleTreeNode currentRightSibling; - do - { - currentRightSibling = getRightSibling(); - allRightSiblings.add(currentRightSibling); - } - while (currentRightSibling.hasRightSibling()); - } - - return allRightSiblings; - } - - /** - * Checks if this node has a parent - * - * @return true, if successful - */ - public boolean hasParent() - { - return getParent() != null; - } - - /** - * Checks if this node has a right sibling - * - * @return true, if successful - */ - public boolean hasRightSibling() - { - return getRightSibling() != null; - } - - /** - * Checks if this node has a left most child - * - * @return true, if successful - */ - public boolean hasLeftMostChild() - { - return getLeftMostChild() != null; - } - - - public Set> getSubTree() - { - Set> subTree = new LinkedHashSet<>(); - if (hasLeftMostChild()) - { - SimpleTreeNode leftMostChild = getLeftMostChild(); - } - return subTree; - } - - @Override - public void accept(Visitor> visitor) - { - visitor.visit(this); - if (hasLeftMostChild()) - { - getLeftMostChild().accept(visitor); - } - if (hasRightSibling()) - { - getRightSibling().accept(visitor); - } - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/SimpleTreeNodeTest.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/SimpleTreeNodeTest.java deleted file mode 100644 index 018ed37..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/SimpleTreeNodeTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.tree; - -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertTrue; - -import java.util.Set; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -public class SimpleTreeNodeTest -{ - SimpleTreeNode root; - SimpleTreeNode firstChild; - SimpleTreeNode secondChild; - SimpleTreeNode firstGrandChild; - SimpleTreeNode firstGrandGrandChild; - SimpleTreeNode secondGrandGrandChild; - SimpleTreeNode firstGrandGrandGrandChild; - SimpleTreeNode secondGrandChild; - SimpleTreeNode thirdGrandChild; - SimpleTreeNode thirdChild; - SimpleTreeNode fourthGrandChild; - SimpleTreeNode fifthGrandChild; - - @Test - public void testRightSilbing() - { - boolean hasRightSibling; - SimpleTreeNode rightSibling; - - rightSibling = root.getRightSibling(); - assertNull(rightSibling); - assertFalse(root.hasRightSibling()); - - hasRightSibling = firstChild.hasRightSibling(); - assertTrue(hasRightSibling); - rightSibling = firstChild.getRightSibling(); - assertEquals(secondChild, rightSibling); - - hasRightSibling = secondChild.hasRightSibling(); - assertTrue(hasRightSibling); - rightSibling = secondChild.getRightSibling(); - assertEquals(thirdChild, rightSibling); - - hasRightSibling = thirdChild.hasRightSibling(); - assertFalse(hasRightSibling); - rightSibling = thirdChild.getRightSibling(); - assertNull(rightSibling); - - } - - /** - * Set up the tree structure for the unit tests - * @formatter:off - * +- root("I'm root") - * +- firstChild("I'm the first child") - * +- secondChild("I'm the second child") - * | +- firstGrandChild("I'm the first grand child") - * | | +- firstGrandGrandChild("I'm the first grand grand child") - * | | +- secondGrandGrandChild("I'm the second grand grand child) - * | | | +- firstGrandGrandGrandChild ("I'm the first grand grand grand child") - * | +- secondGrandChild("I'm the second grand child") - * | +- thirdGrandChild(null) - * +- thirdChild("I'm the third child") - * | +- fourthGrandChild(null) - * | +- fifthGrandChild("I'm the fifth grand child") - * @formatter:on - */ - @BeforeMethod - public void setup() - { - root = SimpleTreeNode. builder().leftMostChild(firstChild).value("I'm root") - .build(); - - firstChild = SimpleTreeNode. builder().parent(root).rightSibling(secondChild) - .value("I'm the first child").build(); - - secondChild = SimpleTreeNode. builder().parent(root).leftMostChild(firstGrandChild) - .rightSibling(thirdChild).value("I'm the second child").build(); - - - firstGrandChild = SimpleTreeNode. builder().parent(secondChild) - .leftMostChild(firstGrandGrandChild).rightSibling(secondGrandChild) - .value("I'm the first grand child").build(); - firstGrandGrandChild = SimpleTreeNode. builder().parent(firstGrandChild) - .rightSibling(secondGrandGrandChild).value("I'm the first grand grand child").build(); - secondGrandGrandChild = SimpleTreeNode. builder().parent(firstGrandChild) - .leftMostChild(firstGrandGrandGrandChild).value("I'm the second grand grand child") - .build(); - - firstGrandGrandGrandChild = SimpleTreeNode. builder().parent(secondGrandGrandChild) - .value("I'm the first grand grand grand child").build(); - secondGrandChild = SimpleTreeNode. builder().parent(secondChild) - .rightSibling(thirdGrandChild).value("I'm the second grand child").build(); - thirdGrandChild = SimpleTreeNode. builder().parent(secondChild).value(null).build(); - - thirdChild = SimpleTreeNode. builder().parent(root).leftMostChild(fourthGrandChild) - .value("I'm the third child").build(); - fourthGrandChild = SimpleTreeNode. builder().parent(thirdChild) - .rightSibling(fifthGrandChild).value(null).build(); - fifthGrandChild = SimpleTreeNode. builder().parent(thirdChild) - .value("I'm the fifth grand child").build(); - // initialize left most child and right sibling - - root.setLeftMostChild(firstChild); - firstChild.setRightSibling(secondChild); - - secondChild.setLeftMostChild(firstGrandChild); - secondChild.setRightSibling(thirdChild); - - firstGrandChild.setLeftMostChild(firstGrandGrandChild); - firstGrandChild.setRightSibling(secondGrandChild); - - firstGrandGrandChild.setRightSibling(secondGrandGrandChild); - - secondGrandGrandChild.setLeftMostChild(firstGrandGrandGrandChild); - - secondGrandChild.setRightSibling(thirdGrandChild); - - thirdChild.setLeftMostChild(fourthGrandChild); - - fourthGrandChild.setRightSibling(fifthGrandChild); - } - - @Test - public void testGetAllSilbings() - { - Set> allSiblings = root.getAllSiblings(); - assertEquals(allSiblings.size(), 0); - allSiblings = secondChild.getAllSiblings(); - assertEquals(allSiblings.size(), 3); - } - - @Test - public void testGetAllRightSiblings() - { - Set> allRightSiblings = root.getAllSiblings(); - assertEquals(allRightSiblings.size(), 0); - allRightSiblings = secondChild.getAllRightSiblings(); - assertEquals(allRightSiblings.size(), 1); - } - - @Test - public void testGetAllLeftSiblings() - { - Set> allRightSiblings = root.getAllSiblings(); - assertEquals(allRightSiblings.size(), 0); - allRightSiblings = secondChild.getAllLeftSiblings(); - assertEquals(allRightSiblings.size(), 1); - } - - @Test - public void testVisitor() - { - root.accept(new DisplayValueOfSimpleTreeNodeVisitor<>()); - TraverseSimpleTreeNodeVisitor traverseVisitor; - traverseVisitor = new TraverseSimpleTreeNodeVisitor<>(); - root.accept(traverseVisitor); - Set> allTreeNodes = traverseVisitor.getAllTreeNodes(); - assertEquals(allTreeNodes.size(), 12); - } - -} diff --git a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/TraverseSimpleTreeNodeVisitor.java b/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/TraverseSimpleTreeNodeVisitor.java deleted file mode 100644 index 8853bfb..0000000 --- a/visitor/src/test/java/io/github/astrapi69/design/pattern/visitor/example/tree/TraverseSimpleTreeNodeVisitor.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * The MIT License - * - * Copyright (C) 2015 Asterios Raptis - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package io.github.astrapi69.design.pattern.visitor.example.tree; - -import java.util.LinkedHashSet; -import java.util.Set; - -import lombok.Getter; -import io.github.astrapi69.design.pattern.visitor.Visitor; - -public class TraverseSimpleTreeNodeVisitor implements Visitor> -{ - - @Getter - final Set> allTreeNodes = new LinkedHashSet<>(); - - @Override - public void visit(SimpleTreeNode simpleTreeNode) - { - allTreeNodes.add(simpleTreeNode); - } -} diff --git a/visitor/src/test/resources/log4j2-test.xml b/visitor/src/test/resources/log4j2-test.xml deleted file mode 100644 index 7d76608..0000000 --- a/visitor/src/test/resources/log4j2-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file