private CommandExecutionResult executeInternal(
      ActivityDiagram system, RegexResult arg, IEntity note) {

    note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)));

    IEntity activity = system.getLastEntityConsulted();
    if (activity == null) {
      activity = system.getStart();
    }

    final Link link;

    final Position position =
        Position.valueOf(arg.get("POSITION", 0).toUpperCase()).withRankdir(system.getRankdir());

    final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();

    if (position == Position.RIGHT) {
      link = new Link(activity, note, type, null, 1);
    } else if (position == Position.LEFT) {
      link = new Link(note, activity, type, null, 1);
    } else if (position == Position.BOTTOM) {
      link = new Link(activity, note, type, null, 2);
    } else if (position == Position.TOP) {
      link = new Link(note, activity, type, null, 2);
    } else {
      throw new IllegalArgumentException();
    }
    system.addLink(link);
    return CommandExecutionResult.ok();
  }
 static EntityType getTypeIfExisting(ActivityDiagram system, String code) {
   if (system.entityExist(code)) {
     final IEntity ent = system.entities().get(code);
     if (ent.getType() == EntityType.BRANCH) {
       return EntityType.BRANCH;
     }
   }
   return EntityType.ACTIVITY;
 }
  static IEntity getEntity(
      ActivityDiagram system, Map<String, RegexPartialMatch> arg, final boolean start) {
    final String suf = start ? "" : "2";

    final RegexPartialMatch openBracket = arg.get("OPENBRACKET" + suf);
    if (openBracket != null && openBracket.get(0) != null) {
      return system.createInnerActivity();
    }
    if (arg.get("STAR" + suf).get(0) != null) {
      if (start) {
        return system.getStart();
      }
      return system.getEnd();
    }
    final String code = arg.get("CODE" + suf).get(0);
    if (code != null) {
      return system.getOrCreate(code, code, getTypeIfExisting(system, code));
    }
    final String bar = arg.get("BAR" + suf).get(0);
    if (bar != null) {
      return system.getOrCreate(bar, bar, EntityType.SYNCHRO_BAR);
    }
    final RegexPartialMatch quoted = arg.get("QUOTED" + suf);
    if (quoted.get(0) != null) {
      final String quotedCode = quoted.get(1) == null ? quoted.get(0) : quoted.get(1);
      return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system, quotedCode));
    }
    final String first = arg.get("FIRST" + suf).get(0);
    if (first == null) {
      return system.getLastEntityConsulted();
    }
    throw new UnsupportedOperationException();
  }