code: private long getNextAlignedWindowTs(long startTs, long endTs) {
          long nextTs = windowManager.getEarliestEventTs(startTs, endTs);
          if (nextTs == Long.MAX_VALUE || (nextTs % slidingIntervalMs == 0)) {
              return nextTs;
          }
          return nextTs + (slidingIntervalMs - (nextTs % slidingIntervalMs));
      }
docs: Computes the next window by scanning the events in the window and
  finds the next aligned window between the startTs and endTs. Return the end ts
  of the next aligned window, i.e. the ts when the window should fire.
  
  @param startTs the start timestamp (excluding)
  @param endTs the end timestamp (including)
  @return the aligned window end ts for the next window or Long.MAX_VALUE if there
  are no more events to be processed.