private CommandExecutionResult executeArgSpecial2(
      AbstractClassOrObjectDiagram diagram, RegexResult arg) {
    final Code clName1 = Code.of(arg.get("COUPLE2", 0));
    final Code clName2 = Code.of(arg.get("COUPLE2", 1));
    if (diagram.leafExist(clName1) == false) {
      return CommandExecutionResult.error("No class " + clName1);
    }
    if (diagram.leafExist(clName2) == false) {
      return CommandExecutionResult.error("No class " + clName2);
    }

    final Code ent1 =
        Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1)));
    final IEntity cl1 = diagram.getOrCreateLeaf(ent1, null, null);

    final LinkType linkType = getLinkType(arg);
    final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
    // final int length = getQueueLength(arg);
    // final String weight = arg.get("HEADER").get(0);

    final boolean result = diagram.associationClass(2, clName1, clName2, cl1, linkType, label);
    if (result == false) {
      return CommandExecutionResult.error("Cannot have more than 2 assocications");
    }

    return CommandExecutionResult.ok();
  }
  private CommandExecutionResult executePackageLink(
      AbstractClassOrObjectDiagram diagram, RegexResult arg) {
    final IEntity cl1 =
        diagram.getGroup(
            Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1))));
    final IEntity cl2 =
        diagram.getGroup(
            Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1))));

    final LinkType linkType = getLinkType(arg);
    final Direction dir = getDirection(arg);
    final int queue;
    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = 1;
    } else {
      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);
    final Link link =
        new Link(
            cl1,
            cl2,
            linkType,
            labelLink,
            queue,
            firstLabel,
            secondLabel,
            diagram.getLabeldistance(),
            diagram.getLabelangle());

    diagram.resetPragmaLabel();
    addLink(diagram, link, arg.get("HEADER", 0));
    return CommandExecutionResult.ok();
  }
 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));
   }
 }
 public CommandLinkLollipop(AbstractClassOrObjectDiagram diagram) {
   super(diagram, getRegexConcat(diagram.getUmlDiagramType()));
 }
  @Override
  protected CommandExecutionResult executeArg(
      AbstractClassOrObjectDiagram diagram, RegexResult arg) {
    Code ent1 = Code.of(arg.get("ENT1", 1));
    Code ent2 = Code.of(arg.get("ENT2", 1));
    if (ent1 == null) {
      return executeArgSpecial1(diagram, arg);
    }
    if (ent2 == null) {
      return executeArgSpecial2(diagram, arg);
    }
    ent1 = ent1.eventuallyRemoveStartingAndEndingDoubleQuote();
    ent2 = ent2.eventuallyRemoveStartingAndEndingDoubleQuote();
    if (diagram.isGroup(ent1) && diagram.isGroup(ent2)) {
      return executePackageLink(diagram, arg);
    }

    final IEntity cl1 =
        diagram.isGroup(ent1)
            ? diagram.getGroup(
                Code.of(
                    StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1))))
            : diagram.getOrCreateLeaf(ent1, null, null);
    final IEntity cl2 =
        diagram.isGroup(ent2)
            ? diagram.getGroup(
                Code.of(
                    StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1))))
            : diagram.getOrCreateLeaf(ent2, null, null);

    if (arg.get("ENT1", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0));
      if (type != LeafType.OBJECT) {
        ((ILeaf) cl1).muteToType(type, null);
      }
    }
    if (arg.get("ENT2", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0));
      if (type != LeafType.OBJECT) {
        ((ILeaf) cl2).muteToType(type, null);
      }
    }
    if (arg.get("ENT1", 2) != null) {
      cl1.setStereotype(
          new Stereotype(
              arg.get("ENT1", 2),
              diagram.getSkinParam().getCircledCharacterRadius(),
              diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }
    if (arg.get("ENT2", 2) != null) {
      cl2.setStereotype(
          new Stereotype(
              arg.get("ENT2", 2),
              diagram.getSkinParam().getCircledCharacterRadius(),
              diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }

    final LinkType linkType = getLinkType(arg);
    final Direction dir = getDirection(arg);
    final int queue;
    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = 1;
    } else {
      queue = getQueueLength(arg);
    }

    String firstLabel = arg.get("FIRST_LABEL", 0);
    String secondLabel = arg.get("SECOND_LABEL", 0);

    String labelLink = null;

    if (arg.get("LABEL_LINK", 0) != null) {
      labelLink = arg.get("LABEL_LINK", 0);
      if (firstLabel == null && secondLabel == null) {
        final Pattern p1 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)[%g]([^%g]+)[%g]$");
        final Matcher m1 = p1.matcher(labelLink);
        if (m1.matches()) {
          firstLabel = m1.group(1);
          labelLink =
              StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim();
          secondLabel = m1.group(3);
        } else {
          final Pattern p2 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)$");
          final Matcher m2 = p2.matcher(labelLink);
          if (m2.matches()) {
            firstLabel = m2.group(1);
            labelLink =
                StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim();
            secondLabel = null;
          } else {
            final Pattern p3 = MyPattern.cmpile("^([^%g]+)[%g]([^%g]+)[%g]$");
            final Matcher m3 = p3.matcher(labelLink);
            if (m3.matches()) {
              firstLabel = null;
              labelLink =
                  StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim())
                      .trim();
              secondLabel = m3.group(2);
            }
          }
        }
      }
      labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink);
    }

    LinkArrow linkArrow = LinkArrow.NONE;
    if ("<".equals(labelLink)) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = null;
    } else if (">".equals(labelLink)) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = null;
    } else if (labelLink != null && labelLink.startsWith("< ")) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.startsWith("> ")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.endsWith(" >")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    } else if (labelLink != null && labelLink.endsWith(" <")) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    }

    Link link =
        new Link(
            cl1,
            cl2,
            linkType,
            Display.getWithNewlines(labelLink),
            queue,
            firstLabel,
            secondLabel,
            diagram.getLabeldistance(),
            diagram.getLabelangle());

    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }
    link.setLinkArrow(linkArrow);
    applyStyle(arg.getLazzy("ARROW_STYLE", 0), link);

    addLink(diagram, link, arg.get("HEADER", 0));

    return CommandExecutionResult.ok();
  }