public abstract static class ObfuscatingToStringStyle.Builder extends Object
ToStringStyle
objects.
In addition, it can create Suppliers
of obfuscating ToStringStyle
objects. These can be used as a more light-weight
way of creating obfuscating ToStringStyle
objects; whereas creating obfuscating ToStringStyle
objects using build()
will always copy its internal settings, Suppliers
created using supplier()
will create obfuscating
ToStringStyle
objects from a shared copy instead. You should use supplier()
instead of build()
if you plan on
creating multiple obfuscating ToStringStyle
objects with the same settings.
Modifier and Type | Class and Description |
---|---|
static class |
ObfuscatingToStringStyle.Builder.Snapshot
A snapshot of the settings of a
ObfuscatingToStringStyle.Builder . |
Modifier and Type | Method and Description |
---|---|
abstract ObfuscatingToStringStyle |
build()
Creates a new obfuscating
ToStringStyle with the fields and obfuscators added to this builder. |
abstract ObfuscatingToStringStyle.Builder |
caseInsensitiveByDefault()
Sets the default case sensitivity for new fields to
CaseSensitivity.CASE_INSENSITIVE . |
abstract ObfuscatingToStringStyle.Builder |
caseSensitiveByDefault()
Sets the default case sensitivity for new fields to
CaseSensitivity.CASE_SENSITIVE . |
static ObfuscatingToStringStyle.Builder |
create(Function<? super ObfuscatingToStringStyle.Builder,? extends ObfuscatingToStringStyle> fromBuilderConstructor,
Function<? super ObfuscatingToStringStyle.Builder.Snapshot,? extends ObfuscatingToStringStyle> fromSnapshotConstructor)
Creates a new builder.
|
abstract ObfuscatingToStringStyle.Builder |
excludeSummariesByDefault()
Indicates that by default field summaries will not be obfuscated (default).
|
abstract ObfuscatingToStringStyle.Builder |
includeSummariesByDefault()
Indicates that by default field summaries will be obfuscated.
|
abstract ObfuscatingToStringStyle.Builder.Snapshot |
snapshot()
Creates a new snapshot of this builder.
|
Supplier<ObfuscatingToStringStyle> |
supplier()
Creates a new
Supplier that will create obfuscating ToStringStyle objects with the properties and obfuscators added to this
builder. |
<R> R |
transform(Function<? super ObfuscatingToStringStyle.Builder,? extends R> f)
This method allows the application of a function to this builder.
|
abstract ObfuscatingToStringStyle.FieldConfigurer |
withField(String fieldName,
Obfuscator obfuscator)
Adds a field to obfuscate.
|
abstract ObfuscatingToStringStyle.FieldConfigurer |
withField(String fieldName,
Obfuscator obfuscator,
CaseSensitivity caseSensitivity)
Adds a field to obfuscate.
|
public static ObfuscatingToStringStyle.Builder create(Function<? super ObfuscatingToStringStyle.Builder,? extends ObfuscatingToStringStyle> fromBuilderConstructor, Function<? super ObfuscatingToStringStyle.Builder.Snapshot,? extends ObfuscatingToStringStyle> fromSnapshotConstructor)
This builder will use two factories to build ObfuscatingToStringStyle
and Suppliers
of
ObfuscatingToStringStyles
based on the settings of this builder. This allows the building of sub classes
of ObfuscatingToStringStyle
and Suppliers
of such sub classes; just create two constructors that delegate to
ObfuscatingToStringStyle(Builder)
and
ObfuscatingToStringStyle(ObfuscatingToStringStyle.Builder.Snapshot)
respectively, and provide these
constructors as factories to this Builder
constructor.
For example:
public final class MyToStringStyle extends ObfuscatingToStringStyle {
private MyToStringStyle(Builder builder) {
super(builder);
// custom configuration
}
private MyToStringStyle(Snapshot snapshot) {
super(snapshot);
// custom configuration
}
public static Builder builder() {
return Builder.create(MyToStringStyle::new, MyToStringStyle::new);
}
}
fromBuilderConstructor
- The factory to build ObfuscatingToStringStyles
based on the current settings
of this builder.fromSnapshotConstructor
- The factory to build ObfuscatingToStringStyles
based on a snapshot of this
builder.NullPointerException
- If either of the given factories is null
.public abstract ObfuscatingToStringStyle.FieldConfigurer withField(String fieldName, Obfuscator obfuscator)
withField(String, Obfuscator, CaseSensitivity)
with the last specified default case sensitivity
using caseSensitiveByDefault()
or caseInsensitiveByDefault()
. The default is CaseSensitivity.CASE_SENSITIVE
.fieldName
- The name of the field. It will be treated case sensitively.obfuscator
- The obfuscator to use for obfuscating the field.ToStringStyle
objects.NullPointerException
- If the given field name or obfuscator is null
.IllegalArgumentException
- If a field with the same name and the same case sensitivity was already added.public abstract ObfuscatingToStringStyle.FieldConfigurer withField(String fieldName, Obfuscator obfuscator, CaseSensitivity caseSensitivity)
fieldName
- The name of the field.obfuscator
- The obfuscator to use for obfuscating the field.caseSensitivity
- The case sensitivity for the key.NullPointerException
- If the given field name, obfuscator or case sensitivity is null
.IllegalArgumentException
- If a field with the same name and the same case sensitivity was already added.public abstract ObfuscatingToStringStyle.Builder caseSensitiveByDefault()
CaseSensitivity.CASE_SENSITIVE
. This is the default setting.
Note that this will not change the case sensitivity of any field that was already added.
public abstract ObfuscatingToStringStyle.Builder caseInsensitiveByDefault()
CaseSensitivity.CASE_INSENSITIVE
.
Note that this will not change the case sensitivity of any field that was already added.
public abstract ObfuscatingToStringStyle.Builder includeSummariesByDefault()
Note that this will not change what will be obfuscated for any field that was already added.
public abstract ObfuscatingToStringStyle.Builder excludeSummariesByDefault()
Note that this will not change what will be obfuscated for any field that was already added.
public <R> R transform(Function<? super ObfuscatingToStringStyle.Builder,? extends R> f)
Any exception thrown by the function will be propagated to the caller.
R
- The type of the result of the function.f
- The function to apply.public abstract ObfuscatingToStringStyle.Builder.Snapshot snapshot()
public abstract ObfuscatingToStringStyle build()
ToStringStyle
with the fields and obfuscators added to this builder.ToStringStyle
.public Supplier<ObfuscatingToStringStyle> supplier()
Supplier
that will create obfuscating ToStringStyle
objects with the properties and obfuscators added to this
builder.
Unlike build()
, this method will create a snapshot
of the current settings of this builder and reuses those to
create obfuscating ToStringStyle
objects. This makes this method more light-weight when you need to create multiple obfuscating
ToStringStyle
objects with the current settings of this builder.
Supplier
.Copyright © 2020–2022. All rights reserved.