All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opengamma.sdk.margin.TenorStringConverter Maven / Gradle / Ivy

There is a newer version: 3.6.4
Show newest version
/*
 * 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 cls, String str) {
    return str.startsWith("P") ? Period.parse(str) : Period.parse("P" + str);
  }

  @Override
  public Class getEffectiveType() {
    return Period.class;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy