Uploaded image for project: 'WildFly Core'
  1. WildFly Core
  2. WFCORE-6218

Add Stream variant to PersistentResourceXMLDescription.PersistentResourceXMLBuilder

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 20.0.0.Beta6, 20.0.0.Final
    • 20.0.0.Beta5
    • Server
    • None

      When constructing a PersistentResourceXMLDescription, it is very convenient to use Streams, whether to filter a set of attributes that do not apply to a given schema version, or to combine multiple sets of attributes.

      e.g.

      PersistentResourceXMLDescriptionBuilder builder = builder(PATH_ELEMENT);
      Stream<? extends AttributeDefinition> attributes = Stream.concat(MyResourceDefinition.ATTRIBUTES.stream(), MyParentResourceDefinition.ATTRIBUTES.stream());
      if (!schema.since(Schema.VERSION_2)) {
          attributes = attributes.filter(Predicate.not(Set.of(MyResourceDefinition.FOO, MyResourceDefinition.BAR)::contains));
      }
      attributes::forEach(builder:addAttribute);
      

      However, in order to use this pattern fluently, most implementations will end up with the same static method:

      static PersistentResourceXMLDescriptionBuilder addAttributes(PersistentResourceXMLDescriptionBuilder builder, Stream<? extends AttributeDefinition> attributes) {
          attributes::forEach(builder::addAttribute);
          return builder;
      }
      

      Adding a stream-based addAttributes(...) method avoids the need for implementors to duplicate this method.

            pferraro@redhat.com Paul Ferraro
            pferraro@redhat.com Paul Ferraro
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: