title: What's the most concise / best way to write this java code?
body: <p>I'm writing a simple distributed java rmi application and I have a bunch of methods that each need to iterate through a map of client interfaces in order to call various other methods on those interfaces, like so:</p>
  
  <pre><code>public void methodX (arg1, arg2) {
    Iterator&lt;String&gt; itr = clients.keySet().iterator;
    while (itr.hasNext()) {
      String name = itr.next();
      if (!"mod".equals(name)) {
        try {
          clients.get(name).methodXX(arg1, arg2);
        } catch(RemoteException ex) {
          // do something
        }
      }
    }
  }
  
  public void methodY (arg1, arg2, arg3) {
    Iterator&lt;String&gt; itr = clients.keySet().iterator;
    while (itr.hasNext()) {
      String name = itr.next();
      if (!"mod".equals(name)) {
        try {
          clients.get(name).methodYY(arg1, arg2, arg3);
        } catch(RemoteException ex) {
          // do something
        }
      }
    }
  }
  </code></pre>
  
  <p>Now I modified these so that instead they each call a single method doAll by passing a new argument called MESSAGE_TYPE, like so:</p>
  
  <pre><code>public void methodX (arg1, arg2) {
    doAll(MESSAGE_TYPE.METHODX, arg1, arg2, null);
  }
  
  public void methodY (arg1, arg2, arg3) {
    doAll(MESSAGE_TYPE_METHODY, arg1, arg2, arg3);
  }
  </code></pre>
  
  <p>And the doAll method:</p>
  
  <pre><code>public void doAll(msg_type, arg1, arg2, arg3) {
   Iterator&lt;String&gt; itr = clients.keySet().iterator;
    while (itr.hasNext()) {
      String name = itr.next();
      if (!"mod".equals(name)) {
        try {
          switch(msg_type) {
            case METHODX:
              clients.get(name).methodXX(arg1, arg2);
              break;
            case METHODY:
              clients.get(name).methodYY(arg1, arg2, arg3);
              break;
          }
        } catch(RemoteException ex) {
          // do something
        }
      }
    }
  }
  </code></pre>
  
  <p>Now there are many more methods like this, and so my doAll method needs to take a bunch of args and each methodXX that calls it pass a bunch of nulls to it.</p>
  
  <p>Can I rewrite this so it's more concise? If so, can you provide an example?</p>