TrackSearch { public static boolean matchTrack(@NonNull TrackMetadata track, @NonNull String filter) { final StringBuilder sb = new StringBuilder(); if (track.place != null) { sb.append(track.place.name); sb.append(' '); sb.append(track.place.region); sb.append(' '); sb.append(track.place.country); sb.append(' '); sb.append(track.place.objectType); if (track.place.wingsuitable) { sb.append(" wingsuit"); } if ("DZ".equals(track.place.objectType)) { sb.append(" skydive"); } if (track.place.isBASE()) { sb.append(" BASE"); } } if (track.suit != null) { sb.append(' ').append(track.suit); } if (track.canopy != null) { sb.append(' ').append(track.canopy); } final String superString = sb.toString().toLowerCase(); for (String token : filter.toLowerCase().split(" ")) { if (!superString.contains(token)) { return false; } } return true; }  static boolean matchTrack(@NonNull TrackMetadata track, @NonNull String filter);  }
@Test public void matchTrack() { final TrackMetadata track = new TrackMetadata("tid", 10000000L, "nowish", "http", "kml", null); track.suit = "Corvid"; track.canopy = "OSP"; assertTrue(TrackSearch.matchTrack(track, "")); assertTrue(TrackSearch.matchTrack(track, " ")); assertFalse(TrackSearch.matchTrack(track, "BASE")); assertFalse(TrackSearch.matchTrack(track, "Skydive")); assertTrue(TrackSearch.matchTrack(track, "Corvi")); assertTrue(TrackSearch.matchTrack(track, "Corvid")); assertTrue(TrackSearch.matchTrack(track, "OSP")); assertTrue(TrackSearch.matchTrack(track, "co sp")); assertFalse(TrackSearch.matchTrack(track, "crv")); }
@Test public void matchTrackWithPlace() { final TrackMetadata trackNoPlace = new TrackMetadata("tid", 10000000L, "nowish", "http", "kml", null); assertFalse(TrackSearch.matchTrack(trackNoPlace, "Norway")); final Place place = new Place("Fjord", "", "Norway", 68.165,16.593, 1364, "E", 1000, true); final TrackMetadata track = new TrackMetadata("tid", 10000000L, "nowish", "http", "kml", place); assertTrue(TrackSearch.matchTrack(track, "Fjord")); assertTrue(TrackSearch.matchTrack(track, "Norway")); assertTrue(TrackSearch.matchTrack(track, "Fjord Norway")); assertTrue(TrackSearch.matchTrack(track, "fjo no")); }