Add missing Javadoc to all functions in GraphPath.java

This commit is contained in:
Hakan 2022-03-15 15:04:53 +01:00 committed by dragonmacher
parent 6772528f0b
commit 6755e43de8

View file

@ -30,14 +30,26 @@ public class GraphPath<V> {
private Set<V> pathSet = new HashSet<>();
private List<V> pathList = new ArrayList<>();
/**
* Default constructor.
*/
public GraphPath() {
// default constructor
}
/**
* Constructor with a vertex.
*
* @param v the first vertex of the newly initialized GraphPath object
*/
public GraphPath(V v) {
add(v);
}
/**
* Creates a new GraphPath object by performing a shallow copy on another GraphPath object.
*
* @return the new shallow copy of the original GraphPath object
*/
public GraphPath<V> copy() {
GraphPath<V> newPath = new GraphPath<>();
newPath.pathList.addAll(pathList);
@ -45,6 +57,13 @@ public class GraphPath<V> {
return newPath;
}
/**
* Check if a GraphPath starts with another Graphpath.
*
* @param otherPath the other GraphPath for which we are checking if the current GraphPath
* starts with it.
* @return true if the current GraphPath starts with otherPath, false otherwise
*/
public boolean startsWith(GraphPath<V> otherPath) {
if (size() < otherPath.size()) {
return false;
@ -58,6 +77,14 @@ public class GraphPath<V> {
return true;
}
/**
* Return all vertices that two GraphPaths have in common. For example if you have
* a-b-c-d-e-f and a-b-c-d-k-l-z, the common start path will be a-b-c-d. If there is no common
* start path, an empty GraphPath object is returned.
*
* @param other the other GraphPath to get the common start path of
* @return a new GraphPath object containing the common start path vertices
*/
public GraphPath<V> getCommonStartPath(GraphPath<V> other) {
int n = Math.min(size(), other.size());
for (int i = 0; i < n; i++) {
@ -68,31 +95,68 @@ public class GraphPath<V> {
return subPath(0, n);
}
/**
* Return the size of the GraphPath.
*
* @return size of the GraphPath
*/
public int size() {
return pathList.size();
}
/**
* Check if vertex v is in the GraphPath.
*
* @return true if vertex v is in this GraphPath
*/
public boolean contains(V v) {
return pathSet.contains(v);
}
/**
* Add a vertex to the GraphPath.
*
* @param v the new vertex
*/
public void add(V v) {
pathSet.add(v);
pathList.add(v);
}
/**
* Get last vertex of GraphPath.
*
* @return last vertex of GraphPath
*/
public V getLast() {
return pathList.get(pathList.size() - 1);
}
/**
* Get the depth of the vertex that is specified by the parameter.
*
* @param v the vertex for which we get the depth
* @return the depth of the vertex
*/
public int depth(V v) {
return pathList.indexOf(v);
}
/**
* Get vertex that is specified by the parameter.
*
* @param depth of the vertex to retrieve
* @return the vertex
*/
public V get(int depth) {
return pathList.get(depth);
}
/**
* Remove the last vertex of the GraphPath.
*
* @return the removed vertex
*/
public V removeLast() {
V v = pathList.remove(pathList.size() - 1);
pathSet.remove(v);
@ -100,11 +164,10 @@ public class GraphPath<V> {
}
/**
* Returns all entries that are before the given vertex in this path. The results will
* include the vertex.
* Return a set with all of the predecessors of the vertex in the GraphPath.
*
* @param v the vertex
* @return the predecessors
* @param v the vertex we want to get the predecessors of
* @return the predecessors of the vertex as a set, return empty set if there are none
*/
public Set<V> getPredecessors(V v) {
Set<V> set = new HashSet<>();
@ -118,11 +181,10 @@ public class GraphPath<V> {
}
/**
* Returns all entries that are later in this path than the given vertex. The results will
* include the vertex.
*
* @param v the vertex
* @return the successors
* Return a set with all of the successors of the vertex in the GraphPath.
*
* @param v the vertex we want to get the successors of
* @return the successors of the vertex as a set, return empty set if there are none
*/
public Set<V> getSuccessors(V v) {
Set<V> set = new HashSet<>();
@ -141,6 +203,13 @@ public class GraphPath<V> {
return pathList.toString();
}
/**
* Get a part of the whole GraphPath, similar to substring with strings.
*
* @param start the start of the subpart of the GraphPath
* @param end the end of the subpart of the GraphPath
* @return a new GraphPath which is a subPath of the original GraphPath from start to end
*/
public GraphPath<V> subPath(int start, int end) {
GraphPath<V> subPath = new GraphPath<>();
subPath.pathList = new ArrayList<>(pathList.subList(start, end));