• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FromString类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.joda.convert.FromString的典型用法代码示例。如果您正苦于以下问题:Java FromString类的具体用法?Java FromString怎么用?Java FromString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FromString类属于org.joda.convert包,在下文中一共展示了FromString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a {@code UniqueId} from a formatted scheme and value.
 * <p>
 * This parses the identifier from the form produced by {@code toString()}
 * which is {@code <SCHEME>~<VALUE>~<VERSION>}.
 * 
 * @param str  the unique identifier to parse, not null
 * @return the unique identifier, not null
 * @throws IllegalArgumentException if the identifier cannot be parsed
 */
@FromString
public static UniqueId parse(String str) {
  ArgumentChecker.notEmpty(str, "str");
  if (str.contains("~") == false) {
    str = StringUtils.replace(str, "::", "~");  // leniently parse old data
  }
  String[] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, "~");
  switch (split.length) {
    case 2:
      return UniqueId.of(split[0], split[1], null);
    case 3:
      return UniqueId.of(split[0], split[1], split[2]);
  }
  throw new IllegalArgumentException("Invalid identifier format: " + str);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:UniqueId.java


示例2: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a {@code DoublesPair} from the standard string format.
 * <p>
 * The standard format is '[$first, $second]'. Spaces around the values are trimmed.
 * 
 * @param pairStr  the text to parse, not null
 * @return the parsed pair, not null
 */
@FromString
public static DoublesPair parse(final String pairStr) {
  ArgumentChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() < 5) {
    throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr);
  }
  if (pairStr.charAt(0) != '[') {
    throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr);
  }
  if (pairStr.charAt(pairStr.length() - 1) != ']') {
    throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr);
  }
  String[] split = StringUtils.split(pairStr.substring(1, pairStr.length() - 1), ',');
  if (split.length != 2) {
    throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr);
  }
  double first = Double.parseDouble(split[0].trim());
  double second = Double.parseDouble(split[1].trim());
  return new DoublesPair(first, second);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:29,代码来源:DoublesPair.java


示例3: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses an {@code LongDoublePair} from the standard string format.
 * <p>
 * The standard format is '[$first, $second]'. Spaces around the values are trimmed.
 * 
 * @param pairStr  the text to parse, not null
 * @return the parsed pair, not null
 */
@FromString
public static LongDoublePair parse(final String pairStr) {
  ArgumentChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() < 5) {
    throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr);
  }
  if (pairStr.charAt(0) != '[') {
    throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr);
  }
  if (pairStr.charAt(pairStr.length() - 1) != ']') {
    throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr);
  }
  String[] split = StringUtils.split(pairStr.substring(1, pairStr.length() - 1), ',');
  if (split.length != 2) {
    throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr);
  }
  long first = Long.parseLong(split[0].trim());
  double second = Double.parseDouble(split[1].trim());
  return new LongDoublePair(first, second);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:29,代码来源:LongDoublePair.java


示例4: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses an {@code IntDoublePair} from the standard string format.
 * <p>
 * The standard format is '[$first, $second]'. Spaces around the values are trimmed.
 * 
 * @param pairStr  the text to parse, not null
 * @return the parsed pair, not null
 */
@FromString
public static IntDoublePair parse(final String pairStr) {
  ArgumentChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() < 5) {
    throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr);
  }
  if (pairStr.charAt(0) != '[') {
    throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr);
  }
  if (pairStr.charAt(pairStr.length() - 1) != ']') {
    throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr);
  }
  String[] split = StringUtils.split(pairStr.substring(1, pairStr.length() - 1), ',');
  if (split.length != 2) {
    throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr);
  }
  int first = Integer.parseInt(split[0].trim());
  double second = Double.parseDouble(split[1].trim());
  return new IntDoublePair(first, second);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:29,代码来源:IntDoublePair.java


示例5: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses the string to produce a {@code CurrencyAmount}.
 * <p>
 * This parses the {@code toString} format of '${currency} ${amount}'.
 * 
 * @param amountStr  the amount string, not null
 * @return the currency amount
 * @throws IllegalArgumentException if the amount cannot be parsed
 */
