/** * Matches sources on origin:name only. * - If a matching source already exist in the sourceMap, remove from the dataStore first before add (as the * curr source may not equal due to a different source id). * - Otherwise, just add to the dataStore * - finally, add the source and sourceKey to the sourceMap */ public void put(Source source, InstanceInfo instanceInfo) { String sourceKey = sourceKey(source); Source currIfExist = sourceMap.get(sourceKey); if (currIfExist != null) { dataMap.remove(currIfExist); } dataMap.put(source, instanceInfo); sourceMap.put(sourceKey, source); }
/** * @return the current stored source that matches the given source's origin and name (but not necessarily id). */ private Source getMatchingSource(Source source) { String key = sourceKey(source); return sourceMap.get(key); }
/** * Matches sources on origin:name:id. * - If a matching source already exist in the sourceMap, and has the same id as the input source, do removal * - If a matching source already exist in the sourceMap, but have a different id as the input source, no-op * - Otherwise, no-op */ public InstanceInfo remove(Source source) { String sourceKey = sourceKey(source); Source currIfExist = sourceMap.get(sourceKey); if (currIfExist != null) { if (currIfExist.getId().equals(source.getId())) { sourceMap.remove(sourceKey); return dataMap.remove(currIfExist); } else { // no-op return null; } } else { // no-op return null; } }