/*
 * Copyright 2016, Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kiwi.core;

import java.util.ArrayDeque;

/** PropagQueue */
public class PropagQueue {

  private final ArrayDeque<Propagator> queue = new ArrayDeque<Propagator>();

  /** Enqueues the propagator for propagation if needed. 
   * 
   *  Side effect: this method sets the inQueue boolean of propagator to true. 
   */
  public void enqueue(Propagator propagator) {
    if (!propagator.enqueued) {
      queue.addLast(propagator);
      propagator.enqueued = true;
    }
  }

  // Propagate all the propagator in the queue. Note that propagation is
  // likely to enqueue additional propagator while it is running. The method
  // return true if the propagation succeeded and false otherwise. The enqueued
  // boolean of all the propagator in the queue is set to false no matter if
  // the propagation succeeded or not.
  public boolean propagate() {
    boolean feasible = true;
    while (!queue.isEmpty()) {
      Propagator propagator = queue.removeFirst();
      // Propagate only if unfailed.
      feasible = feasible && propagator.propagate();
      // Dequeue the propagator after propagation to prevent
      // it from enqueuing itself.
      propagator.enqueued = false;
    }
    return feasible;
  }
}

@@ -692,16 +692,188 @@
 Queue %7B%0A
+  // The propagation queue that contains all the propagators waiting for%0A  // propagation. All the contained propagator should have their enqueued%0A  // boolean set to true.
 %0A  priva
@@ -949,16 +949,22 @@
 %0A%0A  /** 
+%0A   * 
 Enqueues
@@ -1018,16 +1018,24 @@
 * %0A   * 
+%3Cp%3E%0A   *
  Side ef
@@ -1065,15 +1065,16 @@
 the 
-inQ
+enq
 ueue
+d
  boo
@@ -1102,16 +1102,26 @@
  true. %0A
+   * %3C/p%3E%0A
    */%0A  
@@ -1282,64 +1282,144 @@
 %0A  /
-/ Propagate all the propagator in the queue. Note that p
+**%0A   * Propagates the pending propagators.%0A   * %0A   * %3Cp%3E%0A   * Propagate all the propagators contained in the propagation queue.%0A   * P
 ropa
@@ -1427,21 +1427,16 @@
 ation is
-%0A  //
  likely 
@@ -1467,16 +1467,17 @@
 opagator
+s
  while i
@@ -1480,16 +1480,21 @@
 le it is
+%0A   *
  running
@@ -1503,26 +1503,179 @@
 The 
+propagation stops either when the queue is empty, or if%0A   * a propagator failed (meaning that the problem is infeasible).%0A   * %3C/p%3E%0A   * %0A   * %3Cp%3E%0A   * The 
 method
-%0A  //
  return
+s
  tru
@@ -1704,162 +1704,276 @@
 ucce
-e
 ded 
-and
+or
  false 
-otherwise
+if a%0A   * propagator failed
 . The 
-en
 queue
-d%0A  // boolean of all the propagator in the queue is
+ is empty at the end of the propagation and all%0A   * propagators contained in the queue have their enqueued boolean
  set to
+%0A   *
  false
- no matter if%0A  // the propagation succeeded or not.
+.%0A   * %3C/p%3E%0A   * %0A   * @return true if propagation succeeded, false otherwise.%0A   */
 %0A  p
@@ -2142,16 +2142,37 @@
  if 
-unfai
+the problem is still feasib
 le
-d
 .%0A  
@@ -2282,25 +2282,16 @@
  prevent
-%0A      //
  it from
@@ -2301,16 +2301,26 @@
 queuing 
+%0A      // 
 itself.%0A

Add Java doc to PropagQueue.