Class SequenceCollection
- java.lang.Object
-
- randoop.sequence.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 ofComponentManager
.To find all the sequences that create values of a given type, Randoop first uses the
SubTypeSet
to find the setT
of feasible subtypes, and returns the range ofT
(that is, all the sequences mapped to by any t∈T) in the sequence map.
-
-
Field Summary
Fields Modifier and Type Field Description private int
sequenceCount
Number of sequences in the collection: sum of sizes of all values in sequenceMap.private Map<Type,SimpleArrayList<Sequence>>
sequenceMap
For each type, all the sequences that produce one or more values of exactly the given type.private Set<Type>
typesAndSupertypes
A set of all the types that can be created with the sequences in this, and all their supertypes.private SubTypeSet
typeSet
A set of all the types that can be created with the sequences in this.
-
Constructor Summary
Constructors Constructor Description SequenceCollection()
Create a new, empty collection.SequenceCollection(Collection<Sequence> initialSequences)
Create a new collection and adds the given initial sequences.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Sequence sequence)
Add a sequence to this collection.void
addAll(Collection<Sequence> col)
All all the given sequences to this collection.void
addAll(SequenceCollection components)
Add all the given sequences to this collection.private void
checkRep()
void
clear()
Removes all sequences from this collection.Set<Sequence>
getAllSequences()
Returns the set of all sequences in this collection.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.TypeInstantiator
getTypeInstantiator()
void
log()
int
size()
private void
updateCompatibleMap(Sequence sequence, Type type)
Add the entry (type, sequence) tosequenceMap
.
-
-
-
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 assequenceMap.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 thantypeSet
.
-
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) tosequenceMap
.- Parameters:
sequence
- the sequencetype
- theType
-
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 soughtexactMatch
- the flag to indicate whether an exact type match is requiredonlyReceivers
- 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
-
getTypeInstantiator
public TypeInstantiator getTypeInstantiator()
-
log
public void log()
-
-