|
| 1 | +package org.evomaster.client.java.instrumentation.shared.dto; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Collections; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Objects; |
| 8 | + |
| 9 | +/** |
| 10 | + * Serializable representation of the control-dependence information of a method. |
| 11 | + * Contains only the data needed by EvoMaster core: branch objective identifiers, |
| 12 | + * the subset that are roots, and the parent→child relationships between them. |
| 13 | + */ |
| 14 | +public class ControlDependenceGraphDto implements Serializable { |
| 15 | + |
| 16 | + private static final long serialVersionUID = -1703430508792441369L; |
| 17 | + |
| 18 | + private String className; |
| 19 | + private String methodName; |
| 20 | + private List<BranchObjectiveDto> objectives = new ArrayList<>(); |
| 21 | + private List<Integer> rootObjectiveIds = new ArrayList<>(); |
| 22 | + private List<DependencyEdgeDto> edges = new ArrayList<>(); |
| 23 | + |
| 24 | + public ControlDependenceGraphDto() { |
| 25 | + } |
| 26 | + |
| 27 | + public ControlDependenceGraphDto(String className, |
| 28 | + String methodName, |
| 29 | + List<BranchObjectiveDto> objectives, |
| 30 | + List<Integer> rootObjectiveIds, |
| 31 | + List<DependencyEdgeDto> edges) { |
| 32 | + this.className = className; |
| 33 | + this.methodName = methodName; |
| 34 | + if (objectives != null) { |
| 35 | + this.objectives = new ArrayList<>(objectives); |
| 36 | + } |
| 37 | + if (rootObjectiveIds != null) { |
| 38 | + this.rootObjectiveIds = new ArrayList<>(rootObjectiveIds); |
| 39 | + } |
| 40 | + if (edges != null) { |
| 41 | + this.edges = new ArrayList<>(edges); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + public String getClassName() { |
| 46 | + return className; |
| 47 | + } |
| 48 | + |
| 49 | + public void setClassName(String className) { |
| 50 | + this.className = className; |
| 51 | + } |
| 52 | + |
| 53 | + public String getMethodName() { |
| 54 | + return methodName; |
| 55 | + } |
| 56 | + |
| 57 | + public void setMethodName(String methodName) { |
| 58 | + this.methodName = methodName; |
| 59 | + } |
| 60 | + |
| 61 | + public List<BranchObjectiveDto> getObjectives() { |
| 62 | + return Collections.unmodifiableList(objectives); |
| 63 | + } |
| 64 | + |
| 65 | + public void setObjectives(List<BranchObjectiveDto> objectives) { |
| 66 | + this.objectives = objectives == null ? new ArrayList<>() : new ArrayList<>(objectives); |
| 67 | + } |
| 68 | + |
| 69 | + public List<Integer> getRootObjectiveIds() { |
| 70 | + return Collections.unmodifiableList(rootObjectiveIds); |
| 71 | + } |
| 72 | + |
| 73 | + public void setRootObjectiveIds(List<Integer> rootObjectiveIds) { |
| 74 | + this.rootObjectiveIds = rootObjectiveIds == null ? new ArrayList<>() : new ArrayList<>(rootObjectiveIds); |
| 75 | + } |
| 76 | + |
| 77 | + public List<DependencyEdgeDto> getEdges() { |
| 78 | + return Collections.unmodifiableList(edges); |
| 79 | + } |
| 80 | + |
| 81 | + public void setEdges(List<DependencyEdgeDto> edges) { |
| 82 | + this.edges = edges == null ? new ArrayList<>() : new ArrayList<>(edges); |
| 83 | + } |
| 84 | + |
| 85 | + public void addObjective(BranchObjectiveDto objective) { |
| 86 | + if (objective != null) { |
| 87 | + this.objectives.add(objective); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + public void addRootObjectiveId(Integer id) { |
| 92 | + if (id != null) { |
| 93 | + this.rootObjectiveIds.add(id); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public void addEdge(DependencyEdgeDto edge) { |
| 98 | + if (edge != null) { |
| 99 | + this.edges.add(edge); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Descriptor and numeric id for a branch objective (true or false outcome). |
| 105 | + */ |
| 106 | + public static class BranchObjectiveDto implements Serializable { |
| 107 | + |
| 108 | + private static final long serialVersionUID = -8122197698885173402L; |
| 109 | + |
| 110 | + private int id; |
| 111 | + private String descriptiveId; |
| 112 | + |
| 113 | + public BranchObjectiveDto() { |
| 114 | + } |
| 115 | + |
| 116 | + public BranchObjectiveDto(int id, String descriptiveId) { |
| 117 | + this.id = id; |
| 118 | + this.descriptiveId = descriptiveId; |
| 119 | + } |
| 120 | + |
| 121 | + public int getId() { |
| 122 | + return id; |
| 123 | + } |
| 124 | + |
| 125 | + public void setId(int id) { |
| 126 | + this.id = id; |
| 127 | + } |
| 128 | + |
| 129 | + public String getDescriptiveId() { |
| 130 | + return descriptiveId; |
| 131 | + } |
| 132 | + |
| 133 | + public void setDescriptiveId(String descriptiveId) { |
| 134 | + this.descriptiveId = descriptiveId; |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public boolean equals(Object o) { |
| 139 | + if (this == o) return true; |
| 140 | + if (o == null || getClass() != o.getClass()) return false; |
| 141 | + BranchObjectiveDto that = (BranchObjectiveDto) o; |
| 142 | + return id == that.id && Objects.equals(descriptiveId, that.descriptiveId); |
| 143 | + } |
| 144 | + |
| 145 | + @Override |
| 146 | + public int hashCode() { |
| 147 | + return Objects.hash(id, descriptiveId); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Directed edge describing that {@code parentObjectiveId} must be covered before {@code childObjectiveId}. |
| 153 | + */ |
| 154 | + public static class DependencyEdgeDto implements Serializable { |
| 155 | + |
| 156 | + private static final long serialVersionUID = 3167520314102399629L; |
| 157 | + |
| 158 | + private int parentObjectiveId; |
| 159 | + private int childObjectiveId; |
| 160 | + |
| 161 | + public DependencyEdgeDto() { |
| 162 | + } |
| 163 | + |
| 164 | + public DependencyEdgeDto(int parentObjectiveId, int childObjectiveId) { |
| 165 | + this.parentObjectiveId = parentObjectiveId; |
| 166 | + this.childObjectiveId = childObjectiveId; |
| 167 | + } |
| 168 | + |
| 169 | + public int getParentObjectiveId() { |
| 170 | + return parentObjectiveId; |
| 171 | + } |
| 172 | + |
| 173 | + public void setParentObjectiveId(int parentObjectiveId) { |
| 174 | + this.parentObjectiveId = parentObjectiveId; |
| 175 | + } |
| 176 | + |
| 177 | + public int getChildObjectiveId() { |
| 178 | + return childObjectiveId; |
| 179 | + } |
| 180 | + |
| 181 | + public void setChildObjectiveId(int childObjectiveId) { |
| 182 | + this.childObjectiveId = childObjectiveId; |
| 183 | + } |
| 184 | + |
| 185 | + @Override |
| 186 | + public boolean equals(Object o) { |
| 187 | + if (this == o) return true; |
| 188 | + if (o == null || getClass() != o.getClass()) return false; |
| 189 | + DependencyEdgeDto that = (DependencyEdgeDto) o; |
| 190 | + return parentObjectiveId == that.parentObjectiveId && |
| 191 | + childObjectiveId == that.childObjectiveId; |
| 192 | + } |
| 193 | + |
| 194 | + @Override |
| 195 | + public int hashCode() { |
| 196 | + return Objects.hash(parentObjectiveId, childObjectiveId); |
| 197 | + } |
| 198 | + } |
| 199 | +} |
| 200 | + |
0 commit comments