Package bm.target
Class FileBooleanState
java.lang.Object
bm.target.FileBooleanState
- All Implemented Interfaces:
StateProvider,FileState
Provides the state of a file based on a boolean predicate only, meaning the file can only be in
two states: either the predicate returns
true or it returns false.-
Constructor Summary
ConstructorsConstructorDescriptionFileBooleanState(Path targetPath, Predicate<Path> fileFeature) Creates a file state which adds the same constant value inaddState(java.util.function.Consumer<byte[]>)if and only if the given feature is true. -
Method Summary
Modifier and TypeMethodDescriptionvoidGiven a sink forbyte[]this method should provide bytes representing a target's value.Provides known files.The path of the target this objects represents.static FileBooleanStateisDirectoryState(Path targetPath) Creates a file state which is in statetrueif the given path exists as a directory.static FileBooleanStateisRegularFileState(Path targetPath) Creates a file state which is in statetrueif the given path exists as a regular file.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface bm.target.FileState
getManagedRelative, toFileTarget, toFileTarget
-
Constructor Details
-
FileBooleanState
Creates a file state which adds the same constant value inaddState(java.util.function.Consumer<byte[]>)if and only if the given feature is true.This is typically used for targets which are fulfilled if a directory exists.
FileTarget.directoryCreateTarget(java.nio.file.Path)is a convenience method to create such a target with a simple default builder.- Parameters:
targetPath- for which to maintain the boolean statefileFeature- which defines the state
-
-
Method Details
-
isDirectoryState
Creates a file state which is in statetrueif the given path exists as a directory. See alsoFileTarget.directoryCreateTarget(java.nio.file.Path).- Parameters:
targetPath- to test- Returns:
- the state
-
isRegularFileState
Creates a file state which is in statetrueif the given path exists as a regular file.- Parameters:
targetPath- to test- Returns:
- the state
-
getTargetPath
Description copied from interface:FileStateThe path of the target this objects represents.- Specified by:
getTargetPathin interfaceFileState- Returns:
- path of the target
-
getManagedFiles
Description copied from interface:FileStateProvides known files.- Specified by:
getManagedFilesin interfaceFileState- Returns:
- the list of files in the directory managed by this target or the single file it represents
-
addState
Description copied from interface:StateProviderGiven a sink forbyte[]this method should provide bytes representing a target's value. If the value changes, the bytes provided must change too. But the bytes may also change if the value was not actually changed, though this will result in unnecessary builts of a target.This should not mingle in any dependency data.
As examples consider the full byte content of a file or only its last modified time. The latter changes even if a file is overwritten by itself, but for some cases, i.e. huge files, the time stamp may be preferable.
- Specified by:
addStatein interfaceStateProvider- Parameters:
sink- into which to fill the state representing bytes
-