Search in sources :

Example 1 with CraftPropertyName

use of au.gov.amsa.ais.rx.CraftPropertyName in project risky by amsa-code.

the class OperatorCraftProperty method call.

@Override
public Subscriber<? super Timestamped<? extends AisMessage>> call(final Subscriber<? super CraftProperty> child) {
    return new Subscriber<Timestamped<? extends AisMessage>>(child) {

        @Override
        public void onCompleted() {
            if (!isUnsubscribed())
                child.onCompleted();
        }

        @Override
        public void onError(Throwable e) {
            if (!isUnsubscribed())
                child.onError(e);
        }

        @SuppressWarnings("unchecked")
        @Override
        public void onNext(Timestamped<? extends AisMessage> m) {
            if (m.message() instanceof AisShipStaticA) {
                handleShipStatic((Timestamped<AisShipStaticA>) m, child);
            } else if (m.message() instanceof AisPositionBExtended)
                handleAisPositionBExtended((Timestamped<AisPositionBExtended>) m, child);
        }

        private void handleShipStatic(Timestamped<AisShipStaticA> m, Subscriber<? super CraftProperty> child) {
            handleProperty(child, m, CraftPropertyName.CALLSIGN, m.message().getCallsign());
            handleProperty(child, m, CraftPropertyName.DESTINATION, m.message().getDestination());
            handleProperty(child, m, CraftPropertyName.DIMENSION_A, m.message().getDimensionA());
            handleProperty(child, m, CraftPropertyName.DIMENSION_B, m.message().getDimensionB());
            handleProperty(child, m, CraftPropertyName.DIMENSION_C, m.message().getDimensionC());
            handleProperty(child, m, CraftPropertyName.DIMENSION_D, m.message().getDimensionD());
            handleProperty(child, m, CraftPropertyName.IMO_NUMBER, m.message().getImo());
            handleProperty(child, m, CraftPropertyName.LENGTH_METRES, m.message().getLengthMetres());
            handleProperty(child, m, CraftPropertyName.DRAUGHT_METRES, m.message().getMaximumPresentStaticDraughtMetres());
            handleProperty(child, m, CraftPropertyName.NAME, m.message().getName());
            handleProperty(child, m, CraftPropertyName.SHIP_TYPE, m.message().getShipType());
            handleProperty(child, m, CraftPropertyName.WIDTH_METRES, m.message().getWidthMetres());
        }

        private void handleAisPositionBExtended(Timestamped<AisPositionBExtended> m, Subscriber<? super CraftProperty> child) {
            handleProperty(child, m, CraftPropertyName.DIMENSION_A, m.message().getDimensionA());
            handleProperty(child, m, CraftPropertyName.DIMENSION_B, m.message().getDimensionB());
            handleProperty(child, m, CraftPropertyName.DIMENSION_C, m.message().getDimensionC());
            handleProperty(child, m, CraftPropertyName.DIMENSION_D, m.message().getDimensionD());
            handleProperty(child, m, CraftPropertyName.LENGTH_METRES, m.message().getLengthMetres());
            handleProperty(child, m, CraftPropertyName.NAME, m.message().getName());
            handleProperty(child, m, CraftPropertyName.SHIP_TYPE, m.message().getShipType());
            handleProperty(child, m, CraftPropertyName.WIDTH_METRES, m.message().getWidthMetres());
        }

        private <R extends AisMessage & HasMmsi> void handleProperty(Subscriber<? super CraftProperty> child, Timestamped<R> m, CraftPropertyName name, Object value) {
            if (!isUnsubscribed() && value != null)
                child.onNext(new CraftProperty(new Mmsi(m.message().getMmsi()), name, value.toString(), m.time()));
        }
    };
}
Also used : HasMmsi(au.gov.amsa.ais.HasMmsi) Mmsi(au.gov.amsa.ais.rx.Mmsi) Subscriber(rx.Subscriber) Timestamped(au.gov.amsa.ais.Timestamped) CraftPropertyName(au.gov.amsa.ais.rx.CraftPropertyName) AisShipStaticA(au.gov.amsa.ais.message.AisShipStaticA) AisMessage(au.gov.amsa.ais.AisMessage) AisPositionBExtended(au.gov.amsa.ais.message.AisPositionBExtended) CraftProperty(au.gov.amsa.ais.rx.CraftProperty) HasMmsi(au.gov.amsa.ais.HasMmsi)

Aggregations

AisMessage (au.gov.amsa.ais.AisMessage)1 HasMmsi (au.gov.amsa.ais.HasMmsi)1 Timestamped (au.gov.amsa.ais.Timestamped)1 AisPositionBExtended (au.gov.amsa.ais.message.AisPositionBExtended)1 AisShipStaticA (au.gov.amsa.ais.message.AisShipStaticA)1 CraftProperty (au.gov.amsa.ais.rx.CraftProperty)1 CraftPropertyName (au.gov.amsa.ais.rx.CraftPropertyName)1 Mmsi (au.gov.amsa.ais.rx.Mmsi)1 Subscriber (rx.Subscriber)1