title: Reuse a method with nested for-loops that only differs by some lines inside the inner loop
body: <p>I have a java method that basically looks like this:</p>
  <pre><code>public static Map&lt;String, List&lt;MyObject&gt;&gt; myMappingMethod(List&lt;A&gt; listOfA, List&lt;B&gt; listOfB) {
      final Map&lt;String, List&lt;MyObject&gt;&gt; results = new HashMap&lt;&gt;();
      
      for (A objA : listOfA) {
          if (!objA.meetsSomeCriteria()) {
              continue;
          }
  
          for (B objB : listOfB) {
              if (!objB.meetsSomeCriteria()) {
                  continue;
              }
              
              createFileWithIntermediateResultsFrom(objA, objB);   // &lt;-- seldomly needed
  
              // create new List&lt;MyObject&gt; from objA and objB and add to results
          }
      }
      
      return results;
  }
  </code></pre>
  <p>Now I want to basically duplicate this method and leave out the the <code>createFileWithIntermediateResultsFrom(objA, objB);</code> part cause usually I don't need that (but can't take it out, cause it is needed for like 1 %).</p>
  <p><strong>How to avoid copy&amp;paste with one line deletion and also avoid introducing some kind of &quot;debug&quot;-parameter?</strong></p>
  <p>(If possible, I don't want to change the signature to <code>myMappingMethod(List&lt;A&gt; listOfA, List&lt;B&gt; listOfB, boolean createDbgFile)</code>)</p>