@Test public void getIndex() { RegisterSet registerSet = new RegisterSet(); Register r1 = new Register("R1"); Register r2 = new Register("R2"); registerSet.put(1, r1); registerSet.put(2, r2); assertEquals(1, registerSet.getIndex("R1")); assertEquals(2, registerSet.getIndex("R2")); assertEquals(-1, registerSet.getIndex("Unknown register name")); }
int getIndex(String name) { name = name.toUpperCase(); for (Integer i : registers.keySet()) { if (registers.get(i).getName().equals(name)) { return i; } } return -1; }
RegisterSet implements Target, MongoSerializable { int getIndex(String name) { name = name.toUpperCase(); for (Integer i : registers.keySet()) { if (registers.get(i).getName().equals(name)) { return i; } } return -1; } }
RegisterSet implements Target, MongoSerializable { int getIndex(String name) { name = name.toUpperCase(); for (Integer i : registers.keySet()) { if (registers.get(i).getName().equals(name)) { return i; } } return -1; } RegisterSet(); }
RegisterSet implements Target, MongoSerializable { int getIndex(String name) { name = name.toUpperCase(); for (Integer i : registers.keySet()) { if (registers.get(i).getName().equals(name)) { return i; } } return -1; } RegisterSet(); Register getRegister(int index); Register getRegister(String name); @Override int get(int address); @Override void set(int address, int value); void put(int index, Register register); void clear(); @Override Document mongoSerialise(); static RegisterSet deserialize(Document obj); static RegisterSet deserialize(JSONObject json); @Override String toString(); }
RegisterSet implements Target, MongoSerializable { int getIndex(String name) { name = name.toUpperCase(); for (Integer i : registers.keySet()) { if (registers.get(i).getName().equals(name)) { return i; } } return -1; } RegisterSet(); Register getRegister(int index); Register getRegister(String name); @Override int get(int address); @Override void set(int address, int value); void put(int index, Register register); void clear(); @Override Document mongoSerialise(); static RegisterSet deserialize(Document obj); static RegisterSet deserialize(JSONObject json); @Override String toString();  }