Class RefreshUtil

java.lang.Object
de.murmelmeister.murmelapi.utils.update.RefreshUtil

public final class RefreshUtil extends Object
The RefreshUtil class provides utility methods for managing refresh events and notifying listeners.

This class contains static methods for setting a refresh listener, marking as refreshed, and checking and resetting the refresh status. It uses an AtomicBoolean to keep track of the refresh status and an ArrayList to store the registered listeners.

To use this class, first implement the RefreshListener interface with the desired functionality to be executed when a refresh occurs. Call the setRefreshListener method to register the listener. When a refresh event happens, the onRefreshOccurred method of all registered listeners will be invoked. The markAsRefreshed method is used to set the refresh status to true and invoke the onRefreshOccurred method of all registered listeners. The checkAndResetRefreshStatus method is used to check the refresh status and reset it to false.

Note that the RefreshListener interface is marked as a functional interface, which means it can be used with lambda expressions.

See Also:
  • Field Details

  • Constructor Details

    • RefreshUtil

      public RefreshUtil()
  • Method Details

    • setRefreshListener

      public static void setRefreshListener(RefreshListener listener)
      Sets a refresh listener for the RefreshUtil class.

      This method adds the specified listener to the list of registered listeners for refresh events. When a refresh event occurs, the registered listeners will be notified by invoking their RefreshListener.onRefreshOccurred() method.

      Parameters:
      listener - the refresh listener to be added
      See Also:
    • markAsRefreshed

      public static void markAsRefreshed()
      Sets the refresh status as refreshed and triggers the RefreshListener.onRefreshOccurred() method for all registered listeners. This method is used to indicate that a refresh event has occurred and notify all registered listeners about it.

      The refresh status is managed by an AtomicBoolean variable that is initially set to false. When markAsRefreshed() is called, the refresh status is set to true using AtomicBoolean.set(boolean).

      For each listener in the registered listeners list, the RefreshListener.onRefreshOccurred() method is invoked. This allows all registered listeners to perform the desired functionality when a refresh event occurs.

      See Also:
    • checkAndResetRefreshStatus

      public static boolean checkAndResetRefreshStatus()
      Checks the refresh status and resets it to false.

      This method returns the current refresh status by invoking AtomicBoolean.getAndSet(boolean) on the AtomicBoolean variable HAS_REFRESH. The refresh status is then reset to false.

      Returns:
      the current refresh status before resetting it
      See Also: