util.js 659 B

12345678910111213141516171819202122232425
  1. const ThreadLocalRandom = Java.type('java.util.concurrent.ThreadLocalRandom');
  2. module.exports = {
  3. randomWorld: () => {
  4. return 1 + ThreadLocalRandom.current().nextInt(10000)
  5. },
  6. /**
  7. * Returns the value of the "queries" getRequest parameter, which is an integer
  8. * bound between 1 and 500 with a default value of 1.
  9. *
  10. * @param request the current HTTP request
  11. * @return the value of the "queries" parameter
  12. */
  13. getQueries: (request) => {
  14. let param = request.getParam("queries");
  15. if (param == null) {
  16. return 1;
  17. }
  18. // invalid params are converted to 1
  19. return Math.min(500, parseInt(param, 10) || 1);
  20. }
  21. };