我很抱歉听起来像一个简单的问题,但我似乎无法弄清楚在我的Hashtable中输入两个键的语法。
已经在整个网络上搜索过,找不到示例。
这是我的声明:
private Hashtable<Integer, Map<Integer, BACnetObject>> liftList = new Hashtable<Integer, Map<Integer, BACnetObject>>();
以下是我尝试使用语法的一些尝试:
BACnetObject l = ........;
liftList.put(0, (0, l));
liftList.put(0, new Map(0, l));
liftList.put(0, Map<0, l>);
我在Eclipse工作,它帮助最多的是建议我没有提出适用的论点。
来自Eclipse:
The method put(Integer, Map<Integer,BACnetObject>) in the type Hashtable<Integer,Map<Integer,BACnetObject>> is not applicable for the arguments (int)
我想要实现的目标:
我循环遍历两种不同类型的对象,每次迭代需要两个键才能访问正确的第二个对象。 这是我的代码:
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.
}
请告诉我你的想法,谢谢。