BrightSide Workbench Full Report + Source Code
EntityVertex.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.entities.graph;
20 
21 import java.util.Objects;
22 import org.turro.html.Colors;
23 import org.turro.path.Path;
24 
29 public class EntityVertex {
30 
31  private final String entityPath, name;
32  private boolean source;
33 
34  public EntityVertex(String entityPath, String name) {
35  this.entityPath = entityPath;
36  this.name = name;
37  }
38 
39  public String getIdentifier() {
40  return entityPath;
41  }
42 
43  public String getName() {
44  return escape(name);
45  }
46 
47  public String getColor() {
48  return switch(Path.pathFrom(entityPath).getRoot()) {
49  case "contact" -> (source ? "#fbbd08" : "#a5673f");
50  case "dossier-category" -> "#e03997";
51  case "dossier" -> "#a333c8";
52  case "issue" -> "#6435c9";
53  case "publication" -> "#21ba45";
54  default -> "#777777";
55  };
56  }
57 
58  public String getFontColor() {
59  return Colors.of(getColor()).font().css();
60  }
61 
62  public boolean isSource() {
63  return source;
64  }
65 
66  public void setSource(boolean source) {
67  this.source = source;
68  }
69 
70  /* Utils */
71 
72  private String escape(String value) {
73  return value.replaceAll("\\{", "(")
74  .replaceAll("\\}", ")")
75  .replaceAll("[\\&\\#\\$\\:]", "_")
76  .replaceAll("[\"\']", "-");
77  }
78 
79  @Override
80  public int hashCode() {
81  int hash = 5;
82  hash = 29 * hash + Objects.hashCode(this.entityPath);
83  return hash;
84  }
85 
86  @Override
87  public boolean equals(Object obj) {
88  if (this == obj) {
89  return true;
90  }
91  if (obj == null) {
92  return false;
93  }
94  if (getClass() != obj.getClass()) {
95  return false;
96  }
97  final EntityVertex other = (EntityVertex) obj;
98  return Objects.equals(this.entityPath, other.entityPath);
99  }
100 
101 }
102 
EntityVertex(String entityPath, String name)