Skip to content

Commit 25176b7

Browse files
authored
DOCSP-33345: Java comments pt. 8 (#477)
* DOCSP-33345: Java comments pt. 8 * small edit * add quotes
1 parent 4831458 commit 25176b7

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

source/includes/fundamentals/code-snippets/Monolight.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fundamentals.monolightcodec;
22

3+
// Defines a custom class that contains fields describing a light
34
// start class
45
public class Monolight {
56
private PowerStatus powerStatus = PowerStatus.OFF;

source/includes/fundamentals/code-snippets/MonolightCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bson.codecs.EncoderContext;
99
import org.bson.codecs.configuration.CodecRegistry;
1010

11+
// Implements the Codec interface by overriding the encode(), decode(), and getEncoderClass() methods
1112
// start class
1213
public class MonolightCodec implements Codec<Monolight>{
1314

@@ -19,6 +20,7 @@ public MonolightCodec(CodecRegistry registry) {
1920
this.integerCodec = registry.get(Integer.class);
2021
}
2122

23+
// Defines an encode() method to convert Monolight enum values to BSON values
2224
@Override
2325
public void encode(BsonWriter writer, Monolight value, EncoderContext encoderContext) {
2426
writer.writeStartDocument();
@@ -29,6 +31,7 @@ public void encode(BsonWriter writer, Monolight value, EncoderContext encoderCon
2931
writer.writeEndDocument();
3032
}
3133

34+
// Defines a decode() method to convert BSON values to Monolight enum values
3235
@Override
3336
public Monolight decode(BsonReader reader, DecoderContext decoderContext) {
3437
Monolight monolight = new Monolight();
@@ -49,6 +52,7 @@ public Monolight decode(BsonReader reader, DecoderContext decoderContext) {
4952
return monolight;
5053
}
5154

55+
// Returns an instance of the Monolight class, since Java cannot infer the class type
5256
@Override
5357
public Class<Monolight> getEncoderClass() {
5458
return Monolight.class;

source/includes/fundamentals/code-snippets/Query.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,51 @@ public static void main(String [] args){
5050
}
5151

5252
private void comparisonFilter(){
53+
// Creates a filter to match documents that have a "qty" value over 7
5354
// begin comparisonFilter
5455
Bson filter = Filters.gt("qty", 7);
56+
57+
// Retrieves documents that match the filter and prints them as JSON
5558
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
5659
// end comparisonFilter
5760
}
5861

5962
private void logicalFilter(){
63+
// Creates a filter to match documents that have a "qty" value less than or equal to 7 and a "color" value of "pink"
6064
// begin logicalFilter
6165
Bson filter = Filters.and(Filters.lte("qty", 5), Filters.ne("color", "pink"));
66+
67+
// Retrieves documents that match the filter and prints them as JSON
6268
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
6369
// end logicalFilter
6470
}
6571

6672
private void elementFilter(){
73+
// Creates a filter to match documents that contain the "rating" field
6774
// begin elementFilter
6875
Bson filter = Filters.exists("rating");
76+
77+
// Retrieves documents that match the filter and prints them as JSON
6978
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
7079
// end elementFilter
7180
}
7281

7382
private void evaluationFilter(){
83+
// Creates a filter to match documents that have a "color" value ending with the letter "k"
7484
// begin evaluationFilter
7585
Bson filter = Filters.regex("color", "k$");
86+
87+
// Retrieves documents that match the filter and prints them as JSON
7688
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
7789
// end evaluationFilter
7890
}
7991

8092
private void arrayFilter(){
93+
// Creates a filter to match documents whose "vendor" values are an array of 3 elements
8194
// begin arrayFilter
8295
Bson filter = Filters.size("vendor", 3);
96+
97+
// Retrieves documents that match the filter and prints them as JSON
8398
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
8499
// end arrayFilter
85100
}

0 commit comments

Comments
 (0)