-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNode.java
More file actions
63 lines (51 loc) · 1.41 KB
/
Copy pathNode.java
File metadata and controls
63 lines (51 loc) · 1.41 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
package com.ufl.pagerank;
import org.apache.commons.lang.StringUtils;
import java.io.IOException;
import java.util.Arrays;
public class Node {
private double pageRank = 0.25;
private String[] adjacencyList;
public double getPageRank() {
return pageRank;
}
public Node setPageRank(double pageRank) {
this.pageRank = pageRank;
return this;
}
public String[] getAdjacencyList() {
return adjacencyList;
}
public Node setAdjacencyList(String[] adjacencyList) {
this.adjacencyList = adjacencyList;
return this;
}
public boolean isNode() {
return adjacencyList != null;
}
public String printNode() {
StringBuilder sb = new StringBuilder();
sb.append(pageRank);
if (getAdjacencyList() != null) {
sb.append('\t').append(StringUtils.join(getAdjacencyList(), '\t'));
}
return sb.toString();
}
/**
* This function updates the adjacency list of a node before the start of every map and reduce
* task of next iteration using the values of previous iteration
* @param value
* @return
* @throws IOException
*/
public static Node afterMapReduce(String value) throws IOException {
String[] parts = StringUtils.splitPreserveAllTokens(value, '\t');
if (parts.length < 1) {
throw new IOException();
}
Node node = new Node().setPageRank(Double.valueOf(parts[0]));
if (parts.length > 1) {
node.setAdjacencyList(Arrays.copyOfRange(parts, 1, parts.length));
}
return node;
}
}