net.sourceforge.plantuml.abel.EntityFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
/* +=======================================================================
* |
* | PlantUML : a free UML diagram generator
* |
* +=======================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/liberapay (only 1€ per month!)
* https://plantuml.com/paypal
*
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the MIT License.
*
* See http://opensource.org/licenses/MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* PlantUML can occasionally display sponsored or advertising messages. Those
* messages are usually generated on welcome or error images and never on
* functional diagrams.
* See https://plantuml.com/professional if you want to remove them
*
* Images (whatever their format : PNG, SVG, EPS...) generated by running PlantUML
* are owned by the author of their corresponding sources code (that is, their
* textual description in PlantUML language). Those images are not covered by
* this MIT license.
*
* The generated images can then be used without any reference to the MIT license.
* It is not even necessary to stipulate that they have been generated with PlantUML,
* although this will be appreciated by the PlantUML team.
*
* There is an exception : if the textual description in PlantUML language is also covered
* by any license, then the generated images are logically covered
* by the very same license.
*
* This is the IGY distribution (Install GraphViz by Yourself).
* You have to install GraphViz and to setup the GRAPHVIZ_DOT environment variable
* (see https://plantuml.com/graphviz-dot )
*
* Icons provided by OpenIconic : https://useiconic.com/open
* Archimate sprites provided by Archi : http://www.archimatetool.com
* Stdlib AWS provided by https://github.com/milo-minderbinder/AWS-PlantUML
* Stdlib Icons provided https://github.com/tupadr3/plantuml-icon-font-sprites
* ASCIIMathML (c) Peter Jipsen http://www.chapman.edu/~jipsen
* ASCIIMathML (c) David Lippman http://www.pierce.ctc.edu/dlippman
* CafeUndZopfli ported by Eugene Klyuchnikov https://github.com/eustas/CafeUndZopfli
* Brotli (c) by the Brotli Authors https://github.com/google/brotli
* Themes (c) by Brett Schwarz https://github.com/bschwarz/puml-themes
* Twemoji (c) by Twitter at https://twemoji.twitter.com/
*
*/
package net.sourceforge.plantuml.abel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import net.sourceforge.plantuml.cucadiagram.Bodier;
import net.sourceforge.plantuml.cucadiagram.BodierJSon;
import net.sourceforge.plantuml.cucadiagram.BodierMap;
import net.sourceforge.plantuml.cucadiagram.BodyFactory;
import net.sourceforge.plantuml.cucadiagram.HideOrShow;
import net.sourceforge.plantuml.cucadiagram.ICucaDiagram;
import net.sourceforge.plantuml.plasma.Plasma;
import net.sourceforge.plantuml.plasma.Quark;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.stereo.Stereotype;
public final class EntityFactory implements IEntityFactory {
private final List links = new ArrayList<>();
private int rawLayout;
private final Plasma namespace;
private final Quark root;
private final Entity rootGroup;
private final List hides2;
private final List removed;
final private ICucaDiagram diagram;
//
public EntityFactory(List hides2, List removed, ICucaDiagram diagram) {
this.hides2 = hides2;
this.removed = removed;
this.diagram = diagram;
this.namespace = new Plasma();
this.root = namespace.root();
this.rootGroup = new Entity(this.root, this, null, GroupType.ROOT, 0);
}
public boolean isHidden(Entity leaf) {
final Entity other = isNoteWithSingleLinkAttachedTo(leaf);
if (other != null && other != leaf)
return isHidden(other);
boolean hidden = false;
for (HideOrShow hide : hides2)
hidden = hide.apply(hidden, leaf);
return hidden;
}
public boolean isRemoved(Stereotype stereotype) {
boolean result = false;
for (HideOrShow hide : removed)
result = hide.apply(result, stereotype);
return result;
}
public boolean isRemoved(Entity leaf) {
final Entity other = isNoteWithSingleLinkAttachedTo(leaf);
if (other instanceof Entity)
return isRemoved((Entity) other);
boolean result = false;
for (HideOrShow hide : removed)
result = hide.apply(result, leaf);
return result;
}
private Entity isNoteWithSingleLinkAttachedTo(Entity note) {
if (note.getLeafType() != LeafType.NOTE)
return null;
assert note.getLeafType() == LeafType.NOTE;
Entity other = null;
for (Link link : this.getLinks()) {
if (link.getType().isInvisible())
continue;
if (link.contains(note) == false)
continue;
if (other != null)
return null;
other = link.getOther(note);
if (other.getLeafType() == LeafType.NOTE)
return null;
}
return other;
}
public boolean isRemovedIgnoreUnlinked(Entity leaf) {
boolean result = false;
for (HideOrShow hide : removed)
if (hide.isAboutUnlinked() == false)
result = hide.apply(result, leaf);
return result;
}
final public Entity createLeaf(Quark quark, LeafType entityType, Set hides) {
final Bodier bodier;
if (Objects.requireNonNull(entityType) == LeafType.MAP)
bodier = new BodierMap();
else if (Objects.requireNonNull(entityType) == LeafType.JSON)
bodier = new BodierJSon();
else
bodier = BodyFactory.createLeaf(entityType, hides);
final Entity result = new Entity(quark, this, bodier, entityType, rawLayout);
bodier.setLeaf(result);
return result;
}
public Entity createGroup(Quark quark, GroupType groupType, Set hides) {
Objects.requireNonNull(groupType);
if (quark.getData() != null)
return quark.getData();
final Bodier bodier = BodyFactory.createGroup(hides);
final Entity result = new Entity(quark, this, bodier, groupType, rawLayout);
return result;
}
public Entity getRootGroup() {
return rootGroup;
}
public final Collection leafs() {
final List result = new ArrayList<>();
for (Quark quark : quarks()) {
if (quark.isRoot())
continue;
final Entity data = quark.getData();
if (data != null && data.isGroup() == false)
result.add(data);
}
return Collections.unmodifiableCollection(result);
}
public final Collection groups() {
final List result = new ArrayList<>();
for (Quark quark : quarks()) {
if (quark.isRoot())
continue;
final Entity data = quark.getData();
if (data != null && data.isGroup())
result.add(data);
}
return Collections.unmodifiableCollection(result);
}
public final Collection groupsAndRoot() {
final List result = new ArrayList<>();
for (Quark quark : quarks()) {
final Entity data = quark.getData();
if (data != null && data.isGroup())
result.add(data);
}
return Collections.unmodifiableCollection(result);
}
public void incRawLayout() {
rawLayout++;
}
public final List getLinks() {
return Collections.unmodifiableList(links);
}
public void addLink(Link link) {
if (link.isSingle() && containsSimilarLink(link))
return;
links.add(link);
}
private boolean containsSimilarLink(Link other) {
for (Link link : links)
if (other.sameConnections(link))
return true;
return false;
}
public void removeLink(Link link) {
final boolean ok = links.remove(link);
if (ok == false)
throw new IllegalArgumentException();
}
public ICucaDiagram getDiagram() {
return diagram;
}
// ----------
public Collection> quarks() {
final List> result = new ArrayList<>();
for (Quark quark : namespace.quarks())
result.add(quark);
return result;
}
public Quark root() {
return root;
}
public void setSeparator(String namespaceSeparator) {
namespace.setSeparator(namespaceSeparator);
// printspace.setSeparator(namespaceSeparator);
}
public Quark firstWithName(String full) {
final Quark tmp = namespace.firstWithName(full);
return tmp;
}
public int countByName(String full) {
return namespace.countByName(full);
}
}