|
28 | 28 | public class ReceiverRegistrationHolder { |
29 | 29 |
|
30 | 30 | private EComponentHolder holder; |
31 | | - private Map<Set<String>, JFieldVar> intentFilterFields = new HashMap<Set<String>, JFieldVar>(); |
| 31 | + private Map<IntentFilterData, JFieldVar> intentFilterFields = new HashMap<IntentFilterData, JFieldVar>(); |
32 | 32 | private IllegalStateException illegalStateException = new IllegalStateException("This shouldn't happen unless the validation is bad"); |
33 | 33 |
|
34 | 34 | public ReceiverRegistrationHolder(EComponentHolder holder) { |
35 | 35 | this.holder = holder; |
36 | 36 | } |
37 | 37 |
|
38 | | - public JFieldVar getIntentFilterField(String[] actions) { |
39 | | - Arrays.sort(actions); |
40 | | - Set<String> actionSet = new HashSet<String>(Arrays.asList(actions)); |
41 | | - JFieldVar intentFilterField = intentFilterFields.get(actionSet); |
| 38 | + public JFieldVar getIntentFilterField(String[] actions, String[] dataSchemes) { |
| 39 | + IntentFilterData intentFilterData = new IntentFilterData(actions, dataSchemes); |
| 40 | + JFieldVar intentFilterField = intentFilterFields.get(intentFilterData); |
42 | 41 | if (intentFilterField == null) { |
43 | | - intentFilterField = createIntentFilterField(actionSet); |
44 | | - intentFilterFields.put(actionSet, intentFilterField); |
| 42 | + intentFilterField = createIntentFilterField(intentFilterData); |
| 43 | + intentFilterFields.put(intentFilterData, intentFilterField); |
45 | 44 | } |
46 | 45 | return intentFilterField; |
47 | 46 | } |
48 | 47 |
|
49 | | - private JFieldVar createIntentFilterField(Set<String> actionSet) { |
50 | | - String intentFilterName = "intentFilter"+(intentFilterFields.size()+1)+ ModelConstants.GENERATION_SUFFIX; |
| 48 | + private JFieldVar createIntentFilterField(IntentFilterData intentFilterData) { |
| 49 | + String intentFilterName = "intentFilter" + (intentFilterFields.size() + 1) + ModelConstants.GENERATION_SUFFIX; |
51 | 50 | JExpression newIntentFilterExpr = _new(classes().INTENT_FILTER); |
52 | 51 | JFieldVar intentFilterField = getGeneratedClass().field(PRIVATE | FINAL, classes().INTENT_FILTER, intentFilterName, newIntentFilterExpr); |
53 | 52 |
|
54 | 53 | JBlock initBody = holder.getInitBody(); |
55 | | - for(String action : actionSet) { |
| 54 | + for (String action : intentFilterData.getActionSet()) { |
56 | 55 | initBody.invoke(intentFilterField, "addAction").arg(action); |
57 | 56 | } |
| 57 | + for (String dataScheme : intentFilterData.getDataSchemeSet()) { |
| 58 | + initBody.invoke(intentFilterField, "addDataScheme").arg(dataScheme); |
| 59 | + } |
58 | 60 |
|
59 | 61 | return intentFilterField; |
60 | 62 | } |
@@ -86,4 +88,61 @@ public JDefinedClass getGeneratedClass() { |
86 | 88 | public ProcessHolder.Classes classes() { |
87 | 89 | return holder.classes(); |
88 | 90 | } |
| 91 | + |
| 92 | + private static class IntentFilterData { |
| 93 | + |
| 94 | + private final Set<String> actionSet; |
| 95 | + private final Set<String> dataSchemeSet; |
| 96 | + |
| 97 | + public IntentFilterData(String[] actions, String[] dataSchemes) { |
| 98 | + actionSet = new HashSet<String>(Arrays.asList(actions)); |
| 99 | + dataSchemeSet = new HashSet<String>(Arrays.asList(dataSchemes)); |
| 100 | + } |
| 101 | + |
| 102 | + public Set<String> getActionSet() { |
| 103 | + return actionSet; |
| 104 | + } |
| 105 | + |
| 106 | + public Set<String> getDataSchemeSet() { |
| 107 | + return dataSchemeSet; |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public int hashCode() { |
| 112 | + final int prime = 31; |
| 113 | + int result = 1; |
| 114 | + result = prime * result + (actionSet == null ? 0 : actionSet.hashCode()); |
| 115 | + result = prime * result + (dataSchemeSet == null ? 0 : dataSchemeSet.hashCode()); |
| 116 | + return result; |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public boolean equals(Object obj) { |
| 121 | + if (this == obj) { |
| 122 | + return true; |
| 123 | + } |
| 124 | + if (obj == null) { |
| 125 | + return false; |
| 126 | + } |
| 127 | + if (getClass() != obj.getClass()) { |
| 128 | + return false; |
| 129 | + } |
| 130 | + IntentFilterData other = (IntentFilterData) obj; |
| 131 | + if (actionSet == null) { |
| 132 | + if (other.actionSet != null) { |
| 133 | + return false; |
| 134 | + } |
| 135 | + } else if (!actionSet.equals(other.actionSet)) { |
| 136 | + return false; |
| 137 | + } |
| 138 | + if (dataSchemeSet == null) { |
| 139 | + if (other.dataSchemeSet != null) { |
| 140 | + return false; |
| 141 | + } |
| 142 | + } else if (!dataSchemeSet.equals(other.dataSchemeSet)) { |
| 143 | + return false; |
| 144 | + } |
| 145 | + return true; |
| 146 | + } |
| 147 | + } |
89 | 148 | } |
0 commit comments