public synchronized boolean isValid(int maxAllowedWindowsWithExtrapolation) {
    int currentArrayIndex = arrayIndex(currentWindowIndex());
    // The total number of valid window indices should exclude the current window index.
    int numValidIndicesAdjustment = _validity.get(currentArrayIndex) ? 1 : 0;
    boolean allIndicesValid = _validity.cardinality() - numValidIndicesAdjustment == _counts.length - 1;
    // All indices should be valid and should not have more than maxAllowedWindowsWithExtrapolation extrapolations.
    return allIndicesValid && numWindowsWithExtrapolation() <= maxAllowedWindowsWithExtrapolation;
  }
@Test
  public void testIsValid() {
    RawMetricValues rawValues = new RawMetricValues(NUM_WINDOWS_TO_KEEP, MIN_SAMPLES_PER_WINDOW, NUM_RAW_METRICS);
    rawValues.updateOldestWindowIndex(0);
    MetricSample<String, IntegerEntity> m = getMetricSample(10, 10, 10);

    for (int i = 0; i < NUM_WINDOWS_TO_KEEP; i++) {
      for (int j = 0; j < MIN_SAMPLES_PER_WINDOW - 1; j++) {
        addSample(rawValues, m, i);
      }
    }
    assertTrue(rawValues.isValid(5));
    assertFalse(rawValues.isValid(4));
    addSample(rawValues, m, 0);
    assertTrue(rawValues.isValid(4));
  }