1 | package de.uka.ipd.sdq.pcmsolver.transformations; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.HashMap; |
5 | import java.util.List; |
6 | import java.util.Map; |
7 | |
8 | import de.uka.ipd.sdq.pcm.allocation.AllocationContext; |
9 | import de.uka.ipd.sdq.pcm.resourceenvironment.CommunicationLinkResourceSpecification; |
10 | import de.uka.ipd.sdq.pcm.seff.ExternalCallAction; |
11 | import de.uka.ipd.sdq.pcmsolver.Pair; |
12 | |
13 | /** |
14 | * Stores triples of {@link ExternalCallAction}, {@link AllocationContext}, and |
15 | * {@link CommunicationLinkResourceSpecification} to retrieve the linking |
16 | * resource used if the call is issued to the allocation context. So to say, |
17 | * realizes something like a Map<ExternalCallAction,Map<AllocationContext, |
18 | * CommunicationLinkResourceSpecification>>. But does not use only maps |
19 | * internally because not so many elements are expected. |
20 | * |
21 | * @author martens |
22 | * |
23 | */ |
24 | class CallsToLinkResourcesMap { |
25 | |
26 | /** |
27 | * |
28 | */ |
29 | Map<ExternalCallAction, List<Pair<AllocationContext, CommunicationLinkResourceSpecification>>> internalMap = new HashMap<ExternalCallAction, List<Pair<AllocationContext, CommunicationLinkResourceSpecification>>>(); |
30 | |
31 | /** |
32 | * |
33 | * @param eca |
34 | * @param allCtx |
35 | * @return |
36 | */ |
37 | public CommunicationLinkResourceSpecification get(ExternalCallAction eca, |
38 | AllocationContext allCtx) { |
39 | List<Pair<AllocationContext, CommunicationLinkResourceSpecification>> listForEca = internalMap |
40 | .get(eca); |
41 | if (listForEca == null) { |
42 | return null; |
43 | } |
44 | for (Pair<AllocationContext, CommunicationLinkResourceSpecification> pair : listForEca) { |
45 | if (pair.getFirst().getId().equals(allCtx.getId())) { |
46 | return pair.getSecond(); |
47 | } |
48 | } |
49 | return null; |
50 | } |
51 | |
52 | /** |
53 | * |
54 | * @param eca |
55 | * @param nextAllCtx |
56 | * @param clrs |
57 | */ |
58 | public void put(ExternalCallAction eca, AllocationContext nextAllCtx, |
59 | CommunicationLinkResourceSpecification clrs) { |
60 | Pair<AllocationContext, CommunicationLinkResourceSpecification> pair = new Pair<AllocationContext, CommunicationLinkResourceSpecification>( |
61 | nextAllCtx, clrs); |
62 | List<Pair<AllocationContext, CommunicationLinkResourceSpecification>> listForEca = internalMap |
63 | .get(eca); |
64 | if (listForEca == null) { |
65 | listForEca = new ArrayList<Pair<AllocationContext, CommunicationLinkResourceSpecification>>(); |
66 | internalMap.put(eca, listForEca); |
67 | } |
68 | listForEca.add(pair); |
69 | |
70 | } |
71 | } |