@Test public void testCreateTargetFilterPredicate_mmsiAndBaseAreaOnly() throws Exception { Predicate<TargetInfo> predicate = TrackResource.createTargetFilterPredicate( Sets.newHashSet(219000000, 219000001, 219000002), Sets.newHashSet( BoundingBox.create(Position.create(55.0, 10.0), Position.create(56.2, 12), CoordinateSystem.CARTESIAN) ), null ); TargetInfo targetInfo = Mockito.mock(TargetInfo.class); when(targetInfo.getMmsi()).thenReturn(123123123); when(targetInfo.getPosition()).thenReturn(Position.create(54.9, 9.9)); assertFalse(predicate.test(targetInfo)); targetInfo = Mockito.mock(TargetInfo.class); when(targetInfo.getMmsi()).thenReturn(123123123); when(targetInfo.getPosition()).thenReturn(Position.create(55.9, 10.9)); assertTrue(predicate.test(targetInfo)); targetInfo = Mockito.mock(TargetInfo.class); when(targetInfo.getMmsi()).thenReturn(219000001); when(targetInfo.getPosition()).thenReturn(Position.create(54.9, 9.9)); assertTrue(predicate.test(targetInfo)); targetInfo = Mockito.mock(TargetInfo.class); when(targetInfo.getMmsi()).thenReturn(219000001); when(targetInfo.getPosition()).thenReturn(Position.create(55.9, 10.9)); assertTrue(predicate.test(targetInfo)); }
static Predicate<TargetInfo> createTargetFilterPredicate(Set<Integer> mmsis, Set<Area> baseAreas, Set<Area> areas) { Predicate<TargetInfo> mmsiPredicate = null; if (mmsis != null && mmsis.size() > 0) { mmsiPredicate = targetInfo -> mmsis.contains(targetInfo.getMmsi()); } Predicate<TargetInfo> baseAreaPredicate = null; if (baseAreas != null && baseAreas.size() > 0) { baseAreaPredicate = targetInfo -> baseAreas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> areaPredicate = null; if (areas != null && areas.size() > 0) { areaPredicate = targetInfo -> areas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> resultingAreaPredicate = null; if(baseAreaPredicate != null && areaPredicate == null){ resultingAreaPredicate = baseAreaPredicate; }else if (baseAreaPredicate != null && areaPredicate != null){ resultingAreaPredicate = baseAreaPredicate.and(areaPredicate); }else{ resultingAreaPredicate = areaPredicate; } if (mmsiPredicate == null && resultingAreaPredicate == null) return t -> true; else if (mmsiPredicate != null && resultingAreaPredicate == null) return mmsiPredicate; else if (mmsiPredicate == null && resultingAreaPredicate != null) return resultingAreaPredicate; else return mmsiPredicate.or(resultingAreaPredicate); }
TrackResource { static Predicate<TargetInfo> createTargetFilterPredicate(Set<Integer> mmsis, Set<Area> baseAreas, Set<Area> areas) { Predicate<TargetInfo> mmsiPredicate = null; if (mmsis != null && mmsis.size() > 0) { mmsiPredicate = targetInfo -> mmsis.contains(targetInfo.getMmsi()); } Predicate<TargetInfo> baseAreaPredicate = null; if (baseAreas != null && baseAreas.size() > 0) { baseAreaPredicate = targetInfo -> baseAreas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> areaPredicate = null; if (areas != null && areas.size() > 0) { areaPredicate = targetInfo -> areas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> resultingAreaPredicate = null; if(baseAreaPredicate != null && areaPredicate == null){ resultingAreaPredicate = baseAreaPredicate; }else if (baseAreaPredicate != null && areaPredicate != null){ resultingAreaPredicate = baseAreaPredicate.and(areaPredicate); }else{ resultingAreaPredicate = areaPredicate; } if (mmsiPredicate == null && resultingAreaPredicate == null) return t -> true; else if (mmsiPredicate != null && resultingAreaPredicate == null) return mmsiPredicate; else if (mmsiPredicate == null && resultingAreaPredicate != null) return resultingAreaPredicate; else return mmsiPredicate.or(resultingAreaPredicate); } }
TrackResource { static Predicate<TargetInfo> createTargetFilterPredicate(Set<Integer> mmsis, Set<Area> baseAreas, Set<Area> areas) { Predicate<TargetInfo> mmsiPredicate = null; if (mmsis != null && mmsis.size() > 0) { mmsiPredicate = targetInfo -> mmsis.contains(targetInfo.getMmsi()); } Predicate<TargetInfo> baseAreaPredicate = null; if (baseAreas != null && baseAreas.size() > 0) { baseAreaPredicate = targetInfo -> baseAreas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> areaPredicate = null; if (areas != null && areas.size() > 0) { areaPredicate = targetInfo -> areas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> resultingAreaPredicate = null; if(baseAreaPredicate != null && areaPredicate == null){ resultingAreaPredicate = baseAreaPredicate; }else if (baseAreaPredicate != null && areaPredicate != null){ resultingAreaPredicate = baseAreaPredicate.and(areaPredicate); }else{ resultingAreaPredicate = areaPredicate; } if (mmsiPredicate == null && resultingAreaPredicate == null) return t -> true; else if (mmsiPredicate != null && resultingAreaPredicate == null) return mmsiPredicate; else if (mmsiPredicate == null && resultingAreaPredicate != null) return resultingAreaPredicate; else return mmsiPredicate.or(resultingAreaPredicate); }  }
TrackResource { static Predicate<TargetInfo> createTargetFilterPredicate(Set<Integer> mmsis, Set<Area> baseAreas, Set<Area> areas) { Predicate<TargetInfo> mmsiPredicate = null; if (mmsis != null && mmsis.size() > 0) { mmsiPredicate = targetInfo -> mmsis.contains(targetInfo.getMmsi()); } Predicate<TargetInfo> baseAreaPredicate = null; if (baseAreas != null && baseAreas.size() > 0) { baseAreaPredicate = targetInfo -> baseAreas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> areaPredicate = null; if (areas != null && areas.size() > 0) { areaPredicate = targetInfo -> areas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> resultingAreaPredicate = null; if(baseAreaPredicate != null && areaPredicate == null){ resultingAreaPredicate = baseAreaPredicate; }else if (baseAreaPredicate != null && areaPredicate != null){ resultingAreaPredicate = baseAreaPredicate.and(areaPredicate); }else{ resultingAreaPredicate = areaPredicate; } if (mmsiPredicate == null && resultingAreaPredicate == null) return t -> true; else if (mmsiPredicate != null && resultingAreaPredicate == null) return mmsiPredicate; else if (mmsiPredicate == null && resultingAreaPredicate != null) return resultingAreaPredicate; else return mmsiPredicate.or(resultingAreaPredicate); }   }
TrackResource { static Predicate<TargetInfo> createTargetFilterPredicate(Set<Integer> mmsis, Set<Area> baseAreas, Set<Area> areas) { Predicate<TargetInfo> mmsiPredicate = null; if (mmsis != null && mmsis.size() > 0) { mmsiPredicate = targetInfo -> mmsis.contains(targetInfo.getMmsi()); } Predicate<TargetInfo> baseAreaPredicate = null; if (baseAreas != null && baseAreas.size() > 0) { baseAreaPredicate = targetInfo -> baseAreas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> areaPredicate = null; if (areas != null && areas.size() > 0) { areaPredicate = targetInfo -> areas.stream().anyMatch(area -> targetInfo.getPosition() != null && area.contains(targetInfo.getPosition())); } Predicate<TargetInfo> resultingAreaPredicate = null; if(baseAreaPredicate != null && areaPredicate == null){ resultingAreaPredicate = baseAreaPredicate; }else if (baseAreaPredicate != null && areaPredicate != null){ resultingAreaPredicate = baseAreaPredicate.and(areaPredicate); }else{ resultingAreaPredicate = areaPredicate; } if (mmsiPredicate == null && resultingAreaPredicate == null) return t -> true; else if (mmsiPredicate != null && resultingAreaPredicate == null) return mmsiPredicate; else if (mmsiPredicate == null && resultingAreaPredicate != null) return resultingAreaPredicate; else return mmsiPredicate.or(resultingAreaPredicate); }    }