@@ -53,18 +53,18 @@ public class ContributionListing {
5353 Map <String , Contribution > librariesByImportHeader ;
5454 // TODO: Every contribution is getting added twice
5555 // and nothing is replaced ever.
56- List <Contribution > allContributions ;
56+ Set <Contribution > allContributions ;
5757 boolean listDownloaded ;
5858 boolean listDownloadFailed ;
5959 ReentrantLock downloadingListingLock ;
6060
6161
6262 private ContributionListing () {
63- listeners = new ArrayList <ChangeListener >();
64- advertisedContributions = new ArrayList <AvailableContribution >();
65- librariesByCategory = new HashMap <String , List < Contribution > >();
66- librariesByImportHeader = new HashMap <String , Contribution >();
67- allContributions = new ArrayList < Contribution >();
63+ listeners = new ArrayList <>();
64+ advertisedContributions = new ArrayList <>();
65+ librariesByCategory = new HashMap <>();
66+ librariesByImportHeader = new HashMap <>();
67+ allContributions = new LinkedHashSet < >();
6868 downloadingListingLock = new ReentrantLock ();
6969
7070 //listingFile = Base.getSettingsFile("contributions.txt");
@@ -96,7 +96,6 @@ private void setAdvertisedList(File file) {
9696 for (Contribution contribution : advertisedContributions ) {
9797 addContribution (contribution );
9898 }
99- Collections .sort (allContributions , COMPARATOR );
10099 }
101100
102101
@@ -139,11 +138,8 @@ protected void replaceContribution(Contribution oldLib, Contribution newLib) {
139138 }
140139 }
141140
142- for (int i = 0 ; i < allContributions .size (); i ++) {
143- if (allContributions .get (i ) == oldLib ) {
144- allContributions .set (i , newLib );
145- }
146- }
141+ allContributions .remove (oldLib );
142+ allContributions .add (newLib );
147143
148144 notifyChange (oldLib , newLib );
149145 }
@@ -169,7 +165,6 @@ private void addContribution(Contribution contribution) {
169165 }
170166 allContributions .add (contribution );
171167 notifyAdd (contribution );
172- Collections .sort (allContributions , COMPARATOR );
173168 }
174169 }
175170
@@ -234,43 +229,7 @@ protected Set<String> getCategories(Contribution.Filter filter) {
234229 }
235230
236231
237- // public List<Contribution> getAllContributions() {
238- // return new ArrayList<Contribution>(allContributions);
239- // }
240-
241-
242- // public List<Contribution> getLibararies(String category) {
243- // ArrayList<Contribution> libinfos =
244- // new ArrayList<Contribution>(librariesByCategory.get(category));
245- // Collections.sort(libinfos, nameComparator);
246- // return libinfos;
247- // }
248-
249-
250- protected List <Contribution > getFilteredLibraryList (String category , List <String > filters ) {
251- ArrayList <Contribution > filteredList =
252- new ArrayList <Contribution >(allContributions );
253-
254- Iterator <Contribution > it = filteredList .iterator ();
255- while (it .hasNext ()) {
256- Contribution libInfo = it .next ();
257- //if (category != null && !category.equals(libInfo.getCategory())) {
258- if (category != null && !libInfo .hasCategory (category )) {
259- it .remove ();
260- } else {
261- for (String filter : filters ) {
262- if (!matches (libInfo , filter )) {
263- it .remove ();
264- break ;
265- }
266- }
267- }
268- }
269- return filteredList ;
270- }
271-
272-
273- private boolean matches (Contribution contrib , String typed ) {
232+ public boolean matches (Contribution contrib , String typed ) {
274233 int colon = typed .indexOf (":" );
275234 if (colon != -1 ) {
276235 String isText = typed .substring (0 , colon );
@@ -601,11 +560,7 @@ public Map<String, Contribution> getLibrariesByImportHeader() {
601560 }
602561
603562
604- static public Comparator <Contribution > COMPARATOR = new Comparator <Contribution >() {
605- public int compare (Contribution o1 , Contribution o2 ) {
606- return o1 .getName ().toLowerCase ().compareTo (o2 .getName ().toLowerCase ());
607- }
608- };
563+ static public Comparator <Contribution > COMPARATOR = Comparator .comparing (o -> o .getName ().toLowerCase ());
609564
610565
611566 public interface ChangeListener {
0 commit comments