Skip to content

Commit eb71593

Browse files
author
Justin Lee
committed
1 parent cb68bf5 commit eb71593

File tree

11 files changed

+1139
-11
lines changed

11 files changed

+1139
-11
lines changed

driver-core/src/main/com/mongodb/client/model/Aggregates.java

Lines changed: 331 additions & 8 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2016 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.client.model;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import static java.util.Arrays.asList;
23+
24+
/**
25+
* The options for a $bucketAuto aggregation pipeline stage
26+
*
27+
* @mongodb.driver.manual reference/operator/aggregation/bucketAuto/ $bucketAuto
28+
* @mongodb.server.release 3.4
29+
* @since 3.4
30+
*/
31+
public class BucketAutoOptions {
32+
private List<BsonField> output;
33+
private BucketGranularity granularity;
34+
35+
/**
36+
* @return the granularity of the bucket definitions
37+
*/
38+
public BucketGranularity getGranularity() {
39+
return granularity;
40+
}
41+
42+
/**
43+
* @return the output document definition
44+
*/
45+
public List<BsonField> getOutput() {
46+
return output == null ? null : new ArrayList<BsonField>(output);
47+
}
48+
49+
/**
50+
* Specifies the granularity of the bucket definitions.
51+
*
52+
* @param granularity the granularity of the bucket definitions
53+
* @return this
54+
* @link the <a href="https://en.wikipedia.org/wiki/Preferred_number">wiki page</a> on preferred numbers
55+
* @see BucketGranularity
56+
*/
57+
public BucketAutoOptions granularity(final BucketGranularity granularity) {
58+
this.granularity = granularity;
59+
return this;
60+
}
61+
62+
/**
63+
* The definition of the output document in each bucket
64+
*
65+
* @param output the output document definition
66+
* @return this
67+
*/
68+
public BucketAutoOptions output(final BsonField... output) {
69+
this.output = asList(output);
70+
return this;
71+
}
72+
73+
/**
74+
* The definition of the output document in each bucket
75+
*
76+
* @param output the output document definition
77+
* @return this
78+
*/
79+
public BucketAutoOptions output(final List<BsonField> output) {
80+
this.output = output;
81+
return this;
82+
}
83+
84+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2016 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.client.model;
18+
19+
/**
20+
* Granularity values for automatic bucketing.
21+
*
22+
* @mongodb.driver.manual reference/operator/aggregation/bucketAuto/ $bucketAuto
23+
* @mongodb.server.release 3.4
24+
* @link <a href="https://en.wikipedia.org/wiki/Preferred_number">Preferred numbers</a>
25+
* @since 3.4
26+
*/
27+
public enum BucketGranularity {
28+
R5,
29+
R10,
30+
R20,
31+
R40,
32+
R80,
33+
SERIES_125("1-2-5"),
34+
E6,
35+
E12,
36+
E24,
37+
E48,
38+
E96,
39+
E192,
40+
POWERSOF2;
41+
42+
private final String value;
43+
44+
BucketGranularity() {
45+
value = name();
46+
}
47+
48+
BucketGranularity(final String name) {
49+
value = name;
50+
}
51+
52+
/**
53+
* Tries find the enum instance for the given value
54+
*
55+
* @param value the value to search for
56+
* @return the enum instance
57+
*/
58+
public static BucketGranularity fromString(final String value) {
59+
for (BucketGranularity granularity : BucketGranularity.values()) {
60+
if (granularity.getValue().equals(value)) {
61+
return granularity;
62+
}
63+
}
64+
throw new IllegalArgumentException("No Granularity exists for the value " + value);
65+
}
66+
67+
/**
68+
* Returns the display as defined in the preferred number article
69+
*
70+
* @return the display name
71+
*/
72+
public String getValue() {
73+
return value;
74+
}
75+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2016 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.client.model;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import static java.util.Arrays.asList;
23+
24+
/**
25+
* The options for a $bucket aggregation pipeline stage
26+
*
27+
* @mongodb.driver.manual reference/operator/aggregation/bucketAuto/ $bucket
28+
* @mongodb.server.release 3.4
29+
* @since 3.4
30+
*/
31+
public class BucketOptions {
32+
private Object defaultBucket;
33+
private List<BsonField> output;
34+
35+
/**
36+
* The name of the default bucket for values outside the defined buckets
37+
*
38+
* @param name the bucket value
39+
* @return this
40+
*/
41+
public BucketOptions defaultBucket(final Object name) {
42+
defaultBucket = name;
43+
return this;
44+
}
45+
46+
/**
47+
* @return the default bucket value
48+
*/
49+
public Object getDefaultBucket() {
50+
return defaultBucket;
51+
}
52+
53+
/**
54+
* @return the output document definition
55+
*/
56+
public List<BsonField> getOutput() {
57+
return output == null ? null : new ArrayList<BsonField>(output);
58+
}
59+
60+
/**
61+
* The definition of the output document in each bucket
62+
*
63+
* @param output the output document definition
64+
* @return this
65+
*/
66+
public BucketOptions output(final BsonField... output) {
67+
this.output = asList(output);
68+
return this;
69+
}
70+
71+
/**
72+
* The definition of the output document in each bucket
73+
*
74+
* @param output the output document definition
75+
* @return this
76+
*/
77+
public BucketOptions output(final List<BsonField> output) {
78+
this.output = output;
79+
return this;
80+
}
81+
82+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2016 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.client.model;
18+
19+
import org.bson.conversions.Bson;
20+
21+
import java.util.List;
22+
23+
import static java.util.Arrays.asList;
24+
25+
/**
26+
* Defines a Facet for use in $facet pipeline stages.
27+
*
28+
* @mongodb.driver.manual reference/operator/aggregation/facet/ $facet
29+
* @mongodb.server.release 3.4
30+
* @since 3.4
31+
*/
32+
public class Facet {
33+
private final String name;
34+
private final List<? extends Bson> pipeline;
35+
36+
/**
37+
* @param name the name of this facet
38+
* @param pipeline the facet definition pipeline
39+
*/
40+
public Facet(final String name, final List<? extends Bson> pipeline) {
41+
this.name = name;
42+
this.pipeline = pipeline;
43+
}
44+
45+
/**
46+
* @param name the name of this facet
47+
* @param pipeline the facet definition pipeline
48+
*/
49+
public Facet(final String name, final Bson... pipeline) {
50+
this(name, asList(pipeline));
51+
}
52+
53+
/**
54+
* @return the facet name
55+
*/
56+
public String getName() {
57+
return name;
58+
}
59+
60+
/**
61+
* @return the pipeline definition
62+
*/
63+
public List<? extends Bson> getPipeline() {
64+
return pipeline;
65+
}
66+
}

0 commit comments

Comments
 (0)