-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
188 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
src/main/java/com/redislabs/riot/cli/in/GeneratorHelp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.redislabs.riot.cli.in; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.core.convert.Property; | ||
|
||
import com.github.javafaker.Faker; | ||
|
||
import picocli.CommandLine.Command; | ||
|
||
@Command(name = "faker-help", description = "Print all faker entities") | ||
public class GeneratorHelp implements Runnable { | ||
|
||
private final static List<String> EXCLUDES = Arrays.asList("instance", "options"); | ||
|
||
@Override | ||
public void run() { | ||
Arrays.asList(Faker.class.getDeclaredMethods()).stream().filter(this::accept) | ||
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName())).forEach(this::print); | ||
} | ||
|
||
public boolean accept(Method method) { | ||
if (EXCLUDES.contains(method.getName())) { | ||
return false; | ||
} | ||
return method.getReturnType().getPackage().equals(Faker.class.getPackage()); | ||
} | ||
|
||
public void print(Method method) { | ||
System.out.println(method.getName() + ": " | ||
+ String.join(" ", | ||
Arrays.asList(method.getReturnType().getDeclaredMethods()).stream() | ||
.filter(m -> m.getParameters().length == 0).map(m -> describe(m)) | ||
.collect(Collectors.toList()))); | ||
} | ||
|
||
private String describe(Method method) { | ||
String description = method.getName(); | ||
if (method.getParameters().length > 0) { | ||
description += "("; | ||
description += String.join(", ", | ||
Arrays.asList(method.getParameters()).stream().map(p -> describe(p)).collect(Collectors.toList())); | ||
description += ")"; | ||
} | ||
return description; | ||
} | ||
|
||
private String describe(Parameter parameter) { | ||
return parameter.getType().getSimpleName(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/redislabs/riot/generator/GeneratorFaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.redislabs.riot.generator; | ||
|
||
import java.util.Locale; | ||
|
||
import com.github.javafaker.Faker; | ||
|
||
public class GeneratorFaker extends Faker { | ||
|
||
private GeneratorReader reader; | ||
|
||
public GeneratorFaker(Locale locale, GeneratorReader reader) { | ||
super(locale); | ||
this.reader = reader; | ||
} | ||
|
||
public long sequence() { | ||
return reader.getSequence(); | ||
} | ||
|
||
public int partitions() { | ||
return reader.getPartitions(); | ||
} | ||
|
||
public int partitionIndex() { | ||
return reader.getPartitionIndex(); | ||
} | ||
|
||
} |
Oops, something went wrong.