@Test public void createOrUpdateAreaOfInterest() { safeAction( () -> { final ChannelAddress channel = new ChannelAddress( 1, 0 ); final String filter1 = ValueUtil.randomString(); final String filter2 = ValueUtil.randomString(); final AreaOfInterestService service = AreaOfInterestService.create( null ); final AreaOfInterest areaOfInterest1 = service.createOrUpdateAreaOfInterest( channel, filter1 ); assertEquals( areaOfInterest1.getAddress(), channel ); assertEquals( areaOfInterest1.getFilter(), filter1 ); assertEquals( service.findAreaOfInterestByAddress( channel ), areaOfInterest1 ); assertEquals( service.getAreasOfInterest().size(), 1 ); final AreaOfInterest areaOfInterest2 = service.createOrUpdateAreaOfInterest( channel, filter1 ); assertEquals( areaOfInterest2.getAddress(), channel ); assertEquals( areaOfInterest2.getFilter(), filter1 ); assertEquals( areaOfInterest1, areaOfInterest2 ); assertEquals( service.findAreaOfInterestByAddress( channel ), areaOfInterest2 ); assertEquals( service.getAreasOfInterest().size(), 1 ); final AreaOfInterest subscription3 = service.createOrUpdateAreaOfInterest( channel, filter2 ); assertEquals( subscription3.getAddress(), channel ); assertEquals( subscription3.getFilter(), filter2 ); assertEquals( areaOfInterest1, subscription3 ); assertEquals( service.findAreaOfInterestByAddress( channel ), subscription3 ); assertEquals( service.getAreasOfInterest().size(), 1 ); } ); }
@Nonnull AreaOfInterest createOrUpdateAreaOfInterest( @Nonnull final ChannelAddress address, @Nullable final Object filter ) { final AreaOfInterest areaOfInterest = findAreaOfInterestByAddress( address ); if ( null != areaOfInterest ) { if ( !FilterUtil.filtersEqual( areaOfInterest.getFilter(), filter ) ) { areaOfInterest.setFilter( filter ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestFilterUpdatedEvent( areaOfInterest ) ); } } return areaOfInterest; } else { final AreaOfInterest newAreaOfInterest = AreaOfInterest.create( Replicant.areZonesEnabled() ? getReplicantContext() : null, address, filter ); attach( newAreaOfInterest ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestCreatedEvent( newAreaOfInterest ) ); } return newAreaOfInterest; } }
AreaOfInterestService extends ReplicantService { @Nonnull AreaOfInterest createOrUpdateAreaOfInterest( @Nonnull final ChannelAddress address, @Nullable final Object filter ) { final AreaOfInterest areaOfInterest = findAreaOfInterestByAddress( address ); if ( null != areaOfInterest ) { if ( !FilterUtil.filtersEqual( areaOfInterest.getFilter(), filter ) ) { areaOfInterest.setFilter( filter ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestFilterUpdatedEvent( areaOfInterest ) ); } } return areaOfInterest; } else { final AreaOfInterest newAreaOfInterest = AreaOfInterest.create( Replicant.areZonesEnabled() ? getReplicantContext() : null, address, filter ); attach( newAreaOfInterest ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestCreatedEvent( newAreaOfInterest ) ); } return newAreaOfInterest; } } }
AreaOfInterestService extends ReplicantService { @Nonnull AreaOfInterest createOrUpdateAreaOfInterest( @Nonnull final ChannelAddress address, @Nullable final Object filter ) { final AreaOfInterest areaOfInterest = findAreaOfInterestByAddress( address ); if ( null != areaOfInterest ) { if ( !FilterUtil.filtersEqual( areaOfInterest.getFilter(), filter ) ) { areaOfInterest.setFilter( filter ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestFilterUpdatedEvent( areaOfInterest ) ); } } return areaOfInterest; } else { final AreaOfInterest newAreaOfInterest = AreaOfInterest.create( Replicant.areZonesEnabled() ? getReplicantContext() : null, address, filter ); attach( newAreaOfInterest ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestCreatedEvent( newAreaOfInterest ) ); } return newAreaOfInterest; } } AreaOfInterestService( @Nullable final ReplicantContext context ); }
AreaOfInterestService extends ReplicantService { @Nonnull AreaOfInterest createOrUpdateAreaOfInterest( @Nonnull final ChannelAddress address, @Nullable final Object filter ) { final AreaOfInterest areaOfInterest = findAreaOfInterestByAddress( address ); if ( null != areaOfInterest ) { if ( !FilterUtil.filtersEqual( areaOfInterest.getFilter(), filter ) ) { areaOfInterest.setFilter( filter ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestFilterUpdatedEvent( areaOfInterest ) ); } } return areaOfInterest; } else { final AreaOfInterest newAreaOfInterest = AreaOfInterest.create( Replicant.areZonesEnabled() ? getReplicantContext() : null, address, filter ); attach( newAreaOfInterest ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestCreatedEvent( newAreaOfInterest ) ); } return newAreaOfInterest; } } AreaOfInterestService( @Nullable final ReplicantContext context ); @Observable( expectSetter = false ) @Nonnull Stream<AreaOfInterest> areasOfInterest(); }
AreaOfInterestService extends ReplicantService { @Nonnull AreaOfInterest createOrUpdateAreaOfInterest( @Nonnull final ChannelAddress address, @Nullable final Object filter ) { final AreaOfInterest areaOfInterest = findAreaOfInterestByAddress( address ); if ( null != areaOfInterest ) { if ( !FilterUtil.filtersEqual( areaOfInterest.getFilter(), filter ) ) { areaOfInterest.setFilter( filter ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestFilterUpdatedEvent( areaOfInterest ) ); } } return areaOfInterest; } else { final AreaOfInterest newAreaOfInterest = AreaOfInterest.create( Replicant.areZonesEnabled() ? getReplicantContext() : null, address, filter ); attach( newAreaOfInterest ); if ( Replicant.areSpiesEnabled() && getReplicantContext().getSpy().willPropagateSpyEvents() ) { getReplicantContext().getSpy().reportSpyEvent( new AreaOfInterestCreatedEvent( newAreaOfInterest ) ); } return newAreaOfInterest; } } AreaOfInterestService( @Nullable final ReplicantContext context ); @Observable( expectSetter = false ) @Nonnull Stream<AreaOfInterest> areasOfInterest();  }