@NotNull
  public static List<SymfonyInstallerVersion> getVersions(@NotNull String jsonContent) {

    JsonObject jsonObject = new JsonParser().parse(jsonContent).getAsJsonObject();

    List<SymfonyInstallerVersion> symfonyInstallerVersions = new ArrayList<>();

    // prevent adding duplicate version on alias names
    Set<String> aliasBranches = new HashSet<>();

    // get alias version, in most common order
    for (String s : new String[] {"latest", "lts"}) {
      JsonElement asJsonObject = jsonObject.get(s);
      if (asJsonObject == null) {
        continue;
      }

      String asString = asJsonObject.getAsString();
      aliasBranches.add(asString);

      symfonyInstallerVersions.add(
          new SymfonyInstallerVersion(s, String.format("%s (%s)", asString, s)));
    }

    List<SymfonyInstallerVersion> branches = new ArrayList<>();
    Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();
    for (Map.Entry<String, JsonElement> entry : entries) {
      if (!entry.getKey().matches("^\\d+\\.\\d+$")) {
        continue;
      }

      // "2.8.0-dev", "2.8.0-DEV" is not supported
      String asString = entry.getValue().getAsString();
      if (asString.matches(".*[a-zA-Z].*") || aliasBranches.contains(asString)) {
        continue;
      }

      branches.add(
          new SymfonyInstallerVersion(
              asString, String.format("%s (%s)", entry.getKey(), asString)));
    }

    branches.sort(Comparator.comparing(SymfonyInstallerVersion::getVersion));

    Collections.reverse(branches);

    symfonyInstallerVersions.addAll(branches);

    // we need reverse order for sorting them on version string
    List<SymfonyInstallerVersion> installableVersions = new ArrayList<>();
    for (JsonElement installable : jsonObject.getAsJsonArray("installable")) {
      installableVersions.add(new SymfonyInstallerVersion(installable.getAsString()));
    }
    Collections.reverse(installableVersions);

    symfonyInstallerVersions.addAll(installableVersions);
    return symfonyInstallerVersions;
  }
