code: protected void appendAppId(ApplicationId appId, Message m) {
      if (appId == null) {
        return;
      }
  
      // check if any application-id avp is already present.
      // we could use m.getApplicationIdAvps().size() > 0 but this should spare a few cpu cycles
      for (Avp avp : m.getAvps()) {
        int code = avp.getCode();
        if (code == Avp.ACCT_APPLICATION_ID || code == Avp.AUTH_APPLICATION_ID || code == Avp.VENDOR_SPECIFIC_APPLICATION_ID) {
          return;
        }
      }
  
      if (appId.getVendorId() == 0) {
        if (appId.getAcctAppId() != 0) {
          m.getAvps().addAvp(Avp.ACCT_APPLICATION_ID, appId.getAcctAppId(), true, false, true);
        }
        if (appId.getAuthAppId() != 0) {
          m.getAvps().addAvp(Avp.AUTH_APPLICATION_ID, appId.getAuthAppId(), true, false, true);
        }
      }
      else {
        AvpSet avp = m.getAvps().addGroupedAvp(Avp.VENDOR_SPECIFIC_APPLICATION_ID, true, false);
        avp.addAvp(Avp.VENDOR_ID, appId.getVendorId(), true, false, true);
        if (appId.getAuthAppId() != 0) {
          avp.addAvp(Avp.AUTH_APPLICATION_ID, appId.getAuthAppId(), true, false, true);
        }
        if (appId.getAcctAppId() != 0) {
          avp.addAvp(Avp.ACCT_APPLICATION_ID, appId.getAcctAppId(), true, false, true);
        }
      }
    }
docs: Appends an *-Application-Id AVP to the message, if none is present already.
  
  @param appId the application-id value
  @param m the message to append the *-Application-Id