1 package com.github.javaparser.symbolsolver.resolution.typeinference;
2 
3 import com.github.javaparser.resolution.types.ResolvedType;
4 
5 import java.util.LinkedList;
6 import java.util.List;
7 
8 /**
9  * @author Federico Tomassetti
10  */
11 public class InstantiationSet {
12 
13     private List<Instantiation> instantiations;
14 
allInferenceVariablesAreResolved(BoundSet boundSet)15     public boolean allInferenceVariablesAreResolved(BoundSet boundSet) {
16         throw new UnsupportedOperationException();
17     }
18 
empty()19     public static InstantiationSet empty() {
20         return EMPTY;
21     }
22 
23     private static final InstantiationSet EMPTY = new InstantiationSet();
24 
InstantiationSet()25     private InstantiationSet() {
26         instantiations = new LinkedList<>();
27     }
28 
withInstantiation(Instantiation instantiation)29     public InstantiationSet withInstantiation(Instantiation instantiation) {
30         InstantiationSet newInstance = new InstantiationSet();
31         newInstance.instantiations.addAll(this.instantiations);
32         newInstance.instantiations.add(instantiation);
33         return newInstance;
34     }
35 
isEmpty()36     public boolean isEmpty() {
37         return instantiations.isEmpty();
38     }
39 
40     @Override
equals(Object o)41     public boolean equals(Object o) {
42         if (this == o) return true;
43         if (o == null || getClass() != o.getClass()) return false;
44 
45         InstantiationSet that = (InstantiationSet) o;
46 
47         return instantiations.equals(that.instantiations);
48     }
49 
50     @Override
hashCode()51     public int hashCode() {
52         return instantiations.hashCode();
53     }
54 
55     @Override
toString()56     public String toString() {
57         return "InstantiationSet{" +
58                 "instantiations=" + instantiations +
59                 '}';
60     }
61 
apply(ResolvedType type)62     public ResolvedType apply(ResolvedType type) {
63         for (Instantiation instantiation : instantiations) {
64             type = type.replaceTypeVariables(instantiation.getInferenceVariable().getTypeParameterDeclaration(), instantiation.getProperType());
65         }
66         return type;
67     }
68 }
69