зеркало из https://github.com/microsoft/Dhalion.git
Add builder methods for Array Types
This commit is contained in:
Родитель
541850f1f6
Коммит
18057d4369
|
@ -84,6 +84,12 @@ public class MeasurementsArray {
|
|||
});
|
||||
}
|
||||
|
||||
public MeasurementsArray of(Collection<Measurement> measurements) {
|
||||
MeasurementsArray array = new MeasurementsArray();
|
||||
array.addAll(measurements);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains all {@link Measurement}s with given component names.
|
||||
*
|
||||
|
@ -262,7 +268,8 @@ public class MeasurementsArray {
|
|||
/**
|
||||
* Sorts the {@link Measurement}s in this collection in the order of the specified keys
|
||||
*
|
||||
* @param sortKeys one or more sort keys, e.g. {@link SortKey#COMPONENT}
|
||||
* @param descending false for ascending order, true for descending
|
||||
* @param sortKeys one or more sort keys, e.g. {@link SortKey#COMPONENT}
|
||||
* @return ordered {@link Measurement}s
|
||||
*/
|
||||
public MeasurementsArray sort(boolean descending, SortKey... sortKeys) {
|
||||
|
@ -297,26 +304,14 @@ public class MeasurementsArray {
|
|||
* @return the first {@link Measurement}, if present
|
||||
*/
|
||||
public Measurement first() {
|
||||
if (measurements.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Table result = measurements.first(1);
|
||||
Collection<Measurement> measurementCollection = new MeasurementsArray(result).get();
|
||||
return measurementCollection.iterator().next();
|
||||
return get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the last {@link Measurement}, if present
|
||||
*/
|
||||
public Measurement last() {
|
||||
if (measurements.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Table result = measurements.last(1);
|
||||
Collection<Measurement> measurementCollection = new MeasurementsArray(result).get();
|
||||
return measurementCollection.iterator().next();
|
||||
return get(measurements.rowCount() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -325,15 +320,31 @@ public class MeasurementsArray {
|
|||
public Collection<Measurement> get() {
|
||||
ArrayList<Measurement> result = new ArrayList<>();
|
||||
for (int i = 0; i < measurements.rowCount(); i++) {
|
||||
result.add(new Measurement(component.get(i),
|
||||
instance.get(i),
|
||||
type.get(i),
|
||||
Instant.ofEpochMilli(timeStamps.get(i)),
|
||||
value.get(i)));
|
||||
result.add(row2Obj(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index position in the table
|
||||
* @return {@link Measurement} at the requested position
|
||||
*/
|
||||
public Measurement get(int index) {
|
||||
if (index < 0 || index >= measurements.rowCount() || measurements.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return row2Obj(index);
|
||||
}
|
||||
|
||||
private Measurement row2Obj(int index) {
|
||||
return new Measurement(component.get(index),
|
||||
instance.get(index),
|
||||
type.get(index),
|
||||
Instant.ofEpochMilli(timeStamps.get(index)),
|
||||
value.get(index));
|
||||
}
|
||||
|
||||
public String toStringForDebugging() {
|
||||
return measurements.print(measurements.rowCount());
|
||||
}
|
||||
|
|
|
@ -192,7 +192,8 @@ public class SymptomsArray {
|
|||
/**
|
||||
* Sorts the {@link Symptom}s in this collection in the order of the specified keys
|
||||
*
|
||||
* @param sortKeys one or more sort keys, e.g. {@link SortKey#ID}
|
||||
* @param descending false for ascending order, true for descending
|
||||
* @param sortKeys one or more sort keys, e.g. {@link SortKey#ID}
|
||||
* @return ordered {@link Symptom}s
|
||||
*/
|
||||
public SymptomsArray sort(boolean descending, SortKey... sortKeys) {
|
||||
|
@ -255,14 +256,31 @@ public class SymptomsArray {
|
|||
public Collection<Symptom> get() {
|
||||
ArrayList<Symptom> result = new ArrayList<>();
|
||||
for (int i = 0; i < symptoms.rowCount(); i++) {
|
||||
result.add(new Symptom(id.get(i),
|
||||
type.get(i),
|
||||
Instant.ofEpochMilli(timeStamp.get(i)),
|
||||
Collections.singletonList(assignment.get(i))));
|
||||
result.add(row2Obj(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index position in the table
|
||||
* @return {@link Symptom} at the requested position
|
||||
*/
|
||||
public Symptom get(int index) {
|
||||
if (index < 0 || index >= symptoms.rowCount() || symptoms.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return row2Obj(index);
|
||||
}
|
||||
|
||||
private Symptom row2Obj(int index) {
|
||||
return new Symptom(id.get(index),
|
||||
type.get(index),
|
||||
Instant.ofEpochMilli(timeStamp.get(index)),
|
||||
Collections.singletonList(assignment.get(index)));
|
||||
}
|
||||
|
||||
|
||||
public String toStringForDebugging() {
|
||||
return symptoms.print(symptoms.rowCount());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче