code: private boolean rule2(double sample) {
          if (!hasMean()) {
              return false;
          }
  
          if (sample > mean.getResult()) {
              if (rule2Count > 0) {
                  ++rule2Count;
              } else {
                  rule2Count = 1;
              }
          } else {
              if (rule2Count < 0) {
                  --rule2Count;
              } else {
                  rule2Count = -1;
              }
          }
  
          return Math.abs(rule2Count) >= 9;
      }
docs: Nine (or more) points in a row are on the same side of the mean