Record Class StringTarget
- Record Components:
name- is the name of the targetcontent- is a method which returns the string value representing the targetdependencies- are other targets this one depends onbuilder- is used to re-create the string value which can then be retrieved withcontent(), though usually it should be rather seldom that a builder is needed.
- All Implemented Interfaces:
StateProvider,Target
fromProperty(java.lang.String, java.lang.String) and fromEnv(java.lang.String, java.lang.String).
Neverthless, a StringTarget may have a builder. Think of a string obtained from
reading a database.
I DON'T GET IT
- Why is
contentnot just a string? - Why do we have it at all, and not just the builder which provides a value on demand?
As for the latter, the content provides
the value of the target at the start of the build, while the builder may or may not be called
to change this value. (Hardly ever needed.) For the former, the content shall fetch the string
from wherever it comes during the Machine.update(bm.machine.Target)
process and not already while setting up the dependency graph. This shall be the same as
the content of files is not read while setting up the dependency graph.
-
Constructor Summary
ConstructorsConstructorDescriptionStringTarget(String name, Supplier<String> content) Creates an instance with no dependencies and a no-op builder.Creates an instance with a no-op builder.StringTarget(String name, Supplier<String> content, List<Target> dependencies, ConsumeOrThrow<Target> builder) Creates an instance of aStringTargetrecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidGiven a sink forbyte[]this method should provide bytes representing a target's value.builder()Returns the value of thebuilderrecord component.content()Returns the value of thecontentrecord component.A shortcut forcontent().get().Returns the value of thedependenciesrecord component.final booleanIndicates whether some other object is "equal to" this one.static StringTargetCreates an instance for the value of an environment variable with no builder and setting thecontentto a method retrieving the environment variable.static StringTargetCreates an instance for the value from the given map with no builder and setting thecontent()fo a method retrieven the value from the map when requested.static StringTargetfromProperty(String propertyName, String dflt) Creates an instance for the value of a property with no builder and setting thecontentto a method retrieving the property.Return the list of targets this one depends on when being build.getName()The name of the target, unique within the graph of targets.final inthashCode()Returns a hash code value for this object.name()Returns the value of thenamerecord component.voidrecreate()Recreate this target.final StringtoString()Returns a string representation of this record class.withBuilder(ConsumeOrThrow<Target> newBuilder) Returns a shallow copy ofthiswith the new builder.withDependencies(List<Target> newDependencies) Returns a shallow copy ofthiswith the new list of dependencies.
-
Constructor Details
-
StringTarget
Creates an instance with a no-op builder. SeeStringTarget(String, Supplier, List, ConsumeOrThrow) -
StringTarget
Creates an instance with no dependencies and a no-op builder. SeeStringTarget(String, Supplier, List, ConsumeOrThrow) -
StringTarget
public StringTarget(String name, Supplier<String> content, List<Target> dependencies, ConsumeOrThrow<Target> builder) Creates an instance of aStringTargetrecord class.- Parameters:
name- the value for thenamerecord componentcontent- the value for thecontentrecord componentdependencies- the value for thedependenciesrecord componentbuilder- the value for thebuilderrecord component
-
-
Method Details
-
fromProperty
Creates an instance for the value of a property with no builder and setting thecontentto a method retrieving the property.- Parameters:
dflt- is allowed to benull
-
fromEnv
Creates an instance for the value of an environment variable with no builder and setting thecontentto a method retrieving the environment variable.- Parameters:
dflt- is allowed to benull
-
fromMap
Creates an instance for the value from the given map with no builder and setting thecontent()fo a method retrieven the value from the map when requested. -
withBuilder
Returns a shallow copy ofthiswith the new builder. -
withDependencies
Returns a shallow copy ofthiswith the new list of dependencies. -
currentValue
A shortcut forcontent().get(). -
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
-
getName
Description copied from interface:TargetThe name of the target, unique within the graph of targets. It is used as the key for keeping a persistent state of the target in aStateStore. Some state stores have restrictions on characters which cannot be used.Note: using a non unique name can only be detected during the build and only if both targets of the same name are traversed.
-
getDependencies
Description copied from interface:TargetReturn the list of targets this one depends on when being build. This should list all targets whose change should trigger a rebuild of this target.- Specified by:
getDependenciesin interfaceTarget- Returns:
- the dependencies of this target
-
recreate
Description copied from interface:TargetRecreate this target.- Specified by:
recreatein interfaceTarget- Throws:
BuildProblemException- as needed
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
dependencies
Returns the value of thedependenciesrecord component.- Returns:
- the value of the
dependenciesrecord component
-
builder
Returns the value of thebuilderrecord component.- Returns:
- the value of the
builderrecord component
-