-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageRank.java
More file actions
115 lines (83 loc) · 2.04 KB
/
PageRank.java
File metadata and controls
115 lines (83 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package bigdata;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
public class PageRank implements Writable {
String node;
double pageRankValue;
ArrayList<String> links; //links array stores the nodes that the node points to
PageRank()
{
}
PageRank(Text value)
{
String []line= value.toString().split("\\s+");
this.node= line[0];
this.pageRankValue= Double.valueOf(line[1]);
links=new ArrayList<String>();
for (int i=2; i< line.length; i++)
{
this.links.add((line[i]));
}
}
ArrayList<String> getLinks()
{
return this.links;
}
String getNode()
{
return this.node;
}
double getPageRankValue()
{
return this.pageRankValue;
}
void setPageRankValue(double value)
{
this.pageRankValue=value;
}
@Override
public String toString() {
StringBuilder resultantString= new StringBuilder();
resultantString.append(String.format("%.3f", pageRankValue));
resultantString.append(" ");
for (int i=0; i< links.size(); i++)
{
resultantString.append(links.get(i));
if (i<links.size()-1)
{
resultantString.append(" ");
}
}
return resultantString.toString();
}//end of toString method
@Override
public void readFields(DataInput DataInput) throws IOException {
// TODO Auto-generated method stub
this.node=DataInput.readUTF();
this.pageRankValue= DataInput.readDouble();
this.links=new ArrayList<String>();
try
{
while (true)
{
String next=DataInput.readUTF();
this.links.add(next);
}
}
catch(EOFException e)
{
}
}
@Override
public void write(DataOutput dataOutput) throws IOException {
dataOutput.writeUTF(node);
dataOutput.writeDouble(pageRankValue);
for (int i=0; i<this.links.size(); i++)
dataOutput.writeUTF(this.links.get(i));
}
}