Repository navigation
Expand file tree
/
Copy pathWebsite.java
More file actions
95 lines (84 loc) · 1.93 KB
/
Copy pathWebsite.java
File metadata and controls
95 lines (84 loc) · 1.93 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
package edu.coursera.distributed;
import java.util.LinkedList;
import java.util.Iterator;
import java.io.Serializable;
/**
* A single website in a graph of websites.
*/
public final class Website implements Serializable {
/**
* Unique ID for this website.
*/
private int id;
/**
* List of edges from this website (i.e. links to other websites),
* represented by a list of the IDs for the destination sites.
*/
private LinkedList<Integer> edges;
/**
* Constructor.
*
* @param setId ID of this website
*/
public Website(final int setId) {
this.id = setId;
this.edges = new LinkedList<Integer>();
}
/**
* Constructor, default initializes ID to -1.
*/
public Website() {
this(-1);
}
/**
* Add an outbound edge from this website.
*
* @param target Destination of the new outbound edge
*/
void addEdge(final int target) {
edges.add(target);
}
/**
* Get the unique ID of this website.
*
* @return ID of this site
*/
int getId() {
return id;
}
/**
* Get the number of outbound edges from this website.
*
* @return Number of edges outbound from this site.
*/
int getNEdges() {
return edges.size();
}
/**
* Get an iterator over edges outbound from this site, defined by the
* integer IDs of the destination sites.
*
* @return Iterator over target site IDs of outbound edges.
*/
Iterator<Integer> edgeIterator() {
return edges.iterator();
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(final Object o) {
if (o instanceof Website) {
Website other = (Website) o;
return other.id == id;
}
return false;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return id;
}
}