-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFloatColumn.java
More file actions
39 lines (35 loc) · 1.11 KB
/
FloatColumn.java
File metadata and controls
39 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.rcsb.cif.model;
import java.util.Arrays;
import java.util.stream.DoubleStream;
/**
* A column that provides float data.
*/
public interface FloatColumn extends Column<double[]> {
/**
* Type-safe access to the native type of data stored in this column.
* @param row the index to retrieve
* @return an double value
*/
double get(int row);
/**
* A DoubleStream of all registered values.
* @return doubles
*/
default DoubleStream values() {
double[] array = getArray();
return array != null ? Arrays.stream(array) : DoubleStream.empty();
}
/**
* This is how all FloatColumns parse their data.
* @param text the raw data
* @return a double
*/
static double parseFloat(String text) {
if (text.isEmpty() || ValueKind.isValueKindToken(text)) {
return 0;
}
// some formats specify uncertain decimal places like: 0.00012(3) - ignore them (in agreement with Mol*)
int index = text.indexOf('(');
return Double.parseDouble(index == -1 ? text : text.substring(0, index));
}
}