Source:
<code>private void deployUnallocatedStreamModules(CuratorFramework client, Container container) throws Exception { List<ModuleDeploymentRequestsPath> requestedModulesPaths = getAllModuleDeploymentRequests(); for (ChildData data : streamDeployments.getCurrentData()) { String streamName = ZooKeeperUtils.deploymentNameConverter.convert(data); final Stream stream = ZooKeeperUtils.loadStream(client, streamName, streamFactory); if (stream != null) { List<ModuleDeploymentRequestsPath> requestedModules = ModuleDeploymentRequestsPath.getModulesForDeploymentUnit( requestedModulesPaths, streamName); Set<String> deployedModules = new HashSet<String>(); for (String deployedModule : client.getChildren().forPath(Paths.build(data.getPath(), Paths.MODULES))) { deployedModules.add(Paths.stripPath(new StreamDeploymentsPath(Paths.build(data.getPath(), Paths.MODULES, deployedModule)).getModule())); } Collection<ModuleDescriptor> deployedDescriptors = new ArrayList<ModuleDescriptor>(); for (ModuleDeploymentRequestsPath path : requestedModules) { ModuleDescriptor moduleDescriptor = stream.getModuleDescriptor(path.getModuleLabel()); if ((path.getModuleSequence().equals("0") || !deployedModules.contains(path.getModule())) <START> && !deployedDescriptors.contains(moduleDescriptor)) { <END> deployedDescriptors.add(moduleDescriptor); RuntimeModuleDeploymentProperties moduleDeploymentProperties = new RuntimeModuleDeploymentProperties(); moduleDeploymentProperties.putAll(ZooKeeperUtils.bytesToMap(moduleDeploymentRequests.getCurrentData( path.build()).getData())); deployModule(container, new ModuleDeployment(stream, moduleDescriptor, moduleDeploymentProperties)); } } } } }</code><technical_language>Consider a HashSet instead of ArrayList - this do contains invocation in if clause sets allow duplicates</technical_language>

Target:
private void deployUnallocatedStreamModules(CuratorFramework client, Container container) throws Exception { List<ModuleDeploymentRequestsPath> requestedModulesPaths = getAllModuleDeploymentRequests(); for (ChildData data : streamDeployments.getCurrentData()) { String streamName = ZooKeeperUtils.stripPathConverter.convert(data); final Stream stream = DeploymentLoader.loadStream(client, streamName, streamFactory); if (stream != null) { List<ModuleDeploymentRequestsPath> requestedModules = ModuleDeploymentRequestsPath.getModulesForDeploymentUnit( requestedModulesPaths, streamName); Set<String> deployedModules = new HashSet<String>(); for (String deployedModule : client.getChildren().forPath(Paths.build(data.getPath(), Paths.MODULES))) { deployedModules.add(Paths.stripPath(new StreamDeploymentsPath(Paths.build(data.getPath(), Paths.MODULES, deployedModule)).getModuleInstanceAsString())); } Set<ModuleDescriptor> deployedDescriptors = new HashSet<ModuleDescriptor>(); for (ModuleDeploymentRequestsPath path : requestedModules) { ModuleDescriptor moduleDescriptor = stream.getModuleDescriptor(path.getModuleLabel()); if ((path.getModuleSequence().equals("0") || !deployedModules.contains(path.getModuleInstanceAsString())) && !deployedDescriptors.contains(moduleDescriptor)) { deployedDescriptors.add(moduleDescriptor); RuntimeModuleDeploymentProperties moduleDeploymentProperties = new RuntimeModuleDeploymentProperties(); moduleDeploymentProperties.putAll(ZooKeeperUtils.bytesToMap(moduleDeploymentRequests.getCurrentData( path.build()).getData())); deployModule(container, new ModuleDeployment(stream, moduleDescriptor, moduleDeploymentProperties)); } } } } }