com.github.fridujo.rabbitmq.mock.RandomStringGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rabbitmq-mock Show documentation
Show all versions of rabbitmq-mock Show documentation
Mock for RabbitMQ Java amqp-client
package com.github.fridujo.rabbitmq.mock;
import java.util.Random;
import java.util.stream.Collectors;
class RandomStringGenerator {
private final String prefix;
private final char[] availableCharacters;
private final int length;
RandomStringGenerator(String prefix, String availableCharacters, int length) {
this.prefix = prefix;
this.availableCharacters = availableCharacters.toCharArray();
this.length = length;
}
String generate() {
return prefix + new Random().ints(length, 0, availableCharacters.length)
.mapToObj(i -> availableCharacters[i])
.map(String::valueOf)
.collect(Collectors.joining());
}
}