コード例 #1
0
ファイル: Frequency.java プロジェクト: hmedkouri/Strata
 /**
  * Parses a formatted string representing the frequency.
  *
  * <p>The format can either be based on ISO-8601, such as 'P3M' or without the 'P' prefix e.g.
  * '2W'.
  *
  * <p>The period must be positive and non-zero.
  *
  * @param toParse the string representing the frequency
  * @return the frequency
  * @throws IllegalArgumentException if the frequency cannot be parsed
  */
 @FromString
 public static Frequency parse(String toParse) {
   ArgChecker.notNull(toParse, "toParse");
   if (toParse.equalsIgnoreCase("Term")) {
     return TERM;
   }
   String prefixed = toParse.startsWith("P") ? toParse : "P" + toParse;
   try {
     return Frequency.of(Period.parse(prefixed));
   } catch (DateTimeParseException ex) {
     throw new IllegalArgumentException(ex);
   }
 }
コード例 #2
0
ファイル: Frequency.java プロジェクト: hmedkouri/Strata
 /**
  * Normalizes the months and years of this tenor.
  *
  * <p>This method returns a tenor of an equivalent length but with any number of months greater
  * than 12 normalized into a combination of months and years.
  *
  * @return the normalized tenor
  */
 public Frequency normalized() {
   Period norm = period.normalized();
   return (norm != period ? Frequency.of(norm) : this);
 }