1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 10:20:54 +00:00
plantuml/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java

580 lines
20 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2013-12-10 19:36:50 +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
*
2013-12-10 19:36:50 +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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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
* Contribution : Hisashi Miyashita
2013-12-10 19:36:50 +00:00
*
*
*/
package net.sourceforge.plantuml.classdiagram.command;
2022-12-17 11:10:05 +00:00
import net.sourceforge.plantuml.StringUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2017-03-12 17:22:02 +00:00
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.UrlBuilder;
2022-03-13 12:22:51 +00:00
import net.sourceforge.plantuml.UrlMode;
import net.sourceforge.plantuml.baraye.EntityImp;
import net.sourceforge.plantuml.baraye.Quark;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.command.regex.RegexOptional;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.LeafType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Link;
2022-08-24 16:46:33 +00:00
import net.sourceforge.plantuml.cucadiagram.LinkArg;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
2017-10-07 09:46:53 +00:00
import net.sourceforge.plantuml.descdiagram.command.CommandLinkElement;
2020-05-17 21:15:50 +00:00
import net.sourceforge.plantuml.descdiagram.command.Labels;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorParser;
import net.sourceforge.plantuml.graphic.color.ColorType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
2021-02-02 10:12:15 +00:00
import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.Direction;
import net.sourceforge.plantuml.utils.LineLocation;
2013-12-10 19:36:50 +00:00
final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrObjectDiagram> {
2021-05-23 15:35:13 +00:00
private static final String SINGLE = "[.\\\\]{0,2}[%pLN_]+(?:[.\\\\]{1,2}[%pLN_]+)*";
private static final String SINGLE_GUILLEMENT = "[%g][.\\\\]{0,2}[%pLN_]+(?:[.\\\\]{1,2}[%pLN_]+)*[%g]";
2020-10-12 20:56:58 +00:00
private static final String SINGLE2 = "(?:" + SINGLE + "|" + SINGLE_GUILLEMENT + ")";
private static final String COUPLE = "\\([%s]*(" + SINGLE2 + ")[%s]*,[%s]*(" + SINGLE2 + ")[%s]*\\)";
2016-12-14 21:01:03 +00:00
2013-12-10 19:36:50 +00:00
public CommandLinkClass(UmlDiagramType umlDiagramType) {
super(getRegexConcat(umlDiagramType));
}
static private RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) {
2019-06-26 19:24:49 +00:00
return RegexConcat.build(CommandLinkClass.class.getName() + umlDiagramType, RegexLeaf.start(), //
new RegexOptional( //
new RegexConcat( //
new RegexLeaf("HEADER", "@([\\d.]+)"), //
RegexLeaf.spaceOneOrMore() //
)), new RegexOr( //
2020-02-18 21:24:31 +00:00
new RegexLeaf("ENT1", getClassIdentifier()), //
new RegexLeaf("COUPLE1", COUPLE)), //
2022-08-23 16:39:27 +00:00
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2022-08-23 16:39:27 +00:00
new RegexOptional(new RegexConcat( //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("[\\[]"), //
new RegexLeaf("QUALIFIER1", "([^\\[\\]]+)"), //
new RegexLeaf("[\\]]"), //
RegexLeaf.spaceOneOrMore() //
)), //
2019-06-26 19:24:49 +00:00
new RegexOptional(new RegexLeaf("FIRST_LABEL", "[%g]([^%g]+)[%g]")), //
RegexLeaf.spaceZeroOrMore(), //
2013-12-10 19:36:50 +00:00
new RegexConcat(
2020-02-18 21:24:31 +00:00
//
new RegexLeaf("ARROW_HEAD1",
2022-10-05 20:32:57 +00:00
"((?<=[%s])+[ox]|[)#\\[<*+^}]|\\<_|\\<\\|[\\:\\|]|[<\\[]\\||\\}o|\\}\\||\\|o|\\|\\|)?"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_BODY1", "([-=.]+)"), //
2017-10-07 09:46:53 +00:00
new RegexLeaf("ARROW_STYLE1", "(?:\\[(" + CommandLinkElement.LINE_STYLE + ")\\])?"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_DIRECTION", "(left|right|up|down|le?|ri?|up?|do?)?"), //
2019-06-26 19:24:49 +00:00
new RegexOptional(new RegexLeaf("INSIDE", "(0|\\(0\\)|\\(0|0\\))(?=[-=.~])")), //
2017-10-07 09:46:53 +00:00
new RegexLeaf("ARROW_STYLE2", "(?:\\[(" + CommandLinkElement.LINE_STYLE + ")\\])?"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_BODY2", "([-=.]*)"), //
new RegexLeaf("ARROW_HEAD2",
2020-08-25 17:24:17 +00:00
"([ox][%s]+|:\\>\\>?|_\\>|[(#\\]>*+^\\{]|[\\|\\:]\\|\\>|\\|[>\\]]|o\\{|\\|\\{|o\\||\\|\\|)?")), //
2022-08-23 16:39:27 +00:00
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2022-08-23 16:39:27 +00:00
new RegexOptional(new RegexLeaf("SECOND_LABEL", "[%g]([^%g]+)[%g]")), //
new RegexOptional(new RegexConcat( //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("[\\[]"), //
new RegexLeaf("QUALIFIER2", "([^\\[\\]]+)"), //
new RegexLeaf("[\\]]"), //
RegexLeaf.spaceOneOrMore() //
)), //
RegexLeaf.spaceZeroOrMore(), //
2016-12-14 21:01:03 +00:00
new RegexOr( //
2017-03-12 17:22:02 +00:00
new RegexLeaf("ENT2", getClassIdentifier()), //
2016-12-14 21:01:03 +00:00
new RegexLeaf("COUPLE2", COUPLE)), //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2015-09-28 20:42:17 +00:00
color().getRegex(), //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2022-12-17 11:01:10 +00:00
UrlBuilder.OPTIONAL, //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
new RegexOptional( //
new RegexConcat( //
new RegexLeaf(":"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("LABEL_LINK", "(.+)") //
)), RegexLeaf.end());
2013-12-10 19:36:50 +00:00
}
2015-09-28 20:42:17 +00:00
private static ColorParser color() {
return ColorParser.simpleColor(ColorType.LINE);
}
2015-04-07 18:18:37 +00:00
private static String getClassIdentifier() {
2021-05-23 15:35:13 +00:00
return "(" + getSeparator() + "?[%pLN_$]+(?:" + getSeparator() + "[%pLN_$]+)*|[%g][^%g]+[%g])";
2015-04-07 18:18:37 +00:00
}
2016-02-07 21:13:01 +00:00
public static String getSeparator() {
return "(?:\\.|::|\\\\|\\\\\\\\)";
2015-04-07 18:18:37 +00:00
}
2013-12-10 19:36:50 +00:00
@Override
2019-06-26 19:24:49 +00:00
protected CommandExecutionResult executeArg(AbstractClassOrObjectDiagram diagram, LineLocation location,
2021-02-02 10:12:15 +00:00
RegexResult arg) throws NoSuchColorException {
2016-07-04 19:06:50 +00:00
String ent1String = diagram.cleanIdForQuark(arg.get("ENT1", 0));
String ent2String = diagram.cleanIdForQuark(arg.get("ENT2", 0));
2022-05-21 09:41:00 +00:00
if (ent1String == null && ent2String == null)
2017-09-03 16:59:24 +00:00
return executeArgSpecial3(diagram, arg);
2016-01-09 12:15:40 +00:00
2022-05-21 09:41:00 +00:00
if (ent1String == null)
2013-12-10 19:36:50 +00:00
return executeArgSpecial1(diagram, arg);
2022-05-21 09:41:00 +00:00
if (ent2String == null)
2013-12-10 19:36:50 +00:00
return executeArgSpecial2(diagram, arg);
2019-12-10 21:45:49 +00:00
// if (isGroupButNotTheCurrentGroup(diagram, ent1String) && isGroupButNotTheCurrentGroup(diagram, ent2String)) {
// return executePackageLink(diagram, arg);
// }
2013-12-10 19:36:50 +00:00
String port1 = null;
String port2 = null;
final LinkType linkType = getLinkType(arg);
if (ent1String.contains("::") && diagram.getPlasma().getIfExistsFromName(ent1String) == null) {
port1 = diagram.getPortId(ent1String);
ent1String = diagram.removePortId(ent1String);
2023-01-11 21:47:15 +00:00
}
if (ent2String.contains("::") && diagram.getPlasma().getIfExistsFromName(ent2String) == null) {
port2 = diagram.getPortId(ent2String);
ent2String = diagram.removePortId(ent2String);
2016-07-04 19:06:50 +00:00
}
final Quark quark1 = diagram.quarkInContext(ent1String, false);
final Quark quark2 = diagram.quarkInContext(ent2String, false);
EntityImp cl1 = (EntityImp) quark1.getData();
if (cl1 == null)
cl1 = diagram.reallyCreateLeaf(quark1, Display.getWithNewlines(quark1.getName()), LeafType.CLASS, null);
EntityImp cl2 = (EntityImp) quark2.getData();
if (cl2 == null)
cl2 = diagram.reallyCreateLeaf(quark2, Display.getWithNewlines(quark2.getName()), LeafType.CLASS, null);
2013-12-10 19:36:50 +00:00
final Direction dir = getDirection(arg);
final int queue;
2022-05-21 09:41:00 +00:00
if (dir == Direction.LEFT || dir == Direction.RIGHT)
2013-12-10 19:36:50 +00:00
queue = 1;
2022-05-21 09:41:00 +00:00
else
2013-12-10 19:36:50 +00:00
queue = getQueueLength(arg);
2020-05-17 21:15:50 +00:00
final Labels labels = new Labels(arg);
2013-12-10 19:36:50 +00:00
2022-08-24 16:46:33 +00:00
final String kal1 = arg.get("QUALIFIER1", 0);
2022-08-26 16:00:28 +00:00
final String kal2 = arg.get("QUALIFIER2", 0);
2022-08-24 16:46:33 +00:00
final LinkArg linkArg = LinkArg
.build(labels.getDisplay(), queue, diagram.getSkinParam().classAttributeIconSize() > 0)
2022-10-05 20:32:57 +00:00
.withQuantifier(labels.getFirstLabel(), labels.getSecondLabel())
2022-08-26 16:00:28 +00:00
.withDistanceAngle(diagram.getLabeldistance(), diagram.getLabelangle()).withKal(kal1, kal2);
2022-08-24 16:46:33 +00:00
Link link = new Link(diagram.getEntityFactory(), diagram.getSkinParam().getCurrentStyleBuilder(), cl1, cl2,
2022-11-04 17:36:03 +00:00
linkType, linkArg);
2017-03-12 17:22:02 +00:00
if (arg.get("URL", 0) != null) {
2022-03-13 12:22:51 +00:00
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
2017-03-12 17:22:02 +00:00
final Url url = urlBuilder.getUrl(arg.get("URL", 0));
link.setUrl(url);
}
2016-07-04 19:06:50 +00:00
link.setPortMembers(port1, port2);
2013-12-10 19:36:50 +00:00
2022-05-21 09:41:00 +00:00
if (dir == Direction.LEFT || dir == Direction.UP)
2013-12-10 19:36:50 +00:00
link = link.getInv();
2022-05-21 09:41:00 +00:00
2020-05-17 21:15:50 +00:00
link.setLinkArrow(labels.getLinkArrow());
2022-09-18 17:08:06 +00:00
link.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()));
link.applyStyle(arg.getLazzy("ARROW_STYLE", 0));
2020-08-25 17:24:17 +00:00
link.setCodeLine(location);
2013-12-10 19:36:50 +00:00
addLink(diagram, link, arg.get("HEADER", 0));
return CommandExecutionResult.ok();
}
// private boolean isGroupButNotTheCurrentGroup(AbstractClassOrObjectDiagram diagram, String code) {
// if (diagram.getCurrentGroup().getCodeGetName().equals(code))
// return false;
//
// return diagram.isGroup(code);
// }
2022-05-21 09:41:00 +00:00
2020-01-12 22:13:17 +00:00
2013-12-10 19:36:50 +00:00
private void addLink(AbstractClassOrObjectDiagram diagram, Link link, String weight) {
diagram.addLink(link);
if (weight == null) {
// final LinkType type = link.getType();
// --|> highest
// --*, -->, --o normal
// ..*, ..>, ..o lowest
// if (type.isDashed() == false) {
// if (type.contains(LinkDecor.EXTENDS)) {
// link.setWeight(3);
// }
// if (type.contains(LinkDecor.ARROW) ||
// type.contains(LinkDecor.COMPOSITION)
// || type.contains(LinkDecor.AGREGATION)) {
// link.setWeight(2);
// }
// }
} else {
link.setWeight(Double.parseDouble(weight));
}
}
2021-05-06 21:23:05 +00:00
private CommandExecutionResult executePackageLink(AbstractClassOrObjectDiagram diagram, RegexResult arg)
throws NoSuchColorException {
2020-01-12 22:13:17 +00:00
final String ent1String = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 0), "\"");
final String ent2String = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 0), "\"");
final EntityImp cl1 = diagram.getGroup(ent1String);
final EntityImp cl2 = diagram.getGroup(ent2String);
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Direction dir = getDirection(arg);
final int queue;
2022-05-21 09:41:00 +00:00
if (dir == Direction.LEFT || dir == Direction.RIGHT)
2013-12-10 19:36:50 +00:00
queue = 1;
2022-05-21 09:41:00 +00:00
else
2013-12-10 19:36:50 +00:00
queue = getQueueLength(arg);
final Display labelLink = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
final String firstLabel = arg.get("FIRST_LABEL", 0);
final String secondLabel = arg.get("SECOND_LABEL", 0);
2022-08-24 16:46:33 +00:00
final LinkArg linkArg = LinkArg.build(labelLink, queue, diagram.getSkinParam().classAttributeIconSize() > 0);
final Link link = new Link(diagram.getEntityFactory(), diagram.getSkinParam().getCurrentStyleBuilder(), cl1,
2022-11-04 17:36:03 +00:00
cl2, linkType, linkArg.withQuantifier(firstLabel, secondLabel)
.withDistanceAngle(diagram.getLabeldistance(), diagram.getLabelangle()));
2022-09-18 17:08:06 +00:00
link.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()));
2013-12-10 19:36:50 +00:00
diagram.resetPragmaLabel();
2015-09-28 20:42:17 +00:00
2022-09-18 17:08:06 +00:00
link.applyStyle(arg.getLazzy("ARROW_STYLE", 0));
2015-09-28 20:42:17 +00:00
2013-12-10 19:36:50 +00:00
addLink(diagram, link, arg.get("HEADER", 0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial1(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
2020-10-12 20:56:58 +00:00
final String name1A = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE1", 0));
final String name1B = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE1", 1));
2022-05-21 09:41:00 +00:00
Quark quark1A = diagram.quarkInContext(name1A, false);
Quark quark1B = diagram.quarkInContext(name1B, false);
if (quark1A.getData() != null == false)
return CommandExecutionResult.error("No class " + name1A);
if (quark1B.getData() != null == false)
return CommandExecutionResult.error("No class " + name1B);
EntityImp cl1A = (EntityImp) quark1A.getData();
EntityImp cl1B = (EntityImp) quark1B.getData();
final String id2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 0), "\"");
final Quark ent2 = diagram.quarkInContext(id2, false);
2013-12-10 19:36:50 +00:00
EntityImp cl2 = (EntityImp) ent2.getData();
if (cl2 == null)
cl2 = diagram.reallyCreateLeaf(ent2, Display.getWithNewlines(ent2.getName()), LeafType.CLASS, null);
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
final boolean result = diagram.associationClass(1, cl1A, cl1B, cl2, linkType, label);
2022-05-21 09:41:00 +00:00
if (result == false)
2013-12-10 19:36:50 +00:00
return CommandExecutionResult.error("Cannot have more than 2 assocications");
return CommandExecutionResult.ok();
}
2017-10-07 09:46:53 +00:00
private CommandExecutionResult executeArgSpecial2(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
final String name2A = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE2", 0));
final String name2B = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE2", 1));
2017-09-03 16:59:24 +00:00
final Quark quark2A = diagram.quarkInContext(name2A, false);
final Quark quark2B = diagram.quarkInContext(name2B, false);
2017-10-07 09:46:53 +00:00
if (quark2A.getData() != null == false)
return CommandExecutionResult.error("No class " + name2A);
2017-09-03 16:59:24 +00:00
if (quark2B.getData() != null == false)
return CommandExecutionResult.error("No class " + name2B);
final EntityImp cl2A = (EntityImp) quark2A.getData();
final EntityImp cl2B = (EntityImp) quark2B.getData();
2022-05-21 09:41:00 +00:00
final String id1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 0), "\"");
final Quark ent1 = diagram.quarkInContext(id1, false);
2013-12-10 19:36:50 +00:00
EntityImp cl1 = (EntityImp) ent1.getData();
if (cl1 == null)
cl1 = diagram.reallyCreateLeaf(ent1, Display.getWithNewlines(ent1.getName()), LeafType.CLASS, null);
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
final boolean result = diagram.associationClass(2, cl2A, cl2B, cl1, linkType, label);
2022-05-21 09:41:00 +00:00
if (result == false)
2013-12-10 19:36:50 +00:00
return CommandExecutionResult.error("Cannot have more than 2 assocications");
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial3(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
final String name1A = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE1", 0));
final String name1B = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE1", 1));
final String name2A = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE2", 0));
final String name2B = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("COUPLE2", 1));
final Quark quark1A = diagram.quarkInContext(name1A, false);
final Quark quark1B = diagram.quarkInContext(name1B, false);
final Quark quark2A = diagram.quarkInContext(name2A, false);
final Quark quark2B = diagram.quarkInContext(name2B, false);
if (quark1A.getData() != null == false)
return CommandExecutionResult.error("No class " + name1A);
if (quark1B.getData() != null == false)
return CommandExecutionResult.error("No class " + name1B);
if (quark2A.getData() != null == false)
return CommandExecutionResult.error("No class " + name2A);
if (quark2B.getData() != null == false)
return CommandExecutionResult.error("No class " + name2B);
final EntityImp cl1A = (EntityImp) quark1A.getData();
final EntityImp cl1B = (EntityImp) quark1B.getData();
final EntityImp cl2A = (EntityImp) quark2A.getData();
final EntityImp cl2B = (EntityImp) quark2B.getData();
final LinkType linkType = getLinkType(arg);
final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
return diagram.associationClass(cl1A, cl1B, cl2A, cl2B, linkType, label);
}
2013-12-10 19:36:50 +00:00
private LinkDecor getDecors1(String s) {
if (s == null)
2013-12-10 19:36:50 +00:00
return LinkDecor.NONE;
2015-05-31 18:56:03 +00:00
s = StringUtils.trin(s);
2022-05-21 09:41:00 +00:00
if ("<|".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.EXTENDS;
2022-05-21 09:41:00 +00:00
if ("<|:".equals(s))
return LinkDecor.DEFINEDBY;
2022-05-21 09:41:00 +00:00
if ("<||".equals(s))
return LinkDecor.REDEFINES;
2022-05-21 09:41:00 +00:00
if ("}".equals(s))
2016-12-01 20:29:25 +00:00
return LinkDecor.CROWFOOT;
2022-05-21 09:41:00 +00:00
if ("}o".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.CIRCLE_CROWFOOT;
2022-05-21 09:41:00 +00:00
if ("}|".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.LINE_CROWFOOT;
2022-05-21 09:41:00 +00:00
if ("|o".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.CIRCLE_LINE;
2022-05-21 09:41:00 +00:00
if ("||".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.DOUBLE_LINE;
2022-05-21 09:41:00 +00:00
if ("<".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.ARROW;
2022-05-21 09:41:00 +00:00
if ("^".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.EXTENDS;
2022-05-21 09:41:00 +00:00
if ("+".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.PLUS;
2022-05-21 09:41:00 +00:00
if ("o".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.AGREGATION;
2022-05-21 09:41:00 +00:00
if ("x".equals(s))
2016-09-29 19:51:18 +00:00
return LinkDecor.NOT_NAVIGABLE;
2022-05-21 09:41:00 +00:00
if ("*".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.COMPOSITION;
2022-05-21 09:41:00 +00:00
if ("#".equals(s))
2017-04-05 17:37:42 +00:00
return LinkDecor.SQUARE;
2022-05-21 09:41:00 +00:00
if (")".equals(s))
2017-03-21 21:37:59 +00:00
return LinkDecor.PARENTHESIS;
2022-05-21 09:41:00 +00:00
2013-12-10 19:36:50 +00:00
return LinkDecor.NONE;
}
private LinkDecor getDecors2(String s) {
2022-05-21 09:41:00 +00:00
if (s == null)
2013-12-10 19:36:50 +00:00
return LinkDecor.NONE;
2022-05-21 09:41:00 +00:00
2015-05-31 18:56:03 +00:00
s = StringUtils.trin(s);
2022-05-21 09:41:00 +00:00
if ("|>".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.EXTENDS;
2022-05-21 09:41:00 +00:00
if (":|>".equals(s))
return LinkDecor.DEFINEDBY;
2022-05-21 09:41:00 +00:00
if ("||>".equals(s))
return LinkDecor.REDEFINES;
2022-05-21 09:41:00 +00:00
if (">".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.ARROW;
2022-05-21 09:41:00 +00:00
if ("{".equals(s))
2016-12-01 20:29:25 +00:00
return LinkDecor.CROWFOOT;
2022-05-21 09:41:00 +00:00
if ("o{".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.CIRCLE_CROWFOOT;
2022-05-21 09:41:00 +00:00
if ("|{".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.LINE_CROWFOOT;
2022-05-21 09:41:00 +00:00
if ("o|".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.CIRCLE_LINE;
2022-05-21 09:41:00 +00:00
if ("||".equals(s))
2017-01-21 22:25:28 +00:00
return LinkDecor.DOUBLE_LINE;
2022-05-21 09:41:00 +00:00
if ("^".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.EXTENDS;
2022-05-21 09:41:00 +00:00
if ("+".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.PLUS;
2022-05-21 09:41:00 +00:00
if ("o".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.AGREGATION;
2022-05-21 09:41:00 +00:00
if ("x".equals(s))
2016-09-29 19:51:18 +00:00
return LinkDecor.NOT_NAVIGABLE;
2022-05-21 09:41:00 +00:00
if ("*".equals(s))
2013-12-10 19:36:50 +00:00
return LinkDecor.COMPOSITION;
2022-05-21 09:41:00 +00:00
if ("#".equals(s))
2017-04-05 17:37:42 +00:00
return LinkDecor.SQUARE;
2022-05-21 09:41:00 +00:00
if ("(".equals(s))
2017-03-21 21:37:59 +00:00
return LinkDecor.PARENTHESIS;
2022-05-21 09:41:00 +00:00
2013-12-10 19:36:50 +00:00
return LinkDecor.NONE;
}
private LinkType getLinkType(RegexResult arg) {
2020-08-25 17:24:17 +00:00
final LinkDecor decors1 = getDecors1(getArrowHead1(arg));
final LinkDecor decors2 = getDecors2(getArrowHead2(arg));
2013-12-10 19:36:50 +00:00
LinkType result = new LinkType(decors2, decors1);
2022-05-21 09:41:00 +00:00
if (arg.get("ARROW_BODY1", 0).contains(".") || arg.get("ARROW_BODY2", 0).contains("."))
2017-10-07 09:46:53 +00:00
result = result.goDashed();
2022-05-21 09:41:00 +00:00
2015-04-07 18:18:37 +00:00
final String middle = arg.get("INSIDE", 0);
2022-05-21 09:41:00 +00:00
if ("0".equals(middle))
2015-04-07 18:18:37 +00:00
result = result.withMiddleCircle();
2022-05-21 09:41:00 +00:00
else if ("0)".equals(middle))
2015-04-07 18:18:37 +00:00
result = result.withMiddleCircleCircled1();
2022-05-21 09:41:00 +00:00
else if ("(0".equals(middle))
2015-04-07 18:18:37 +00:00
result = result.withMiddleCircleCircled2();
2022-05-21 09:41:00 +00:00
else if ("(0)".equals(middle))
2015-04-07 18:18:37 +00:00
result = result.withMiddleCircleCircled();
2022-05-21 09:41:00 +00:00
2013-12-10 19:36:50 +00:00
return result;
}
private int getQueueLength(RegexResult arg) {
String s = getFullArrow(arg);
s = s.replaceAll("[^-.=]", "");
return s.length();
}
private Direction getDirection(RegexResult arg) {
2020-11-21 17:33:24 +00:00
// final LinkDecor decors1 = getDecors1(getArrowHead1(arg));
// final LinkDecor decors2 = getDecors2(getArrowHead2(arg));
2013-12-10 19:36:50 +00:00
String s = getFullArrow(arg);
s = s.replaceAll("[^-.=\\w]", "");
2022-05-21 09:41:00 +00:00
if (s.startsWith("o"))
2013-12-10 19:36:50 +00:00
s = s.substring(1);
2022-05-21 09:41:00 +00:00
if (s.endsWith("o"))
2013-12-10 19:36:50 +00:00
s = s.substring(0, s.length() - 1);
Direction result = StringUtils.getQueueDirection(s);
2020-11-21 17:33:24 +00:00
// if (isInversed(decors1, decors2) && s.matches(".*\\w.*")) {
// result = result.getInv();
// }
2013-12-10 19:36:50 +00:00
return result;
}
2020-08-25 17:24:17 +00:00
private String getArrowHead1(RegexResult arg) {
return getArrowHead(arg, "ARROW_HEAD1");
}
private String getArrowHead2(RegexResult arg) {
return getArrowHead(arg, "ARROW_HEAD2");
}
private String getArrowHead(RegexResult arg, final String key) {
return notNull(arg.get(key, 0));
}
2013-12-10 19:36:50 +00:00
private String getFullArrow(RegexResult arg) {
2020-08-25 17:24:17 +00:00
return getArrowHead1(arg) + notNull(arg.get("ARROW_BODY1", 0)) + notNull(arg.get("ARROW_DIRECTION", 0))
+ notNull(arg.get("ARROW_BODY2", 0)) + getArrowHead2(arg);
2013-12-10 19:36:50 +00:00
}
public static String notNull(String s) {
2022-05-21 09:41:00 +00:00
if (s == null)
2013-12-10 19:36:50 +00:00
return "";
return s;
}
}