List of usage examples for java.util List removeAll
boolean removeAll(Collection<?> c);
From source file:cc.kave.commons.pointsto.evaluation.TimeEvaluation.java
private void initializeStmtCountTimes(Collection<PointsToAnalysisFactory> ptFactories, List<Context> contexts) { analysisTimes = new ArrayList<>(ptFactories.size() * contexts.size()); List<Context> zeroStmtsContexts = new ArrayList<>(); StatementCounterVisitor counter = new StatementCounterVisitor(); for (Context context : contexts) { int count = context.getSST().accept(counter, null); if (count == 0) { zeroStmtsContexts.add(context); } else {/*from www . j a v a 2s. c om*/ stmtCounts.put(context, count); } } contexts.removeAll(zeroStmtsContexts); log("Removed %d contexts with zero statements\n", zeroStmtsContexts.size()); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.common.informationflow.InformationFlowGraphConverter.java
private String buildEdgeLabel(List<String> edgeLabelPrefixes, String edgeLabelSuffix) { List<String> allEdgeLabels = Lists.newArrayList(edgeLabelPrefixes); allEdgeLabels.add(edgeLabelSuffix);//from www. j a va 2 s . c o m allEdgeLabels.removeAll(Collections.singleton("")); return StringUtils.join(allEdgeLabels, "; "); }
From source file:com.hubrick.raml.mojo.AbstractSpringWebMojo.java
protected JCodeModel generateCodeModel() { final FileSetManager fileSetManager = new FileSetManager(); final List<String> includedFiles = Arrays.asList(fileSetManager.getIncludedFiles(fileset)); final List<String> excludedFiles = Arrays.asList(fileSetManager.getExcludedFiles(fileset)); includedFiles.removeAll(excludedFiles); // parse RAML files final Map<String, Raml> ramlFileIndex = includedFiles.stream().collect(toMap(file -> file, file -> { getLog().info("Parsing " + file); final RamlDocumentBuilder ramlDocumentBuilder = new RamlDocumentBuilder( new FileResourceLoader(fileset.getDirectory())); return ramlDocumentBuilder.build(file); }));/*from w w w. ja va 2 s.c o m*/ // generate model classes out of schemas getLog().info("Generating model classes"); final Map<InlineSchemaReference, SchemaMetaInfo> schemaIndex = ramlFileIndex.entrySet().stream() .flatMap(ramlEntry -> ramlEntry.getValue().getSchemas().stream() .flatMap(i -> i.entrySet().stream() .map(schemaEntry -> new SchemaMetaInfo(schemaEntry.getKey(), schemaEntry.getValue(), JavaNames.joinPackageMembers(basePackage, modelPackage), JavaNames.toSimpleClassName(schemaEntry.getKey()), ramlEntry.getKey())))) .collect(toMap(schemaMetaInfo -> InlineSchemaReference.of(schemaMetaInfo.getRamlFile(), schemaMetaInfo.getName()), schemaMetaInfo -> schemaMetaInfo)); final JCodeModel codeModel = new JCodeModel(); schemaIndex.values().forEach(schemaMetaInfo -> { try { final RuleFactory ruleFactory = new RuleFactory(); final GenerationConfigAdapter generationConfig = new GenerationConfigAdapter(schemaGenerator); ruleFactory.setGenerationConfig(generationConfig); ruleFactory.setAnnotator(requireAnnotator(generationConfig.getAnnotationStyle())); final SchemaGenerator schemaGenerator = new SchemaGenerator(); final SchemaMapper schemaMapper = new SchemaMapper(ruleFactory, schemaGenerator); final JType jType = schemaMapper.generate(codeModel, schemaMetaInfo.getClassName(), schemaMetaInfo.getPackageName(), schemaMetaInfo.getSchema(), new File(fileset.getDirectory(), schemaMetaInfo.getRamlFile()).toURI()); schemaMetaInfo.setJType(jType); if (getLog().isInfoEnabled()) { getLog().info("Completed " + jType.fullName()); } } catch (IOException e) { if (getLog().isErrorEnabled()) { getLog().info("Error when generating " + JavaNames .joinPackageMembers(schemaMetaInfo.getPackageName(), schemaMetaInfo.getClassName())); } throw new RuntimeException("Error while generating model class: " + schemaMetaInfo.getPackageName() + "." + schemaMetaInfo.getClassName(), e); } }); if (!ramlFileIndex.isEmpty()) { getLog().info("Generating controller classes"); // generate resources ramlFileIndex.entrySet().stream().forEach(ramlEntry -> { final String file = ramlEntry.getKey(); final Raml raml = ramlEntry.getValue(); // build action index final List<ActionMetaInfo> actions = ResourceList.of(raml).flatten() .map(resource -> resource.getActions().values()).flatMap(actionList -> actionList.stream()) .map(action -> createActionMetaInfo(action)).collect(toList()); final JType jType = RestControllerClassGenerator.builder().setCodeModel(codeModel).setFile(file) .setRaml(raml).setSchemaIndex(schemaIndex).setActionDefinitions(actions) .setBasePackage(basePackage).build().generate(); if (getLog().isInfoEnabled()) { getLog().info("Completed " + jType.fullName()); } }); } return codeModel; }
From source file:de.metas.procurement.webui.ui.model.ProductQtyReportRepository.java
public List<Product> getProductsNotContracted() { if (_productsNotContracted == null) { synchronized (this) { if (_productsNotContracted == null) { final List<Product> productsNotContracted = new ArrayList<>( productSuppliesRepository.getAllSharedProducts()); final Collection<Product> contractedProducts = getProductsContracted(); productsNotContracted.removeAll(contractedProducts); Collections.sort(productsNotContracted, Product.comparatorByName(i18n.getLocale())); _productsNotContracted = ImmutableList.copyOf(productsNotContracted); }// w w w . j a v a 2 s . com } } return _productsNotContracted; }
From source file:org.cricket.hawkeye.service.download.CricDataDownloadControlServiceImpl.java
private boolean modifyDownloadControlFileInternal(String path, List<String> itemList, boolean pending, boolean adding) throws DownloadControlServiceException { if (path == null || path.isEmpty()) { throw new DownloadControlServiceException("empty path"); }/* w ww . j a v a 2 s .c o m*/ boolean result = false; String downloadControlFileStr = this.getDownloadControlFileInternal(path); File downloadControlFile = new File(downloadControlFileStr); if (downloadControlFile.exists()) { Properties props = this.getCommonService().loadProperties(downloadControlFile); if (props == null) { throw new DownloadControlServiceException( "unable to load control file {" + downloadControlFileStr + "}"); } String value = null; if (pending) { value = props.getProperty(DOWNLOADCONTROL_PENDING); } else { value = props.getProperty(DOWNLOADCONTROL_FINISHED); } StringBuilder sb = new StringBuilder(); if (adding) { sb = new StringBuilder(value).append(DOWNLOADCONTROL_SEPARATOR) .append(this.getCommonService().stringify(itemList, DOWNLOADCONTROL_SEPARATOR)); } else { List<String> pendingValueList = this.getCommonService().listify(value, DOWNLOADCONTROL_SEPARATOR); boolean removed = pendingValueList.removeAll(itemList); sb.append(this.getCommonService().stringify(pendingValueList, DOWNLOADCONTROL_SEPARATOR)); } if (pending) { props.setProperty(DOWNLOADCONTROL_PENDING, sb.toString()); } else { props.setProperty(DOWNLOADCONTROL_FINISHED, sb.toString()); } this.getCommonService().saveProperties(props, downloadControlFileStr); result = true; } else { result = false; } return result; }
From source file:com.linkedin.pinot.controller.helix.core.rebalance.ReplicaGroupRebalanceSegmentStrategy.java
/** * Modifies in-memory idealstate to rebalance segments for table with replica-group based segment assignment * @param idealState old idealstate//w w w .ja va 2 s . com * @param tableConfig a table config * @param replicaGroupPartitionAssignment a replica group partition assignment * @return a rebalanced idealstate */ private IdealState rebalanceSegments(IdealState idealState, TableConfig tableConfig, ReplicaGroupPartitionAssignment replicaGroupPartitionAssignment) { Map<String, Map<String, String>> segmentToServerMapping = idealState.getRecord().getMapFields(); Map<String, LinkedList<String>> serverToSegments = buildServerToSegmentMapping(segmentToServerMapping); List<String> oldServerInstances = new ArrayList<>(serverToSegments.keySet()); List<String> serverInstances = replicaGroupPartitionAssignment.getAllInstances(); // Compute added and removed servers List<String> addedServers = new ArrayList<>(serverInstances); addedServers.removeAll(oldServerInstances); List<String> removedServers = new ArrayList<>(oldServerInstances); removedServers.removeAll(serverInstances); // Add servers to the mapping for (String server : addedServers) { serverToSegments.put(server, new LinkedList<String>()); } // Remove servers from the mapping for (String server : removedServers) { serverToSegments.remove(server); } // Check if rebalance can cause the data inconsistency Set<String> segmentsToCover = segmentToServerMapping.keySet(); Set<String> coveredSegments = new HashSet<>(); for (Map.Entry<String, LinkedList<String>> entry : serverToSegments.entrySet()) { coveredSegments.addAll(entry.getValue()); } coveredSegments.removeAll(segmentsToCover); if (!coveredSegments.isEmpty()) { LOGGER.warn("Some segments may temporarily be unavailable during the rebalance. " + "This may cause incorrect answer for the query."); } // Fetch replica group configs ReplicaGroupStrategyConfig replicaGroupConfig = tableConfig.getValidationConfig() .getReplicaGroupStrategyConfig(); boolean mirrorAssignment = replicaGroupConfig.getMirrorAssignmentAcrossReplicaGroups(); int numPartitions = replicaGroupPartitionAssignment.getNumPartitions(); int numReplicaGroups = replicaGroupPartitionAssignment.getNumReplicaGroups(); // For now, we don't support for rebalancing partition level replica group so "numPartitions" will be 1. for (int partitionId = 0; partitionId < numPartitions; partitionId++) { List<String> referenceReplicaGroup = new ArrayList<>(); for (int replicaId = 0; replicaId < numReplicaGroups; replicaId++) { List<String> serversInReplicaGroup = replicaGroupPartitionAssignment .getInstancesfromReplicaGroup(partitionId, replicaId); if (replicaId == 0) { // We need to keep the first replica group in case of mirroring. referenceReplicaGroup.addAll(serversInReplicaGroup); } else if (mirrorAssignment) { // Copy the segment assignment from the reference replica group for (int i = 0; i < serversInReplicaGroup.size(); i++) { serverToSegments.put(serversInReplicaGroup.get(i), serverToSegments.get(referenceReplicaGroup.get(i))); } continue; } // Uniformly distribute the segments among servers in a replica group rebalanceReplicaGroup(serversInReplicaGroup, serverToSegments, segmentsToCover); } } // Update Idealstate with rebalanced segment assignment Map<String, Map<String, String>> serverToSegmentsMapping = buildSegmentToServerMapping(serverToSegments); for (Map.Entry<String, Map<String, String>> entry : serverToSegmentsMapping.entrySet()) { idealState.setInstanceStateMap(entry.getKey(), entry.getValue()); } idealState.setReplicas(Integer.toString(numReplicaGroups)); return idealState; }
From source file:com.comcast.cats.service.ir.redrat.RedRatManagerImpl.java
@SuppressWarnings("unchecked") @Schedule(second = "0", minute = "*/5", hour = "*", persistent = false) @AccessTimeout(value = TelnetConnection.DEFAULT_READ_TIMEOUT, unit = TimeUnit.MILLISECONDS) public synchronized void refresh() { // TODO: Once MDS in CATS 4 is available this should obtain data from // MDS./*w w w .j ava2s . c o m*/ // For now, it will be made available through keymanager web app. logger.info("RedRatManager refresh "); KeyManagerProxy kmProxy = keyManagerProxyProvider.get(); logger.info("RedRatManager refresh kmProxy " + kmProxy); if (kmProxy != null) { List<IrDeviceDTO> irDevicesDTOList = kmProxy.getIrDevices(); logger.info("RedRatManager refresh irDevicesDTOList " + irDevicesDTOList); List<RedRatDevice> irDevicesNewList = processDTO(irDevicesDTOList); logger.info("RedRatManager refresh " + irDevicesNewList); if (irDevicesNewList != null) { List<RedRatDevice> removedIrDevices = new ArrayList<RedRatDevice>(irDevices); Collection<RedRatDevice> retainedDevicesCollection = null; if (!irDevices.isEmpty()) { retainedDevicesCollection = CollectionUtils.intersection(irDevices, irDevicesNewList); logger.info("RedRatManager refresh retainedDevicesCollection " + retainedDevicesCollection); removedIrDevices.removeAll(retainedDevicesCollection); } logger.info("RedRatManager refresh removedIrDevices " + removedIrDevices); boolean response = false; if (removedIrDevices != null && !removedIrDevices.isEmpty()) { for (RedRatDevice removedDevice : removedIrDevices) { RedRatHub redratHub = irNetBoxHubMap.get(removedDevice); response = redratHub.blackListRedRat(removedDevice); } } logger.info("RedRatManager blacklist response " + response); //lets whitelist all boxes all times //else if we restart the hub (to accommodate a new keyset // we'll have no way of whitelisting already added boxes unless we redploy. if (irDevicesNewList != null && !irDevicesNewList.isEmpty()) { for (RedRatDevice redratDevice : irDevicesNewList) { RedRatHub redratHub = irNetBoxHubMap.get(redratDevice); response = redratHub.whiteListRedRat(redratDevice); } } logger.info("RedRatManager whitelist response " + response); irDevices = irDevicesNewList; } } }
From source file:es.bsc.autonomic.powermodeller.DataSet.java
public DataSet addColumns(String newColName, List<String> colNames) { if (!header.containsAll(colNames)) { logger.error("Not all the columns to be added belonged to this DataSet."); throw new DataSetException("Not all the columns to be added belonged to this DataSet."); }//w w w . j a v a 2s.c om List<String> newColumns = new ArrayList<String>(header); newColumns.removeAll(colNames); List<Double> sumatoryColumn = new ArrayList<Double>(); if (colNames.size() > 0) { sumatoryColumn = getCol(colNames.get(0)); if (colNames.size() > 1) { for (int i = 1; i < colNames.size(); i++) { List<Double> addingColumn = getCol(colNames.get(i)); for (int j = 0; j < sumatoryColumn.size(); j++) { sumatoryColumn.set(j, sumatoryColumn.get(j) + addingColumn.get(j)); } } } } List<List<Double>> newDataSetColumns = new ArrayList<List<Double>>(); for (String column : newColumns) { newDataSetColumns.add(getCol(column)); } newDataSetColumns.add(sumatoryColumn); newColumns.add(newColName); DataSet ret = new DataSet(newDataSetColumns, newColumns); if (colNames.contains(this.getIndependent())) { ret.setIndependent(newColName); logger.debug( "Changing independent variable column from " + this.getIndependent() + " to " + newColName); } else { ret.setIndependent(this.getIndependent()); } return ret; }
From source file:br.com.uol.runas.classloader.ClassLoaderGC.java
private void deregisterJdbcDrivers(WeakReference<ClassLoader> classLoader) { final List<?> drivers = Reflections.getStaticFieldValue(DriverManager.class, "registeredDrivers"); final Map<Object, Driver> toDeregister = new HashMap<>(); for (Object info : drivers) { final Driver driver = Reflections.getFieldValue(info, "driver"); if (Objects.equals(classLoader.get(), driver.getClass().getClassLoader())) { toDeregister.put(info, driver); }// w w w . ja va 2s .c om } drivers.removeAll(toDeregister.keySet()); }