Skip to content

Commit

Permalink
Merge d53a131 into 33f96e1
Browse files Browse the repository at this point in the history
  • Loading branch information
sachsgit committed Aug 20, 2019
2 parents 33f96e1 + d53a131 commit f9a964b
Show file tree
Hide file tree
Showing 12 changed files with 22,048 additions and 53 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -62,6 +62,7 @@ Fakers
* App
* Artist
* Avatar
* Babylon5
* Back To The Future
* Aviation
* Beer
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/github/javafaker/Babylon5.java
@@ -0,0 +1,17 @@
package com.github.javafaker;

public class Babylon5 {
private final Faker faker;

protected Babylon5(Faker faker) {
this.faker = faker;
}

public String character() {
return faker.resolve("babylon5.characters");
}

public String quote() {
return faker.resolve("babylon5.quotes");
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/github/javafaker/Faker.java
Expand Up @@ -93,6 +93,7 @@ public class Faker {
private final Relationships relationships;
private final Nation nation;
private final Dune dune;
private final Babylon5 babylon5;

public Faker() {
this(Locale.ENGLISH);
Expand Down Expand Up @@ -187,6 +188,7 @@ public Faker(Locale locale, Random random) {
this.relationships = new Relationships(this);
this.nation = new Nation(this);
this.dune = new Dune(this);
this.babylon5 = new Babylon5(this);
}

/**
Expand Down Expand Up @@ -609,6 +611,10 @@ public Dune dune() {
return dune;
}

public Babylon5 babylon5() {
return babylon5;
}

public String resolve(String key) {
return this.fakeValuesService.resolve(key, this, this);
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/github/javafaker/service/FakeValues.java
Expand Up @@ -12,7 +12,7 @@ public class FakeValues implements FakeValuesInterface {
private final Locale locale;
private final String filename;
private final String path;
private Map values;
private Map<?,?> values;

FakeValues(Locale locale) {
this(locale, getFilename(locale), getFilename(locale));
Expand Down Expand Up @@ -44,15 +44,15 @@ private static String language(Locale l) {
}

@Override
public Map get(String key) {
public Map<?,?> get(String key) {
if (values == null) {
values = loadValues();
}

return values == null ? null : (Map) values.get(key);
return values == null ? null : (Map<?,?>) values.get(key);
}

private Map loadValues() {
private Map<?,?> loadValues() {
String pathWithLocaleAndFilename = "/" + locale.getLanguage() + "/" + this.filename;
String pathWithFilename = "/" + filename + ".yml";
String pathWithLocale = "/" + locale.getLanguage() + ".yml";
Expand All @@ -70,12 +70,12 @@ private Map loadValues() {
return null;
}

final Map valuesMap = new Yaml().loadAs(stream, Map.class);
Map localeBased = (Map) valuesMap.get(locale.getLanguage());
final Map<?,?> valuesMap = new Yaml().loadAs(stream, Map.class);
Map<?,?> localeBased = (Map<?,?>) valuesMap.get(locale.getLanguage());
if (localeBased == null) {
localeBased = (Map) valuesMap.get(filename);
localeBased = (Map<?,?>) valuesMap.get(filename);
}
return (Map) localeBased.get("faker");
return (Map<?,?>) localeBased.get("faker");
}

private InputStream findStream(String filename) {
Expand Down
Expand Up @@ -3,5 +3,5 @@
import java.util.Map;

public interface FakeValuesInterface {
Map get(String key);
Map<?,?> get(String key);
}
Expand Up @@ -122,7 +122,9 @@ private Locale normalizeLocale(Locale locale) {
* @return
*/
public Object fetch(String key) {
List<Object> valuesArray = (List) fetchObject(key);
List<?> valuesArray = new ArrayList<Object>();
if (fetchObject(key) instanceof ArrayList)
valuesArray = (ArrayList<?>)fetchObject(key);
return valuesArray == null ? null : valuesArray.get(randomService.nextInt(valuesArray.size()));
}

Expand Down Expand Up @@ -176,7 +178,6 @@ public String safeFetch(String key, String defaultIfNull) {
* dot. E.g. name.first_name
* @return
*/
@SuppressWarnings("unchecked")
public Object fetchObject(String key) {
String[] path = key.split("\\.");

Expand All @@ -186,7 +187,7 @@ public Object fetchObject(String key) {
for (int p = 0; currentValue != null && p < path.length; p++) {
String currentPath = path[p];
if (currentValue instanceof Map) {
currentValue = ((Map) currentValue).get(currentPath);
currentValue = ((Map<?,?>) currentValue).get(currentPath);
} else {
currentValue = ((FakeValuesInterface) currentValue).get(currentPath);
}
Expand Down
Expand Up @@ -34,6 +34,7 @@ public String getPath() {
"aqua_teen_hunger_force.yml",
"artist.yml",
"aviation.yml",
"babylon5.yml",
"back_to_the_future.yml",
"bank.yml",
"beer.yml",
Expand Down

0 comments on commit f9a964b

Please sign in to comment.