Source:
<code>public static void addFromFacet(@CheckForNull String ancestorImageId, @Nonnull String descendantImageId, @Nonnull Run<?,?> run) throws IOException { long timestamp = System.currentTimeMillis(); if (ancestorImageId != null) { Fingerprint f = make(run, ancestorImageId); Collection<FingerprintFacet> facets = f.getFacets(); DockerAncestorFingerprintFacet ancestorFacet = null; <START> for (FingerprintFacet facet : facets) { <END> if (facet instanceof DockerAncestorFingerprintFacet) { ancestorFacet = (DockerAncestorFingerprintFacet) facet; break; } } BulkChange bc = new BulkChange(f); try { if (ancestorFacet == null) { ancestorFacet = new DockerAncestorFingerprintFacet(f, timestamp, ancestorImageId); facets.add(ancestorFacet); } ancestorFacet.addDescendantImageId(descendantImageId); ancestorFacet.addFor(run); bc.commit(); } finally { bc.abort(); } } Fingerprint f = make(run, descendantImageId); Collection<FingerprintFacet> facets = f.getFacets(); DockerDescendantFingerprintFacet descendantFacet = null; for (FingerprintFacet facet : facets) { if (facet instanceof DockerDescendantFingerprintFacet) { descendantFacet = (DockerDescendantFingerprintFacet) facet; break; } } BulkChange bc = new BulkChange(f); try { if (descendantFacet == null) { descendantFacet = new DockerDescendantFingerprintFacet(f, timestamp, descendantImageId); facets.add(descendantFacet); } descendantFacet.addAncestorImageId(ancestorImageId); descendantFacet.addFor(run); bc.commit(); } finally { bc.abort(); } }</code><technical_language>Off-topic: sense finally decouple this code snippet somewhere. E.g. public static @CheckForNull @SuppressWarnings("unchecked") <TFacet extends FingerprintFacet> TFacet getFacet (@Nonnull Fingerprint fingerprint, Class<TFacet> facetClass) { for ( FingerprintFacet facet : fingerprint.getFacets()) { if (facetClass.isAssignableFrom(facet.getClass())) { return (TFacet)facet; } } return null; }</technical_language>

Target:
public static void addFromFacet(@CheckForNull String ancestorImageId, @Nonnull String descendantImageId, @Nonnull Run<?,?> run) throws IOException { long timestamp = System.currentTimeMillis(); if (ancestorImageId != null) { Fingerprint f = make(run, ancestorImageId); Collection<FingerprintFacet> facets = f.getFacets(); DockerDescendantFingerprintFacet descendantFacet = null; for (FingerprintFacet facet : facets) { if (facet instanceof DockerDescendantFingerprintFacet) { descendantFacet = (DockerDescendantFingerprintFacet) facet; break; } } BulkChange bc = new BulkChange(f); try { if (descendantFacet == null) { descendantFacet = new DockerDescendantFingerprintFacet(f, timestamp, ancestorImageId); facets.add(descendantFacet); } descendantFacet.addDescendantImageId(descendantImageId); descendantFacet.addFor(run); bc.commit(); } finally { bc.abort(); } } Fingerprint f = make(run, descendantImageId); Collection<FingerprintFacet> facets = f.getFacets(); DockerAncestorFingerprintFacet ancestorFacet = null; for (FingerprintFacet facet : facets) { if (facet instanceof DockerAncestorFingerprintFacet) { ancestorFacet = (DockerAncestorFingerprintFacet) facet; break; } } BulkChange bc = new BulkChange(f); try { if (ancestorFacet == null) { ancestorFacet = new DockerAncestorFingerprintFacet(f, timestamp, descendantImageId); facets.add(ancestorFacet); } if (ancestorImageId != null) { ancestorFacet.addAncestorImageId(ancestorImageId); } ancestorFacet.addFor(run); bc.commit(); } finally { bc.abort(); } }