Changeset 1200


Ignore:
Timestamp:
Jul 10, 2011, 10:50:38 PM (6 years ago)
Author:
stefan
Message:
 
Location:
trunk/src/jlatexeditor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/PackagesExtractor.java

    r1196 r1200  
    9393      } else
    9494      if (localName.equals("package")) {
    95         pack = new Package(attrList.getValue("name"), attrList.getValue("options"), attrList.getValue("requiresPackages"), attrList.getValue("title"), attrList.getValue("description"), attrList.getValue("debPackage"));
     95        pack = new Package(attrList.getValue("name"), attrList.getValue("options"), attrList.getValue("requiresPackages"), attrList.getValue("title"), attrList.getValue("description"), attrList.getValue("debPackage"), attrList.getValue("usageCount"));
    9696        packages.add(pack.name, pack);
    9797      }
     
    134134    private String description;
    135135    private String debPackage;
    136 
    137     public Package(String name, String optionsList, String requiresPackagesList, String title, String description, String debPackage) {
     136    private int usageCount;
     137
     138    public Package(String name, String optionsList, String requiresPackagesList, String title, String description, String debPackage, String usageCount) {
    138139      this.name = name;
    139140      if (optionsList != null) {
     
    146147      this.description = description;
    147148      this.debPackage = debPackage;
     149      if (usageCount != null) {
     150        this.usageCount = Integer.parseInt(usageCount);
     151      }
    148152    }
    149153
     
    185189    }
    186190
     191    public HashSet<Package> getRequiredPackagesRecursively() {
     192      return addRequiredPackagesRecursively(new HashSet<Package>());
     193    }
     194
     195    public HashSet<Package> addRequiredPackagesRecursively(HashSet<Package> reqPackages) {
     196      if (!reqPackages.contains(this)) {
     197        reqPackages.add(this);
     198        for (Package reqPackage : getRequiresPackages()) {
     199          reqPackage.addRequiredPackagesRecursively(reqPackages);
     200        }
     201      }
     202      return reqPackages;
     203    }
     204
    187205    public ArrayList<Package> getDependantPackages() {
    188206      return dependantPackages;
     
    215233    }
    216234
     235    public int getUsageCount() {
     236      return usageCount;
     237    }
     238
    217239    @Override
    218240    public int compareTo(Package that) {
  • trunk/src/jlatexeditor/codehelper/PackageImportSuggester.java

    r1188 r1200  
    1010
    1111import java.io.File;
    12 import java.util.ArrayList;
    13 import java.util.Collections;
    14 import java.util.HashSet;
    15 import java.util.List;
     12import java.util.*;
    1613
    1714/**
     
    6259
    6360    if (commands != null) {
     61      // build HashSet with all packages directly and indirectly imported in this document
     62      HashSet<PackagesExtractor.Package> directlyImportedPackagesHash = new HashSet<PackagesExtractor.Package>();
     63      HashSet<PackagesExtractor.Package> indirectlyImportedPackagesHash = new HashSet<PackagesExtractor.Package>();
     64      for (Package pack : backgroundParser.getPackages()) {
     65        PackagesExtractor.Package aPackage = PackagesExtractor.getPackageParser().getPackages().get(pack.getName());
     66        if (aPackage != null) {
     67          directlyImportedPackagesHash.add(aPackage);
     68          aPackage.addRequiredPackagesRecursively(indirectlyImportedPackagesHash);
     69        }
     70      }
     71
     72      // build HashSet with all packages directly or indirectly providing the given command
     73      HashSet<PackagesExtractor.Package> dependentPackagesHash = new HashSet<PackagesExtractor.Package>();
     74      for (PackagesExtractor.Command command : commands) {
     75        command.getPack().addDependantPackagesRecursively(dependentPackagesHash);
     76      }
     77
    6478      // build up lists of imported and importable packages providing the command
    6579      ArrayList<PackagesExtractor.Package> importablePackages = new ArrayList<PackagesExtractor.Package>();
    6680      ArrayList<PackagesExtractor.Package> importedPackages = new ArrayList<PackagesExtractor.Package>();
     81      for (PackagesExtractor.Package pack : dependentPackagesHash) {
     82        if (indirectlyImportedPackagesHash.contains(pack)) {
     83          importedPackages.add(pack);
     84        } else {
     85          importablePackages.add(pack);
     86        }
     87      }
     88      /*
    6789      for (PackagesExtractor.Command command : commands) {
    6890        PackagesExtractor.Package pack = command.getPack();
    69         if (!importedPackages.contains(pack) && !importablePackages.contains(pack)) {
    70           if (backgroundParser.getPackages().contains(pack.getName())) {
    71             importedPackages.add(pack);
    72           } else {
    73             importablePackages.add(pack);
     91        for (PackagesExtractor.Package depPack : pack.getDependantPackagesRecursively()) {
     92          if (!importedPackages.contains(depPack) && !importablePackages.contains(depPack)) {
     93            if (backgroundParser.getPackages().contains(pack.getName())) {
     94              importedPackages.add(pack);
     95            } else {
     96              importablePackages.add(pack);
     97            }
    7498          }
    7599        }
    76100      }
    77       Collections.sort(importedPackages);
    78       Collections.sort(importablePackages);
     101      */
     102      Comparator<PackagesExtractor.Package> comparator = new Comparator<PackagesExtractor.Package>() {
     103        @Override
     104        public int compare(PackagesExtractor.Package o1, PackagesExtractor.Package o2) {
     105          if (o1.getUsageCount() > o2.getUsageCount()) return -1;
     106          if (o1.getUsageCount() == o2.getUsageCount()) return o1.getName().compareToIgnoreCase(o2.getName());
     107          return 1;
     108        }
     109      };
     110      Collections.sort(importedPackages, comparator);
     111      Collections.sort(importablePackages, comparator);
    79112
    80113      for (PackagesExtractor.Package pack : importedPackages) {
Note: See TracChangeset for help on using the changeset viewer.