예제 #2
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 public static TreePath getPathFromRoot(TreeNode node) {
   final ArrayList<TreeNode> path = new ArrayList<TreeNode>();
   do {
     path.add(node);
     node = node.getParent();
   } while (node != null);
   Collections.reverse(path);
   return new TreePath(path.toArray());
 }
  @Nullable
  @SuppressWarnings({"HardCodedStringLiteral"})
  private JPanel readExternalPanel(
      final Element element, @Nullable JPanel panel, Ref<EditorWindow> currentWindow) {
    final Element splitterElement = element.getChild("splitter");
    if (splitterElement != null) {
      return readSplitter(panel, splitterElement, currentWindow);
    }

    final Element leaf = element.getChild("leaf");
    if (leaf == null) {
      return null;
    }

    EditorWindow window = (panel == null) ? new EditorWindow(this) : findWindowWith(panel);
    LOG.assertTrue(window != null);

    @SuppressWarnings("unchecked")
    final List<Element> children = ContainerUtil.newArrayList(leaf.getChildren("file"));
    if (UISettings.getInstance().ACTIVATE_RIGHT_EDITOR_ON_CLOSE) {
      Collections.reverse(children);
    }

    VirtualFile currentFile = null;
    for (final Element file : children) {
      try {
        final HistoryEntry entry =
            new HistoryEntry(getManager().getProject(), file.getChild(HistoryEntry.TAG), true);
        boolean isCurrent = Boolean.valueOf(file.getAttributeValue("current")).booleanValue();
        getManager().openFileImpl3(window, entry.myFile, false, entry, isCurrent);
        if (getManager().isFileOpen(entry.myFile)) {
          window.setFilePinned(
              entry.myFile, Boolean.valueOf(file.getAttributeValue("pinned")).booleanValue());
          if (Boolean.valueOf(file.getAttributeValue("current-in-tab")).booleanValue()) {
            currentFile = entry.myFile;
          }
        }
      } catch (InvalidDataException e) {
        // OK
      }
    }
    if (currentFile != null) {
      final EditorComposite editor = window.findFileComposite(currentFile);
      if (editor != null) {
        window.setSelectedEditor(editor, true);
      }
    }
    return window.myPanel;
  }
  private static CompositePackagingElement<?> getOrCreateModifiableParent(
      CompositePackagingElement<?> parentElement, PackagingElementNode<?> node) {
    PackagingElementNode<?> current = node;
    List<String> dirNames = new ArrayList<String>();
    while (current != null && !(current instanceof ArtifactRootNode)) {
      final PackagingElement<?> packagingElement = current.getFirstElement();
      if (!(packagingElement instanceof DirectoryPackagingElement)) {
        return parentElement;
      }
      dirNames.add(((DirectoryPackagingElement) packagingElement).getDirectoryName());
      current = current.getParentNode();
    }

    if (current == null) return parentElement;
    final PackagingElement<?> rootElement = current.getElementIfSingle();
    if (!(rootElement instanceof CompositePackagingElement<?>)) return parentElement;

    Collections.reverse(dirNames);
    String path = StringUtil.join(dirNames, "/");
    return PackagingElementFactory.getInstance()
        .getOrCreateDirectory((CompositePackagingElement<?>) rootElement, path);
  }
  @Nullable
  @SuppressWarnings({"HardCodedStringLiteral"})
  private JPanel readExternalPanel(
      final Element element, @Nullable JPanel panel, Ref<EditorWindow> currentWindow) {
    final Element splitterElement = element.getChild("splitter");
    if (splitterElement != null) {
      return readSplitter(panel, splitterElement, currentWindow);
    }

    final Element leaf = element.getChild("leaf");
    if (leaf == null) {
      return null;
    }

    final EditorWindow window = panel == null ? new EditorWindow(this) : findWindowWith(panel);
    LOG.assertTrue(window != null);

    @SuppressWarnings("unchecked")
    final List<Element> children = ContainerUtil.newArrayList(leaf.getChildren("file"));
    if (UISettings.getInstance().ACTIVATE_RIGHT_EDITOR_ON_CLOSE) {
      Collections.reverse(children);
    }

    // trim to EDITOR_TAB_LIMIT, ignoring CLOSE_NON_MODIFIED_FILES_FIRST policy
    for (Iterator<Element> iterator = children.iterator();
        iterator.hasNext() && UISettings.getInstance().EDITOR_TAB_LIMIT < children.size(); ) {
      Element child = iterator.next();
      if (!Boolean.valueOf(child.getAttributeValue(PINNED)).booleanValue()) {
        iterator.remove();
      }
    }

    VirtualFile currentFile = null;
    for (int i = 0; i < children.size(); i++) {
      final Element file = children.get(i);
      try {
        final FileEditorManagerImpl fileEditorManager = getManager();
        final HistoryEntry entry =
            new HistoryEntry(fileEditorManager.getProject(), file.getChild(HistoryEntry.TAG), true);
        final boolean isCurrent = Boolean.valueOf(file.getAttributeValue("current")).booleanValue();
        fileEditorManager.openFileImpl4(window, entry.myFile, false, entry, isCurrent, i);
        if (fileEditorManager.isFileOpen(entry.myFile)) {
          window.setFilePinned(
              entry.myFile, Boolean.valueOf(file.getAttributeValue(PINNED)).booleanValue());
          if (Boolean.valueOf(file.getAttributeValue("current-in-tab")).booleanValue()) {
            currentFile = entry.myFile;
          }
        }

      } catch (InvalidDataException e) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
          LOG.error(e);
        }
      }
    }
    if (currentFile != null) {
      final EditorComposite editor = window.findFileComposite(currentFile);
      if (editor != null) {
        window.setSelectedEditor(editor, true);
      }
    }
    return window.myPanel;
  }
예제 #6
0
  /** Add the UI components for the given file sequence to the panel. */
  private void addFileSeqPanel(FileSeq fseq) {
    boolean isPresentInWorking = false;
    if ((pStatus != null) && pStatus.hasLightDetails()) {
      NodeDetailsLight details = pStatus.getLightDetails();
      NodeMod mod = details.getWorkingVersion();
      if (mod != null) {
        if (mod.getPrimarySequence().equals(fseq)) isPresentInWorking = true;
        else {
          for (FileSeq sfseq : mod.getSecondarySequences()) {
            if (sfseq.equals(fseq)) {
              isPresentInWorking = true;
              break;
            }
          }
        }
      }
    }

    /* collate the row information */
    ArrayList<VersionID> vids = new ArrayList<VersionID>();
    ArrayList<FileSeq> singles = new ArrayList<FileSeq>();
    TreeSet<FileSeq> enabled = new TreeSet<FileSeq>();
    TreeMap<FileSeq, FileState> fstates = new TreeMap<FileSeq, FileState>();
    TreeMap<FileSeq, NativeFileInfo> finfos = new TreeMap<FileSeq, NativeFileInfo>();
    TreeMap<FileSeq, QueueState> qstates = new TreeMap<FileSeq, QueueState>();
    TreeMap<FileSeq, Boolean[]> novel = new TreeMap<FileSeq, Boolean[]>();
    {
      TreeMap<FileSeq, Integer> wsingles = new TreeMap<FileSeq, Integer>();
      if ((pStatus != null) && pStatus.hasLightDetails()) {
        if (isPresentInWorking) {
          if (pStatus.hasHeavyDetails()) {
            NodeDetailsHeavy details = pStatus.getHeavyDetails();

            FileState[] fs = details.getFileStates(fseq);
            QueueState[] qs = details.getQueueStates();
            NativeFileInfo[] infos = details.getFileInfos(fseq);
            if ((fs != null) && (qs != null) && (infos != null)) {
              int wk;
              for (wk = 0; wk < fs.length; wk++) {
                FileSeq sfseq = new FileSeq(fseq, wk);
                wsingles.put(sfseq, wk);

                fstates.put(sfseq, fs[wk]);
                finfos.put(sfseq, infos[wk]);
                qstates.put(sfseq, qs[wk]);

                if (fs[wk] != FileState.CheckedIn) enabled.add(sfseq);
              }
            }
          } else {
            NodeDetailsLight details = pStatus.getLightDetails();

            int wk;
            for (wk = 0; wk < fseq.numFrames(); wk++) {
              FileSeq sfseq = new FileSeq(fseq, wk);
              wsingles.put(sfseq, wk);

              if (details.getVersionState() == VersionState.CheckedIn) {
                fstates.put(sfseq, FileState.CheckedIn);
                qstates.put(sfseq, QueueState.Undefined);
              } else {
                enabled.add(sfseq);
              }
            }
          }
        }

        {
          vids.addAll(pNovelty.keySet());
          Collections.reverse(vids);

          int idx = 0;
          for (VersionID vid : vids) {
            TreeMap<FileSeq, boolean[]> table = pNovelty.get(vid);
            for (FileSeq nfseq : table.keySet()) {
              if (fseq.similarTo(nfseq)) {
                boolean[] flags = table.get(nfseq);

                int wk;
                for (wk = 0; wk < flags.length; wk++) {
                  FileSeq sfseq = new FileSeq(nfseq, wk);
                  if (!wsingles.containsKey(sfseq)) wsingles.put(sfseq, null);

                  Boolean[] rflags = novel.get(sfseq);
                  if (rflags == null) {
                    rflags = new Boolean[pNovelty.size()];
                    novel.put(sfseq, rflags);
                  }

                  rflags[idx] = new Boolean(flags[wk]);
                }

                break;
              }
            }

            idx++;
          }
        }
      }

      TreeMap<Integer, FileSeq> order = new TreeMap<Integer, FileSeq>();
      for (FileSeq sfseq : wsingles.keySet()) {
        int frame = -1;
        if (sfseq.hasFrameNumbers()) frame = sfseq.getFrameRange().getStart();

        order.put(frame, sfseq);
      }

      singles.addAll(order.values());
    }

    /* add the panel */
    {
      JFileSeqPanel panel =
          new JFileSeqPanel(
              this,
              pManagerPanel,
              pStatus,
              pPrivilegeDetails,
              fseq,
              vids,
              pOffline,
              singles,
              fstates,
              finfos,
              qstates,
              enabled,
              novel,
              pIsListLayout);

      if (pIsListLayout) pFileSeqsBox.add(panel);
      else pFileSeqsTab.addTab(fseq.getFilePattern().toString(), sTabIcon, panel);

      pFileSeqPanels.put(fseq, panel);
    }
  }
  private RebaseInfo collectRebaseInfo() {
    final Set<VirtualFile> roots = new HashSet<VirtualFile>();
    final Set<VirtualFile> rootsWithMerges = new HashSet<VirtualFile>();
    final Map<VirtualFile, List<String>> reorderedCommits =
        new HashMap<VirtualFile, List<String>>();
    final Map<VirtualFile, Set<String>> uncheckedCommits = new HashMap<VirtualFile, Set<String>>();
    for (int i = 0; i < myTreeRoot.getChildCount(); i++) {
      CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i);
      Root r = (Root) node.getUserObject();
      Set<String> unchecked = new HashSet<String>();
      uncheckedCommits.put(r.root, unchecked);
      if (r.commits.size() == 0) {
        if (r.remoteCommits > 0) {
          roots.add(r.root);
        }
        continue;
      }
      boolean seenCheckedNode = false;
      boolean reorderNeeded = false;
      boolean seenMerges = false;
      for (int j = 0; j < node.getChildCount(); j++) {
        if (node.getChildAt(j) instanceof CheckedTreeNode) {
          CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j);
          Commit commit = (Commit) commitNode.getUserObject();
          seenMerges |= commit.isMerge;
          if (commitNode.isChecked()) {
            seenCheckedNode = true;
          } else {
            unchecked.add(commit.commitId());
            if (seenCheckedNode) {
              reorderNeeded = true;
            }
          }
        }
      }
      if (seenMerges) {
        rootsWithMerges.add(r.root);
      }
      if (r.remoteCommits > 0 || reorderNeeded) {
        roots.add(r.root);
      }
      if (reorderNeeded) {
        List<String> reordered = new ArrayList<String>();
        for (int j = 0; j < node.getChildCount(); j++) {
          if (node.getChildAt(j) instanceof CheckedTreeNode) {
            CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j);
            if (!commitNode.isChecked()) {
              Commit commit = (Commit) commitNode.getUserObject();
              reordered.add(commit.revision.asString());
            }
          }
        }
        for (int j = 0; j < node.getChildCount(); j++) {
          if (node.getChildAt(j) instanceof CheckedTreeNode) {
            CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j);
            if (commitNode.isChecked()) {
              Commit commit = (Commit) commitNode.getUserObject();
              reordered.add(commit.revision.asString());
            }
          }
        }
        Collections.reverse(reordered);
        reorderedCommits.put(r.root, reordered);
      }
    }
    final GitVcsSettings.UpdateChangesPolicy p =
        UpdatePolicyUtils.getUpdatePolicy(myStashRadioButton, myShelveRadioButton);
    assert p == GitVcsSettings.UpdateChangesPolicy.STASH
        || p == GitVcsSettings.UpdateChangesPolicy.SHELVE;

    return new RebaseInfo(reorderedCommits, rootsWithMerges, uncheckedCommits, roots, p);
  }
예제 #8
0
  // This method will construct the best possible path by using the A* search algorithm
  private static List<String> AStarSearch(Polygon[] finalPolygons) {

    List<String> completedPath = new ArrayList<String>();
    String[] Ender = ePoint.split(",");

    // The final goal point
    double endx = Double.parseDouble(Ender[0]);
    double endy = Double.parseDouble(Ender[1]);

    //////////////////////////////////////////////////
    // Correct path from the example map:
    // (1,3)  (2,6)  (14,8)  (22,19)  (28,19)  (31,19)  (34,19)
    //////////////////////////////////////////////////

    // set of points to be evaluated, initially only containing start point
    List<Points> openset = new ArrayList<Points>();
    // set of points already evaluated
    List<Points> closedset = new ArrayList<Points>();

    // The initial starting point
    GStartx = Startx;
    GStarty = Starty;

    // G-score is the calculated cost from the start to the current point

    // Calculating F score, which is the distance between the current starting point and the final
    // end point
    double F_Cost = distance(Startx, Starty, endx, endy);

    // initializing variables for each point

    // current x and y location, current "came from" x and y location
    int currX, currY, currCamex, currCamey;

    // current G-Score and F-Score
    double currG, currF;

    double tentGscore, tentFscore;
    openset.add(new Points((int) Startx, (int) Starty, 0, 0, F_Cost, -1, -1));
    boolean dummy = true;

    // while the openset is not empty
    while (openset.size() != 0) {

      // get the next Point to be evaluated in the openset with the lowest f-score

      // filling variables with the information from the point being evaluated
      currX = openset.get(0).XPoint;
      currY = openset.get(0).YPoint;
      currF = openset.get(0).costF;
      currG = openset.get(0).costG;
      currCamex = openset.get(0).camefromx;
      currCamey = openset.get(0).camefromy;
      Startx = currX;
      Starty = currY;

      // If the current point equals the goal point, start constructing a path back to the start
      if (currX == endx && currY == endy) {
        // add the last point to the closed set
        closedset.add(new Points(currX, currY, 0, currG, currF, currCamex, currCamey));
        for (int r = closedset.size() - 1; r >= 0; r--) {

          // Loop from the end to the start of the closed set
          // From the end point, look at the point that was "travelled from" and add that point to
          // the path
          if ((currX == closedset.get(r).XPoint) && (currY == closedset.get(r).YPoint)) {

            completedPath.add(" (" + currX + "," + currY + ") ");

            currX = closedset.get(r).camefromx;
            currY = closedset.get(r).camefromy;
          }
        }

        // Reverse the order from start to finish and print the path
        Collections.reverse(completedPath);
        System.out.print("Best path: ");
        for (String omg : completedPath) {
          // Final, constructed path
          System.out.print(omg);
        }

        // End the algorithm
        break;
      }

      // Check which points can be seen and travelled to from the current point
      List<Points> Seeable = visible(finalPolygons);

      // Before evaluating the current point, remove it from the openset and add it to the closed
      // set
      openset.remove(0);
      closedset.add(new Points(currX, currY, 0, currG, currF, currCamex, currCamey));

      // loop through all of the seeable points from the current point
      for (Points neighbor : Seeable) {
        int wanz = 0;

        // Tentative F-Score = current G Score and the distance between current point and the
        // neighbor point
        tentGscore = currG + neighbor.lineLength;
        tentFscore = tentGscore + distance(neighbor.XPoint, neighbor.YPoint, endx, endy);

        for (int j = 0; j < closedset.size() - 1; j++) {
          // if neighbor point is in closedset and the tentative FScore is >= the neighbor's FScore
          if ((neighbor.XPoint == closedset.get(j).XPoint)
              && (neighbor.YPoint == closedset.get(j).YPoint)) {

            // give the neighbor the F and G score it already has in the closed set
            neighbor.costF = closedset.get(j).costF;
            neighbor.costG = closedset.get(j).costG;
          }
        }

        // if the neighbor point is not in the open set, or the tentative FScore of the current
        // point is less than the FScore of the neighbor point
        if ((!openset.contains(neighbor)) || tentFscore < neighbor.costF) {

          // assign the current point as the "travelled from" point for the neighbor point
          neighbor.camefromx = currX;
          neighbor.camefromy = currY;

          // give the F and G scores of the current point to the neighbor point
          neighbor.costG = tentGscore;
          neighbor.costF = tentFscore;

          // Check to see if the current neighbor is in the open set
          for (int i = 0; i < openset.size() - 1; i++) {
            if ((neighbor.XPoint == openset.get(i).XPoint)
                && (neighbor.YPoint == openset.get(i).YPoint)) {
              wanz++;
            }
          }

          // If not, add to the open set
          if (wanz == 0) {
            openset = addStuff(openset, neighbor);
          }
        }
      }
    }
    return completedPath;
  }