/** * Builds a new {@link ImmutableParameter ImmutableParameter}. * @return An immutable instance of Parameter * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableParameter build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableParameter(name, value); }
/** * Fill a builder with attribute values from the provided {@code Parameter} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Parameter instance) { Objects.requireNonNull(instance, "instance"); name(instance.getName()); Optional<String> valueOptional = instance.getValue(); if (valueOptional.isPresent()) { value(valueOptional); } return this; }
/** * Creates an immutable copy of a {@link Parameter} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Parameter instance */ public static ImmutableParameter copyOf(Parameter instance) { if (instance instanceof ImmutableParameter) { return (ImmutableParameter) instance; } return ImmutableParameter.builder() .from(instance) .build(); }
/** * Creates a builder for {@link ImmutableParameter ImmutableParameter}. * @return A new ImmutableParameter builder */ public static ImmutableParameter.Builder builder() { return new ImmutableParameter.Builder(); }
/** * generate parameters from the "ITEM_DATA" of a "web_submit_data" * @param extractPart the extract containing only the "ITEM_DATA" of the "web_submit_data" */ @VisibleForTesting public static List<Parameter> buildPostParamsFromExtract(List<String> extractPart) { List<Item> items = MethodUtils.parseItemList(extractPart); return items.stream() .filter(item -> item.getAttribute("Name").isPresent()) .<Parameter>map(item -> ImmutableParameter.builder().name(item.getAttribute("Name").get()).value(item.getAttribute("Value")).build()) .collect(Collectors.toList()); }