Class FieldWithDefault<T>

java.lang.Object
software.amazon.awssdk.services.s3.internal.FieldWithDefault<T>

public abstract class FieldWithDefault<T> extends Object
A helper class for setting a field's value to a default if it isn't specified, while still keeping track of whether the value was from the default or from the field. For example, a "profile name" field-with-default might be set to "null" with a default of "foo". value() returns "foo", while isDefault() can be used to keep track of the fact that the value was from the default.
  • Method Details

    • create

      public static <T> FieldWithDefault<T> create(T field, T defaultValue)
      Create a FieldWithDefault using the provided field and its default value. If the field is null, the default value will be returned by value() and isDefault() will return true. If the field is not null, the field value will be returned by value() and isDefault() will return false.
      See Also:
    • createLazy

      public static <T> FieldWithDefault<T> createLazy(T field, Supplier<T> defaultValue)
      Create a FieldWithDefault using the provided field and its default value. If the field is null, the default value will be returned by value() and isDefault() will return true. If the field is not null, the field value will be returned by value() and isDefault() will return false.

      This differs from create(Object, Object) in that the default value won't be resolved if the provided field is not null. The default value also won't be resolved until the first value() call. This is useful for delaying expensive calculations until right before they're needed.

    • value

      public abstract T value()
      Retrieve the value of this field.
    • isDefault

      public abstract boolean isDefault()
      True, if the value returned by value() is the default value (i.e. the field is null). False otherwise.
    • valueOrNullIfDefault

      public abstract T valueOrNullIfDefault()
      Return the field exactly as it was specified when the field-with-default was created. If the field was null, this will return null. This will not resolve the default if this is a field from createLazy(Object, Supplier).