private static ArrayList<ShortestPath> ShortestPath(ArrayList<DNVNode> list, DNVNode source){
ArrayList<ShortestPath> SP = new ArrayList<ShortestPath>();
ShortestPath object = new ShortestPath();
int index = 0;
int alt = 0;
boolean end = false;
boolean stop = false;
ShortestPath node1 = new ShortestPath();
ShortestPath node2 = new ShortestPath();
//Initialization
for(int i=0;i<list.size();i++){
object = new ShortestPath();
object.setSource(list.get(i));
object.setDistance(999999999);
SP.add(object);
}
//get the source index and set its distance to 0
for(int i=0;i<SP.size();i++){
if(source.toString().compareToIgnoreCase(SP.get(i).getSource().toString()) == 0){
SP.get(i).setDistance(0);
}
}
while(list.isEmpty() == false && end == false){
//get the node with the lowest distance value
node1 = getLowerDistanceValueObject(SP,list);
//if the visited node's distance == 9999999999 then we break
if(node1.getDistance() != 999999999){
list.remove(list.indexOf(node1.getSource()));
//get all neighbors of the current node
List<DNVNode> tmp = new ArrayList<DNVNode>(node1.getSource().getNeighbors(true));
for(int i=0;i<tmp.size();i++){
//get the DNVNode source value
DNVNode tempNode = new DNVNode();
tempNode = tmp.get(i);
//change the previous node2 by the new one
for(int x=0;x<SP.size();x++){
if(SP.get(x).getSource().toString().compareToIgnoreCase(tempNode.toString()) == 0){
node2 = SP.get(x);
}
}
//get the new distance between both nodes
alt = node1.getDistance()+1;
//if new distance is lower than the previous one, set the new distance and the new previous node
if(alt < node2.getDistance()){
node2.setDistance(alt);
node2.setPreviousNode(node1.getSource());
}
}
}else{
end = true;
}