InMemoryInterpolatedYieldCurveDefinitionMaster implements InterpolatedYieldCurveDefinitionMaster, InterpolatedYieldCurveDefinitionSource, ChangeProvider { @Override public synchronized YieldCurveDefinitionDocument get(UniqueId uid) { ArgumentChecker.notNull(uid, "objectIdentifiable"); if (!uid.isLatest()) { throw new IllegalArgumentException("Only latest version supported by '" + getUniqueIdScheme() + "'"); } if (!getUniqueIdScheme().equals(uid.getScheme())) { throw new DataNotFoundException("Scheme '" + uid.getScheme() + "' not valid for '" + getUniqueIdScheme() + "'"); } final int i = uid.getValue().indexOf('_'); if (i <= 0) { throw new DataNotFoundException("Identifier '" + uid.getValue() + "' not valid for '" + getUniqueIdScheme() + "'"); } final String name = uid.getValue().substring(0, i); final String iso = uid.getValue().substring(i + 1); final Currency currency; try { currency = Currency.of(iso); } catch (IllegalArgumentException e) { throw new DataNotFoundException("Identifier '" + uid.getValue() + "' not valid for '" + getUniqueIdScheme() + "'", e); } final TreeMap<Instant, YieldCurveDefinition> definitions = _definitions.get(Pairs.of(currency, name)); if (definitions == null) { throw new DataNotFoundException("Curve definition not found"); } final YieldCurveDefinition definition = definitions.lastEntry().getValue(); if (definition == null) { throw new DataNotFoundException("Curve definition not found"); } return new YieldCurveDefinitionDocument(uid, definition); } 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 public void testGet() { final YieldCurveDefinitionDocument ycdoc = _master.get(UniqueId.of(_master.getUniqueIdScheme(), "1_USD")); assertNotNull(ycdoc); final YieldCurveDefinition yc = ycdoc.getYieldCurveDefinition(); assertNotNull(yc); assertEquals("A", yc.getInterpolatorName()); }