es.moki.ratelimitj.redis.LimitRuleJsonSerialiser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ratelimitj-redis Show documentation
Show all versions of ratelimitj-redis Show documentation
The RateLimitJ project aims to provide a modular rate limiting solution
package es.moki.ratelimitj.redis;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import es.moki.ratelimitj.core.limiter.request.RequestLimitRule;
import java.util.OptionalInt;
class LimitRuleJsonSerialiser {
String encode(Iterable rules) {
JsonArray jsonArray = Json.array().asArray();
rules.forEach(rule -> jsonArray.add(toJsonArray(rule)));
return jsonArray.toString();
}
private JsonArray toJsonArray(RequestLimitRule rule) {
JsonArray array = Json.array().asArray().add(rule.getDurationSeconds()).add(rule.getLimit());
OptionalInt precision = rule.getPrecision();
if (precision.isPresent()) {
array.add(precision.getAsInt());
}
return array;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy