Class WatchEvent


  • public class WatchEvent
    extends Object
    The library publishes these events to all subscribers, they are immutable and safe to share around.
    • Constructor Detail

      • WatchEvent

        public WatchEvent​(WatchEvent.Kind kind,
                          Path rootPath)
        Internal constructor an end user should never call, creates a new watch event for the root of a watch
        Parameters:
        kind - kind of watch event
        rootPath - the path of the registered watch
      • WatchEvent

        public WatchEvent​(WatchEvent.Kind kind,
                          Path rootPath,
                          @Nullable Path relativePath)
        Internal constructor an end user should never call, creates a new watch event
        Parameters:
        kind - kind of watch event
        rootPath - the path of the registered watch
        relativePath - the child path of the event
    • Method Detail

      • getKind

        public WatchEvent.Kind getKind()
        Returns:
        the kind of watch event
      • getRelativePath

        public Path getRelativePath()
        Returns:
        the path relative to the monitored root, it can be empty path if it's the root.
      • getRootPath

        public Path getRootPath()
        Returns:
        A copy of the root path that this event belongs to.
      • calculateFullPath

        public Path calculateFullPath()
        Returns:
        utility function that resolves the relative path to the full path.
      • getFileName

        public @Nullable Path getFileName()
        Returns:
        The file name of the full path of this event, or null if it has zero elements (cf. Path.getFileName()), but without calculating the full path. This method is equivalent to, but more efficient than, calculateFullPath().getFileName().
      • areEquivalent

        public static boolean areEquivalent​(WatchEvent e1,
                                            WatchEvent e2)

        Tests the equivalence of two events. Two events are equivalent when they have equal kinds, equal root paths, and equal relative paths.

        Note: This method applies different logic to compare events than (the default implementation of) method Object.equals(Object), which shouldn't be overridden. This is because events should normally be compared in terms of their identities (e.g., two successive modifications of the same file result in events that are equivalent, but not equal; they need to be distinguishable in collections).

        Parameters:
        e1 - event 1
        e2 - event 2
        Returns:
        true if e1 and e2 are the same path and kind