Source:
<code>public Resource viewDistribution(@PathParam("distributionId") String distributionId) { if (StringUtils.isBlank(distributionId)) { return this; } if (isSiteMode() && RuntimeSnapshot.LIVE_ALIASES.contains(distributionId)) { return ctx.newObject(Resource404.TYPE); } List<DistributionSnapshot> snaps = getSnapshotManager().listPersistentSnapshots((ctx.getCoreSession())); if (distributionId.matches(VERSION_REGEX.toString())) { String finalDistributionId = distributionId; <START> Optional<DistributionSnapshot> distribution = snaps.stream() .filter(s -> s.getVersion().equals(finalDistributionId)) .findFirst(); if (distribution.isPresent()) { return ctx.newObject(RedirectResource.TYPE, finalDistributionId, distribution.get().getKey()); } else { return ctx.newObject(Resource404.TYPE); } <END> } String orgDistributionId = distributionId; Boolean embeddedMode = Boolean.FALSE; if (SnapshotManager.DISTRIBUTION_ALIAS_ADM.equals(distributionId)) { embeddedMode = Boolean.TRUE; } else { if (!isSiteMode()) { snaps.add(getRuntimeDistribution()); } distributionId = SnapshotResolverHelper.findBestMatch(snaps, distributionId); } if (StringUtils.isBlank(distributionId)) { if (!isSiteMode()) { distributionId = SnapshotManager.DISTRIBUTION_ALIAS_CURRENT; } else { return ctx.newObject(Resource404.TYPE); } } if (!orgDistributionId.equals(distributionId)) { return ctx.newObject(RedirectResource.TYPE, orgDistributionId, distributionId); } ctx.setProperty(ApiBrowserConstants.EMBEDDED_MODE_MARKER, embeddedMode); ctx.setProperty("distribution", getSnapshotManager().getSnapshot(distributionId, ctx.getCoreSession())); ctx.setProperty(DIST_ID, distributionId); return ctx.newObject(ApiBrowser.TYPE, distributionId, embeddedMode); }</code><technical_language>do below: java return snaps.stream() .filter(s -> s.getVersion().equals(finalDistributionId)) .findFirst() .map(distribution -> ctx.newObject(RedirectResource.TYPE, finalDistributionId, distribution.getKey())) .orElseGet(() -> ctx.newObject(Resource404.TYPE));</technical_language>

Target:
public Resource viewDistribution(@PathParam("distributionId") String distributionId) { if (StringUtils.isBlank(distributionId)) { return this; } if (isSiteMode() && RuntimeSnapshot.LIVE_ALIASES.contains(distributionId)) { return ctx.newObject(Resource404.TYPE); } List<DistributionSnapshot> snaps = getSnapshotManager().listPersistentSnapshots((ctx.getCoreSession())); if (distributionId.matches(VERSION_REGEX.toString())) { String finalDistributionId = distributionId; return snaps.stream() .filter(s -> s.getVersion().equals(finalDistributionId)) .findFirst() .map(distribution -> ctx.newObject(RedirectResource.TYPE, finalDistributionId, distribution.getKey())) .orElseGet(() -> ctx.newObject(Resource404.TYPE)); } boolean showRuntimeSnapshot = showRuntimeSnapshot(); String orgDistributionId = distributionId; Boolean embeddedMode = Boolean.FALSE; if (SnapshotManager.DISTRIBUTION_ALIAS_ADM.equals(distributionId)) { if (!showRuntimeSnapshot) { return ctx.newObject(Resource404.TYPE); } embeddedMode = Boolean.TRUE; } else { if (showRuntimeSnapshot) { snaps.add(getRuntimeDistribution()); } distributionId = SnapshotResolverHelper.findBestMatch(snaps, distributionId); } if (StringUtils.isBlank(distributionId)) { return ctx.newObject(Resource404.TYPE); } if (!orgDistributionId.equals(distributionId)) { return ctx.newObject(RedirectResource.TYPE, orgDistributionId, distributionId); } ctx.setProperty(ApiBrowserConstants.EMBEDDED_MODE_MARKER, embeddedMode); ctx.setProperty(DIST, getSnapshotManager().getSnapshot(distributionId, ctx.getCoreSession())); ctx.setProperty(DIST_ID, distributionId); return ctx.newObject(ApiBrowser.TYPE, distributionId, embeddedMode); }