Skip to content

Commit e0a9f63

Browse files
authored
fixed several coding style issues (#36)
* fixed several coding style issues
1 parent be583ee commit e0a9f63

File tree

85 files changed

+492
-479
lines changed

Some content is hidden

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

85 files changed

+492
-479
lines changed

pom.xml

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,37 @@
9494
<target>1.7</target>
9595
</configuration>
9696
</plugin>
97-
<plugin>
98-
<artifactId>maven-assembly-plugin</artifactId>
99-
<version>2.4</version>
100-
<configuration>
101-
<archive>
102-
<manifest>
103-
<mainClass>ldbc.snb.datagen.generator.LDBCDatagen</mainClass>
104-
</manifest>
105-
</archive>
106-
<descriptorRefs>
107-
<descriptorRef>jar-with-dependencies</descriptorRef>
108-
</descriptorRefs>
109-
</configuration>
110-
</plugin>
97+
<plugin>
98+
<groupId>org.walkmod.maven.plugins</groupId>
99+
<artifactId>walkmod-maven-plugin</artifactId>
100+
<version>1.0.3</version>
101+
<executions>
102+
<execution>
103+
<phase>generate-sources</phase>
104+
<goals>
105+
<goal>apply</goal>
106+
</goals>
107+
<configuration>
108+
<chains>pmd</chains>
109+
<properties>configurationFile=rulesets/java/basic.xml</properties>
110+
</configuration>
111+
</execution>
112+
</executions>
113+
</plugin>
114+
<plugin>
115+
<artifactId>maven-assembly-plugin</artifactId>
116+
<version>2.4</version>
117+
<configuration>
118+
<archive>
119+
<manifest>
120+
<mainClass>ldbc.snb.datagen.generator.LDBCDatagen</mainClass>
121+
</manifest>
122+
</archive>
123+
<descriptorRefs>
124+
<descriptorRef>jar-with-dependencies</descriptorRef>
125+
</descriptorRefs>
126+
</configuration>
127+
</plugin>
111128
</plugins>
112129
</build>
113130
</project>

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ public int getLocation(IP ip) {
137137
}
138138

139139
public IP getRandomIPFromLocation(Random random, int locationIdx) {
140-
while (placeDictionary.getType(locationIdx) != "country") {
141-
locationIdx = placeDictionary.belongsTo(locationIdx);
140+
int finalLocationIndex = locationIdx;
141+
while (placeDictionary.getType(finalLocationIndex) != "country") {
142+
finalLocationIndex = placeDictionary.belongsTo(finalLocationIndex);
142143
}
143-
ArrayList<IP> countryIPs = ipsByCountry.get(locationIdx);
144+
ArrayList<IP> countryIPs = ipsByCountry.get(finalLocationIndex);
144145
int idx = random.nextInt(countryIPs.size());
145146

146147
IP networkIp = countryIPs.get(idx);
@@ -164,21 +165,18 @@ public IP getRandomIP(Random random) {
164165
return getRandomIPFromLocation(random, randomLocationIdx);
165166
}
166167

167-
private boolean changeUsualIp(Random randomDiffIP, Random randomDiffIPForTravelers, long date) {
168+
private boolean changeUsualIp(Random randomDiffIPForTravelers, long date) {
168169
double diffIpForTravelersProb = randomDiffIPForTravelers.nextDouble();
169170
boolean isTravelSeason = DateGenerator.isTravelSeason(date);
170-
if ((isTravelSeason && diffIpForTravelersProb < probDiffIPinTravelSeason) ||
171-
(!isTravelSeason && diffIpForTravelersProb < probDiffIPnotTravelSeason)) {
172-
return true;
173-
}
174-
return false;
171+
return (isTravelSeason && diffIpForTravelersProb < probDiffIPinTravelSeason) ||
172+
(!isTravelSeason && diffIpForTravelersProb < probDiffIPnotTravelSeason);
175173
}
176174

177175
public IP getIP(Random randomIP, Random randomDiffIP, Random randomDiffIPForTravelers, IP ip, long date) {
178-
return (changeUsualIp(randomDiffIP, randomDiffIPForTravelers, date)) ? new IP(ip.getIp(), ip.getMask()) : getRandomIP(randomIP);
176+
return (changeUsualIp(randomDiffIPForTravelers, date)) ? new IP(ip.getIp(), ip.getMask()) : getRandomIP(randomIP);
179177
}
180178

181179
public IP getIP(Random randomIP, Random randomDiffIP, Random randomDiffIPForTravelers, IP ip, long date, int countryId) {
182-
return (changeUsualIp(randomDiffIP, randomDiffIPForTravelers, date)) ? new IP(ip.getIp(), ip.getMask()) : getRandomIPFromLocation(randomIP, countryId);
180+
return (changeUsualIp(randomDiffIPForTravelers, date)) ? new IP(ip.getIp(), ip.getMask()) : getRandomIPFromLocation(randomIP, countryId);
183181
}
184182
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ public class NamesDictionary {
5555

5656
private static final int topN = 30;
5757

58-
PlaceDictionary locationDic;
59-
60-
HashMap<Integer, Vector<String>> surNamesByLocations;
61-
Vector<HashMap<Integer, Vector<String>>> givenNamesByLocationsMale; // Year / Location / Names
62-
Vector<HashMap<Integer, Vector<String>>> givenNamesByLocationsFemale;
63-
64-
GeometricDist geoDist;
58+
private PlaceDictionary locationDic;
59+
private HashMap<Integer, Vector<String>> surNamesByLocations;
60+
private Vector<HashMap<Integer, Vector<String>>> givenNamesByLocationsMale; // Year / Location / Names
61+
private Vector<HashMap<Integer, Vector<String>>> givenNamesByLocationsFemale;
62+
private GeometricDist geoDist;
6563

6664
public NamesDictionary( PlaceDictionary locationDic ) {
6765
this.locationDic = locationDic;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ private void readCities(String fileName) {
254254
BufferedReader dictionary = new BufferedReader(
255255
new InputStreamReader(getClass().getResourceAsStream(fileName), "UTF-8"));
256256

257-
int cities = 0;
258257
String line;
259258
while ((line = dictionary.readLine()) != null) {
260259
String data[] = line.split(SEPARATOR_CITY);
@@ -274,8 +273,6 @@ private void readCities(String fileName) {
274273
citiesByCountry.get(countryId).add(placeId.getId());
275274

276275
cityNames.put(data[1], placeId.getId());
277-
278-
cities++;
279276
}
280277
}
281278
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class TagTextDictionary {
5757
*/
5858
private double reducedTextRatio;
5959

60-
StringBuilder returnString = null;
60+
private StringBuilder returnString = null;
6161

6262
public TagTextDictionary(TagDictionary tagDic, double reducedTextRatio) {
6363
this.tagText = new HashMap<Integer, String>();
@@ -153,12 +153,8 @@ public String generateText(Random randomTextSize, TreeSet<Integer> tags, int tex
153153
}
154154
}
155155

156-
if (!(returnString.charAt(returnString.length()-1) == '.')) {
157-
if (returnString.length() == 1) {
158-
returnString.append(".");
159-
} else {
160-
returnString.append(".");
161-
}
156+
if (returnString.charAt(returnString.length()-1) != '.') {
157+
returnString.append(".");
162158
}
163159
if (returnString.length() < textSize - 1) {
164160
returnString.append(" ");

src/main/java/ldbc/snb/datagen/generator/BTERKnowsGenerator.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
package ldbc.snb.datagen.generator;
22

3-
import java.io.BufferedReader;
4-
import java.io.IOException;
5-
import java.io.InputStreamReader;
6-
import java.util.ArrayList;
7-
import java.util.Collections;
8-
import java.util.HashMap;
9-
import java.util.Iterator;
10-
import java.util.LinkedList;
11-
import java.util.Map;
12-
import java.util.Random;
13-
import java.util.TreeMap;
14-
3+
import ldbc.snb.datagen.objects.Knows;
4+
import ldbc.snb.datagen.objects.Person;
155
import org.apache.commons.math3.util.Pair;
166
import org.apache.hadoop.conf.Configuration;
177
import org.roaringbitmap.RoaringBitmap;
188

19-
import ldbc.snb.datagen.objects.Knows;
20-
import ldbc.snb.datagen.objects.Person;
9+
import java.io.BufferedReader;
10+
import java.io.IOException;
11+
import java.io.InputStreamReader;
12+
import java.util.*;
2113

2214
/**
2315
* Created by aprat on 12/07/16.
@@ -33,9 +25,8 @@ public class BTERKnowsGenerator implements KnowsGenerator{
3325
private ArrayList<RoaringBitmap> closedCommunities = new ArrayList<RoaringBitmap>();
3426
private RoaringBitmap smallDegreeNodes = new RoaringBitmap();
3527
private RoaringBitmap [] adjacencyMatrix;
36-
private int count = 0;
3728

38-
public int BinarySearch(ArrayList<Pair<Long,Double>> array, Long degree) {
29+
public int binarySearch(ArrayList<Pair<Long,Double>> array, Long degree) {
3930
int min = 0;
4031
int max = array.size();
4132
while(min <= max) {
@@ -53,7 +44,7 @@ public int BinarySearch(ArrayList<Pair<Long,Double>> array, Long degree) {
5344
return max;
5445
}
5546

56-
void generateCommunities(RoaringBitmap block) {
47+
private void generateCommunities(RoaringBitmap block) {
5748
Iterator<Integer> iter = block.iterator();
5849
while(iter.hasNext()) {
5950
int node = iter.next();
@@ -72,7 +63,7 @@ void generateCommunities(RoaringBitmap block) {
7263
}
7364
}
7465

75-
void generateEdgesInCommunity(RoaringBitmap community) {
66+
private void generateEdgesInCommunity(RoaringBitmap community) {
7667
Iterator<Integer> iter = community.iterator();
7768
while(iter.hasNext()) {
7869
int nodeA = iter.next();
@@ -90,7 +81,7 @@ void generateEdgesInCommunity(RoaringBitmap community) {
9081
}
9182
}
9283

93-
void generateRemainingEdges() {
84+
private void generateRemainingEdges() {
9485
LinkedList<Integer> stubs = new LinkedList<Integer>();
9586
for(int i = 0; i < graphSize; ++i) {
9687
long difference = expectedDegree[i]-adjacencyMatrix[i].getCardinality();
@@ -133,7 +124,7 @@ public void generateKnows(ArrayList<Person> persons, int seed, ArrayList<Float>
133124
int maxExpectedDegree = 0;
134125
for(int i = 0; i < graphSize; ++i) {
135126
adjacencyMatrix[i].clear();
136-
expectedDegree[i] = Knows.target_edges(persons.get(i),percentages,step_index);
127+
expectedDegree[i] = Knows.targetEdges(persons.get(i),percentages,step_index);
137128
maxExpectedDegree = maxExpectedDegree < expectedDegree[i] ? (int)expectedDegree[i] : maxExpectedDegree;
138129
}
139130
p = new double[maxExpectedDegree+1];
@@ -157,7 +148,7 @@ public void generateKnows(ArrayList<Person> persons, int seed, ArrayList<Float>
157148
p[1] = 0.0;
158149
for(int i = 2; i < maxExpectedDegree+1; ++i) {
159150
int degree = i;
160-
int pos = BinarySearch(ccDistribution,(long)degree);
151+
int pos = binarySearch(ccDistribution,(long)degree);
161152
if(ccDistribution.get(pos).getKey() == degree || pos == (ccDistribution.size() - 1)) {
162153
p[degree] = ccDistribution.get(pos).getValue();
163154
} else if( pos < ccDistribution.size() - 1 ){
@@ -221,8 +212,6 @@ public void generateKnows(ArrayList<Person> persons, int seed, ArrayList<Float>
221212
Knows.createKnow(random, persons.get(i), persons.get(next));
222213
}
223214
}
224-
count++;
225-
226215
}
227216

228217
@Override

src/main/java/ldbc/snb/datagen/generator/ClusteringKnowsGenerator.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public class ClusteringKnowsGenerator implements KnowsGenerator {
1515

16-
Random rand;
16+
private Random rand;
1717
private ArrayList<Float> percentages = null;
1818
private int stepIndex = 0;
1919
private float targetCC = 0.0f;
@@ -105,7 +105,7 @@ private Community findSolution( ArrayList<Person> persons, int begin, int last)
105105
Person p = persons.get(i);
106106
PersonInfo pInfo = new PersonInfo();
107107
pInfo.index_ = i;
108-
pInfo.degree_ = Knows.target_edges(p,percentages,stepIndex);
108+
pInfo.degree_ = Knows.targetEdges(p,percentages,stepIndex);
109109
pInfo.original_degree_ = (long)(p.maxNumKnows());
110110
nodes.add(pInfo);
111111
}
@@ -120,7 +120,7 @@ private Community findSolution( ArrayList<Person> persons, int begin, int last)
120120
periphery.add(pI);
121121
}
122122
}
123-
return checkBudget(persons, core, periphery);
123+
return checkBudget(core, periphery);
124124
}
125125

126126
private ArrayList<Long> createInitialBudget( ArrayList<PersonInfo> core) {
@@ -136,7 +136,7 @@ private ArrayList<Long> createInitialBudget( ArrayList<PersonInfo> core, float p
136136
return budget;
137137
}
138138

139-
private Community checkBudget(ArrayList<Person> persons, ArrayList<PersonInfo> core, ArrayList<PersonInfo> periphery) {
139+
private Community checkBudget(ArrayList<PersonInfo> core, ArrayList<PersonInfo> periphery) {
140140
ArrayList<Long> temp_budget = createInitialBudget(core);
141141
Collections.sort(periphery, new PersonInfoComparator());
142142
for(PersonInfo pI : periphery ) {
@@ -380,7 +380,7 @@ private void refineCommunities( ClusteringInfo cInfo, ArrayList<Community> commu
380380
System.out.println("Clustering Coefficient after refinement: " + currentCC);
381381
}
382382

383-
float step(int n) {
383+
private float step(int n) {
384384
return 3.0f/(float)n;
385385
}
386386

@@ -465,7 +465,7 @@ private void createEdgesCommunityPeriphery(ClusteringInfo cInfo, ArrayList<Perso
465465
//System.out.println("Time to create core-periphery edges: "+(end-start));
466466
}
467467

468-
private void fillGraphWithRemainingEdges(ClusteringInfo cInfo, ArrayList<Community> communities, ArrayList<Person> persons) {
468+
private void fillGraphWithRemainingEdges(ArrayList<Community> communities, ArrayList<Person> persons) {
469469
ArrayList<PersonInfo> stubs = new ArrayList<PersonInfo> ();
470470
LinkedList<Integer> indexes = new LinkedList<Integer>();
471471
Integer ii = 0;
@@ -506,7 +506,8 @@ private void fillGraphWithRemainingEdges(ClusteringInfo cInfo, ArrayList<Communi
506506

507507
public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float> percentages, int step_index ) {
508508

509-
long start, end;
509+
long start;
510+
long end;
510511
rand.setSeed(seed);
511512
this.percentages = percentages;
512513
this.stepIndex = step_index;
@@ -568,14 +569,14 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
568569
createEdgesCommunityCore(persons, c);
569570
createEdgesCommunityPeriphery(cInfo, persons, c);
570571
}
571-
fillGraphWithRemainingEdges(cInfo, communities, persons);
572+
fillGraphWithRemainingEdges(communities, persons);
572573
end = System.currentTimeMillis();
573574
System.out.println("Time to generate graph: "+(end-start));
574575

575576
graph = new PersonGraph(persons);
576577
System.out.println("Computing clustering coefficient");
577578
double finalCC = 0;
578-
ArrayList<Double> clusteringCoefficient = GraphUtils.ClusteringCoefficientList(graph);
579+
ArrayList<Double> clusteringCoefficient = GraphUtils.clusteringCoefficientList(graph);
579580
int i = 0;
580581
for( Person p : persons) {
581582
long degree = graph.neighbors(p.accountId()).size();
@@ -585,7 +586,7 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
585586
i++;
586587
}
587588
finalCC /= persons.size();
588-
//double finalCC = GraphUtils.ClusteringCoefficient(graph);
589+
//double finalCC = GraphUtils.clusteringCoefficient(graph);
589590

590591
System.out.println("Clustering coefficient of the generated graph: "+finalCC);
591592
double delta = targetCC - finalCC;
@@ -613,7 +614,7 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
613614
int countDegreeZero = 0;
614615
for( Person p : persons ) {
615616
if(cInfo.is_core_.get(index)) {
616-
long target = Knows.target_edges(p, percentages, step_index);
617+
long target = Knows.targetEdges(p, percentages, step_index);
617618
if (p.knows().size() > target) {
618619
sumMore += -target + p.knows().size();
619620
countMore++;

src/main/java/ldbc/snb/datagen/generator/CommentGenerator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ public class CommentGenerator {
2525
private String[] shortComments_ = {"ok", "good", "great", "cool", "thx", "fine", "LOL", "roflol", "no way!", "I see", "right", "yes", "no", "duh", "thanks", "maybe"};
2626
private TextGenerator generator;
2727
private LikeGenerator likeGenerator_;
28-
private Comment comment_;
2928
/* A set of random number generator for different purposes.*/
3029

3130
public CommentGenerator(TextGenerator generator, LikeGenerator likeGenerator){
3231
this.generator = generator;
3332
this.likeGenerator_ = likeGenerator;
34-
this.comment_ = new Comment();
3533
}
3634

3735
public long createComments(RandomGeneratorFarm randomFarm, final Forum forum, final Post post, long numComments, long startId, PersonActivityExporter exporter) throws IOException {

src/main/java/ldbc/snb/datagen/generator/DatagenParams.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public static void readConf( Configuration conf ) {
296296
} catch (Exception e) {
297297
System.out.println("Error reading scale factors");
298298
System.err.println(e.getMessage());
299-
System.exit(-1);
299+
throw e;
300300
}
301301

302302
try {
@@ -324,8 +324,7 @@ public static void readConf( Configuration conf ) {
324324
System.out.println(" ... Start Year " + startYear);
325325
System.out.println(" ... Num Years " + numYears);
326326
} catch (Exception e) {
327-
System.err.println(e.getMessage());
328-
System.exit(-1);
327+
throw new RuntimeException(e);
329328
}
330329
}
331330
}

0 commit comments

Comments
 (0)