Minor: Re-use Random in ContentRepositoryUtils instead of creating new one
This commit is contained in:
committed by
Petri Tuomola
parent
6125cccef0
commit
8c342a7d88
+5
-18
@@ -31,12 +31,10 @@ import org.apache.fineract.infrastructure.documentmanagement.exception.ContentMa
|
|||||||
|
|
||||||
public final class ContentRepositoryUtils {
|
public final class ContentRepositoryUtils {
|
||||||
|
|
||||||
private ContentRepositoryUtils() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
|
private ContentRepositoryUtils() {}
|
||||||
|
|
||||||
public enum ImageMIMEtype {
|
public enum ImageMIMEtype {
|
||||||
|
|
||||||
GIF("image/gif"), JPEG("image/jpeg"), PNG("image/png");
|
GIF("image/gif"), JPEG("image/jpeg"), PNG("image/png");
|
||||||
@@ -177,27 +175,16 @@ public final class ContentRepositoryUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a random String
|
* Generate a random String.
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String generateRandomString() {
|
public static String generateRandomString() {
|
||||||
final String characters = "abcdefghijklmnopqrstuvwxyz123456789";
|
final String characters = "abcdefghijklmnopqrstuvwxyz123456789";
|
||||||
final int length = generateRandomNumber();
|
// length is a random number between 5 to 16
|
||||||
|
final int length = random.nextInt(11) + 5;
|
||||||
final char[] text = new char[length];
|
final char[] text = new char[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
text[i] = characters.charAt(random.nextInt(characters.length()));
|
text[i] = characters.charAt(random.nextInt(characters.length()));
|
||||||
}
|
}
|
||||||
return new String(text);
|
return new String(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random number between 5 to 16
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int generateRandomNumber() {
|
|
||||||
final Random randomGenerator = new Random();
|
|
||||||
return randomGenerator.nextInt(11) + 5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user