0

I am sorry for what sounds like a simple question but I cannot seem to figure out the syntax of putting in two keys for a value in my Hashtable.

Already searched throughout the web and could not find an example.

Here is my declaration:

private Hashtable<Integer, Map<Integer, BACnetObject>> liftList = new Hashtable<Integer, Map<Integer, BACnetObject>>();

Here is some of my attempts at getting the syntax correct:

BACnetObject l = ........;
liftList.put(0, (0, l));
liftList.put(0, new Map(0, l));
liftList.put(0, Map<0, l>);

I am working in Eclipse and the most it does to help is suggest that I am not putting the applicable argument.

From Eclipse: The method put(Integer, Map<Integer,BACnetObject>) in the type Hashtable<Integer,Map<Integer,BACnetObject>> is not applicable for the arguments (int)

What I am trying to achieve:

I am looping through two different types of objects and need two keys to access the correct second object each iteration. Here is my code:

private Hashtable<Integer, LocalDevice> localList = new Hashtable<Integer, LocalDevice>(); //comes from xml
private Hashtable<Integer, IController> controllerList = new Hashtable<Integer, IController>();
private Hashtable<Integer, Map<Integer, BACnetObject>> liftList = new Hashtable<Integer, Map<Integer, BACnetObject>>();

for(int i = 0; i < localList.size(); i++)
{
      BACnetObject eg = new BACnetObject(localList.get(i), localList.get(i).getNextInstanceObjectIdentifier(ObjectType.ElevatorGroupType));
      groupId = eg.getId();
      eg.setProperty(PropertyIdentifier.objectIdentifier, new ObjectIdentifier(ObjectType.ElevatorGroupType, 0));
      eg.setProperty(PropertyIdentifier.objectName, new CharacterString("MCE group"));
      eg.setProperty(PropertyIdentifier.objectType, new ObjectType(128));
      eg.setProperty(PropertyIdentifier.description, new CharacterString("ICue"));
      eg.setProperty(PropertyIdentifier.machineRoomID, /*comes from xml??*/mr.getId());
      eg.setProperty(PropertyIdentifier.groupID, new Unsigned8(0));
      eg.setProperty(PropertyIdentifier.groupMembers, lifts);

      localList.get(i).addObject(eg);


      //if(controllerList.get(i).isConnected())
      if(true)
      {
            //int numOfCars = controllerList.get(i).getNumberOfControllers();
            int numOfCars = 3;
            Map<Float, Map<Float, Integer>> map = new HashMap<>();
            //Hashtable<Integer, Map<Integer, BACnetObject>> maps = new Hashtable<>();
            //Hashtable<Integer, Map<Integer, BACnetObject>> liftList = new Hashtable<Integer, Map<Integer, BACnetObject>>();

            for(int j = 0; j < numOfCars; j++)
            {
                final int p = j;
                final int ii = i;
                liftList.put(i, new Hashtable(){{put(j,l);}}); //The "duplicate" answer suggests doing it this way, but it gives me a bunch of warnings and it just overall seems messy. I am looking for a different way to do this.
            }

Let me know your ideas please, thanks.

KS7X
  • 332
  • 2
  • 15
  • @HovercraftFullOfEels Sure, Ill add a description of that to my question. – KS7X Oct 06 '16 at 23:07
  • `liftList.get(0).put(0, l)` – 4castle Oct 06 '16 at 23:07
  • @4castle that brings up a null exception. I am assuming its because nothing has been put in that index yet. – KS7X Oct 07 '16 at 18:22
  • @HovercraftFullOfEels I have revised the question. Can you please open this question again so I can get an answer? – KS7X Oct 07 '16 at 21:19
  • If you don't like the first answer, use the second answer (which IMO is better). You should be using an if statement to put a new hasmap if it doesn't yet exist. – 4castle Oct 07 '16 at 23:21

0 Answers0