Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.69 KB | None | 0 0
  1. // Disconnect
  2. /** Disconnect me from my current successor, if any. */
  3.         void disconnect() {
  4.             Sq next = _successor;
  5.             if (next == null) {
  6.                 return;
  7.             }
  8.             _unconnected += 1; // increase number of squares that haven't been connected
  9.             next._predecessor = _successor = null;
  10.             if (_sequenceNum == 0) {
  11.                 // FIXME: If both this and next are now one-element groups,
  12.                 //        release their former group and set both group
  13.                 //        numbers to -1.
  14.                 //        Otherwise, if either is now a one-element group, set
  15.                 //        its group number to -1 without releasing the group
  16.                 //        number.
  17.                 //        Otherwise, the group has been split into two multi-
  18.                 //        element groups.  Create a new group for next.
  19.                 if ((this._predecessor == null) && (next._successor == null)) { // Cond 1
  20.                     releaseGroup(this._head._group);
  21.                     this._head._group = -1;
  22.                     next._head._group = -1;
  23.                 }
  24.                 else if ((this._predecessor == null) || (next._successor == null)) { // Cond 2
  25.                     if ((this._predecessor == null))
  26.                         this._head._group = -1;
  27.                     else
  28.                         next._head._group = -1;
  29.                 }
  30.                 else {
  31.                     next._head._group = newGroup();
  32.                 }
  33.             } else {
  34.                 // FIXME: If neither this nor any square in its group that
  35.                 //        precedes it has a fixed sequence number, set all
  36.                 //        their sequence numbers to 0 and create a new group
  37.                 //        for them if this has a current predecessor (other
  38.                 //        set group to -1).
  39.                 // FIXME: If neither next nor any square in its group that
  40.                 //        follows it has a fixed sequence number, set all
  41.                 //        their sequence numbers to 0 and create a new
  42.                 //        group for them if next has a current successor
  43.                 //        (otherwise set next's group to -1.)
  44.                 boolean noFixedNums = this._hasFixedNum;
  45.                 Sq predecessorPtr = this._predecessor;
  46.                 while (predecessorPtr != null) {
  47.                     boolean tempBool = false;
  48.                     if (!(predecessorPtr._hasFixedNum))
  49.                         tempBool = true;
  50.                     noFixedNums = (noFixedNums && tempBool);
  51.                     predecessorPtr = predecessorPtr._predecessor;
  52.                 }
  53.                 if (noFixedNums) { // condition #1
  54.                     this._sequenceNum = 0;
  55.                     Sq predecessorPtr2 = this._predecessor;
  56.                     while (predecessorPtr2 != null) {
  57.                         predecessorPtr2._sequenceNum = 0;
  58.                         predecessorPtr2 = predecessorPtr2._predecessor;
  59.                     }
  60.                     if (this._predecessor != null) {
  61.                         this._head._group = newGroup();
  62.                     }
  63.                     else {
  64.                         this._head._group = -1;
  65.                     }
  66.                 }
  67.                 boolean noFixedNums2 = next._hasFixedNum;
  68.                 Sq successorPtr = next._successor;
  69.                 while (successorPtr != null) {
  70.                     boolean tempBool = false;
  71.                     if (!(successorPtr._hasFixedNum))
  72.                         tempBool = true;
  73.                     noFixedNums2 = (noFixedNums2 && tempBool);
  74.                     successorPtr = successorPtr._successor;
  75.                 }
  76.                 if (noFixedNums2) { // condition #2
  77.                     next._sequenceNum = 0;
  78.                     Sq successorPtr2 = next._successor;
  79.                     while (successorPtr2 != null) {
  80.                         successorPtr2._sequenceNum = 0;
  81.                         successorPtr2 = successorPtr2._successor;
  82.                     }
  83.                     if (next._successor != null) {
  84.                         next._head._group = newGroup();
  85.                     }
  86.                     else {
  87.                         next._head._group = -1;
  88.                     }
  89.                 }
  90.             }
  91.             // FIXME: Set the _head of next and all squares in its group to
  92.             //        next.
  93.             next._head = next;
  94.             Sq successorPtr = next._successor;
  95.             while (successorPtr != null) {
  96.                 successorPtr._head = next;
  97.                 successorPtr = successorPtr._successor;
  98.             }
  99.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement