Uploaded image for project: 'DMR'
  1. DMR
  2. DMR-41

Add ModelNode.asListOrEmpty()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 1.5.0.Final
    • None
    • None

      It would be nice if you could do this:

      for (ModelNode ref : PROXIES.resolveModelAttribute(context, model).asListOrEmpty()) {
          String asString = ref.asString();
          this.outboundSocketBindings.add(new InjectedValueDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, asString), OutboundSocketBinding.class));
      }
      

      instead of this:

      ModelNode node = PROXIES.resolveModelAttribute(context, model);
      if (node.isDefined()) for (ModelNode ref : node.asList()) {
          String asString = ref.asString();
          this.outboundSocketBindings.add(new InjectedValueDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, asString), OutboundSocketBinding.class));
      }
      

      The asListOrEmpty method would return a Collections.emptyList() if the value is undefined, similarly to the existing asStringOrNull and related methods.

              dlloyd@redhat.com David Lloyd
              dlloyd@redhat.com David Lloyd
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: