All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rapid7.armor.interval.IntervalStrategyFixed Maven / Gradle / Ivy

There is a newer version: 0.0.52
Show newest version
package com.rapid7.armor.interval;

import java.time.Instant;
import java.util.regex.Pattern;

public class IntervalStrategyFixed implements IntervalStrategy {
  private static final long INTERVAL_UNITS = 60 * 1000;
  private static final Pattern INTERVAL_PATTERN = Pattern.compile("\\d+");

  private final long interval;

  public IntervalStrategyFixed(long interval) {
    this.interval = interval;
  }

  @Override
  public String getInterval() {
    return Long.toString(interval / INTERVAL_UNITS);
  }

  @Override
  public String getIntervalStart(Instant timestamp) {
    return Instant.ofEpochMilli(timestamp.toEpochMilli() / interval * interval).toString();
  }

  @Override
  public String getIntervalStart(Instant timestamp, int offset) {
    return Instant.ofEpochMilli(((timestamp.toEpochMilli() / interval) + offset) * interval).toString();
  }

  @Override
  public boolean supports(String interval) {
    return INTERVAL_PATTERN.matcher(interval).matches();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy