-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add builders for percentile and median accumulators/window functions (#…
- Loading branch information
Showing
13 changed files
with
661 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
driver-core/src/main/com/mongodb/client/model/ApproximateQuantileMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.client.model; | ||
|
||
import com.mongodb.annotations.Sealed; | ||
|
||
|
||
/** | ||
* @see QuantileMethod#approximate() | ||
* @since 4.10 | ||
* @mongodb.server.release 7.0 | ||
*/ | ||
@Sealed | ||
public interface ApproximateQuantileMethod extends QuantileMethod { | ||
} | ||
|
76 changes: 76 additions & 0 deletions
76
driver-core/src/main/com/mongodb/client/model/QuantileMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.client.model; | ||
|
||
import com.mongodb.annotations.Sealed; | ||
import org.bson.BsonString; | ||
import org.bson.BsonValue; | ||
|
||
import static com.mongodb.assertions.Assertions.notNull; | ||
|
||
/** | ||
* This interface represents a quantile method used in quantile accumulators of the {@code $group} and | ||
* {@code $setWindowFields} stages. | ||
* <p> | ||
* It provides methods for creating and converting quantile methods to {@link BsonValue}. | ||
* </p> | ||
* | ||
* @see Accumulators#percentile(String, Object, Object, QuantileMethod) | ||
* @see Accumulators#median(String, Object, QuantileMethod) | ||
* @see WindowOutputFields#percentile(String, Object, Object, QuantileMethod, Window) | ||
* @see WindowOutputFields#median(String, Object, QuantileMethod, Window) | ||
* @since 4.10 | ||
* @mongodb.server.release 7.0 | ||
*/ | ||
@Sealed | ||
public interface QuantileMethod { | ||
/** | ||
* Returns a {@link QuantileMethod} instance representing the "approximate" quantile method. | ||
* | ||
* @return The requested {@link QuantileMethod}. | ||
*/ | ||
static ApproximateQuantileMethod approximate() { | ||
return new QuantileMethodBson(new BsonString("approximate")); | ||
} | ||
|
||
/** | ||
* Creates a {@link QuantileMethod} from a {@link BsonValue} in situations when there is no builder method | ||
* that better satisfies your needs. | ||
* This method cannot be used to validate the syntax. | ||
* <p> | ||
* <i>Example</i><br> | ||
* The following code creates two functionally equivalent {@link QuantileMethod}s, | ||
* though they may not be {@linkplain Object#equals(Object) equal}. | ||
* <pre>{@code | ||
* QuantileMethod method1 = QuantileMethod.approximate(); | ||
* QuantileMethod method2 = QuantileMethod.of(new BsonString("approximate")); | ||
* }</pre> | ||
* | ||
* @param method A {@link BsonValue} representing the required {@link QuantileMethod}. | ||
* @return The requested {@link QuantileMethod}. | ||
*/ | ||
static QuantileMethod of(final BsonValue method) { | ||
notNull("method", method); | ||
return new QuantileMethodBson(method); | ||
} | ||
|
||
/** | ||
* Converts this object to {@link BsonValue}. | ||
* | ||
* @return A {@link BsonValue} representing this {@link QuantileMethod}. | ||
*/ | ||
BsonValue toBsonValue(); | ||
} |
50 changes: 50 additions & 0 deletions
50
driver-core/src/main/com/mongodb/client/model/QuantileMethodBson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.client.model; | ||
|
||
import org.bson.BsonValue; | ||
|
||
import java.util.Objects; | ||
|
||
final class QuantileMethodBson implements ApproximateQuantileMethod { | ||
private final BsonValue bsonValue; | ||
|
||
QuantileMethodBson(final BsonValue bsonValue) { | ||
this.bsonValue = bsonValue; | ||
} | ||
|
||
@Override | ||
public BsonValue toBsonValue() { | ||
return bsonValue; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
QuantileMethodBson that = (QuantileMethodBson) o; | ||
return Objects.equals(bsonValue, that.bsonValue); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(bsonValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.