@Override public synchronized YieldCurveDefinitionDocument update(YieldCurveDefinitionDocument document) { ArgumentChecker.notNull(document, "document"); ArgumentChecker.notNull(document.getYieldCurveDefinition(), "document.yieldCurveDefinition"); final Currency currency = document.getYieldCurveDefinition().getCurrency(); final String name = document.getYieldCurveDefinition().getName(); final UniqueId uid = UniqueId.of(getUniqueIdScheme(), name + "_" + currency.getCode()); if (!uid.equals(document.getUniqueId())) { throw new IllegalArgumentException("Invalid unique identifier"); } final Pair<Currency, String> key = Pair.of(currency, name); final TreeMap<Instant, YieldCurveDefinition> value = _definitions.get(key); if (value == null) { throw new DataNotFoundException("UID '" + uid + "' not found"); } if (_sourceVersionCorrection.getVersionAsOf() != null) { // Don't need to keep the old values before the one needed by "versionAsOfInstant" final Instant oldestNeeded = value.floorKey(_sourceVersionCorrection.getVersionAsOf()); value.headMap(oldestNeeded).clear(); } else { // Don't need any old values value.clear(); } Instant now = Instant.now(); value.put(now, document.getYieldCurveDefinition()); document.setUniqueId(uid); changeManager().entityChanged(ChangeType.CHANGED, uid.getObjectId(), null, null, now); return document; }
// ------------------------------------------------------------------------- @Override public synchronized YieldCurveDefinitionDocument add(YieldCurveDefinitionDocument document) { ArgumentChecker.notNull(document, "document"); ArgumentChecker.notNull(document.getYieldCurveDefinition(), "document.yieldCurveDefinition"); final Currency currency = document.getYieldCurveDefinition().getCurrency(); final String name = document.getYieldCurveDefinition().getName(); final Pair<Currency, String> key = Pair.of(currency, name); if (_definitions.containsKey(key)) { throw new IllegalArgumentException("Duplicate definition"); } final TreeMap<Instant, YieldCurveDefinition> value = new TreeMap<Instant, YieldCurveDefinition>(); Instant now = Instant.now(); value.put(now, document.getYieldCurveDefinition()); _definitions.put(key, value); final UniqueId uid = UniqueId.of(getUniqueIdScheme(), name + "_" + currency.getCode()); document.setUniqueId(uid); changeManager() .entityChanged( ChangeType.ADDED, document.getObjectId(), document.getVersionFromInstant(), document.getVersionToInstant(), now); return document; }
@Override public synchronized YieldCurveDefinitionDocument addOrUpdate( YieldCurveDefinitionDocument document) { ArgumentChecker.notNull(document, "document"); ArgumentChecker.notNull(document.getYieldCurveDefinition(), "document.yieldCurveDefinition"); final Currency currency = document.getYieldCurveDefinition().getCurrency(); final String name = document.getYieldCurveDefinition().getName(); final Pair<Currency, String> key = Pair.of(currency, name); TreeMap<Instant, YieldCurveDefinition> value = _definitions.get(key); final UniqueId uid = UniqueId.of(getUniqueIdScheme(), name + "_" + currency.getCode()); Instant now = Instant.now(); if (value != null) { if (_sourceVersionCorrection.getVersionAsOf() != null) { // 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(); } } else { // Don't need any old values value.clear(); } value.put(now, document.getYieldCurveDefinition()); changeManager().entityChanged(ChangeType.CHANGED, uid.getObjectId(), null, null, now); } else { value = new TreeMap<Instant, YieldCurveDefinition>(); value.put(now, document.getYieldCurveDefinition()); _definitions.put(key, value); changeManager() .entityChanged( ChangeType.ADDED, uid.getObjectId(), document.getVersionFromInstant(), document.getVersionToInstant(), now); } document.setUniqueId(uid); return document; }