class ListGatewayCommand extends GfshCommand {

  protected void accumulateListGatewayResult(ResultModel result,
      Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans,
      Map<String, GatewayReceiverMXBean> gatewayReceiverBeans) {
    if (!gatewaySenderBeans.isEmpty()) {
      TabularResultModel gatewaySenders = result.addTable("gatewaySenders");
      gatewaySenders.setHeader(CliStrings.SECTION_GATEWAY_SENDER);
      for (Map.Entry<String, Map<String, GatewaySenderMXBean>> entry : gatewaySenderBeans
          .entrySet()) {
        for (Map.Entry<String, GatewaySenderMXBean> memberToBean : entry.getValue().entrySet()) {
          gatewaySenders.accumulate(CliStrings.RESULT_GATEWAY_SENDER_ID, entry.getKey());
          gatewaySenders.accumulate(CliStrings.RESULT_HOST_MEMBER, memberToBean.getKey());
          gatewaySenders.accumulate(CliStrings.RESULT_REMOTE_CLUSTER,
              memberToBean.getValue().getRemoteDSId() + "");
          gatewaySenders.accumulate(CliStrings.RESULT_TYPE, memberToBean.getValue().isParallel()
              ? CliStrings.SENDER_PARALLEL : CliStrings.SENDER_SERIAL);
          gatewaySenders.accumulate(CliStrings.RESULT_STATUS, getStatus(memberToBean.getValue()));
          gatewaySenders.accumulate(CliStrings.RESULT_QUEUED_EVENTS,
              memberToBean.getValue().getEventQueueSize() + "");
          gatewaySenders.accumulate(CliStrings.RESULT_RECEIVER,
              memberToBean.getValue().getGatewayReceiver());
        }
      }
    }

    if (!gatewayReceiverBeans.isEmpty()) {
      TabularResultModel gatewaySenders = result.addTable("gatewayReceivers");
      gatewaySenders.setHeader(CliStrings.SECTION_GATEWAY_RECEIVER);
      for (Map.Entry<String, GatewayReceiverMXBean> entry : gatewayReceiverBeans.entrySet()) {
        gatewaySenders.accumulate(CliStrings.RESULT_HOST_MEMBER, entry.getKey());
        gatewaySenders.accumulate(CliStrings.RESULT_PORT, entry.getValue().getPort() + "");
        gatewaySenders.accumulate(CliStrings.RESULT_SENDERS_COUNT,
            entry.getValue().getClientConnectionCount() + "");
        if (entry.getValue() == null || entry.getValue().getConnectedGatewaySenders() == null) {
          gatewaySenders.accumulate(CliStrings.RESULT_SENDER_CONNECTED, "");
        } else {
          gatewaySenders.accumulate(CliStrings.RESULT_SENDER_CONNECTED,
              Arrays.stream(entry.getValue().getConnectedGatewaySenders()).collect(joining(", ")));
        }
      }
    }
  }

}