WorkingTreeModifiedEvent.java

  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. import java.util.Collection;
  12. import java.util.Collections;

  13. import org.eclipse.jgit.annotations.NonNull;

  14. /**
  15.  * A {@link org.eclipse.jgit.events.RepositoryEvent} describing changes to the
  16.  * working tree. It is fired whenever a
  17.  * {@link org.eclipse.jgit.dircache.DirCacheCheckout} modifies
  18.  * (adds/deletes/updates) files in the working tree.
  19.  *
  20.  * @since 4.9
  21.  */
  22. public class WorkingTreeModifiedEvent
  23.         extends RepositoryEvent<WorkingTreeModifiedListener> {

  24.     private Collection<String> modified;

  25.     private Collection<String> deleted;

  26.     /**
  27.      * Creates a new {@link org.eclipse.jgit.events.WorkingTreeModifiedEvent}
  28.      * with the given collections.
  29.      *
  30.      * @param modified
  31.      *            repository-relative paths that were added or updated
  32.      * @param deleted
  33.      *            repository-relative paths that were deleted
  34.      */
  35.     public WorkingTreeModifiedEvent(Collection<String> modified,
  36.             Collection<String> deleted) {
  37.         this.modified = modified;
  38.         this.deleted = deleted;
  39.     }

  40.     /**
  41.      * Determines whether there are any changes recorded in this event.
  42.      *
  43.      * @return {@code true} if no files were modified or deleted, {@code false}
  44.      *         otherwise
  45.      */
  46.     public boolean isEmpty() {
  47.         return (modified == null || modified.isEmpty())
  48.                 && (deleted == null || deleted.isEmpty());
  49.     }

  50.     /**
  51.      * Retrieves the {@link java.util.Collection} of repository-relative paths
  52.      * of files that were modified (added or updated).
  53.      *
  54.      * @return the set
  55.      */
  56.     @NonNull
  57.     public Collection<String> getModified() {
  58.         Collection<String> result = modified;
  59.         if (result == null) {
  60.             result = Collections.emptyList();
  61.             modified = result;
  62.         }
  63.         return result;
  64.     }

  65.     /**
  66.      * Retrieves the {@link java.util.Collection} of repository-relative paths
  67.      * of files that were deleted.
  68.      *
  69.      * @return the set
  70.      */
  71.     @NonNull
  72.     public Collection<String> getDeleted() {
  73.         Collection<String> result = deleted;
  74.         if (result == null) {
  75.             result = Collections.emptyList();
  76.             deleted = result;
  77.         }
  78.         return result;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public Class<WorkingTreeModifiedListener> getListenerType() {
  83.         return WorkingTreeModifiedListener.class;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public void dispatch(WorkingTreeModifiedListener listener) {
  88.         listener.onWorkingTreeModified(this);
  89.     }
  90. }