本文整理汇总了Java中com.google.common.primitives.Doubles.tryParse方法的典型用法代码示例。如果您正苦于以下问题:Java Doubles.tryParse方法的具体用法?Java Doubles.tryParse怎么用?Java Doubles.tryParse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.Doubles
的用法示例。
在下文中一共展示了Doubles.tryParse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseToken
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
void parseToken(int i, String token) {
if (dataTypes[i - 2] == null) {
// test double parsing, in case of error we consider it a string time series
if (Doubles.tryParse(token) != null) {
dataTypes[i - 2] = TimeSeriesDataType.DOUBLE;
TDoubleArrayList doubleValues = createDoubleValues();
doubleValues.add(parseDouble(token));
values[i - 2] = doubleValues;
} else {
dataTypes[i - 2] = TimeSeriesDataType.STRING;
List<String> stringValues = createStringValues();
stringValues.add(checkString(token));
values[i - 2] = stringValues;
}
} else {
if (dataTypes[i - 2] == TimeSeriesDataType.DOUBLE) {
((TDoubleArrayList) values[i - 2]).add(parseDouble(token));
} else if (dataTypes[i - 2] == TimeSeriesDataType.STRING) {
((List<String>) values[i - 2]).add(checkString(token));
} else {
throw assertDataType(dataTypes[i - 2]);
}
}
}
示例2: determineType
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
private static URI determineType(final String data) {
if (Ints.tryParse(data) != null) {
return XMLSchema.INTEGER;
} else if (Doubles.tryParse(data) != null) {
return XMLSchema.DOUBLE;
} else if (Floats.tryParse(data) != null) {
return XMLSchema.FLOAT;
} else if (isShort(data)) {
return XMLSchema.SHORT;
} else if (Longs.tryParse(data) != null) {
return XMLSchema.LONG;
} if (Boolean.parseBoolean(data)) {
return XMLSchema.BOOLEAN;
} else if (isByte(data)) {
return XMLSchema.BYTE;
} else if (isDate(data)) {
return XMLSchema.DATETIME;
} else if (isUri(data)) {
return XMLSchema.ANYURI;
}
return XMLSchema.STRING;
}
示例3: doForward
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
@Nullable
protected Boolean doForward(String s) {
if (!Strings.isNullOrEmpty(s)) {
Double d = Doubles.tryParse(s);
if (d != null) {
return d.intValue() == 0 ? false : true;
} else {
s = s.trim();
if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t")) {
return true;
}
}
}
return false;
}
示例4: save
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public void save() {
String text = getTextField().getText();
Double value = Doubles.tryParse(text);
if (value == null) {
getOption().resetToDefault();
load();
} else {
getOption().set(value);
}
}
示例5: toLua
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public static Object toLua(Comparable<?> obj) {
if (obj instanceof IStringSerializable) {
IStringSerializable s = (IStringSerializable) obj;
return s.getName();
}
if (obj instanceof Enum) {
Enum<?> e = (Enum<?>) obj;
return e.name();
}
if (obj instanceof String) {
String str = (String) obj;
if ("true".equals(obj)) {
return true;
}
if ("false".equals(obj)) {
return false;
}
Object result = Ints.tryParse(str);
if (result != null) {
return result;
}
result = Doubles.tryParse(str);
if (result != null) {
return result;
}
}
return Conversions.canonicalRepresentationOf(obj);
}
示例6: getDoubles
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public static Double[] getDoubles(HttpServletRequest request, String fieldName) {
String[] values = request.getParameterValues(fieldName);
if (values == null) {
return null;
}
int len = values.length;
Double[] doubles = new Double[len];
for (int i = 0; i < len; i++) {
doubles[i] = Doubles.tryParse(values[i]);
}
return doubles;
}
示例7: isValid
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public boolean isValid() {
if (EditTextUtils.testIsEmpty(editText))
return false;
return editText.getVisibility() != View.VISIBLE ||
(Doubles.tryParse(EditTextUtils.getText(editText)) != null && Double.parseDouble(EditTextUtils.getText(editText)) >= 0);
}
示例8: isValid
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public boolean isValid() {
String text = EditTextUtils.getText(editText);
if (EditTextUtils.testIsEmpty(editText) || text.isEmpty() || (Doubles.tryParse(EditTextUtils.getText(editText)) == null))
return false;
Double value = Double.parseDouble(text);
return editText.getVisibility() != View.VISIBLE || (value >= range.getLow() && value <= range.getHigh());
}
示例9: mean
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public double mean() {
double sum = 0;
for (E item : this) {
// TODO: Correspond missing value
if (Doubles.tryParse(item.toString()) != null ) {
sum += Double.parseDouble(item.toString());
}
}
return this.size() == 0 ? 0 : sum / this.size();
}
示例10: std
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public double std() {
double sum = 0;
double mean = this.mean();
for (E item: this) {
// TODO: Correspond missing value
if (Doubles.tryParse(item.toString()) != null) {
sum += Math.pow(Double.parseDouble(item.toString()) - mean, 2);
}
}
return this.size() == 0 ? 0 : sum / this.size();
}
示例11: parseDoubleWithCoordPrecision
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
private static Double parseDoubleWithCoordPrecision(String s){
int precedingZeroes = 0;
String t = s;
while(t.startsWith("0")){
precedingZeroes++;
t = t.substring(1);
}
Double c = Doubles.tryParse(t);
if(c == null){
return null;
}
double multiplier = Math.pow(10, 4 - precedingZeroes - Math.floor(Math.log10(c)));
return c * multiplier;
}
示例12: extractNumbers
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
private List<Double> extractNumbers(String text) {
final List<Double> list = new LinkedList<>();
final Matcher matcher = NUMBER.matcher(text);
while (matcher.find()) {
final Double d = Doubles.tryParse(matcher.group().replaceAll(",", ""));
if (d != null) {
list.add(d);
}
}
return list;
}
示例13: hasShortPrefix
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public static boolean hasShortPrefix(String name)
{
return name.startsWith(SHORT_FLAG_PREFIX) && Doubles.tryParse(name) == null;
}
示例14: getContentAsDoubleOrNull
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public Double getContentAsDoubleOrNull() {
if (content instanceof Number) {
return ((Number) content).doubleValue();
}
return content == null ? null : Doubles.tryParse(getContentText());
}
示例15: apply
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override public Double apply(Object input) {
if (input instanceof Double) { return (Double) input; }
if (input instanceof String) { return Doubles.tryParse((String) input); }
if (!Objects2.isParseable(input)) return null;
return Double.parseDouble(input.toString());
}