PatientTumorLocationFunctions { @Nullable public static PatientTumorLocation findTumorLocationForSample(@NotNull List<PatientTumorLocation> patientTumorLocations, @NotNull String sample) { String patientIdentifier = toPatientIdentifier(sample); List<PatientTumorLocation> matchingIdTumorLocations = patientTumorLocations.stream() .filter(patientTumorLocation -> patientTumorLocation.patientIdentifier().equals(patientIdentifier)) .collect(Collectors.toList()); assert matchingIdTumorLocations.size() < 2; if (matchingIdTumorLocations.size() == 1) { return matchingIdTumorLocations.get(0); } else { LOGGER.warn("Could not find patient '{}' in clinical data!", patientIdentifier); return null; } } private  PatientTumorLocationFunctions(); @Nullable static PatientTumorLocation findTumorLocationForSample(@NotNull List<PatientTumorLocation> patientTumorLocations,
            @NotNull String sample);  }
@Test public void canFindPatientTumorLocations() { PatientTumorLocation cpct = ImmutablePatientTumorLocation.builder() .patientIdentifier("CPCT02020202") .primaryTumorLocation("tum1") .cancerSubtype("sub1") .build(); PatientTumorLocation colo = ImmutablePatientTumorLocation.builder() .patientIdentifier("COLO829") .primaryTumorLocation("tum2") .cancerSubtype("sub2") .build(); List<PatientTumorLocation> patientTumorLocations = Lists.newArrayList(cpct, colo); PatientTumorLocation location1 = PatientTumorLocationFunctions.findTumorLocationForSample(patientTumorLocations, "CPCT02020202T"); assertNotNull(location1); assertEquals(cpct.primaryTumorLocation(), location1.primaryTumorLocation()); assertEquals(cpct.cancerSubtype(), location1.cancerSubtype()); PatientTumorLocation location2 = PatientTumorLocationFunctions.findTumorLocationForSample(patientTumorLocations, "COLO829T"); assertNotNull(location2); assertEquals(colo.primaryTumorLocation(), location2.primaryTumorLocation()); assertEquals(colo.cancerSubtype(), location2.cancerSubtype()); PatientTumorLocation location3 = PatientTumorLocationFunctions.findTumorLocationForSample(patientTumorLocations, "any"); assertNull(location3); }