File(s) not publicly available
Flexible selection of output format for sets in Java collections : algorithms and their complexity and reusability
journal contributionposted on 06.12.2017, 00:00 by Wanwu GuoWanwu Guo
Set, a collection of distinct values, is widely used in many applications. There are three applicable set classes included in the Java Collections. TreeSet produces a sorted output in ascending order whereas HashSet provides an output with random order. LinkedHashSet, a subclass of HashSet, produces an output in insertion order, but does not support the sorted output. Three algorithms are proposed in this paper to modify the existing set classes in the Java Collections so that they can provide multiple output formats for users to select from. The algorithm at application-level does not change the current configurations of the set classes, but it offers little reusability. The algorithm at method level introduces an internal method for producing sorted output into the LinkedHashTable class, in addition to its default output in insertion order. This can be achieved without change to other configurations of the class. If this method is placed in the HashSet class, users can freely choose their preferred output format from random order, insertion order, or ascending order. The algorithm at class level proposes a new LinkedTreeSet class that is implemented using both a balanced BST and a doubly linked list. The basic operations of this class may be slightly slower than that in the TreeSet class.