static class AIEngine { new L sentences; new Set sentenceSet; new Map objects; new IdentityHashMap objectToID; long objectIDCounter; S addObject(O o) { S id = objectToID.get(o); if (id == null) { id = "o" + ++objectIDCounter; objects.put(id, o); objectToID.put(o, id); } return id; } S remember(S sentence) { if (!sentenceSet.contains(sentence)) { sentenceSet.add(sentence); sentences.add(sentence); return addObject(sentence); } return null; } void show() { for (S s : sentences) print(" " + s); } A findObjectOfType(Class c) { for (O o : objects.values()) if (o.getClass() == c) return (A) o; return null; } }