Skip to content

Commit

Permalink
Merge pull request #265 from entur/cleanup-code-smells
Browse files Browse the repository at this point in the history
Cleanup code smells
  • Loading branch information
testower authored Sep 20, 2023
2 parents ad76781 + c47b79b commit 3fc5ef1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ public void updateEntityCaches(
stationsUpdater.addOrUpdateStations(feedProvider, delivery, oldDelivery);
}

if (delivery.getGeofencingZones() != null) {
if (
if (
delivery.getGeofencingZones() != null &&
(
feedProvider.getExcludeFeeds() == null ||
!feedProvider.getExcludeFeeds().contains(GBFSFeedName.GeofencingZones)
) {
geofencingZonesUpdater.addOrUpdateGeofencingZones(
feedProvider,
delivery.getGeofencingZones()
);
}
)
) {
geofencingZonesUpdater.addOrUpdateGeofencingZones(
feedProvider,
delivery.getGeofencingZones()
);
}
}

Expand All @@ -89,13 +90,14 @@ private boolean canUpdateVehicles(GbfsDelivery delivery, FeedProvider feedProvid
}

private boolean canUpdateStations(GbfsDelivery delivery, FeedProvider feedProvider) {
if (feedProvider.getExcludeFeeds() != null) {
if (
if (
feedProvider.getExcludeFeeds() != null &&
(
feedProvider.getExcludeFeeds().contains(GBFSFeedName.StationInformation) ||
feedProvider.getExcludeFeeds().contains(GBFSFeedName.StationStatus)
) {
return false;
}
)
) {
return false;
}

return (
Expand Down
33 changes: 11 additions & 22 deletions src/main/java/org/entur/lamassu/metrics/MetricsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,21 @@ public class MetricsService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

private final AtomicInteger vehicleEntityCount = new AtomicInteger();
private final Gauge vehicleEntityCountGauge;
private final AtomicInteger stationEntityCount = new AtomicInteger();
private final Gauge stationEntityCountGauge;

public MetricsService(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
vehicleEntityCountGauge =
Gauge
.builder(
"app.lamassu.entity.count",
vehicleEntityCount,
AtomicInteger::doubleValue
)
.strongReference(true)
.tags(List.of(Tag.of(LABEL_ENTITY, ENTITY_VEHICLE)))
.register(meterRegistry);
stationEntityCountGauge =
Gauge
.builder(
"app.lamassu.entity.count",
stationEntityCount,
AtomicInteger::doubleValue
)
.strongReference(true)
.tags(List.of(Tag.of(LABEL_ENTITY, ENTITY_STATION)))
.register(meterRegistry);
Gauge
.builder("app.lamassu.entity.count", vehicleEntityCount, AtomicInteger::doubleValue)
.strongReference(true)
.tags(List.of(Tag.of(LABEL_ENTITY, ENTITY_VEHICLE)))
.register(meterRegistry);

Gauge
.builder("app.lamassu.entity.count", stationEntityCount, AtomicInteger::doubleValue)
.strongReference(true)
.tags(List.of(Tag.of(LABEL_ENTITY, ENTITY_STATION)))
.register(meterRegistry);
}

public void registerSubscriptionSetup(FeedProvider feedProvider, boolean success) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/entur/lamassu/util/SpatialIndexIdUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.entur.lamassu.cache.VehicleSpatialIndexId;
import org.entur.lamassu.model.entities.Station;
import org.entur.lamassu.model.entities.Vehicle;
import org.entur.lamassu.model.entities.VehicleTypeAvailability;
import org.entur.lamassu.model.provider.FeedProvider;

public class SpatialIndexIdUtil {
Expand Down Expand Up @@ -57,8 +56,8 @@ public static StationSpatialIndexId createStationSpatialIndexId(
// Note: in case no validation is activated, this issue would slip
// silently. On the other hand, logging it here for every station would
// be overwhelming...
id.setAvailableFormFactors(Collections.EMPTY_LIST);
id.setAvailablePropulsionTypes(Collections.EMPTY_LIST);
id.setAvailableFormFactors(Collections.emptyList());
id.setAvailablePropulsionTypes(Collections.emptyList());
}

return id;
Expand Down

0 comments on commit 3fc5ef1

Please sign in to comment.