@FromString
public static CurrencyAmount parse(final String amountStr) {
  ArgumentChecker.notNull(amountStr, "amountStr");
  String[] parts = StringUtils.split(amountStr, ' ');
  if (parts.length != 2) {
    throw new IllegalArgumentException("Unable to parse amount, invalid format: " + amountStr);
  }
  try {
    Currency cur = Currency.parse(parts[0]);
    double amount = Double.parseDouble(parts[1]);
    return new CurrencyAmount(cur, amount);
  } catch (RuntimeException ex) {
    throw new IllegalArgumentException("Unable to parse amount: " + amountStr, ex);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:CurrencyAmount.java


示例6: forID

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Gets a time zone instance for the specified time zone id.
 * <p>
 * The time zone id may be one of those returned by getAvailableIDs.
 * Short ids, as accepted by {@link java.util.TimeZone}, are not accepted.
 * All IDs must be specified in the long format.
 * The exception is UTC, which is an acceptable id.
 * <p>
 * Alternatively a locale independent, fixed offset, datetime zone can
 * be specified. The form <code>[+-]hh:mm</code> can be used.
 * 
 * @param id  the ID of the datetime zone, null means default
 * @return the DateTimeZone object for the ID
 * @throws IllegalArgumentException if the ID is not recognised
 */
@FromString
public static DateTimeZone forID(String id) {
    if (id == null) {
        return getDefault();
    }
    if (id.equals("UTC")) {
        return DateTimeZone.UTC;
    }
    DateTimeZone zone = cProvider.getZone(id);
    if (zone != null) {
        return zone;
    }
    if (id.startsWith("+") || id.startsWith("-")) {
        int offset = parseOffset(id);
        if (offset == 0L) {
            return DateTimeZone.UTC;
        } else {
            id = printOffset(offset);
            return fixedOffsetZone(id, offset);
        }
    }
    throw new IllegalArgumentException("The datetime zone id '" + id + "' is not recognised");
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:39,代码来源:DateTimeZone.java


示例7: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a {@code DoublesPair} from the standard string format.
 * <p>
 * The standard format is '[$first, $second]'. Spaces around the values are trimmed.
 * 
 * @param pairStr  the text to parse
 * @return the parsed pair
 * @throws IllegalArgumentException if the pair cannot be parsed
 */
@FromString
public static DoublesPair parse(String pairStr) {
  ArgChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() < 5) {
    throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr);
  }
  if (pairStr.charAt(0) != '[') {
    throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr);
  }
  if (pairStr.charAt(pairStr.length() - 1) != ']') {
    throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr);
  }
  String content = pairStr.substring(1, pairStr.length() - 1);
  List<String> split = Splitter.on(',').trimResults().splitToList(content);
  if (split.size() != 2) {
    throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr);
  }
  double first = Double.parseDouble(split.get(0));
  double second = Double.parseDouble(split.get(1));
  return new DoublesPair(first, second);
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:31,代码来源:DoublesPair.java


示例8: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a {@code LongDoublePair} from the standard string format.
 * <p>
 * The standard format is '[$first, $second]'. Spaces around the values are trimmed.
 * 
 * @param pairStr  the text to parse
 * @return the parsed pair
 * @throws IllegalArgumentException if the pair cannot be parsed
 */
@FromString
public static LongDoublePair parse(String pairStr) {
  ArgChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() < 5) {
    throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr);
  }
  if (pairStr.charAt(0) != '[') {
    throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr);
  }
  if (pairStr.charAt(pairStr.length() - 1) != ']') {
    throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr);
  }
  String content = pairStr.substring(1, pairStr.length() - 1);
  List<String> split = Splitter.on(',').trimResults().splitToList(content);
  if (split.size() != 2) {
    throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr);
  }
  long first = Long.parseLong(split.get(0));
  double second = Double.parseDouble(split.get(1));
  return new LongDoublePair(first, second);
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:31,代码来源:LongDoublePair.java


示例9: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses an {@code IntDoublePair} from the standard string format.
 * <p>
 * The standard format is '[$first, $second]'. Spaces around the values are trimmed.
 * 
 * @param pairStr  the text to parse
 * @return the parsed pair
 * @throws IllegalArgumentException if the pair cannot be parsed
 */
@FromString
public static IntDoublePair parse(String pairStr) {
  ArgChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() < 5) {
    throw new IllegalArgumentException("Invalid pair format, too short: " + pairStr);
  }
  if (pairStr.charAt(0) != '[') {
    throw new IllegalArgumentException("Invalid pair format, must start with [: " + pairStr);
  }
  if (pairStr.charAt(pairStr.length() - 1) != ']') {
    throw new IllegalArgumentException("Invalid pair format, must end with ]: " + pairStr);
  }
  String content = pairStr.substring(1, pairStr.length() - 1);
  List<String> split = Splitter.on(',').trimResults().splitToList(content);
  if (split.size() != 2) {
    throw new IllegalArgumentException("Invalid pair format, must have two values: " + pairStr);
  }
  int first = Integer.parseInt(split.get(0));
  double second = Double.parseDouble(split.get(1));
  return new IntDoublePair(first, second);
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:31,代码来源:IntDoublePair.java


