1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-10 20:22:26 +00:00
plantuml/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java

227 lines
6.6 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2010-11-15 20:35:36 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
2015-04-07 18:18:37 +00:00
import java.util.ArrayList;
2010-11-15 20:35:36 +00:00
import java.util.Collection;
2015-04-07 18:18:37 +00:00
import java.util.HashMap;
import java.util.HashSet;
2010-11-15 20:35:36 +00:00
import java.util.List;
2015-04-07 18:18:37 +00:00
import java.util.Map;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ISkinParam;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.Pragma;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2023-02-06 21:04:53 +00:00
import net.sourceforge.plantuml.baraye.Entity;
2023-02-08 18:38:46 +00:00
import net.sourceforge.plantuml.baraye.EntityFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
import net.sourceforge.plantuml.cucadiagram.GroupHierarchy;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.DotMode;
2010-11-15 20:35:36 +00:00
final public class DotData implements PortionShower {
final private List<Link> links;
2023-02-06 21:04:53 +00:00
final private Collection<Entity> leafs;
2010-11-15 20:35:36 +00:00
final private UmlDiagramType umlDiagramType;
final private ISkinParam skinParam;
2015-04-07 18:18:37 +00:00
// final private Rankdir rankdir;
2010-11-15 20:35:36 +00:00
final private GroupHierarchy groupHierarchy;
2023-02-06 21:04:53 +00:00
final private Entity topParent;
2010-11-15 20:35:36 +00:00
final private PortionShower portionShower;
2013-12-10 19:36:50 +00:00
final private boolean isHideEmptyDescriptionForState;
final private DotMode dotMode;
2015-04-07 18:18:37 +00:00
final private String namespaceSeparator;
final private Pragma pragma;
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
private final EntityFactory entityFactory;
2010-11-15 20:35:36 +00:00
2020-02-18 21:24:31 +00:00
public EntityFactory getEntityFactory() {
return entityFactory;
}
2023-02-06 21:04:53 +00:00
public DotData(Entity topParent, List<Link> links, Collection<Entity> leafs, UmlDiagramType umlDiagramType,
2022-09-20 20:35:41 +00:00
ISkinParam skinParam, GroupHierarchy groupHierarchy, PortionShower portionShower,
2015-04-07 18:18:37 +00:00
EntityFactory entityFactory, boolean isHideEmptyDescriptionForState, DotMode dotMode,
2022-08-26 16:00:28 +00:00
String namespaceSeparator, Pragma pragma) {
2015-04-07 18:18:37 +00:00
this.namespaceSeparator = namespaceSeparator;
this.pragma = pragma;
2021-05-09 21:14:40 +00:00
this.topParent = Objects.requireNonNull(topParent);
2013-12-10 19:36:50 +00:00
this.dotMode = dotMode;
this.isHideEmptyDescriptionForState = isHideEmptyDescriptionForState;
2010-11-15 20:35:36 +00:00
this.links = links;
2013-12-10 19:36:50 +00:00
this.leafs = leafs;
2010-11-15 20:35:36 +00:00
this.umlDiagramType = umlDiagramType;
this.skinParam = skinParam;
2015-04-07 18:18:37 +00:00
// this.rankdir = rankdir;
2010-11-15 20:35:36 +00:00
this.groupHierarchy = groupHierarchy;
this.portionShower = portionShower;
2013-12-10 19:36:50 +00:00
this.entityFactory = entityFactory;
2010-11-15 20:35:36 +00:00
}
2023-02-06 21:04:53 +00:00
public DotData(Entity topParent, List<Link> links, Collection<Entity> leafs, UmlDiagramType umlDiagramType,
2022-09-20 20:35:41 +00:00
ISkinParam skinParam, GroupHierarchy groupHierarchy, EntityFactory entityFactory,
2022-08-26 16:00:28 +00:00
boolean isHideEmptyDescriptionForState, DotMode dotMode, String namespaceSeparator, Pragma pragma) {
2015-04-07 18:18:37 +00:00
this(topParent, links, leafs, umlDiagramType, skinParam, groupHierarchy, new PortionShower() {
2023-02-06 21:04:53 +00:00
public boolean showPortion(EntityPortion portion, Entity entity) {
2010-11-15 20:35:36 +00:00
return true;
}
2022-09-20 20:35:41 +00:00
}, entityFactory, isHideEmptyDescriptionForState, dotMode, namespaceSeparator, pragma);
2010-11-15 20:35:36 +00:00
}
public UmlDiagramType getUmlDiagramType() {
return umlDiagramType;
}
public ISkinParam getSkinParam() {
return skinParam;
}
public GroupHierarchy getGroupHierarchy() {
return groupHierarchy;
}
public List<Link> getLinks() {
return links;
}
2023-02-06 21:04:53 +00:00
public Collection<Entity> getLeafs() {
2013-12-10 19:36:50 +00:00
return leafs;
2010-11-15 20:35:36 +00:00
}
2023-02-06 21:04:53 +00:00
public final Entity getTopParent() {
2010-11-15 20:35:36 +00:00
return topParent;
}
2023-02-06 21:04:53 +00:00
public boolean isEmpty(Entity g) {
2010-11-15 20:35:36 +00:00
return groupHierarchy.isEmpty(g);
}
2023-02-06 21:04:53 +00:00
public boolean showPortion(EntityPortion portion, Entity entity) {
2010-11-15 20:35:36 +00:00
return portionShower.showPortion(portion, entity);
}
2023-02-06 21:04:53 +00:00
public Entity getRootGroup() {
2013-12-10 19:36:50 +00:00
return entityFactory.getRootGroup();
2011-01-05 18:23:06 +00:00
}
2011-08-08 17:48:29 +00:00
2019-09-22 17:20:16 +00:00
public boolean isDegeneratedWithFewEntities(int nb) {
2019-12-10 21:45:49 +00:00
return entityFactory.groups().size() == 0 && getLinks().size() == 0 && getLeafs().size() == nb;
2019-09-22 17:20:16 +00:00
}
2013-12-10 19:36:50 +00:00
public final boolean isHideEmptyDescriptionForState() {
return isHideEmptyDescriptionForState;
2011-03-26 12:37:27 +00:00
}
2013-12-10 19:36:50 +00:00
public final DotMode getDotMode() {
return dotMode;
2011-08-08 17:48:29 +00:00
}
2011-01-05 18:23:06 +00:00
2015-04-07 18:18:37 +00:00
public final String getNamespaceSeparator() {
return namespaceSeparator;
}
public Pragma getPragma() {
return pragma;
}
public void removeIrrelevantSametail() {
final Map<String, Integer> sametails = new HashMap<String, Integer>();
for (Link link : links) {
if (link.getType().getDecor2().isExtendsLike()) {
2015-04-07 18:18:37 +00:00
link.setSametail(link.getEntity1().getUid());
}
final String sametail = link.getSametail();
if (sametail == null) {
continue;
}
final Integer value = sametails.get(sametail);
sametails.put(sametail, value == null ? 1 : value + 1);
}
2021-05-14 08:42:57 +00:00
final Collection<String> toremove = new HashSet<>();
2015-04-07 18:18:37 +00:00
final int limit = skinParam.groupInheritance();
for (Map.Entry<String, Integer> ent : sametails.entrySet()) {
final String key = ent.getKey();
if (ent.getValue() < limit) {
toremove.add(key);
} else {
2021-05-14 08:42:57 +00:00
final List<Link> some = new ArrayList<>();
2015-04-07 18:18:37 +00:00
for (Link link : links) {
if (key.equals(link.getSametail())) {
some.add(link);
}
}
2023-02-06 21:04:53 +00:00
final Entity leaf = getLeaf(key);
2015-04-07 18:18:37 +00:00
final Neighborhood neighborhood = new Neighborhood(leaf, some, getLinksOfThisLeaf(leaf));
leaf.setNeighborhood(neighborhood);
}
}
for (Link link : links) {
final String sametail = link.getSametail();
if (sametail == null) {
continue;
}
if (toremove.contains(sametail)) {
link.setSametail(null);
}
}
}
2023-02-06 21:04:53 +00:00
private List<Link> getLinksOfThisLeaf(Entity leaf) {
2021-05-14 08:42:57 +00:00
final List<Link> result = new ArrayList<>();
2015-04-07 18:18:37 +00:00
for (Link link : links) {
if (link.contains(leaf)) {
result.add(link);
}
}
return result;
}
2023-02-06 21:04:53 +00:00
private Entity getLeaf(String key) {
for (Entity entity : leafs) {
2015-04-07 18:18:37 +00:00
if (entity.getUid().equals(key)) {
return entity;
}
}
return null;
}
2010-11-15 20:35:36 +00:00
}