Skip to content

Commit

Permalink
Towards even more sophisticated PEBL.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Sep 26, 2016
1 parent fc2041a commit 66e41ed
Show file tree
Hide file tree
Showing 28 changed files with 351 additions and 266 deletions.
22 changes: 15 additions & 7 deletions pebl/src/main/java/pebl/feature/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;

import pebl.HasName;
import pebl.HasID;
Expand All @@ -22,22 +21,31 @@ public class Capability implements HasID, HasName {
private final String name;

@XmlElement(required = true)
private final ResultFormat resultFormat;
private final List<Metric> atomicMetrics;

@XmlElement(name="language")
private final List<Language> languages = new LinkedList<>();

@XmlElement
private final List<ComputedMetric> computedMetrics = new LinkedList<>();

public Capability addMetric(ValueType type, String name, String description, String unit, String groovyScript) {
computedMetrics.add(new ComputedMetric(type, name, description, unit, getID(), groovyScript));

return this;
}

@XmlID
@XmlAttribute(required = true)
private final String id;

Capability() {
this("", new ResultFormat());
this("", Collections.emptyList());
}

public Capability(String name, ResultFormat resultFormat) {
public Capability(String name, List<Metric> atomicMetrics) {
this.name = Objects.requireNonNull(name);
this.resultFormat = Objects.requireNonNull(resultFormat);
this.atomicMetrics = Objects.requireNonNull(new LinkedList<>(atomicMetrics));

this.id = name;
}
Expand All @@ -52,8 +60,8 @@ public String getName() {
return name;
}

public ResultFormat getResultFormat() {
return resultFormat;
public List<Metric> getAtomicMetrics() {
return atomicMetrics;
}

@Override
Expand Down
34 changes: 34 additions & 0 deletions pebl/src/main/java/pebl/feature/ComputedMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pebl.feature;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.eclipse.persistence.oxm.annotations.XmlCDATA;

@XmlAccessorType(XmlAccessType.NONE)
public class ComputedMetric extends Metric {

public static final String SCRIPT_MAX = "MAX";
public static final String SCRIPT_COUNT_TRUE = "COUNT_TRUE";
public static final String SCRIPT_SUM = "SUM";

@XmlElement(required = true)
@XmlCDATA
private final String groovyScript;

public ComputedMetric() {
super();
groovyScript = "";
}

public ComputedMetric(ValueType type, String name, String description, String unit, String idPrefix,
String groovyScript) {
super(type, name, description, unit, idPrefix);
this.groovyScript = groovyScript;
}

public String getGroovyScript() {
return groovyScript;
}
}
11 changes: 11 additions & 0 deletions pebl/src/main/java/pebl/feature/Feature.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pebl.feature;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -34,6 +36,15 @@ public class Feature implements HasID, HasName {
@XmlAttribute(required = true)
private final String id;

@XmlElement
private final List<ComputedMetric> computedMetrics = new LinkedList<>();

public Feature addMetric(ValueType type, String name, String description, String unit, String groovyScript) {
computedMetrics.add(new ComputedMetric(type, name, description, unit, getID(), groovyScript));

return this;
}

public Feature() {
this(new FeatureSet(), "");
}
Expand Down
9 changes: 9 additions & 0 deletions pebl/src/main/java/pebl/feature/FeatureSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public class FeatureSet implements HasID, HasName {
@XmlAttribute(required = true)
private final String id;

@XmlElement
private final List<ComputedMetric> computedMetrics = new LinkedList<>();

public FeatureSet addMetric(ValueType type, String name, String description, String unit, String groovyScript) {
computedMetrics.add(new ComputedMetric(type, name, description, unit, getID(), groovyScript));

return this;
}

FeatureSet() {
this(new Group(), "");
}
Expand Down
9 changes: 9 additions & 0 deletions pebl/src/main/java/pebl/feature/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public class Group implements HasID, HasName {
@XmlAttribute(required = true)
private final String id;

@XmlElement
private final List<ComputedMetric> computedMetrics = new LinkedList<>();

public Group addMetric(ValueType type, String name, String description, String unit, String groovyScript) {
computedMetrics.add(new ComputedMetric(type, name, description, unit, getID(), groovyScript));

return this;
}

public Group() {
this("", new Language(), "");
}
Expand Down
9 changes: 9 additions & 0 deletions pebl/src/main/java/pebl/feature/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public class Language implements HasID, HasName {
@XmlAttribute(required = true)
private final String id;

@XmlElement
private final List<ComputedMetric> computedMetrics = new LinkedList<>();

public Language addMetric(ValueType type, String name, String description, String unit, String groovyScript) {
computedMetrics.add(new ComputedMetric(type, name, description, unit, getID(), groovyScript));

return this;
}

Language() {
this(new Capability(), "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;

@XmlAccessorType(XmlAccessType.NONE)
public class ResultFormatElement {
public class Metric {

@XmlAttribute(required = true)
@XmlID
private final String id;

@XmlElement(required = true)
private final ResultFormatMetric type;
private final ValueType type;

@XmlElement(required = true)
private final String name;
Expand All @@ -21,18 +27,19 @@ public class ResultFormatElement {
@XmlElement(required = true)
private final String unit;

ResultFormatElement() {
this(new ResultFormatMetric(), "", "", "");
public Metric() {
this(new ValueType(), "", "", "", "");
}

public ResultFormatElement(ResultFormatMetric type, String name, String description, String unit) {
public Metric(ValueType type, String name, String description, String unit, String idPrefix) {
this.type = Objects.requireNonNull(type);
this.name = Objects.requireNonNull(name);
this.description = Objects.requireNonNull(description);
this.unit = Objects.requireNonNull(unit);
this.id = idPrefix + "-" + type + "-" + name;
}

public ResultFormatMetric getType() {
public ValueType getType() {
return type;
}

Expand Down
29 changes: 0 additions & 29 deletions pebl/src/main/java/pebl/feature/ResultFormat.java

This file was deleted.

30 changes: 0 additions & 30 deletions pebl/src/main/java/pebl/feature/ResultFormatMetric.java

This file was deleted.

37 changes: 37 additions & 0 deletions pebl/src/main/java/pebl/feature/ValueType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package pebl.feature;

import java.util.Objects;

import javax.xml.bind.annotation.XmlElement;

/**
* Idea: only primitive types, aggregated as a special type (could be removed as well)
*/
public class ValueType {

public static final ValueType BOOLEAN = new ValueType("BOOLEAN");
public static final ValueType LONG = new ValueType("LONG");
public static final ValueType STRING = new ValueType("STRING");
public static final ValueType DOUBLE = new ValueType("DOUBLE");
public static final ValueType AGGREGATED = new ValueType("AGGREGATED");

@XmlElement(required = true)
private final String type;

ValueType() {
this("");
}

public ValueType(String type) {
this.type = Objects.requireNonNull(type);
}

public String getType() {
return type;
}

@Override
public String toString() {
return type;
}
}
11 changes: 0 additions & 11 deletions pebl/src/main/java/pebl/feature/aggregation/AggregatedMetric.java

This file was deleted.

This file was deleted.

36 changes: 36 additions & 0 deletions pebl/src/main/java/pebl/result/Measurement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package pebl.result;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlIDREF;

import pebl.feature.Metric;

@XmlAccessorType(XmlAccessType.NONE)
public class Measurement {

@XmlIDREF
@XmlElement(required = true)
private final Metric metric;

@XmlElement(required = true)
private final Value value;

Measurement() {
this(new Metric(), new Value());
}

public Measurement(Metric metric, Value value) {
this.metric = metric;
this.value = value;
}

public Value getValue() {
return value;
}

public Metric getMetric() {
return metric;
}
}
5 changes: 0 additions & 5 deletions pebl/src/main/java/pebl/result/Metric.java

This file was deleted.

Loading

0 comments on commit 66e41ed

Please sign in to comment.