示例10: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses the string to produce a {@code CurrencyAmount}.
 * <p>
 * This parses the {@code toString} format of '${currency} ${amount}'.
 *
 * @param amountStr  the amount string
 * @return the currency amount
 * @throws IllegalArgumentException if the amount cannot be parsed
 */
@FromString
public static CurrencyAmount parse(String amountStr) {
  ArgChecker.notNull(amountStr, "amountStr");
  List<String> split = Splitter.on(' ').splitToList(amountStr);
  if (split.size() != 2) {
    throw new IllegalArgumentException("Unable to parse amount, invalid format: " + amountStr);
  }
  try {
    Currency cur = Currency.parse(split.get(0));
    double amount = Double.parseDouble(split.get(1));
    return new CurrencyAmount(cur, amount);
  } catch (RuntimeException ex) {
    throw new IllegalArgumentException("Unable to parse amount: " + amountStr, ex);
  }
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:25,代码来源:CurrencyAmount.java


示例11: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a currency pair from a string with format AAA/BBB.
 * <p>
 * The parsed format is '${baseCurrency}/${counterCurrency}'.
 * 
 * @param pairStr  the currency pair as a string AAA/BBB, not null
 * @return the currency pair, not null
 */
@FromString
public static CurrencyPair parse(String pairStr) {
  ArgumentChecker.notNull(pairStr, "pairStr");
  if (pairStr.length() != 7) {
    throw new IllegalArgumentException("Currency pair format must be AAA/BBB");
  }
  Currency base = Currency.of(pairStr.substring(0, 3));
  Currency counter = Currency.of(pairStr.substring(4));
  return new CurrencyPair(base, counter);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:CurrencyPair.java


示例12: of

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Finds a volatility quote unit by name, ignoring case.
 * <p>
 * This method dynamically creates the quote units if it is missing.
 * @param name The name of the instance to find, not null
 * @return The volatility quote units, null if not found
 */
@FromString
public VolatilityQuoteUnits of(final String name) {
  try {
    return INSTANCE.instance(name);
  } catch (final IllegalArgumentException e) {
    ArgumentChecker.notNull(name, "name");
    final VolatilityQuoteUnits quoteUnits = new VolatilityQuoteUnits(name.toUpperCase(Locale.ENGLISH));
    return addInstance(quoteUnits);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:VolatilityQuoteUnitsFactory.java


示例13: of

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Finds a surface quote type by name, ignoring case.
 * <p>
 * This method dynamically creates the quote type if it is missing.
 * @param name The name of the instance to find, not null
 * @return The surface quote type, null if not found
 */
@FromString
public SurfaceQuoteType of(final String name) {
  try {
    return INSTANCE.instance(name);
  } catch (final IllegalArgumentException e) {
    ArgumentChecker.notNull(name, "name");
    final SurfaceQuoteType quoteType = new SurfaceQuoteType(name.toUpperCase(Locale.ENGLISH));
    return addInstance(quoteType);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:SurfaceQuoteTypeFactory.java


示例14: of

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Finds a cube quote type by name, ignoring case.
 * <p>
 * This method dynamically creates the quote type if it is missing.
 * @param name The name of the instance to find, not null
 * @return The cube quote type, null if not found
 */
@FromString
public CubeQuoteType of(final String name) {
  try {
    return INSTANCE.instance(name);
  } catch (final IllegalArgumentException e) {
    ArgumentChecker.notNull(name, "name");
    final CubeQuoteType quoteType = new CubeQuoteType(name.toUpperCase(Locale.ENGLISH));
    return addInstance(quoteType);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:CubeQuoteTypeFactory.java


示例15: of

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Gets an exercise type by name.
 * 
 * @param name  the name to find, not null
 * @return the exercise type, not null
 */
@FromString
public static ExerciseType of(String name) {
  ArgumentChecker.notNull(name, "name");
 
  registerKnownTypes();
  ExerciseType type = s_cache.get(name);
  if (type == null) {
    throw new IllegalArgumentException("Unknown ExerciseType: " + name);
  }
  return type;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:ExerciseType.java


示例16: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a {@code VersionCorrection} from the standard string format.
 * <p>
 * This parses the version-correction from the form produced by {@code toString()}.
 * It consists of 'V' followed by the version, a dot, then 'C' followed by the correction,
 * such as {@code V2011-02-01T12:30:40Z.C2011-02-01T12:30:40Z}.
 * The text 'VLATEST.CLATEST' is used in place of the instant for a latest version and correction.
 * 
 * @param versionCorrection the identifier to parse, not null
 * @return the version-correction combination, not null
 * @throws IllegalArgumentException if the version-correction cannot be parsed
 */
@FromString
public static VersionCorrection parse(String versionCorrection) {
  ArgumentChecker.notEmpty(versionCorrection, "versionCorrection");
  int posC = versionCorrection.indexOf(".C");
  if (versionCorrection.charAt(0) != 'V' || posC < 0) {
    throw new IllegalArgumentException("Invalid identifier format: " + versionCorrection);
  }
  String verStr = versionCorrection.substring(1, posC);
  String corrStr = versionCorrection.substring(posC + 2);
  Instant versionAsOf = parseInstantString(verStr);
  Instant correctedTo = parseInstantString(corrStr);
  return of(versionAsOf, correctedTo);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:VersionCorrection.java


示例17: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses an {@code ExternalId} from a formatted scheme and value.
 * <p>
 * This parses the identifier from the form produced by {@code toString()}
 * which is {@code <SCHEME>~<VALUE>}.
 * 
 * @param str  the external identifier to parse, not null
 * @return the external identifier, not null
 * @throws IllegalArgumentException if the identifier cannot be parsed
 */
@FromString
public static ExternalId parse(String str) {
  ArgumentChecker.notEmpty(str, "str");
  str = StringUtils.replace(str, "::", "~");  // leniently parse old data
  int pos = str.indexOf("~");
  if (pos < 0) {
    throw new IllegalArgumentException("Invalid identifier format: " + str);
  }
  return new ExternalId(ExternalScheme.of(str.substring(0, pos)), str.substring(pos + 1));
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:ExternalId.java


示例18: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses an {@code ObjectId} from a formatted scheme and value.
 * <p>
 * This parses the identifier from the form produced by {@code toString()}
 * which is {@code <SCHEME>~<VALUE>}.
 * 
 * @param str  the object identifier to parse, not null
 * @return the object identifier, not null
 * @throws IllegalArgumentException if the identifier cannot be parsed
 */
@FromString
public static ObjectId parse(String str) {
  ArgumentChecker.notEmpty(str, "str");
  if (str.contains("~") == false) {
    str = StringUtils.replace(str, "::", "~");  // leniently parse old data
  }
  String[] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, "~");
  switch (split.length) {
    case 2:
      return ObjectId.of(split[0], split[1]);
  }
  throw new IllegalArgumentException("Invalid identifier format: " + str);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:ObjectId.java


示例19: parse

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Parses a formatted string representing the tenor.
 * <p>
 * The format is based on ISO-8601, such as 'P3M'.
 * 
 * @param tenorStr  the string representing the tenor, not null
 * @return the tenor, not null
 */
@FromString
@SuppressWarnings("deprecation")
public static Tenor parse(final String tenorStr) {
  ArgumentChecker.notNull(tenorStr, "tenorStr");
  try {
    return new Tenor(DateUtils.toPeriod(tenorStr));
  } catch (DateTimeParseException e) {
    return new Tenor(BusinessDayTenor.valueOf(tenorStr));
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:Tenor.java


示例20: of

import org.joda.convert.FromString; //导入依赖的package包/类
/**
 * Obtains an instance of {@code Currency} for the specified ISO-4217
 * three letter currency code dynamically creating a currency if necessary.
 * <p>
 * A currency is uniquely identified by ISO-4217 three letter code.
 * This method creates the currency if it is not known.
 *
 * @param currencyCode  the three letter currency code, ASCII and upper case, not null
 * @return the singleton instance, not null
 * @throws IllegalArgumentException if the currency code is not three letters
 */
@FromString
public static Currency of(String currencyCode) {
  ArgumentChecker.notNull(currencyCode, "currencyCode");
  // check cache before matching
  Currency previous = s_instanceMap.get(currencyCode);
  if (previous != null) {
    return previous;
  }
  if (currencyCode.matches("[A-Z][A-Z][A-Z]") == false) {
    throw new IllegalArgumentException("Invalid currency code: " + currencyCode);
  }
  s_instanceMap.putIfAbsent(currencyCode, new Currency(currencyCode));
  return s_instanceMap.get(currencyCode);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:Currency.java



注:本文中的org.joda.convert.FromString类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LockService类代码示例发布时间:2022-05-23
下一篇:
Java Messages类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap