0
    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)); //

            }

        }

    }

I try to make a project to represent a building. I've tried this but I can't get the actual value of my Pair (i get the Room@17327b6 Room@14ae5a5 output but I need pairs like 1 - "room" etc. meaning the value of the object class from Pair).

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
student0495
  • 171
  • 3
  • 15
  • 2
    Override `toString()` in `Room`. – Andy Turner Apr 17 '16 at 21:40
  • [How do I print my Java object without getting "SomeType@2f92e0f4"?](http://stackoverflow.com/q/29140402) – Tom Apr 17 '16 at 21:40
  • 1
    I was looking for it too. @Tom nailed it before I found it :D – Tunaki Apr 17 '16 at 21:42
  • @AndyTurner That's why it is a good idea to have a list of common duplicates :D (yes, I know, I'm not Tunaki). – Tom Apr 17 '16 at 21:42
  • @Tom y'know, I really should too. – Andy Turner Apr 17 '16 at 21:43
  • Thank you! It works just fine for the room type ("room" / "hallway") but I also need to return the Integer label. I've tried to create my own method toInteger but I can't use it. – student0495 Apr 17 '16 at 21:50
  • 1
    Just use `return number + name;` in your `toString` implementation, where `number` is the numerical value you like to show and `name` is the name of the room. – Tom Apr 17 '16 at 21:58
  • Already have tried this and managed to get the values separately by spliting them up. Thank you for the answer anyway and mostly thank you guys FOR MARKING THIS AS DUPLICATE :)) – student0495 Apr 17 '16 at 22:25

0 Answers0