import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.javatuples.Pair;
public class Graph {
/*Map for memorizing the hallways and the rooms*/
public static HashMap<Vertices,Pair<Room,Room>> House = new HashMap<Vertices,Pair<Room,Room>>(200);
public static void main(String[] args) throws NullPointerException {
Room r1 = new Room (1,"room");
Room r2 = new Room (2,"room");
Room r3 = new Room (3,"room");
Room r4 = new Room (4,"room");
Room h1 = new Room (5,"hallway");
Vertices v1_1 = new Vertices (1,2);
Vertices v1_2 = new Vertices (1,5);
Vertices v2 = new Vertices (2,5);
Vertices v3 = new Vertices (3,5);
Vertices v4 = new Vertices (4,5);
r1.setDoorNumber(2);
System.out.println(r1.doorNumber);
for (int i = 0; i<r1.doorNumber; i++) {
Door d = new Door("room");
r1.Doors.add(d);
}
r2.setDoorNumber(2);
for (int i = 0; i<r2.doorNumber; i++) {
Door d = new Door("room");
r1.Doors.add(d);
}
r3.setDoorNumber(1);
for (int i = 0; i<r3.doorNumber; i++) {
Door d = new Door("room");
r1.Doors.add(d);
}
r4.setDoorNumber(1);
for (int i = 0; i<r4.doorNumber; i++) {
Door d = new Door("room");
r1.Doors.add(d);
}
House.put(v1_1, Pair.with(r1, r2));
House.put(v1_2, Pair.with(r1, h1));
House.put(v2, Pair.with(r2, h1));
House.put(v3, Pair.with(r3, h1));
House.put(v4, Pair.with(r4, h1));
for (Map.Entry<Vertices,Pair<Room,Room>> entry: House.entrySet())
{
Vertices key = entry.getKey();
Pair<Room, Room> value = entry.getValue();
System.out.println(key.firstLabel + " " + key.secondLabel);
System.out.println(value.getValue(0) + " " + value.getValue(1)); //
}
}
}
我尝试制作一个代表建筑物的项目。我试过这个,但是我无法得到我的对的实际价值(我得到了房间@ 17327b6房间@ 14ae5a5输出,但我需要像1对的房间 - “房间”等等意味着来自Pair的对象类的价值)