Skip to content

Commit

Permalink
Ready for v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
igr committed Jun 12, 2019
1 parent 3150956 commit ee3b3e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ that you can use for some unique IDs :)

Generated names may consist of:

+ adjective (70+ names)
+ color name (50+ names)
+ adjective (1400+)
+ animals (380+)
+ color name (80+)
+ nouns (850+)
+ person name (140+ names)
+ superb name (10+ names)
+ pokemon name (700+ names)
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/oblac/nomen/Nomen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.oblac.nomen.data.Superb;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
Expand Down Expand Up @@ -56,6 +57,15 @@ public Nomen literal(final String literal) {
return this;
}

public Nomen random(final List<String> strings) {
template.add(() -> randomValueFrom(strings));
return this;
}
public Nomen random(final String... strings) {
template.add(() -> randomValueFrom(strings));
return this;
}

/**
* Appends color name.
*/
Expand Down Expand Up @@ -214,6 +224,11 @@ private String randomValueFrom(String... list) {

return list[index];
}
private String randomValueFrom(List<String> list) {
final int index = RND.nextInt(list.size());

return list.get(index);
}

private static final Random RND = new Random();
}

0 comments on commit ee3b3e7

Please sign in to comment.