/**
   * Outputs filled with points listOfPointsToBeConnected. Finds the point with the lowest Y - that
   * will be the first point of the broken line. If It finds several points with equal Ys - makes a
   * line from the most left (lowest X) point to the most right point, then connects this point with
   * next point with the lowest Y from the remaining set. The last point of the broken line will be
   * the point with the highest Y, or if there will be several points with the highest Y - the point
   * with the highest X from this set.
   */
  void connectPoints() {

    ArrayList<MyPoint> pointsInOneRow =
        new ArrayList<MyPoint>(); // will store points with equal Ys.
    MyPoint currentPoint, nextPoint;
    ListIterator<MyPoint> itr;

    while (randomListOfPoints.size() > 0) {

      pointsInOneRow.clear(); // clear the pointsInOneRow.
      itr = randomListOfPoints.listIterator();
      // initialize list iterator and place it before the first element in the randomListOfPoints.
      currentPoint = itr.next(); // the first element from the randomListOfPoints.
      itr.remove(); // delete the first element from the randomListOfPoints.
      if (itr.hasNext()) { // if it's not the end of the randomListOfPoints.

        nextPoint = itr.next(); // the second element from the randomListOfPoints.

      } else {

        // the point not from the range of possible Xs and Ys, so we can be sure that its' Y won't
        // be equal to the currentPoints'.
        nextPoint = new MyPoint(-1, -1);
      }
      pointsInOneRow.add(
          currentPoint); // add current point to a list of points, that lies on one line.
      // if the currentPoint and the nextPoint are on the same line, that is parallel to the X axis.
      while (currentPoint.getY() == nextPoint.getY()) {

        pointsInOneRow.add(
            nextPoint); // add the nextPoint to a list of points, that lies on one line.
        itr.remove(); // delete the second element from the randomListOfPoints .
        currentPoint = nextPoint; // the currentPoint equals to the nextPoint now.
        if (itr.hasNext()) { // if it's not the end of the randomListOfPoints.

          nextPoint = itr.next(); // the second element from the randomListOfPoints.

        } else {

          // the point not from the range of possible Xs and Ys, so we can be sure that its' Y won't
          // be equal to the currentPoints'.
          nextPoint = new MyPoint(-1, -1);
        }
      }

      Collections.sort(
          pointsInOneRow, new XcoordSorterComparator()); // sort the pointsInOneRow by X
      /* add all elements from the pointsInOneRow to the end of the listOfPointsToBeConnected.
       * If the listOfPointsToBeConnected.size == 0 - the first element from the pointsInOneRow will be the start
       * of the broken line, if the listOfPointsToBeConnected.size != 0 - the first element from the
       * pointsInOneRow will be connected with the last element from the listOfPointsToBeConnected*/
      listOfPointsToBeConnected.addAll(listOfPointsToBeConnected.size(), pointsInOneRow);
    }

    System.out.println("\n\nList of connected points:\n" + listOfPointsToBeConnected);
  }
Beispiel #2
0
  private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {

    List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
    if (context.isCreatingNewProject()) {
      builders.add(new EmptyModuleBuilder());
    }
    Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>();
    for (ModuleBuilder builder : builders) {
      BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
      if (builder.isTemplate()) {
        TemplatesGroup group = groupMap.get(builder.getGroupName());
        if (group == null) {
          group = new TemplatesGroup(builder);
        }
        myTemplatesMap.putValue(group, template);
      } else {
        TemplatesGroup group = new TemplatesGroup(builder);
        groupMap.put(group.getName(), group);
        myTemplatesMap.put(group, new ArrayList<ProjectTemplate>());
      }
    }

    MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.getTemplatesMap(context);
    myTemplatesMap.putAllValues(map);

    for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) {
      TemplatesGroup group = new TemplatesGroup(category);
      myTemplatesMap.remove(group);
      myTemplatesMap.put(group, new ArrayList<ProjectTemplate>());
    }

    if (context.isCreatingNewProject()) {
      MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates();
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        myTemplatesMap.putValues(group, localTemplates.get(group.getId()));
      }
    }

    // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593)
    if (PlatformUtils.isIdeaCommunity()) {
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        if (WebModuleTypeBase.WEB_MODULE.equals(group.getId())
            && myTemplatesMap.get(group).isEmpty()) {
          myTemplatesMap.remove(group);
          break;
        }
      }
    }

    List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet());

    // sorting by module type popularity
    final MultiMap<ModuleType, TemplatesGroup> moduleTypes =
        new MultiMap<ModuleType, TemplatesGroup>();
    for (TemplatesGroup group : groups) {
      ModuleType type = getModuleType(group);
      moduleTypes.putValue(type, group);
    }
    Collections.sort(
        groups,
        new Comparator<TemplatesGroup>() {
          @Override
          public int compare(TemplatesGroup o1, TemplatesGroup o2) {
            int i = o2.getWeight() - o1.getWeight();
            if (i != 0) return i;
            int i1 =
                moduleTypes.get(getModuleType(o2)).size()
                    - moduleTypes.get(getModuleType(o1)).size();
            if (i1 != 0) return i1;
            return o1.compareTo(o2);
          }
        });

    Set<String> groupNames =
        ContainerUtil.map2Set(
            groups,
            new Function<TemplatesGroup, String>() {
              @Override
              public String fun(TemplatesGroup group) {
                return group.getParentGroup();
              }
            });

    // move subgroups
    MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>();
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
      TemplatesGroup group = iterator.next();
      String parentGroup = group.getParentGroup();
      if (parentGroup != null
          && groupNames.contains(parentGroup)
          && !group.getName().equals(parentGroup)
          && groupMap.containsKey(parentGroup)) {
        subGroups.putValue(parentGroup, group);
        iterator.remove();
      }
    }
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
      TemplatesGroup group = iterator.next();
      for (TemplatesGroup subGroup : subGroups.get(group.getName())) {
        iterator.add(subGroup);
      }
    }
    return groups;
  }