com.opengamma.sdk.margin.TenorStringConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-margin Show documentation
Show all versions of sdk-margin Show documentation
OpenGamma SDK - Provides access to the Margin service
/*
* Copyright (C) 2018 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.sdk.margin;
import java.time.Period;
import org.joda.convert.TypedStringConverter;
/**
* Converts tenors, not prefixed by 'P', to periods.
*/
class TenorStringConverter implements TypedStringConverter {
@Override
public String convertToString(Period object) {
return object.toString().substring(1);
}
@Override
public Period convertFromString(Class extends Period> cls, String str) {
return str.startsWith("P") ? Period.parse(str) : Period.parse("P" + str);
}
@Override
public Class> getEffectiveType() {
return Period.class;
}
}