List of usage examples for java.util List removeAll
boolean removeAll(Collection<?> c);
From source file:azkaban.jobtype.HadoopSecureSparkWrapper.java
protected static String[] removeNullsFromArgArray(String[] argArray) { List<String> argList = new ArrayList<String>(Arrays.asList(argArray)); argList.removeAll(Collections.singleton(null)); return argList.toArray(new String[argList.size()]); }
From source file:edu.internet2.middleware.openid.security.SecurityUtils.java
/** * Build default list of parameters that should be signed from a given parameter map. This will include all message * parameters and namespace declarations with the exception of signature related parameters and the mode parameter. * The mode parameter is not signed because it would break the signatures on verify requests, since they have a * different mode than the positive assertion message they are verifying. * //from w w w.j a v a 2 s .c o m * @param parameters parameter map to build signed parameter list for * @return list of parameter names that should be signed */ public static List<QName> buildSignedParameters(ParameterMap parameters) { // Build list of message parameters to include in signature List<QName> signedParameters = new ArrayList(); for (String nsURI : parameters.getNamespaces().getURIs()) { QName nsQName = new NamespaceQName(nsURI, parameters.getNamespaces().getAlias(nsURI)); signedParameters.add(nsQName); } signedParameters.addAll(parameters.keySet()); signedParameters.removeAll( Arrays.asList(new QName[] { Parameter.sig.QNAME, Parameter.signed.QNAME, Parameter.mode.QNAME, })); return signedParameters; }
From source file:io.apiman.gateway.platforms.servlet.connectors.ssl.SSLSessionStrategyFactory.java
/** * List A - List B/*from ww w .ja va 2 s. c o m*/ * * @param allowed allowed items * @param disallowed disallowed items * @return allowed items minus disallowed items */ private static String[] arrayDifference(String[] allowed, String[] disallowed, String[] defaultItems) { List<String> allowL = new ArrayList<>(Arrays.asList(optionalVar(allowed, defaultItems))); List<String> disallowL = new ArrayList<>(Arrays.asList(optionalVar(disallowed, EMPTY))); allowL.removeAll(disallowL); return allowL.toArray(new String[allowL.size()]); }
From source file:hudson.plugins.emailext.plugins.recipients.FailingTestSuspectsRecipientProviderTest.java
private static void checkRecipients(final Build build, final String... inAuthors) throws AddressException { ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(null, build, new Launcher.LocalLauncher(StreamTaskListener.fromStdout()), new StreamBuildListener(System.out, Charset.defaultCharset())); EnvVars envVars = new EnvVars(); Set<InternetAddress> to = new HashSet<InternetAddress>(); Set<InternetAddress> cc = new HashSet<InternetAddress>(); Set<InternetAddress> bcc = new HashSet<InternetAddress>(); FailingTestSuspectsRecipientProvider provider = new FailingTestSuspectsRecipientProvider(); provider.addRecipients(context, envVars, to, cc, bcc); final List<InternetAddress> authors = new ArrayList<InternetAddress>(); for (final String author : inAuthors) { authors.add(new InternetAddress(author + AT_DOMAIN)); }// ww w . j a va2s .co m // All of the authors should have received an email, so the list should be empty. authors.removeAll(to); assertTrue("Authors not receiving mail: " + authors.toString(), authors.isEmpty()); assertTrue(cc.isEmpty()); assertTrue(bcc.isEmpty()); }
From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java
/** * Reads in the entire file contents skipping any blank lines. * /* w w w . j a v a 2s. co m*/ * @param in - InputStream to read * @return List<String> List of lines. * @throws IOException */ public static List<String> readResource(InputStream in) throws IOException { List<String> result = new ArrayList<String>(); try (InputStream closeable = in) { result = IOUtils.readLines(closeable, Charset.defaultCharset()); // Well, is this more or less readable the other it's not even as // though the predicate style actually returns a new list. // result.removeIf(StringUtils::isBlank); result.removeAll(Arrays.asList("", null)); } return result; }
From source file:com.evolveum.midpoint.schema.util.CertCampaignTypeUtil.java
public static List<AccessCertificationResponseType> getOutcomesToStopOn( List<AccessCertificationResponseType> stopReviewOn, List<AccessCertificationResponseType> advanceToNextStageOn) { if (!stopReviewOn.isEmpty()) { return stopReviewOn; }//from w w w. j a v a2 s . c o m List<AccessCertificationResponseType> rv = new ArrayList<>( Arrays.asList(AccessCertificationResponseType.values())); rv.removeAll(advanceToNextStageOn); return rv; }
From source file:forge.quest.BoosterUtils.java
private static void populateBalancedFilters(final List<Predicate<CardRules>> colorFilters, final List<Byte> preferredColors, final List<PaperCard> cardPool, final boolean includeArtifacts) { final List<Byte> otherColors = new ArrayList<>(possibleColors); otherColors.removeAll(preferredColors); int colorBias = FModel.getQuestPreferences().getPrefInt(QPref.STARTING_POOL_COLOR_BIAS); double preferredBias = 0; if (preferredColors.isEmpty()) { colorBias = 0;//from w w w . j a va 2s .c om } else { preferredBias = (double) colorBias / preferredColors.size(); } int usedMulticolor = 0, usedPhyrexian = 0; for (int i = 0; i < MAX_BIAS; i++) { if (i < colorBias) { int index = (int) ((double) i / preferredBias); for (@SuppressWarnings("unused") Byte ignored : otherColors) { //Add artifacts here if there's no colorless selection if (i % 8 == 0 && !preferredColors.contains(MagicColor.COLORLESS) && includeArtifacts) { colorFilters.add(CardRulesPredicates.Presets.IS_ARTIFACT); } else if (i % 5 == 0) { //If colorless is the only color selected, add a small chance to get Phyrexian mana cost cards. if (preferredColors.contains(MagicColor.COLORLESS) && preferredColors.size() == 1) { Predicate<CardRules> predicateRules = CardRulesPredicates.cost(StringOp.CONTAINS_IC, "p/"); Predicate<PaperCard> predicateCard = Predicates.compose(predicateRules, PaperCard.FN_GET_RULES); int size = Iterables.size(Iterables.filter(cardPool, predicateCard)); int totalSize = cardPool.size(); double phyrexianAmount = (double) size / totalSize; phyrexianAmount *= 125; if (usedPhyrexian < Math.min(1, phyrexianAmount)) { colorFilters.add(predicateRules); usedPhyrexian++; continue; } } //Try to get multicolored cards that fit into the preferred colors. Predicate<CardRules> predicateRules = Predicates.and( CardRulesPredicates.isColor(preferredColors.get(index)), CardRulesPredicates.Presets.IS_MULTICOLOR); Predicate<PaperCard> predicateCard = Predicates.compose(predicateRules, PaperCard.FN_GET_RULES); //Adjust for the number of multicolored possibilities. This prevents flooding of non-selected //colors if multicolored cards aren't in the selected sets. The more multi-colored cards in the //sets, the more that will be selected. if (usedMulticolor / 8 < Iterables.size(Iterables.filter(cardPool, predicateCard))) { colorFilters.add(predicateRules); usedMulticolor++; } else { //Exceeded multicolor-specific ratio, so here we add a more generic filter. colorFilters.add(CardRulesPredicates.isColor(preferredColors.get(index))); } } else { colorFilters.add(CardRulesPredicates.isMonoColor(preferredColors.get(index))); } } } else { for (Byte color : otherColors) { if (i % 6 == 0) { colorFilters.add(Predicates.and(CardRulesPredicates.isColor(color), CardRulesPredicates.Presets.IS_MULTICOLOR)); } else { colorFilters.add(CardRulesPredicates.isMonoColor(color)); } } } } }
From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java
/** * Generates given number of mutation task, where each task consists of a * given number of mutations. Note: The MutationProperties.PROJECT_PREFIX * variable has to be set.// w w w . j ava 2 s . c om * * @param numberOfTasks * number of tasks that should be created * @param mutationsPerTask * number of mutations per task * @throws IOException */ public static void createMutationTasks(int numberOfTasks, int mutationsPerTask) throws IOException { String prefix = ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix(); int numberOfIds = numberOfTasks * mutationsPerTask; List<Long> mutationIds = getMutations(prefix, numberOfIds); Collections.shuffle(mutationIds); int i = 1; for (; i <= numberOfTasks; i++) { List<Long> idsForTask = new ArrayList<Long>(); if (mutationIds.size() >= mutationsPerTask) { idsForTask.addAll(mutationIds.subList(0, mutationsPerTask)); } else { logger.info("Not enough mutations fetched from db"); idsForTask.addAll(mutationIds); } mutationIds.removeAll(idsForTask); if (idsForTask.size() > 0) { writeListToFile(idsForTask, i, numberOfTasks); } else { logger.info("No more mutations. Finishing after file " + (i - 1)); break; } } i = i - 1; System.out.println("Created " + i + " mutation tasks"); }
From source file:org.openmrs.module.spreadsheetimport.SpreadsheetImportUtil.java
public static File importTemplate(SpreadsheetImportTemplate template, MultipartFile file, String sheetName, List<String> messages, boolean rollbackTransaction) throws Exception { if (file.isEmpty()) { messages.add("file must not be empty"); return null; }/*from w w w .j a v a 2s . c o m*/ // Open file Workbook wb = WorkbookFactory.create(file.getInputStream()); Sheet sheet; if (!StringUtils.hasText(sheetName)) { sheet = wb.getSheetAt(0); } else { sheet = wb.getSheet(sheetName); } // Header row Row firstRow = sheet.getRow(0); if (firstRow == null) { messages.add("Spreadsheet header row must not be null"); return null; } List<String> columnNames = new Vector<String>(); for (Cell cell : firstRow) { columnNames.add(cell.getStringCellValue()); } if (log.isDebugEnabled()) { log.debug("Column names: " + columnNames.toString()); } // Required column names List<String> columnNamesOnlyInTemplate = new Vector<String>(); columnNamesOnlyInTemplate.addAll(template.getColumnNamesAsList()); columnNamesOnlyInTemplate.removeAll(columnNames); if (columnNamesOnlyInTemplate.isEmpty() == false) { messages.add("required column names not present: " + toString(columnNamesOnlyInTemplate)); return null; } // Extra column names? List<String> columnNamesOnlyInSheet = new Vector<String>(); columnNamesOnlyInSheet.addAll(columnNames); columnNamesOnlyInSheet.removeAll(template.getColumnNamesAsList()); if (columnNamesOnlyInSheet.isEmpty() == false) { messages.add( "Extra column names present, these will not be processed: " + toString(columnNamesOnlyInSheet)); } // Process rows boolean skipThisRow = true; for (Row row : sheet) { if (skipThisRow == true) { skipThisRow = false; } else { boolean rowHasData = false; Map<UniqueImport, Set<SpreadsheetImportTemplateColumn>> rowData = template .getMapOfUniqueImportToColumnSetSortedByImportIdx(); for (UniqueImport uniqueImport : rowData.keySet()) { Set<SpreadsheetImportTemplateColumn> columnSet = rowData.get(uniqueImport); for (SpreadsheetImportTemplateColumn column : columnSet) { int idx = columnNames.indexOf(column.getName()); Cell cell = row.getCell(idx); Object value = null; // check for empty cell (new Encounter) if (cell == null) { rowHasData = true; column.setValue(""); continue; } switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: value = new Boolean(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: value = new Byte(cell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { java.util.Date date = cell.getDateCellValue(); value = "'" + new java.sql.Timestamp(date.getTime()).toString() + "'"; } else { value = cell.getNumericCellValue(); } break; case Cell.CELL_TYPE_STRING: // Escape for SQL value = "'" + cell.getRichStringCellValue() + "'"; break; } if (value != null) { rowHasData = true; column.setValue(value); } else column.setValue(""); } } for (UniqueImport uniqueImport : rowData.keySet()) { Set<SpreadsheetImportTemplateColumn> columnSet = rowData.get(uniqueImport); boolean isFirst = true; for (SpreadsheetImportTemplateColumn column : columnSet) { if (isFirst) { // Should be same for all columns in unique import // System.out.println("SpreadsheetImportUtil.importTemplate: column.getColumnPrespecifiedValues(): " + column.getColumnPrespecifiedValues().size()); if (column.getColumnPrespecifiedValues().size() > 0) { Set<SpreadsheetImportTemplateColumnPrespecifiedValue> columnPrespecifiedValueSet = column .getColumnPrespecifiedValues(); for (SpreadsheetImportTemplateColumnPrespecifiedValue columnPrespecifiedValue : columnPrespecifiedValueSet) { // System.out.println(columnPrespecifiedValue.getPrespecifiedValue().getValue()); } } } } } if (rowHasData) { Exception exception = null; try { DatabaseBackend.validateData(rowData); String encounterId = DatabaseBackend.importData(rowData, rollbackTransaction); if (encounterId != null) { for (UniqueImport uniqueImport : rowData.keySet()) { Set<SpreadsheetImportTemplateColumn> columnSet = rowData.get(uniqueImport); for (SpreadsheetImportTemplateColumn column : columnSet) { if ("encounter".equals(column.getTableName())) { int idx = columnNames.indexOf(column.getName()); Cell cell = row.getCell(idx); if (cell == null) cell = row.createCell(idx); cell.setCellValue(encounterId); } } } } } catch (SpreadsheetImportTemplateValidationException e) { messages.add("Validation failed: " + e.getMessage()); return null; } catch (SpreadsheetImportDuplicateValueException e) { messages.add("found duplicate value for column " + e.getColumn().getName() + " with value " + e.getColumn().getValue()); return null; } catch (SpreadsheetImportSQLSyntaxException e) { messages.add("SQL syntax error: \"" + e.getSqlErrorMessage() + "\".<br/>Attempted SQL Statement: \"" + e.getSqlStatement() + "\""); return null; } catch (Exception e) { exception = e; } if (exception != null) { throw exception; } } } } // write back Excel file to a temp location File returnFile = File.createTempFile("sim", ".xls"); FileOutputStream fos = new FileOutputStream(returnFile); wb.write(fos); fos.close(); return returnFile; }
From source file:edu.uci.ics.asterix.optimizer.rules.LoadRecordFieldsRule.java
/** * Rewrite// w ww .j a v a2s . c om * assign $x := field-access($y, "field") * assign $y := record-constructor { "field": Expr, ... } * into * assign $x := Expr * assign $y := record-constructor { "field": Expr, ... } * * @param toPush */ private static boolean findAndEliminateRedundantFieldAccess(AssignOperator assign) throws AlgebricksException { ILogicalExpression expr = getFirstExpr(assign); AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr; ILogicalExpression arg0 = f.getArguments().get(0).getValue(); if (arg0.getExpressionTag() != LogicalExpressionTag.VARIABLE) { return false; } VariableReferenceExpression vre = (VariableReferenceExpression) arg0; LogicalVariable recordVar = vre.getVariableReference(); ILogicalExpression arg1 = f.getArguments().get(1).getValue(); if (arg1.getExpressionTag() != LogicalExpressionTag.CONSTANT) { return false; } ConstantExpression ce = (ConstantExpression) arg1; if (f.getFunctionIdentifier().equals(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME)) { String fldName = ((AString) ((AsterixConstantValue) ce.getValue()).getObject()).getStringValue(); ILogicalExpression fldExpr = findFieldExpression(assign, recordVar, fldName); if (fldExpr != null) { // check the liveness of the new expression List<LogicalVariable> usedVariables = new ArrayList<LogicalVariable>(); fldExpr.getUsedVariables(usedVariables); List<LogicalVariable> liveInputVars = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(assign, liveInputVars); usedVariables.removeAll(liveInputVars); if (usedVariables.size() == 0) { assign.getExpressions().get(0).setValue(fldExpr); return true; } else { return false; } } else { return false; } } else if (f.getFunctionIdentifier().equals(AsterixBuiltinFunctions.FIELD_ACCESS_BY_INDEX)) { // int fldIdx = ((IntegerLiteral) ce.getValue()).getValue(); // TODO return false; } else if (f.getFunctionIdentifier().equals(AsterixBuiltinFunctions.FIELD_ACCESS_NESTED)) { return false; } else { throw new IllegalStateException(); } }