View Javadoc
1   /*
2    * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.events;
11  
12  import java.util.Collection;
13  import java.util.Collections;
14  
15  import org.eclipse.jgit.annotations.NonNull;
16  
17  /**
18   * A {@link org.eclipse.jgit.events.RepositoryEvent} describing changes to the
19   * working tree. It is fired whenever a
20   * {@link org.eclipse.jgit.dircache.DirCacheCheckout} modifies
21   * (adds/deletes/updates) files in the working tree.
22   *
23   * @since 4.9
24   */
25  public class WorkingTreeModifiedEvent
26  		extends RepositoryEvent<WorkingTreeModifiedListener> {
27  
28  	private Collection<String> modified;
29  
30  	private Collection<String> deleted;
31  
32  	/**
33  	 * Creates a new {@link org.eclipse.jgit.events.WorkingTreeModifiedEvent}
34  	 * with the given collections.
35  	 *
36  	 * @param modified
37  	 *            repository-relative paths that were added or updated
38  	 * @param deleted
39  	 *            repository-relative paths that were deleted
40  	 */
41  	public WorkingTreeModifiedEvent(Collection<String> modified,
42  			Collection<String> deleted) {
43  		this.modified = modified;
44  		this.deleted = deleted;
45  	}
46  
47  	/**
48  	 * Determines whether there are any changes recorded in this event.
49  	 *
50  	 * @return {@code true} if no files were modified or deleted, {@code false}
51  	 *         otherwise
52  	 */
53  	public boolean isEmpty() {
54  		return (modified == null || modified.isEmpty())
55  				&& (deleted == null || deleted.isEmpty());
56  	}
57  
58  	/**
59  	 * Retrieves the {@link java.util.Collection} of repository-relative paths
60  	 * of files that were modified (added or updated).
61  	 *
62  	 * @return the set
63  	 */
64  	@NonNull
65  	public Collection<String> getModified() {
66  		Collection<String> result = modified;
67  		if (result == null) {
68  			result = Collections.emptyList();
69  			modified = result;
70  		}
71  		return result;
72  	}
73  
74  	/**
75  	 * Retrieves the {@link java.util.Collection} of repository-relative paths
76  	 * of files that were deleted.
77  	 *
78  	 * @return the set
79  	 */
80  	@NonNull
81  	public Collection<String> getDeleted() {
82  		Collection<String> result = deleted;
83  		if (result == null) {
84  			result = Collections.emptyList();
85  			deleted = result;
86  		}
87  		return result;
88  	}
89  
90  	/** {@inheritDoc} */
91  	@Override
92  	public Class<WorkingTreeModifiedListener> getListenerType() {
93  		return WorkingTreeModifiedListener.class;
94  	}
95  
96  	/** {@inheritDoc} */
97  	@Override
98  	public void dispatch(WorkingTreeModifiedListener listener) {
99  		listener.onWorkingTreeModified(this);
100 	}
101 }