List of usage examples for java.util List removeAll
boolean removeAll(Collection<?> c);
From source file:at.bestsolution.persistence.java.Util.java
public static <O> void syncLists(List<O> targetList, List<O> newList) { Iterator<O> it = targetList.iterator(); List<O> removeItems = new ArrayList<O>(); // remove items not found in new list // do not remove immediately because because then to many notifications // are regenerated while (it.hasNext()) { O next = it.next();/*from ww w. ja v a2 s .c om*/ if (!newList.contains(next)) { removeItems.add(next); } } targetList.removeAll(removeItems); // remove all items from the new list already contained it = newList.iterator(); while (it.hasNext()) { if (targetList.contains(it.next())) { it.remove(); } } targetList.addAll(newList); }
From source file:de.tudarmstadt.ukp.dkpro.core.testing.AssertAnnotations.java
public static void assertTagsetMapping(Class<?> aLayer, String aName, String[] aDefaultMapped, JCas aJCas) { String pattern;/*from ww w .ja v a2 s . co m*/ if (aLayer == POS.class) { pattern = "classpath:/de/tudarmstadt/ukp/dkpro/" + "core/api/lexmorph/tagset/${language}-${tagset}-pos.map"; } else if (aLayer == Dependency.class) { pattern = "classpath:/de/tudarmstadt/ukp/dkpro/" + "core/api/syntax/tagset/${language}-${tagset}-dependency.map"; } else if (aLayer == Constituent.class) { pattern = "classpath:/de/tudarmstadt/ukp/dkpro/" + "core/api/syntax/tagset/${language}-${tagset}-constituency.map"; } else { throw new IllegalArgumentException("Unsupported layer: " + aLayer.getName()); } MappingProvider mp = new MappingProvider(); mp.setDefault(MappingProvider.LOCATION, pattern); mp.setDefault("tagset", aName); mp.configure(aJCas.getCas()); Map<String, String> mapping = mp.getResource(); Assert.assertNotNull("No mapping found for layer [" + aLayer.getName() + "] tagset [" + aName + "]", mapping); List<String> expected = new ArrayList<String>(asList(aDefaultMapped)); Collections.sort(expected); List<String> mappedTags = new ArrayList<String>(mapping.keySet()); Collections.sort(mappedTags); StringBuilder sb = new StringBuilder(); for (TagsetDescription tsd : select(aJCas, TagsetDescription.class)) { sb.append('\t'); sb.append(tsd.getLayer()); sb.append(" - "); sb.append(tsd.getName()); sb.append('\n'); if (StringUtils.equals(aLayer.getName(), tsd.getLayer()) && StringUtils.equals(aName, tsd.getName())) { List<String> actual = new ArrayList<String>(); for (TagDescription td : select(tsd.getTags(), TagDescription.class)) { actual.add(td.getName()); } Collections.sort(actual); // Keep only the unmapped tags actual.removeAll(mappedTags); System.out.printf("%-20s - Layer : %s%n", "Layer", tsd.getLayer()); System.out.printf("%-20s - Tagset : %s%n", "Tagset", tsd.getName()); System.out.printf("%-20s - Expected: %s%n", "Unmapped tags", asCopyableString(expected)); System.out.printf("%-20s - Actual : %s%n", "Unmapped tags", asCopyableString(actual)); assertEquals(asCopyableString(expected, true), asCopyableString(actual, true)); return; } } System.out.println("The CAS does not containg a description for layer [" + aLayer.getName() + "] tagset [" + aName + "]"); System.out.println("What has been found is:\n" + sb); fail("No tagset definition found for layer [" + aLayer.getName() + "] tagset [" + aName + "]"); }
From source file:com.streamsets.pipeline.stage.lib.aws.AWSUtil.java
public static void renameAWSCredentialsConfigs(List<Config> configs) { List<Config> configsToRemove = new ArrayList<>(); List<Config> configsToAdd = new ArrayList<>(); for (Config config : configs) { switch (config.getName()) { case "kinesisConfig.awsAccessKeyId": configsToRemove.add(config); configsToAdd.add(new Config("kinesisConfig.awsConfig.awsAccessKeyId", config.getValue())); break; case "kinesisConfig.awsSecretAccessKey": configsToRemove.add(config); configsToAdd.add(new Config("kinesisConfig.awsConfig.awsSecretAccessKey", config.getValue())); break; default://w w w . j a v a 2 s . co m break; } } configs.removeAll(configsToRemove); configs.addAll(configsToAdd); }
From source file:de.unisb.cs.st.javalanche.mutation.javaagent.MutationsForRun.java
/** * Removes the mutations that have a result from the given list of * mutations./*from w ww. j av a 2s. co m*/ * * @param mutations * the list of mutations to be filtered. */ private static void filterMutationsWithResult(List<Mutation> mutations) { if (mutations != null) { // make sure that we have not got any mutations that have already an // result Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); List<Mutation> toRemove = new ArrayList<Mutation>(); for (Mutation m : mutations) { session.load(m, m.getId()); if (m.getMutationResult() != null) { logger.debug("Found mutation that already has a mutation result " + m); toRemove.add(m); } } mutations.removeAll(toRemove); tx.commit(); session.close(); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.util.CuratorUtil.java
private static String render(JCas aJcas, AnnotationService aAnnotationService, BratAnnotatorModel aBratAnnotatorModel, ColoringStrategy aCurationColoringStrategy) throws IOException { GetDocumentResponse response = new GetDocumentResponse(); // Render invisible baseline annotations (sentence, tokens) SpanAdapter.renderTokenAndSentence(aJcas, response, aBratAnnotatorModel); // Render visible (custom) layers for (AnnotationLayer layer : aBratAnnotatorModel.getAnnotationLayers()) { if (layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName()) || WebAnnoConst.CHAIN_TYPE.equals(layer.getType())) { continue; }//from w ww .j ava2 s.c om List<AnnotationFeature> features = aAnnotationService.listAnnotationFeature(layer); List<AnnotationFeature> invisibleFeatures = new ArrayList<AnnotationFeature>(); for (AnnotationFeature feature : features) { if (!feature.isVisible()) { invisibleFeatures.add(feature); } } features.removeAll(invisibleFeatures); TypeAdapter adapter = getAdapter(aAnnotationService, layer); adapter.render(aJcas, features, response, aBratAnnotatorModel, aCurationColoringStrategy); } StringWriter out = new StringWriter(); JsonGenerator jsonGenerator = JSONUtil.getJsonConverter().getObjectMapper().getJsonFactory() .createJsonGenerator(out); jsonGenerator.writeObject(response); return out.toString(); }
From source file:com.streamsets.pipeline.lib.http.JerseyClientUtil.java
/** * Helper method to upgrade both HTTP stages to the JerseyConfigBean * @param configs List of configs to upgrade. *///from w w w . jav a 2 s. co m public static void upgradeToJerseyConfigBean(List<Config> configs) { List<Config> configsToAdd = new ArrayList<>(); List<Config> configsToRemove = new ArrayList<>(); List<String> movedConfigs = ImmutableList.of("conf.requestTimeoutMillis", "conf.numThreads", "conf.authType", "conf.oauth", "conf.basicAuth", "conf.useProxy", "conf.proxy", "conf.sslConfig"); for (Config config : configs) { if (hasPrefixIn(movedConfigs, config.getName())) { configsToRemove.add(config); configsToAdd.add(new Config(config.getName().replace("conf.", "conf.client."), config.getValue())); } } configsToAdd.add(new Config("conf.client.transferEncoding", RequestEntityProcessing.CHUNKED)); configs.removeAll(configsToRemove); configs.addAll(configsToAdd); }
From source file:com.hpe.application.automation.tools.octane.executor.UFTTestDetectionService.java
private static void removeTestDuplicated(List<AutomatedTest> tests) { Set<String> keys = new HashSet<>(); List<AutomatedTest> testsToRemove = new ArrayList<>(); for (AutomatedTest test : tests) { String key = test.getPackage() + "_" + test.getName(); if (keys.contains(key)) { testsToRemove.add(test);/*from w w w. j av a 2 s . co m*/ } keys.add(key); } tests.removeAll(testsToRemove); }
From source file:eu.trentorise.opendata.josman.Josmans.java
/** * Returns a new list with given relpaths ordered by importance, the first * being the most important.// w w w . j a va2 s . c o m */ static List<String> orderRelpaths(List<String> relpaths) { List<String> ret = new ArrayList(relpaths); String readme = DOCS_FOLDER + "/" + README_MD; String changes = DOCS_FOLDER + "/" + CHANGES_MD; List<String> toSkip = ImmutableList.of(readme, changes); ret.removeAll(toSkip); if (relpaths.contains(readme)) { ret.add(0, readme); } if (relpaths.contains(changes)) { ret.add(ret.size(), changes); } return ImmutableList.copyOf(ret); }
From source file:org.jboss.aerogear.unifiedpush.utils.perf.BatchUtils.java
public static void registerApplicationsViaBatchEndpoint(MassPushApplication massive, Session session) { List<PushApplication> pushApplications = new ArrayList<PushApplication>(massive.getApplications()); while (!pushApplications.isEmpty()) { int toIndex = APPLICATION_PAGING; if (pushApplications.size() < APPLICATION_PAGING) { toIndex = pushApplications.size(); }//from ww w .j a v a2 s . com List<PushApplication> sublist = pushApplications.subList(0, toIndex); MassPushApplication mass = new MassPushApplication(); mass.setApplications(sublist); Response response = session.givenAuthorized().contentType(ContentTypes.json()) .header(Headers.acceptJson()).body(mass).post("/rest/mass/applications/generated"); UnexpectedResponseException.verifyResponse(response, HttpStatus.SC_OK); pushApplications.removeAll(sublist); } }
From source file:net.sourceforge.vulcan.web.JstlFunctions.java
public static List<String> getAvailableDashboardColumns(PageContext pageContext) { final List<String> availableColumns = getAllDashboardColumns(Keys.DASHBOARD_COLUMNS); availableColumns.addAll(getAvailableMetrics()); final PreferencesDto prefs = (PreferencesDto) pageContext.findAttribute(Keys.PREFERENCES); if (prefs != null && prefs.getDashboardColumns() != null) { // Start with the chosen columns in the chosen order. final List<String> userSorted = new ArrayList<String>(Arrays.asList(prefs.getDashboardColumns())); // Remove any columns that are no longer valid. userSorted.retainAll(availableColumns); // Remove duplicates from set of unselected columns. availableColumns.removeAll(userSorted); // Add the unselected columns to the end of the list. userSorted.addAll(availableColumns); return userSorted; }/*from w w w . j ava 2s. c o m*/ return availableColumns; }