Skip to content

Commit 41dd100

Browse files
committed
Fix NPE stuff
1 parent 8af75ce commit 41dd100

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

udmis/src/main/java/com/google/bos/udmi/service/access/ClearBladeIotAccessProvider.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,13 @@ private HashMap<String, CloudModel> fetchDevices(String deviceRegistryId,
440440
response.getDevicesList().stream().map(ClearBladeIotAccessProvider::convertPartial)
441441
.collect(toMap(Entry::getKey, Entry::getValue));
442442
List<String> exists = responseMap.keySet().stream().filter(collect::containsKey).toList();
443-
ifNotTrueThen(exists.isEmpty(), () -> ifNotNullThen(progress,
444-
p -> p.accept("Found duplicate device entries: " + exists)));
443+
ifNotTrueThen(exists.isEmpty(),
444+
() -> progress.accept("Found duplicate device entries: " + exists));
445445

446446
collect.putAll(responseMap);
447447
pageToken = response.getNextPageToken();
448448
queryCount++;
449-
ifNotNullThen(progress, p -> p.accept(getProgressMessage(collect, gatewayListOptions)));
449+
progress.accept(getProgressMessage(collect, gatewayListOptions));
450450
debug(format("fetchDevices %s #%d found %d total %d more %s", deviceRegistryId,
451451
queryCount, responseMap.size(), collect.size(), pageToken != null));
452452
} while (pageToken != null);
@@ -596,10 +596,11 @@ private GatewayModel makeGatewayModel(HashMap<String, CloudModel> boundDevices)
596596

597597
@Override
598598
public CloudModel modelDevice(String registryId, String deviceId, CloudModel cloudModel,
599-
Consumer<String> progress) {
599+
Consumer<String> maybeProgress) {
600600
String devicePath = getDeviceName(registryId, deviceId);
601601
Operation operation = cloudModel.operation;
602602
Resource_type type = ofNullable(cloudModel.resource_type).orElse(Resource_type.DEVICE);
603+
Consumer<String> progress = ofNullable(maybeProgress).orElse(this::bitBucket);
603604
checkState(type == DEVICE || type == GATEWAY, "unexpected resource type " + type);
604605
try {
605606
Device device = convert(cloudModel, deviceId);
@@ -617,6 +618,10 @@ public CloudModel modelDevice(String registryId, String deviceId, CloudModel clo
617618
}
618619
}
619620

621+
private void bitBucket(String s) {
622+
// Do nothing, just drop the messages on the floor.
623+
}
624+
620625
private CloudModel getReply(String registryId, String deviceId, CloudModel request,
621626
String numId) {
622627
CloudModel reply = new CloudModel();
@@ -739,22 +744,18 @@ private void bindDevicesGateways(String registryId, Set<String> gatewayIds,
739744
String opCode = toBind ? "Binding" : "Unbinding";
740745
info("%s %s: gateways %s devices %s", opCode, registryId, gatewayIds, deviceIds);
741746
AtomicInteger opCount = new AtomicInteger(0);
742-
ifNotNullThen(progress,
743-
p -> p.accept(format("%s %d devices on %d gateways", opCode, deviceIds.size(),
744-
gatewayIds.size())));
747+
progress.accept(format("%s %d devices on %d gateways", opCode, deviceIds.size(),
748+
gatewayIds.size()));
745749
gatewayIds.forEach(gatewayId -> {
746750
deviceIds.forEach(deviceId -> {
747-
// ifTrueThen(opCount.incrementAndGet() % OP_PROGRESS_BATCH_SIZE == 0,
748-
// () -> ifNotNullThen(progress,
749-
// p -> p.accept(format("%s %d devices...", opCode, opCount.get()))));
750-
ifNotNullThen(progress, p -> p.accept(format("%s %s from/to %s", opCode, deviceId, gatewayId)));
751+
progress.accept(format("%s %s from/to %s", opCode, deviceId, gatewayId));
751752
ifTrueThen(toBind,
752753
() -> bindDevice(registryId, gatewayId, deviceId),
753754
() -> unbindDevice(registryId, gatewayId, deviceId));
754755
});
755756
});
756-
ifTrueThen(opCount.get() > 0, () -> ifNotNullThen(progress, p -> p.accept(
757-
format("Completed binding %d devices.", opCount.get()))));
757+
ifTrueThen(opCount.get() > 0, () -> progress.accept(
758+
format("Completed binding %d devices.", opCount.get())));
758759
}
759760

760761
private void unbindDevice(String registryId, String gatewayId, String proxyId) {
@@ -923,7 +924,8 @@ public boolean isEnabled() {
923924
}
924925

925926
@Override
926-
public CloudModel listDevices(String registryId, Consumer<String> progress) {
927+
public CloudModel listDevices(String registryId, Consumer<String> maybeProgress) {
928+
Consumer<String> progress = ofNullable(maybeProgress).orElse(this::bitBucket);
927929
return listRegistryDevices(registryId, null, progress);
928930
}
929931

0 commit comments

Comments
 (0)