@Override
public synchronized void remove(ObjectIdentifiable objectIdentifiable) {
ArgumentChecker.notNull(objectIdentifiable, "objectIdentifiable");
if (!getUniqueIdScheme().equals(objectIdentifiable.getObjectId().getScheme())) {
throw new DataNotFoundException("Scheme '" + objectIdentifiable.getObjectId().getScheme() + "' not valid for '" + getUniqueIdScheme() + "'");
}
final int i = objectIdentifiable.getObjectId().getValue().indexOf('_');
if (i <= 0) {
throw new DataNotFoundException("Identifier '" + objectIdentifiable.getObjectId().getValue() + "' not valid for '" + getUniqueIdScheme() + "'");
}
final String name = objectIdentifiable.getObjectId().getValue().substring(0, i);
final String iso = objectIdentifiable.getObjectId().getValue().substring(i + 1);
final Currency currency;
try {
currency = Currency.of(iso);
} catch (IllegalArgumentException e) {
throw new DataNotFoundException("Identifier '" + objectIdentifiable.getObjectId().getValue() + "' not valid for '" + getUniqueIdScheme() + "'", e);
}
final Pair<Currency, String> key = Pair.of(currency, name);
if (_sourceVersionCorrection.getVersionAsOf() != null) {
final TreeMap<Instant, YieldCurveDefinition> value = _definitions.get(key);
if (value == null) {
throw new DataNotFoundException("Curve definition not found");
}
// Don't need to keep the old values before the one needed by "versionAsOfInstant"
final Instant oldestNeeded = value.floorKey(_sourceVersionCorrection.getVersionAsOf());
if (oldestNeeded != null) {
value.headMap(oldestNeeded).clear();
}
// Store a null to indicate the delete
value.put(Instant.now(), null);
} else {
if (_definitions.remove(key) == null) {
throw new DataNotFoundException("Curve definition not found");
}
}
changeManager().entityChanged(ChangeType.REMOVED, objectIdentifiable.getObjectId(), null, null, Instant.now());
}