Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Kit committed Sep 22, 2013
1 parent 26c5d50 commit 60ae010
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 41 deletions.
33 changes: 0 additions & 33 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/annotations/Assumption.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Condition {
double value() default 0.0;
String value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static List<BooleanCondition> parseBooleanConditions(Class<?> c) {
assert (c != null);
List<BooleanCondition> result = new LinkedList<>();
List<Parameter> parameters;
String id;
for (Method m : getAnnotatedMethods(c, Condition.class)) {
if (m == null) {
continue;
Expand All @@ -33,7 +34,8 @@ public static List<BooleanCondition> parseBooleanConditions(Class<?> c) {
} catch (ParametersParseException cepe) {
continue;
}
result.add(new BooleanCondition(parameters, m));
id = m.getAnnotation(Condition.class).value();
result.add(new BooleanCondition(id, parameters, m));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@

public class BooleanCondition extends Invocable {

public BooleanCondition(List<Parameter> parameters, Method method) {
private final String id;

public BooleanCondition(String id, List<Parameter> parameters, Method method) {
super(parameters, method, LockingMode.STRONG);
this.id = id;
}

public BooleanCondition(Method method) {
public BooleanCondition(String id, Method method) {
super(method, LockingMode.STRONG);
this.id = id;
}

public String getId() {
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import cz.cuni.mff.d3s.deeco.exceptions.KMException;
import cz.cuni.mff.d3s.deeco.knowledge.ISession;
Expand All @@ -25,11 +26,11 @@ public KnowledgePath() {
public List<PathNode> getNodes() {
return nodes;
}

public void addNode(PathNode node) {
nodes.add(node);
}

public void join(KnowledgePath knowledgePath) {
nodes.addAll(knowledgePath.getNodes());
}
Expand All @@ -38,14 +39,51 @@ public String getEvaluatedPath(KnowledgeManager km, String coord,
String member, String prepend, ISession session) {
try {
if (prepend != null && !prepend.equals(""))
return prepend + PathGrammar.PATH_SEPARATOR + evaluate(this, km, coord, member, session);
return prepend + PathGrammar.PATH_SEPARATOR
+ evaluate(this, km, coord, member, session);
else
return evaluate(this, km, coord, member, session);
} catch (KMException kme) {
Log.e("Knowledge path evaluation error", kme);
return null;
}
}

public String getEvaluatedPath(KnowledgeManager km,
Map<String, String> replaceFromTo, ISession session) {
try {
return evaluate(this, km, replaceFromTo, session);
} catch (KMException kme) {
Log.e("Knowledge path evaluation error", kme);
return null;
}
}

private String evaluate(KnowledgePath kp, KnowledgeManager km,
Map<String, String> replaceFromTo, ISession session)
throws KMException {
StringBuilder builder = new StringBuilder();
for (PathNode pn : kp.getNodes()) {
if (pn instanceof PathNodeField) {
PathNodeField pnf = (PathNodeField) pn;
if (replaceFromTo.containsKey(pnf.getName()))
builder.append(replaceFromTo.get(pnf.getName()));
else
builder.append(pnf.getName());
} else {
PathNodeMapKey pnmk = (PathNodeMapKey) pn;
String evaluation = evaluate(pnmk.getKeyPath(), km,
replaceFromTo, session);
Object o = km.getKnowledge(evaluation, session);
if (o instanceof Object[] && ((Object[]) o).length == 1)
builder.append((String) ((Object[]) o)[0]);
else
builder.append((String) o);
}
builder.append(PathGrammar.PATH_SEPARATOR);
}
builder.replace(builder.length() - 1, builder.length(), "");
return builder.toString();
}

private String evaluate(KnowledgePath kp, KnowledgeManager km,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EnsembleJob(Ensemble ensemble, String coordinator, String member,
this.coordinator = coordinator;
this.member = member;
this.schedule = ensemble.getSchedule();
this.id = ensemble.getId();
this.id = coordinator + member + ensemble.getId();
}

@Override
Expand Down

0 comments on commit 60ae010

Please sign in to comment.