Skip to content

Commit a11f779

Browse files
Use new dedicated containsElement native method.
1 parent eb89dee commit a11f779

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

objectbox-java/src/main/java/io/objectbox/Property.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,12 @@ private void checkNotStringArray() {
449449
*/
450450
public PropertyQueryCondition<ENTITY> containsElement(String value) {
451451
checkIsStringArray();
452-
return new StringCondition<>(this, Operation.CONTAINS, value);
452+
return new StringCondition<>(this, Operation.CONTAINS_ELEMENT, value);
453453
}
454454

455455
public PropertyQueryCondition<ENTITY> containsElement(String value, StringOrder order) {
456456
checkIsStringArray();
457-
return new StringCondition<>(this, Operation.CONTAINS, value, order);
457+
return new StringCondition<>(this, Operation.CONTAINS_ELEMENT, value, order);
458458
}
459459

460460
private void checkIsStringArray() {

objectbox-java/src/main/java/io/objectbox/query/PropertyQueryConditionImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public enum Operation {
288288
LESS,
289289
LESS_OR_EQUAL,
290290
CONTAINS,
291+
CONTAINS_ELEMENT,
291292
STARTS_WITH,
292293
ENDS_WITH
293294
}
@@ -325,8 +326,10 @@ void applyCondition(QueryBuilder<T> builder) {
325326
builder.lessOrEqual(property, value, order);
326327
break;
327328
case CONTAINS:
328-
// Note: contains used for String[] as well, so do not enforce String type here.
329-
builder.containsNoTypeCheck(property, value, order);
329+
builder.contains(property, value, order);
330+
break;
331+
case CONTAINS_ELEMENT:
332+
builder.containsElement(property, value, order);
330333
break;
331334
case STARTS_WITH:
332335
builder.startsWith(property, value, order);

objectbox-java/src/main/java/io/objectbox/query/QueryBuilder.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ private native long nativeLink(long handle, long storeHandle, int relationOwnerE
182182

183183
private native long nativeContains(long handle, int propertyId, String value, boolean caseSensitive);
184184

185+
private native long nativeContainsElement(long handle, int propertyId, String value, boolean caseSensitive);
186+
185187
private native long nativeStartsWith(long handle, int propertyId, String value, boolean caseSensitive);
186188

187189
private native long nativeEndsWith(long handle, int propertyId, String value, boolean caseSensitive);
@@ -759,7 +761,8 @@ public QueryBuilder<T> contains(Property<T> property, String value, StringOrder
759761
if (String[].class == property.type) {
760762
throw new UnsupportedOperationException("For String[] only containsElement() is supported at this time.");
761763
}
762-
containsNoTypeCheck(property, value, order);
764+
verifyHandle();
765+
checkCombineCondition(nativeContains(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
763766
return this;
764767
}
765768

@@ -770,13 +773,9 @@ public QueryBuilder<T> containsElement(Property<T> property, String value, Strin
770773
if (String[].class != property.type) {
771774
throw new IllegalArgumentException("containsElement is only supported for String[] properties.");
772775
}
773-
containsNoTypeCheck(property, value, order);
774-
return this;
775-
}
776-
777-
void containsNoTypeCheck(Property<T> property, String value, StringOrder order) {
778776
verifyHandle();
779-
checkCombineCondition(nativeContains(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
777+
checkCombineCondition(nativeContainsElement(handle, property.getId(), value, order == StringOrder.CASE_SENSITIVE));
778+
return this;
780779
}
781780

782781
public QueryBuilder<T> startsWith(Property<T> property, String value, StringOrder order) {

0 commit comments

Comments
 (0)