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
12 package org.eclipse.jgit.events;
13
14 import org.eclipse.jgit.lib.Repository;
15
16 /**
17 * Describes a modification made to a repository.
18 *
19 * @param <T>
20 * type of listener this event dispatches to.
21 */
22 public abstract class RepositoryEvent<T extends RepositoryListener> {
23 private Repository repository;
24
25 /**
26 * Set the repository this event occurred on.
27 * <p>
28 * This method should only be invoked once on each event object, and is
29 * automatically set by
30 * {@link org.eclipse.jgit.lib.Repository#fireEvent(RepositoryEvent)}.
31 *
32 * @param r
33 * the repository.
34 */
35 public void setRepository(Repository r) {
36 if (repository == null)
37 repository = r;
38 }
39
40 /**
41 * Get the repository that was changed
42 *
43 * @return the repository that was changed
44 */
45 public Repository getRepository() {
46 return repository;
47 }
48
49 /**
50 * Get type of listener this event dispatches to
51 *
52 * @return type of listener this event dispatches to
53 */
54 public abstract Class<T> getListenerType();
55
56 /**
57 * Dispatch this event to the given listener.
58 *
59 * @param listener
60 * listener that wants this event.
61 */
62 public abstract void dispatch(T listener);
63
64 /** {@inheritDoc} */
65 @SuppressWarnings("nls")
66 @Override
67 public String toString() {
68 String type = getClass().getSimpleName();
69 if (repository == null)
70 return type;
71 return type + "[" + repository + "]";
72 }
73 }