Skip to content

Commit

Permalink
new test
Browse files Browse the repository at this point in the history
update methods to take Object instead of typed overloads
  • Loading branch information
evanchooly committed Jun 11, 2024
1 parent 6698c5d commit 3cee096
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 45 deletions.
54 changes: 9 additions & 45 deletions core/src/main/java/dev/morphia/query/filters/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import dev.morphia.aggregation.expressions.impls.Expression;
import dev.morphia.query.Type;

import org.bson.BsonBinary;
import org.bson.Document;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -49,65 +48,30 @@ public static Filter and(Filter... filters) {
return new LogicalFilter("$and", filters);
}

/**
* Matches numeric or binary values in which a set of bit positions all have a value of 0.
*
* @param field the field to check
* @param positions the value to check
* @return the filter
* @query.filter $bitsAllClear
*/
public static Filter bitsAllClear(String field, int[] positions) {
return new Filter("$bitsAllClear", field, positions);
}

/**
* Matches numeric or binary values in which a set of bit positions all have a value of 0.
*
* @param field the field to check
* @param bitMask the numeric bitmask to use
* @return the filter
* @query.filter $bitsAllClear
*/
public static Filter bitsAllClear(String field, int bitMask) {
return new Filter("$bitsAllClear", field, bitMask);
}

/**
* Matches numeric or binary values in which a set of bit positions all have a value of 0.
*
* @param field the field to check
* @param data the data to use
* @param val the value to check
* @return the filter
* @query.filter $bitsAllClear
* @since 3.0
*/
public static Filter bitsAllClear(String field, byte[] data) {
return new Filter("$bitsAllClear", field, new BsonBinary(data));
}

/**
* Matches numeric or binary values in which a set of bit positions all have a value of 1.
*
* @param field the field to check
* @param bitMask the numeric bitmask to use
* @return the filter
* @query.filter $bitsAllSet
* @since 3.0 changed to take a plain Object instead of overloading
*/
public static Filter bitsAllSet(String field, int bitMask) {
return new Filter("$bitsAllSet", field, bitMask);
public static Filter bitsAllClear(String field, Object val) {
return new Filter("$bitsAllClear", field, val);
}

/**
* Matches numeric or binary values in which a set of bit positions all have a value of 1.
*
* @param field the field to check
* @param positions the value to check
* @param field the field to check
* @param val the value to check
* @return the filter
* @query.filter $bitsAllSet
* @since 3.0 changed to take a plain Object instead of overloading
*/
public static Filter bitsAllSet(String field, int[] positions) {
return new Filter("$bitsAllSet", field, positions);
public static Filter bitsAllSet(String field, Object val) {
return new Filter("$bitsAllSet", field, val);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.morphia.test.query.filters;

import dev.morphia.test.ServerVersion;

import org.testng.annotations.Test;

import static dev.morphia.query.filters.Filters.bitsAllSet;

public class TestBitsAllSet extends FilterTest {
@Test
public void testExample1() {
testQuery(ServerVersion.ANY, false, true, (query) -> query.filter(
bitsAllSet("a", new int[] { 1, 5 })));
}

@Test
public void testExample2() {
testQuery(ServerVersion.ANY, false, true, (query) -> query.filter(
bitsAllSet("a", 50)));
}

@Test
public void testExample3() {
testQuery(ServerVersion.ANY, false, true, (query) -> query.filter(
bitsAllSet("a", new byte[] { 48 })));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db.collection.find( { a: { $bitsAllSet: [ 1, 5 ] } } )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ _id: 1, a: 54, binaryValueofA: "00110110" },
{ _id: 2, a: 20, binaryValueofA: "00010100" },
{ _id: 3, a: 20.0, binaryValueofA: "00010100" },
{ _id: 4, a: BinData(0, "Zg=="), binaryValueofA: "01100110" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" }
{ "_id" : 4, "a" : BinData(0,"Zg=="), "binaryValueofA" : "01100110" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bit Position Array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db.collection.find( { a: { $bitsAllSet: 50 } } )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ _id: 1, a: 54, binaryValueofA: "00110110" },
{ _id: 2, a: 20, binaryValueofA: "00010100" },
{ _id: 3, a: 20.0, binaryValueofA: "00010100" },
{ _id: 4, a: BinData(0, "Zg=="), binaryValueofA: "01100110" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "_id" : 1, "a" : 54, "binaryValueofA" : "00110110" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Integer Bitmask
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db.collection.find( { a: { $bitsAllSet: BinData(0, "MA==") } } )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ _id: 1, a: 54, binaryValueofA: "00110110" },
{ _id: 2, a: 20, binaryValueofA: "00010100" },
{ _id: 3, a: 20.0, binaryValueofA: "00010100" },
{ _id: 4, a: BinData(0, "Zg=="), binaryValueofA: "01100110" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ _id: 1, a: 54, binaryValueofA: "00110110" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BinData Bitmask

0 comments on commit 3cee096

Please sign in to comment.