Class SequenceCollection


  • public class SequenceCollection
    extends Object
    A collection of sequences that makes it efficient to ask for all the sequences that create a value of a given type. This implements Randoop's pool. A SequenceCollection is the main field of ComponentManager.

    To find all the sequences that create values of a given type, Randoop first uses the SubTypeSet to find the set T of feasible subtypes, and returns the range of T (that is, all the sequences mapped to by any t∈T) in the sequence map.

    • Field Detail

      • sequenceMap

        private Map<Type,​SimpleArrayList<Sequence>> sequenceMap
        For each type, all the sequences that produce one or more values of exactly the given type.
      • typeSet

        private SubTypeSet typeSet
        A set of all the types that can be created with the sequences in this. This is the same as sequenceMap.keySet(), but provides additional operations.
      • typesAndSupertypes

        private Set<Type> typesAndSupertypes
        A set of all the types that can be created with the sequences in this, and all their supertypes. Thus, this may be larger than typeSet.
      • sequenceCount

        private int sequenceCount
        Number of sequences in the collection: sum of sizes of all values in sequenceMap.
    • Constructor Detail

      • SequenceCollection

        public SequenceCollection()
        Create a new, empty collection.
      • SequenceCollection

        public SequenceCollection​(Collection<Sequence> initialSequences)
        Create a new collection and adds the given initial sequences.
        Parameters:
        initialSequences - the initial collection of sequences
    • Method Detail

      • checkRep

        private void checkRep()
      • size

        public int size()
      • clear

        public void clear()
        Removes all sequences from this collection.
      • addAll

        public void addAll​(Collection<Sequence> col)
        All all the given sequences to this collection.
        Parameters:
        col - the sequences to add
      • addAll

        public void addAll​(SequenceCollection components)
        Add all the given sequences to this collection.
        Parameters:
        components - the sequences to add
      • add

        public void add​(Sequence sequence)
        Add a sequence to this collection. This method takes into account the active indices in the sequence. If sequence[i] creates a values of type T, and sequence[i].isActive==true, then the sequence is seen as creating a useful value at index i. More precisely, the method/constructor at that index is said to produce a useful value (and if the user later queries for all sequences that create a T, the sequence will be in the collection returned by the query). How a value is deemed useful or not is left up to the client.

        Note that this takes into consideration only the assigned value for each statement. If a statement might side-effect some variable V, then V is considered as an output from the statement that declares/creates V, not the one that side-effects V.

        (An alternative would be to only use outputs from the last statement, and include its inputs as well. That alternative is not implemented. It would probably be faster, but it would not handle the case of a method side-effecting a variable that that was not explicitly passed to it. That case probably isn't important/common.)

        Parameters:
        sequence - the sequence to add to this collection
      • updateCompatibleMap

        private void updateCompatibleMap​(Sequence sequence,
                                         Type type)
        Add the entry (type, sequence) to sequenceMap.
        Parameters:
        sequence - the sequence
        type - the Type
      • getSequencesForType

        public SimpleList<Sequence> getSequencesForType​(Type type,
                                                        boolean exactMatch,
                                                        boolean onlyReceivers)
        Searches through the set of active sequences to find all sequences whose types match with the parameter type.

        If exactMatch==true returns only sequences that declare values of the exact class specified; if exactMatch==false returns sequences declaring values of cls or any other class that can be used as a cls (i.e. a subclass of cls).

        Parameters:
        type - the type desired for the sequences being sought
        exactMatch - the flag to indicate whether an exact type match is required
        onlyReceivers - if true, only return sequences that are appropriate to use as a method call receiver
        Returns:
        list of sequence objects that are of type 'type' and abide by the constraints defined by nullOk
      • getAllSequences

        public Set<Sequence> getAllSequences()
        Returns the set of all sequences in this collection.
        Returns:
        the set of all sequences in this collection
      • log

        public void log()