BrightSide Workbench Full Report + Source Code
FunnelVertexDOT.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.web.funnel.graph;
20 
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Objects;
24 import java.util.Set;
25 import org.turro.elephant.entities.web.WebGoal;
26 import org.turro.elephant.entities.web.WebItem;
27 import org.turro.util.Comparison;
28 
33 public class FunnelVertexDOT implements Comparable<FunnelVertexDOT> {
34 
35  private final Object item;
36  private final String identifier;
37 
38  public FunnelVertexDOT(Object item) {
39  this.item = item;
40  this.identifier = getIdentifier();
41  }
42 
43  public String getIdentifier() {
44  if(item instanceof WebItem webItem) {
45  return webItem.getWebTag();
46  } else if(item instanceof WebGoal webGoal) {
47  return webGoal.getGoalAction();
48  } else {
49  return "#";
50  }
51  }
52 
53  public String getCaption() {
54  if(item instanceof WebItem webItem) {
55  return webItem.getCaption();
56  } else if(item instanceof WebGoal webGoal) {
57  return webGoal.getCaption();
58  } else {
59  return "#";
60  }
61  }
62 
63  public int getOrdering() {
64  if(item instanceof WebItem webItem) {
65  return webItem.getOrdering();
66  } else if(item instanceof WebGoal webGoal) {
67  return webGoal.getOrdering();
68  } else {
69  return 0;
70  }
71  }
72 
73  public String getColor() {
74  if(item instanceof WebItem webItem) {
75  return switch(webItem.getType()) {
76  case TARGET -> "#1EBC30";
77  case SOLUTION -> "#10A3A3";
78  case SERVICE -> "#2185D0";
79  case CHAIN -> "#767676";
80  };
81  } else if(item instanceof WebGoal webGoal) {
82  return "#F2711C";
83  } else {
84  return "#";
85  }
86  }
87 
88  public Set<Object> getNexts() {
89  if(item instanceof WebItem webItem) {
90  Set<Object> set = new HashSet<>();
91  set.addAll(webItem.getNexts());
92  set.addAll(webItem.getGoals());
93  return set;
94  } else {
95  return Collections.EMPTY_SET;
96  }
97  }
98 
99  /* Utils */
100 
101  @Override
102  public int hashCode() {
103  int hash = 5;
104  hash = 29 * hash + Objects.hashCode(this.identifier);
105  return hash;
106  }
107 
108  @Override
109  public boolean equals(Object obj) {
110  if (this == obj) {
111  return true;
112  }
113  if (obj == null) {
114  return false;
115  }
116  if (getClass() != obj.getClass()) {
117  return false;
118  }
119  final FunnelVertexDOT other = (FunnelVertexDOT) obj;
120  return Objects.equals(this.identifier, other.identifier);
121  }
122 
123  /* Comparable */
124 
125  @Override
126  public int compareTo(FunnelVertexDOT o) {
127  return Comparison.ascendant()
128  .compare(getOrdering(), o.getOrdering())
129  .compare(getIdentifier(), o.getIdentifier())
130  .get();
131  }
132 
133 }