RepositoryEvent.java

  1. /*
  2.  * Copyright (C) 2010, Google Inc.
  3.  * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> and others
  4.  *
  5.  * This program and the accompanying materials are made available under the
  6.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  7.  * https://www.eclipse.org/org/documents/edl-v10.php.
  8.  *
  9.  * SPDX-License-Identifier: BSD-3-Clause
  10.  */

  11. package org.eclipse.jgit.events;

  12. import org.eclipse.jgit.lib.Repository;

  13. /**
  14.  * Describes a modification made to a repository.
  15.  *
  16.  * @param <T>
  17.  *            type of listener this event dispatches to.
  18.  */
  19. public abstract class RepositoryEvent<T extends RepositoryListener> {
  20.     private Repository repository;

  21.     /**
  22.      * Set the repository this event occurred on.
  23.      * <p>
  24.      * This method should only be invoked once on each event object, and is
  25.      * automatically set by
  26.      * {@link org.eclipse.jgit.lib.Repository#fireEvent(RepositoryEvent)}.
  27.      *
  28.      * @param r
  29.      *            the repository.
  30.      */
  31.     public void setRepository(Repository r) {
  32.         if (repository == null)
  33.             repository = r;
  34.     }

  35.     /**
  36.      * Get the repository that was changed
  37.      *
  38.      * @return the repository that was changed
  39.      */
  40.     public Repository getRepository() {
  41.         return repository;
  42.     }

  43.     /**
  44.      * Get type of listener this event dispatches to
  45.      *
  46.      * @return type of listener this event dispatches to
  47.      */
  48.     public abstract Class<T> getListenerType();

  49.     /**
  50.      * Dispatch this event to the given listener.
  51.      *
  52.      * @param listener
  53.      *            listener that wants this event.
  54.      */
  55.     public abstract void dispatch(T listener);

  56.     /** {@inheritDoc} */
  57.     @SuppressWarnings("nls")
  58.     @Override
  59.     public String toString() {
  60.         String type = getClass().getSimpleName();
  61.         if (repository == null)
  62.             return type;
  63.         return type + "[" + repository + "]";
  64.     }
  65. }