title: Difference between getAndSet and compareAndSet in AtomicBoolean
body: <p>The thread title should be self-explnatory... I'm a bit confused between the specification of below methos from <code>AtomicBoolean</code> class:</p>
  
  <ul>
  <li><code>java.util.concurrent.atomic.AtomicBoolean#compareAndSet</code></li>
  <li><code>java.util.concurrent.atomic.AtomicBoolean#getAndSet</code></li>
  </ul>
  
  <p>My assemption is that both would result in the same behavior when used as a boolean clause in an <code>if</code> condition:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Test {
    private AtomicBoolean flag = AtomicBoolean(false);
  
    public void processSomeAction() {
      if (flag.getAndSet(false)) { // Shouldn't this be similar to flag.compareAndSet(false)
        // process some action
      }
    }
    //...
    private void internalMutatorMethod() {
      // do some staff then update the atomic flag
      flas.set(true);
    }
  }
  </code></pre>
  
  <p>Assuming that I want to retrieve the current flag value and update it automaticlly, shouldn't both methods produce the same behavior?</p>
  
  <p>I would much appreciate any explanations regarding how and when to use each of those if I'm missing internal differences.</p>