Skip to content

Commit 9f2312b

Browse files
committed
Merge QPid ProtonJ2 with upstream
1 parent 7f6cf97 commit 9f2312b

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/main/qpid/org/apache/qpid/protonj2/client/SourceOptions.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import java.util.Arrays;
2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import java.util.Objects;
2223

2324
import org.apache.qpid.protonj2.client.impl.ClientDeliveryState;
25+
import org.apache.qpid.protonj2.types.DescribedType;
2426

2527
/**
2628
* Options type that carries configuration for link Source types.
@@ -99,6 +101,32 @@ public SourceOptions filters(Map<String, Object> filters) {
99101
return self();
100102
}
101103

104+
/**
105+
* Adds the given named filter into the map of filters (one will be created if not already set).
106+
* <p>
107+
* If a previous filters {@link Map} was assigned this new filter instance will be assigned
108+
* into that existing map, it is not cleared or reallocated. The descriptor should either be
109+
* an Symbol or UnsignedLong that aligns with the filters definition being used.
110+
*
111+
* @param name
112+
* The name to use when adding the described filter to the filters {@link Map}.
113+
* @param descriptor
114+
* The descriptor used for the {@link DescribedType} that will carry the filter.
115+
* @param filter
116+
* The filter value to assign to the filter {@link DescribedType}.
117+
*
118+
* @return this {@link SourceOptions} instance.
119+
*/
120+
public SourceOptions addFilter(String name, Object descriptor, Object filter) {
121+
if (filters == null) {
122+
filters = new HashMap<>();
123+
}
124+
125+
filters.put(name, new FilterDescribedType(descriptor, filter));
126+
127+
return self();
128+
}
129+
102130
/**
103131
* @return the configured default outcome as a {@link DeliveryState} instance.
104132
*/
@@ -139,4 +167,54 @@ public SourceOptions outcomes(DeliveryState.Type... outcomes) {
139167
SourceOptions self() {
140168
return this;
141169
}
170+
171+
private static class FilterDescribedType implements DescribedType {
172+
173+
private final Object descriptor;
174+
private final Object described;
175+
176+
public FilterDescribedType(Object descriptor, Object described) {
177+
this.descriptor = descriptor;
178+
this.described = described;
179+
}
180+
181+
@Override
182+
public Object getDescriptor() {
183+
return descriptor;
184+
}
185+
186+
@Override
187+
public Object getDescribed() {
188+
return this.described;
189+
}
190+
191+
@Override
192+
public String toString() {
193+
return "FilterDescribedType{ descriptor:" + descriptor + ", described:" + described + " }";
194+
}
195+
196+
@Override
197+
public int hashCode() {
198+
return Objects.hash(described, descriptor);
199+
}
200+
201+
@Override
202+
public boolean equals(Object target) {
203+
if (this == target) {
204+
return true;
205+
}
206+
207+
if (target == null) {
208+
return false;
209+
}
210+
211+
if (!(target instanceof DescribedType)) {
212+
return false;
213+
}
214+
215+
final DescribedType other = (DescribedType) target;
216+
217+
return Objects.equals(descriptor, other.getDescriptor()) && Objects.equals(described, other.getDescribed());
218+
}
219+
}
142220
}

0 commit comments

Comments
 (0)