Analysis
Overview
The current search capabilities of ProLists are not sufficient - it's very slow for large collections. So we need a way to optimize this search.
Task requirements
- Provide a way to optimize search in ProList
- This should not break the current use of ProLib
- It will be good if these new search capabilities can be used with the current use of ProList and there will be no need for refactor
Task result
The result should be code and documentation
Implementation idea
Use a map for categorizing the elements of the list by keys. This way required values (that are searched) will be returned by Map#get(key)
Related
How to demo
Show some code, documentation and introduce the new functionality to the others
Design
In order to get better performance without making huge refactoring (introduce new type, replace using old types with the new one etc.) two methods will be added to the ProList interface. Their implementation will be in BaseProList and this will keep other classes and their use with no change.
A new field will be added to BaseProList - a Map instance where will be stored the elements from the list under some key. This doesn't remove the need from the list itself. Nothing of this will remove some existing code. Only new code will be added.
A new class will be added - ListEntry. It will have two field - key : Obejct and value : Object. This class will serve as a helper class for work with the Map.
In the add/remove method of ProList will be added new functionality that will add the parameter to the map with the following rules:
- If the parameter is ListEntry - the key in the map is the key of ListEntry
- if the parameter is Immutable - the key in the map is the Immutable object
- if the parameter is Mutable - the added in the map is null
The two new methods are :
- findAll (key : Object) : List<E> - this method will return all the entries in the list with the specified key
- findOne (key : Object) : E - this method will return only one entry from the list for the key. More - if there are more than one entry an exception will be thrown
Implementation
The task is implemented according to the design
Changesets: [2163]
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)