Skip to content

Commit

Permalink
improve of javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
astrapisixtynine committed Aug 14, 2024
1 parent eb84c32 commit 1dda686
Show file tree
Hide file tree
Showing 57 changed files with 1,080 additions and 425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
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
* 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
{
Expand All @@ -56,7 +58,8 @@ private ApplicationEventBus()
/**
* Retrieves an event source by its key
*
* @param key the key associated with the event source
* @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)
Expand Down Expand Up @@ -94,4 +97,3 @@ public static ApplicationEventBus getInstance()
return instance;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
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
* 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
{
Expand All @@ -46,9 +46,10 @@ public class GenericEventBusTest
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 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()
Expand Down Expand Up @@ -92,10 +93,11 @@ public void testApplicationEventBus()
}

/**
* Event handler method for string-based events
* This method increments the counter each time it is called
* 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
* @param event
* the event string, typically a command or action indicator
*/
@Subscribe
public void onAddition(String event)
Expand All @@ -104,10 +106,11 @@ public void onAddition(String event)
}

/**
* Event handler method for {@link NavigationEventState} events
* This method updates the {@code navigationEventState} field to reflect the state passed in the event
* 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
* @param navigationEventState
* the event containing the new navigation state
*/
@Subscribe
public void onAdditionWithObject(NavigationEventState navigationEventState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
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
* 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<EventObject<NavigationEventState>>
{
Expand All @@ -46,7 +47,8 @@ public class ImportWizardPanelTest implements EventListener<EventObject<Navigati
/**
* Handles the given event by updating the navigation state of the panel
*
* @param event the event containing the new {@link NavigationEventState}
* @param event
* the event containing the new {@link NavigationEventState}
*/
@Override
public void onEvent(EventObject<NavigationEventState> event)
Expand All @@ -57,7 +59,8 @@ public void onEvent(EventObject<NavigationEventState> event)
/**
* Updates the button state based on the given navigation state
*
* @param navigationState the new navigation state to be applied
* @param navigationState
* the new navigation state to be applied
*/
protected void updateButtonState(NavigationEventState navigationState)
{
Expand All @@ -66,19 +69,19 @@ protected void updateButtonState(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
* 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<EventObject<NavigationEventState>> eventSource = ApplicationEventBus
.getImportNavigationState();
.getImportNavigationState();
eventSource.add(this);
// Create an event source object
final EventSource<EventObject<NavigationEventState>> navigationEventStateEventSource = ApplicationEventBus
.getImportNavigationState();
.getImportNavigationState();
// Fire a new event
navigationEventStateEventSource.fireEvent(new EventObject<>(NavigationEventState.UPDATE));
// Verify that the navigationEventState is set to NavigationEventState.UPDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

/**
* 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.
* {@code ImportWizardModel}. It listens for events on the {@code ApplicationEventBus} and updates
* its internal state when an event occurs.
*/
public class ImportProgressPanel implements EventListener<EventObject<ImportWizardModel>>
{
Expand All @@ -43,22 +43,23 @@ public class ImportProgressPanel implements EventListener<EventObject<ImportWiza
ImportWizardModel importWizardModel;

/**
* Constructs a new {@code ImportProgressPanel} and registers it as a listener
* for {@code ImportWizardModel} events on the {@code ApplicationEventBus}
* 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<EventObject<ImportWizardModel>> eventSource = ApplicationEventBus
.getImportWizardModel();
.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.
* 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}
* @param event
* the event object containing the updated {@code ImportWizardModel}
*/
@Override
public void onEvent(EventObject<ImportWizardModel> event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;

import io.github.astrapi69.design.pattern.eventbus.ApplicationEventBus;
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
* 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 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
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
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
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
* 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
{
Expand All @@ -41,21 +41,20 @@ public class ImportWizardPanel
ImportWizardModel model;

/**
* Constructs a new {@code ImportWizardPanel} with a default model
* The default model is initialized with a bundle application name "foobar"
* 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}
* 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));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,28 @@
import io.github.astrapi69.design.pattern.observer.api.Observer;
import io.github.astrapi69.design.pattern.observer.api.Subject;


/**
* A generic implementation from the Observer-Pattern.
*
* 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 <T>
* the generic type
* the generic type of the observable object
*/
public abstract class AbstractObserver<T> implements Observer<T>, ActionCommand
{

/** The subject. */
/** The subject being observed */
protected Subject<T, Observer<T>> subject;

/** The observable. */
/** The current observable object */
private T observable;

/**
* Constructor for a new observer object.
* Constructor for a new observer object
*
* @param subject
* the subject
* the subject to observe
*/
public AbstractObserver(final Subject<T, Observer<T>> subject)
{
Expand All @@ -58,9 +59,9 @@ public AbstractObserver(final Subject<T, Observer<T>> subject)
}

/**
* Gets the observable object.
* Gets the current observable object
*
* @return the observable
* @return the observable object
*/
public synchronized T getObservable()
{
Expand All @@ -76,5 +77,4 @@ public synchronized void update(final T observable)
this.observable = observable;
execute();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,45 @@
import io.github.astrapi69.design.pattern.observer.api.Subject;

/**
* The Class AbstractSubject is an implementation from the interface Subject. This class
* encapsulates the observable and fires an update if the observable changes. The update informs all
* registered observers about the change of the observable.
* 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 <T>
* the generic type of the observable.
* the generic type of the observable object
* @param <O>
* the generic type of the observer
*/
public abstract class AbstractSubject<T, O extends Observer<T>> implements Subject<T, O>
{

/** The observers. */
/** The list of registered observers */
@Getter
private final List<O> observers;
/** The observable object. */

/** The current observable object */
@Getter
private T observable;

/**
* Initialize block.
* Initialization block to create the list of observers
**/
{
observers = new ArrayList<>();
}

/**
* Default constructor for a new subject.
* Default constructor for a new subject with no initial observable
*/
public AbstractSubject()
{
}

/**
* Constructor for a new subject with an observable.
* Constructor for a new subject with an initial observable
*
* @param observable
* the observable
* the initial observable object
*/
public AbstractSubject(final T observable)
{
Expand Down
Loading

0 comments on commit 1dda686

Please sign in to comment.