Skip to content

Commit edd5433

Browse files
committed
Simplify type usage: use interfaces where applicable
1 parent b2ee9bb commit edd5433

File tree

62 files changed

+311
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+311
-244
lines changed

src/main/java/ldbc/snb/datagen/LdbcDatagen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public int runGenerateJob(Configuration conf) throws Exception {
8888

8989
String hadoopPrefix = conf.get("ldbc.snb.datagen.serializer.hadoopDir");
9090
FileSystem fs = FileSystem.get(conf);
91-
ArrayList<Float> percentages = new ArrayList<>();
91+
List<Float> percentages = new ArrayList<>();
9292
percentages.add(0.45f);
9393
percentages.add(0.45f);
9494
percentages.add(0.1f);
@@ -143,7 +143,7 @@ public int runGenerateJob(Configuration conf) throws Exception {
143143

144144
fs.delete(new Path(DatagenParams.hadoopDir + "/persons"), true);
145145
printProgress("Merging the different edge files");
146-
ArrayList<String> edgeFileNames = new ArrayList<>();
146+
List<String> edgeFileNames = new ArrayList<>();
147147
edgeFileNames.add(hadoopPrefix + "/universityEdges");
148148
edgeFileNames.add(hadoopPrefix + "/interestEdges");
149149
edgeFileNames.add(hadoopPrefix + "/randomEdges");

src/main/java/ldbc/snb/datagen/dictionary/BrowserDictionary.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4141
import java.io.IOException;
4242
import java.io.InputStreamReader;
4343
import java.util.ArrayList;
44+
import java.util.List;
4445
import java.util.Random;
4546

4647
public class BrowserDictionary {
4748

4849
private static final String SEPARATOR_ = " ";
49-
private ArrayList<String> browsers_;
50-
private ArrayList<Double> cumulativeDistribution_;
50+
private List<String> browsers_;
51+
private List<Double> cumulativeDistribution_;
5152
private double probAnotherBrowser_ = 0.0f;
5253

5354
public BrowserDictionary(double probAnotherBrowser) {

src/main/java/ldbc/snb/datagen/dictionary/CompanyDictionary.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4242
import java.io.IOException;
4343
import java.io.InputStreamReader;
4444
import java.util.ArrayList;
45+
import java.util.List;
4546
import java.util.Set;
4647
import java.util.TreeMap;
4748

@@ -60,7 +61,7 @@ public class CompanyDictionary {
6061
/**
6162
* < @brief A map containing the location of each company. *
6263
*/
63-
private TreeMap<Integer, ArrayList<Long>> companiesByCountry;
64+
private TreeMap<Integer, List<Long>> companiesByCountry;
6465
/**
6566
* < @brief A map containing the companies of each country. *
6667
*/
@@ -81,7 +82,7 @@ public CompanyDictionary(PlaceDictionary placeDictionary,
8182
this.probUnCorrelatedCompany = probUnCorrelatedCompany;
8283
this.companyName = new TreeMap<>();
8384
this.companyCountry = new TreeMap<>();
84-
this.companiesByCountry = new TreeMap<Integer, ArrayList<Long>>();
85+
this.companiesByCountry = new TreeMap<>();
8586
for (Integer id : placeDictionary.getCountries()) {
8687
this.companiesByCountry.put(id, new ArrayList<>());
8788
}
@@ -135,7 +136,7 @@ public int getCountry(Long company) {
135136
*/
136137
public long getRandomCompany(RandomGeneratorFarm randomFarm, int countryId) {
137138
int locId = countryId;
138-
ArrayList<Integer> countries = placeDictionary.getCountries();
139+
List<Integer> countries = placeDictionary.getCountries();
139140
if (randomFarm.get(RandomGeneratorFarm.Aspect.UNCORRELATED_COMPANY).nextDouble() <= probUnCorrelatedCompany) {
140141
locId = countries.get(randomFarm.get(RandomGeneratorFarm.Aspect.UNCORRELATED_COMPANY_LOCATION)
141142
.nextInt(countries.size()));

src/main/java/ldbc/snb/datagen/dictionary/EmailDictionary.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4141
import java.io.IOException;
4242
import java.io.InputStreamReader;
4343
import java.util.ArrayList;
44+
import java.util.List;
4445
import java.util.Random;
4546

4647

@@ -51,8 +52,8 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
5152
public class EmailDictionary {
5253

5354
private static final String SEPARATOR = " ";
54-
private ArrayList<String> emails;
55-
private ArrayList<Double> cumulativeDistribution;
55+
private List<String> emails;
56+
private List<Double> cumulativeDistribution;
5657

5758
/**
5859
* @brief Constructor.

src/main/java/ldbc/snb/datagen/dictionary/FlashmobTagDictionary.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4242
import java.util.ArrayList;
4343
import java.util.Arrays;
4444
import java.util.HashMap;
45+
import java.util.Map;
4546
import java.util.Iterator;
47+
import java.util.List;
4648
import java.util.Random;
4749
import java.util.TreeSet;
4850

@@ -64,7 +66,7 @@ public class FlashmobTagDictionary {
6466
/**
6567
* < @brief The tag dictionary used to create the flashmob tags.
6668
*/
67-
private HashMap<Integer, ArrayList<FlashmobTag>> flashmobTags;
69+
private Map<Integer, List<FlashmobTag>> flashmobTags;
6870
/**
6971
* < @brief A map of identifiers of tags to flashmob tag instances.
7072
*/
@@ -99,7 +101,7 @@ public FlashmobTagDictionary(TagDictionary tagDictionary,
99101
this.dateGen = dateGen;
100102
this.levelGenerator = new PowerDistribution(flashmobTagMinLevel, flashmobTagMaxLevel, flashmobTagDistExp);
101103
this.random = new Random(0);
102-
this.flashmobTags = new HashMap<Integer, ArrayList<FlashmobTag>>();
104+
this.flashmobTags = new HashMap<>();
103105
this.flashmobTagsPerMonth = flashmobTagsPerMonth;
104106
this.probInterestFlashmobTag = probInterestFlashmobTag;
105107
this.probRandomPerLevel = probRandomPerLevel;
@@ -115,7 +117,7 @@ private void initialize() {
115117
flashmobTagCumDist = new FlashmobTag[numFlashmobTags];
116118
double sumLevels = 0;
117119
for (int i = 0; i < numFlashmobTags; ++i) {
118-
ArrayList<FlashmobTag> instances = flashmobTags.get(tags[i]);
120+
List<FlashmobTag> instances = flashmobTags.get(tags[i]);
119121
if (instances == null) {
120122
instances = new ArrayList<>();
121123
flashmobTags.put(tags[i], instances);
@@ -173,12 +175,12 @@ private boolean selectFlashmobTag(Random rand, int index) {
173175
* @param[in] interests The set of interests.
174176
* @param[in] fromDate The date from which to consider the flashmob tags.
175177
*/
176-
public ArrayList<FlashmobTag> generateFlashmobTags(Random rand, TreeSet<Integer> interests, long fromDate) {
177-
ArrayList<FlashmobTag> result = new ArrayList<>();
178+
public List<FlashmobTag> generateFlashmobTags(Random rand, TreeSet<Integer> interests, long fromDate) {
179+
List<FlashmobTag> result = new ArrayList<>();
178180
Iterator<Integer> it = interests.iterator();
179181
while (it.hasNext()) {
180182
Integer tag = it.next();
181-
ArrayList<FlashmobTag> instances = flashmobTags.get(tag);
183+
List<FlashmobTag> instances = flashmobTags.get(tag);
182184
if (instances != null) {
183185
Iterator<FlashmobTag> it2 = instances.iterator();
184186
while (it2.hasNext()) {

src/main/java/ldbc/snb/datagen/dictionary/IPAddressDictionary.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4343
import java.io.InputStreamReader;
4444
import java.util.ArrayList;
4545
import java.util.HashMap;
46+
import java.util.Map;
47+
import java.util.List;
4648
import java.util.Random;
4749
import java.util.TreeMap;
4850

@@ -53,7 +55,7 @@ public class IPAddressDictionary {
5355
private static final String SEPARATOR_IP = "[.]";
5456
private static final String SEPARATOR_MASK = "/";
5557
private static final int MAX_IP_COUNTRY = 100;
56-
private TreeMap<Integer, ArrayList<IP>> ipsByCountry;
58+
private TreeMap<Integer, List<IP>> ipsByCountry;
5759
/**
5860
* < @brief The country of ips. *
5961
*/
@@ -66,7 +68,7 @@ public class IPAddressDictionary {
6668
public IPAddressDictionary(PlaceDictionary locationDic) {
6769

6870
this.placeDictionary = locationDic;
69-
this.ipsByCountry = new TreeMap<Integer, ArrayList<IP>>();
71+
this.ipsByCountry = new TreeMap<Integer, List<IP>>();
7072
load(DatagenParams.countryAbbrMappingFile, DatagenParams.IPZONE_DIRECTORY);
7173
}
7274

@@ -77,7 +79,7 @@ public IPAddressDictionary(PlaceDictionary locationDic) {
7779
*/
7880
private void load(String mappingFileName, String baseIPdir) {
7981
String line;
80-
HashMap<String, String> countryAbbreMap = new HashMap<>();
82+
Map<String, String> countryAbbreMap = new HashMap<>();
8183
try {
8284
BufferedReader mappingFile = new BufferedReader(new InputStreamReader(getClass()
8385
.getResourceAsStream(mappingFileName), "UTF-8"));
@@ -89,7 +91,7 @@ private void load(String mappingFileName, String baseIPdir) {
8991
}
9092
mappingFile.close();
9193

92-
ArrayList<Integer> countries = placeDictionary.getCountries();
94+
List<Integer> countries = placeDictionary.getCountries();
9395
for (int i = 0; i < countries.size(); i++) {
9496
ipsByCountry.put(countries.get(i), new ArrayList<>());
9597

@@ -126,7 +128,7 @@ public IP getIP(Random random, int countryId) {
126128
while (!placeDictionary.getType(finalLocationIndex).equals("country")) {
127129
finalLocationIndex = placeDictionary.belongsTo(finalLocationIndex);
128130
}
129-
ArrayList<IP> countryIPs = ipsByCountry.get(finalLocationIndex);
131+
List<IP> countryIPs = ipsByCountry.get(finalLocationIndex);
130132
int idx = random.nextInt(countryIPs.size());
131133

132134
IP networkIp = countryIPs.get(idx);

src/main/java/ldbc/snb/datagen/dictionary/LanguageDictionary.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4242
import java.io.InputStreamReader;
4343
import java.util.ArrayList;
4444
import java.util.HashMap;
45+
import java.util.Map;
46+
import java.util.List;
4547
import java.util.Random;
4648

4749

@@ -50,15 +52,15 @@ public class LanguageDictionary {
5052
private static final String SEPARATOR = " ";
5153
private static final String ISO_ENGLISH_CODE = "en";
5254

53-
private ArrayList<String> languages;
55+
private List<String> languages;
5456
/**
5557
* < @brief The array of languages. *
5658
*/
57-
private HashMap<Integer, ArrayList<Integer>> officalLanguagesByCountry;
59+
private Map<Integer, List<Integer>> officalLanguagesByCountry;
5860
/**
5961
* < @brief The official languages by country. *
6062
*/
61-
private HashMap<Integer, ArrayList<Integer>> languagesByCountry;
63+
private Map<Integer, List<Integer>> languagesByCountry;
6264
/**
6365
* < @brief The languages by country. *
6466
*/
@@ -84,8 +86,8 @@ public LanguageDictionary(PlaceDictionary locationDic,
8486
this.probEnglish = probEnglish;
8587
this.probSecondLang = probSecondLang;
8688
this.languages = new ArrayList<>();
87-
this.officalLanguagesByCountry = new HashMap<Integer, ArrayList<Integer>>();
88-
this.languagesByCountry = new HashMap<Integer, ArrayList<Integer>>();
89+
this.officalLanguagesByCountry = new HashMap<>();
90+
this.languagesByCountry = new HashMap<>();
8991
load(DatagenParams.languageDictionaryFile);
9092
}
9193

@@ -145,8 +147,8 @@ public String getLanguageName(int languageId) {
145147
* @return The set of randomly choosen languages.
146148
* @breif Gets a set of random languages from a country.
147149
*/
148-
public ArrayList<Integer> getLanguages(Random random, int country) {
149-
ArrayList<Integer> langSet = new ArrayList<>();
150+
public List<Integer> getLanguages(Random random, int country) {
151+
List<Integer> langSet = new ArrayList<>();
150152
if (officalLanguagesByCountry.get(country).size() != 0) {
151153
int id = random.nextInt(officalLanguagesByCountry.get(country).size());
152154
langSet.add(officalLanguagesByCountry.get(country).get(id));

src/main/java/ldbc/snb/datagen/dictionary/NamesDictionary.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4242
import java.io.IOException;
4343
import java.io.InputStreamReader;
4444
import java.util.HashMap;
45+
import java.util.Map;
4546
import java.util.Random;
4647
import java.util.Vector;
4748

@@ -55,9 +56,9 @@ public class NamesDictionary {
5556
private static final int topN = 30;
5657

5758
private PlaceDictionary locationDic;
58-
private HashMap<Integer, Vector<String>> surNamesByLocations;
59-
private Vector<HashMap<Integer, Vector<String>>> givenNamesByLocationsMale; // Year / Location / Names
60-
private Vector<HashMap<Integer, Vector<String>>> givenNamesByLocationsFemale;
59+
private Map<Integer, Vector<String>> surNamesByLocations;
60+
private Vector<Map<Integer, Vector<String>>> givenNamesByLocationsMale; // Year / Location / Names
61+
private Vector<Map<Integer, Vector<String>>> givenNamesByLocationsFemale;
6162
private GeometricDist geoDist;
6263

6364
public NamesDictionary(PlaceDictionary locationDic) {
@@ -67,18 +68,18 @@ public NamesDictionary(PlaceDictionary locationDic) {
6768
}
6869

6970
private void init() {
70-
surNamesByLocations = new HashMap<Integer, Vector<String>>();
71+
surNamesByLocations = new HashMap<>();
7172
for (Integer id : locationDic.getCountries()) {
7273
surNamesByLocations.put(id, new Vector<>());
7374
}
7475

7576
//assume that there is only 2 periods of birthyears
7677
int birthYearPeriod = 2;
77-
givenNamesByLocationsMale = new Vector<HashMap<Integer, Vector<String>>>(birthYearPeriod);
78-
givenNamesByLocationsFemale = new Vector<HashMap<Integer, Vector<String>>>(birthYearPeriod);
78+
givenNamesByLocationsMale = new Vector<>(birthYearPeriod);
79+
givenNamesByLocationsFemale = new Vector<>(birthYearPeriod);
7980
for (int i = 0; i < birthYearPeriod; i++) {
80-
givenNamesByLocationsMale.add(new HashMap<Integer, Vector<String>>());
81-
givenNamesByLocationsFemale.add(new HashMap<Integer, Vector<String>>());
81+
givenNamesByLocationsMale.add(new HashMap<>());
82+
givenNamesByLocationsFemale.add(new HashMap<>());
8283
for (Integer id : locationDic.getCountries()) {
8384
givenNamesByLocationsMale.lastElement().put(id, new Vector<>());
8485
givenNamesByLocationsFemale.lastElement().put(id, new Vector<>());
@@ -180,7 +181,7 @@ public String getRandomSurname(Random random, int locationId) {
180181
public String getRandomGivenName(Random random, int locationId, boolean isMale, int birthYear) {
181182
String name = "";
182183
int period = (birthYear < 1985) ? 0 : 1;
183-
Vector<HashMap<Integer, Vector<String>>> target = (isMale) ? givenNamesByLocationsMale : givenNamesByLocationsFemale;
184+
Vector<Map<Integer, Vector<String>>> target = (isMale) ? givenNamesByLocationsMale : givenNamesByLocationsFemale;
184185

185186
// Note that, only vector of names for the first period contains list of names not in topN
186187
int nameId = getGeoDistRandomIdx(random, target.get(0).get(locationId).size());
@@ -199,7 +200,7 @@ public String getRandomGivenName(Random random, int locationId, boolean isMale,
199200
*/
200201
public String getMedianGivenName(int locationId, boolean isMale, int birthYear) {
201202
int period = 0;
202-
Vector<HashMap<Integer, Vector<String>>> target = (isMale) ? givenNamesByLocationsMale : givenNamesByLocationsFemale;
203+
Vector<Map<Integer, Vector<String>>> target = (isMale) ? givenNamesByLocationsMale : givenNamesByLocationsFemale;
203204
int size = target.get(period).get(locationId).size();
204205
String name = target.get(period).get(locationId).get(size / 2);
205206
return name;

src/main/java/ldbc/snb/datagen/dictionary/PlaceDictionary.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Linked Data Benchmark Council (http://www.ldbcouncil.org)
4545
import java.util.ArrayList;
4646
import java.util.Arrays;
4747
import java.util.HashMap;
48+
import java.util.Map;
49+
import java.util.List;
4850
import java.util.Random;
4951
import java.util.Set;
5052

@@ -62,27 +64,27 @@ public class PlaceDictionary {
6264
private PlaceZOrder[] sortedPlace;
6365
private Float cumulativeDistribution[];
6466

65-
private ArrayList<Integer> countries;
67+
private List<Integer> countries;
6668
/**
6769
* < @brief The set of countries. *
6870
*/
69-
private HashMap<Integer, Place> places;
71+
private Map<Integer, Place> places;
7072
/**
7173
* < @brief The places by id. *
7274
*/
73-
private HashMap<Integer, Integer> isPartOf;
75+
private Map<Integer, Integer> isPartOf;
7476
/**
7577
* < @brief The location hierarchy. *
7678
*/
77-
private HashMap<Integer, ArrayList<Integer>> citiesByCountry;
79+
private Map<Integer, List<Integer>> citiesByCountry;
7880
/**
7981
* < @brief The cities by country. *
8082
*/
81-
private HashMap<String, Integer> cityNames;
83+
private Map<String, Integer> cityNames;
8284
/**
8385
* < @brief The city names. *
8486
*/
85-
private HashMap<String, Integer> countryNames; /**< @brief The country names. **/
87+
private Map<String, Integer> countryNames; /**< @brief The country names. **/
8688

8789
/**
8890
* Private class used to sort countries by their z-order value.
@@ -111,7 +113,7 @@ public PlaceDictionary() {
111113
this.places = new HashMap<>();
112114
this.isPartOf = new HashMap<>();
113115
this.countries = new ArrayList<>();
114-
this.citiesByCountry = new HashMap<Integer, ArrayList<Integer>>();
116+
this.citiesByCountry = new HashMap<>();
115117
load(DatagenParams.cityDictionaryFile, DatagenParams.countryDictionaryFile);
116118
}
117119

@@ -127,7 +129,7 @@ public Set<Integer> getPlaces() {
127129
* @return The set of countries
128130
* @brief Gets a list of the country ids.
129131
*/
130-
public ArrayList<Integer> getCountries() {
132+
public List<Integer> getCountries() {
131133
return new ArrayList<>(countries);
132134
}
133135

@@ -302,7 +304,7 @@ private void readCountries(String fileName) {
302304
BufferedReader dictionary = new BufferedReader(
303305
new InputStreamReader(getClass().getResourceAsStream(fileName), "UTF-8"));
304306

305-
ArrayList<Float> temporalCumulative = new ArrayList<>();
307+
List<Float> temporalCumulative = new ArrayList<>();
306308

307309
String line;
308310
while ((line = dictionary.readLine()) != null) {
@@ -338,7 +340,7 @@ private void readCountries(String fileName) {
338340
* @brief Reads a continents file name.
339341
*/
340342
private void readContinents(String fileName) {
341-
HashMap<String, Integer> treatedContinents = new HashMap<>();
343+
Map<String, Integer> treatedContinents = new HashMap<>();
342344
try {
343345
BufferedReader dictionary = new BufferedReader(
344346
new InputStreamReader(getClass().getResourceAsStream(fileName), "UTF-8"));

0 commit comments

Comments
 (0)