Skip to content

Commit

Permalink
chore: rm assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Nov 6, 2024
1 parent 4264338 commit fa1a1e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.invertase.firebase.common.ReactNativeFirebaseEventEmitter;
import io.invertase.firebase.common.ReactNativeFirebaseModule;
import java.util.ArrayList;
import java.util.Objects;

public class ReactNativeFirebaseFirestoreCollectionModule extends ReactNativeFirebaseModule {
private static final String SERVICE_NAME = "FirestoreCollection";
Expand Down Expand Up @@ -221,22 +222,18 @@ public void aggregateQuery(

for (int i = 0; i < aggregateQueries.size(); i++) {
ReadableMap aggregateQuery = aggregateQueries.getMap(i);

String aggregateType = aggregateQuery.getString("aggregateType");
String fieldPath = aggregateQuery.getString("field");

assert aggregateType != null;
switch (aggregateType) {
switch (Objects.requireNonNull(aggregateType)) {
case "count":
aggregateFields.add(AggregateField.count());
break;
case "sum":
assert fieldPath != null;
aggregateFields.add(AggregateField.sum(fieldPath));
aggregateFields.add(AggregateField.sum(Objects.requireNonNull(fieldPath)));
break;
case "average":
assert fieldPath != null;
aggregateFields.add(AggregateField.average(fieldPath));
aggregateFields.add(AggregateField.average(Objects.requireNonNull(fieldPath)));
break;
default:
throw new Error("Invalid AggregateType: " + aggregateType);
Expand All @@ -260,23 +257,18 @@ public void aggregateQuery(
String aggType = aggQuery.getString("aggregateType");
String field = aggQuery.getString("field");
String key = aggQuery.getString("key");
assert key != null;
assert aggType != null;
switch (aggType) {

switch (Objects.requireNonNull(aggType)) {
case "count":
result.putDouble(key, Long.valueOf(snapshot.getCount()).doubleValue());
result.putDouble(Objects.requireNonNull(key), Long.valueOf(snapshot.getCount()).doubleValue());
break;
case "sum":
assert field != null;
Number sum = (Number) snapshot.get(sum(field));
assert sum != null;
result.putDouble(key, sum.doubleValue());
Number sum = (Number) snapshot.get(sum(Objects.requireNonNull(field)));
result.putDouble(Objects.requireNonNull(key), Objects.requireNonNull(sum).doubleValue());
break;
case "average":
assert field != null;
Number average = snapshot.get(average(field));
assert average != null;
result.putDouble(key, average.doubleValue());
Number average = snapshot.get(average(Objects.requireNonNull(field)));
result.putDouble(Objects.requireNonNull(key), Objects.requireNonNull(average).doubleValue());
break;
default:
throw new Error("Invalid AggregateType: " + aggType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ - (void)invalidate {
for (NSDictionary *aggregateQuery in aggregateQueries) {
NSString *aggregateType = aggregateQuery[@"aggregateType"];
NSString *fieldPath = aggregateQuery[@"field"];
assert(aggregateType);
assert(fieldPath);

if ([aggregateType isEqualToString:@"count"]) {
[aggregateFields addObject:[FIRAggregateField aggregateFieldForCount]];
Expand Down Expand Up @@ -269,7 +267,6 @@ - (void)invalidate {
NSString *aggregateType = aggregateQuery[@"aggregateType"];
NSString *fieldPath = aggregateQuery[@"field"];
NSString *key = aggregateQuery[@"key"];
assert(key);

if ([aggregateType isEqualToString:@"count"]) {
snapshotMap[key] = snapshot.count;
Expand Down

0 comments on commit fa1a1e8

Please sign in to comment.