本文整理汇总了Java中org.joda.convert.FromString类的典型用法代码示例。如果您正苦于以下问题:Java FromString类的具体用法?Java FromString怎么用?Java FromString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FromString类属于org.joda.convert包,在下文中一共展示了FromString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}