InMemoryInterpolatedYieldCurveDefinitionMaster implements InterpolatedYieldCurveDefinitionMaster, InterpolatedYieldCurveDefinitionSource, ChangeProvider { @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 = Pairs.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; } InMemoryInterpolatedYieldCurveDefinitionMaster(); String getUniqueIdScheme(); void setUniqueIdScheme(final String scheme); @Override synchronized YieldCurveDefinition getDefinition(Currency currency, String name); @Override YieldCurveDefinition getDefinition(final Currency currency, final String name, final VersionCorrection versionCorrection); @Override synchronized YieldCurveDefinitionDocument add(YieldCurveDefinitionDocument document); @Override synchronized YieldCurveDefinitionDocument addOrUpdate(YieldCurveDefinitionDocument document); @Override YieldCurveDefinitionDocument correct(YieldCurveDefinitionDocument document); @Override synchronized YieldCurveDefinitionDocument get(UniqueId uid); @Override synchronized YieldCurveDefinitionDocument get(ObjectIdentifiable objectIdable, VersionCorrection versionCorrection); @Override synchronized void remove(ObjectIdentifiable objectIdentifiable); @Override synchronized YieldCurveDefinitionDocument update(YieldCurveDefinitionDocument document); @Override ChangeManager changeManager(); @Override List<UniqueId> replaceVersions(ObjectIdentifiable objectIdentifiable, List<YieldCurveDefinitionDocument> replacementDocuments); @Override List<UniqueId> replaceAllVersions(ObjectIdentifiable objectIdentifiable, List<YieldCurveDefinitionDocument> replacementDocuments); @Override List<UniqueId> replaceVersion(UniqueId uniqueId, List<YieldCurveDefinitionDocument> replacementDocuments); @Override void removeVersion(final UniqueId uniqueId); @Override UniqueId replaceVersion(YieldCurveDefinitionDocument replacementDocument); @Override UniqueId addVersion(ObjectIdentifiable objectId, YieldCurveDefinitionDocument documentToAdd); @Override Map<UniqueId, YieldCurveDefinitionDocument> get(Collection<UniqueId> uniqueIds); static final String DEFAULT_SCHEME; }
@Test(expectedExceptions = IllegalArgumentException.class) public void testAdd_duplicate() { _master.add(new YieldCurveDefinitionDocument(new YieldCurveDefinition(Currency.USD, null, "1", "E", "L1", "R1", true))); }