Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

In this page you can find the example usage for java.util Set contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.liveneo.plat.utils.StringUtil.java

/**
 * Replaces all HTML-sensitive characters with their entity equivalents in
 * all string values in specified model. Some model values are skipped
 * untouched (their names are contained in exceptions set).
 * /* www. j  a  v  a  2 s.co  m*/
 * @param model
 *            Map of pairs <code>variable -&gt; value</code>.
 * @return Map with encoded string values
 */
public static Map htmlEncodeModelWithExceptions(Map model, Set exceptions) {
    Map result = new HashMap(model.size());
    for (Iterator i = model.entrySet().iterator(); i.hasNext();) {
        Map.Entry entry = (Map.Entry) i.next();
        String key = (String) entry.getKey();
        Object value = (Object) entry.getValue();
        if (exceptions.contains(key)) {
            result.put(key, value);
        } else {
            if (value instanceof String) {
                result.put(key, htmlEncode((String) value));
            } else {
                result.put(key, value);
            }
        }
    }
    return result;
}

From source file:com.wrmsr.wava.analyze.ValueTypeAnalysis.java

public static ValueTypeAnalysis analyze(Node root, boolean isRootUsed) {
    Map<Node, Entry> analyses = newIdentityHashMap();
    Entry rootAnalysis = root.accept(new Visitor<Context, Entry>() {
        private Entry analyzeChild(Node child, Context context) {
            Entry analysis = child.accept(this, context);
            analyses.put(child, analysis);
            return analysis;
        }/*www .j a  v  a  2  s . c  om*/

        @Override
        protected Entry visitNode(Node node, Context context) {
            throw new IllegalStateException();
        }

        @Override
        public Entry visitBinary(Binary node, Context context) {
            Entry left = analyzeChild(node.getLeft(), new Context(true));
            Entry right = analyzeChild(node.getRight(), new Context(true));
            checkState(left.getType() == right.getType());
            checkState(left.getType().isConcrete());
            Type resultType = requireNonNull(
                    node.getOp().getTypeMap().get(ImmutablePair.of(left.getType(), right.getType())));
            checkState(node.getType() == resultType);
            return new Entry(node.getType(),
                    mergeValueInitializations(left.getInitialization(), right.getInitialization()),
                    mergeValueOwnerships(left.getOwnership(), right.getOwnership()),
                    mergeBreakValueTypes(left.getBreakValueTypes(), right.getBreakValueTypes()), context);
        }

        @Override
        public Entry visitBlock(Block node, Context context) {
            List<Node> children = node.getChildren();
            List<Entry> init = listInit(children).map(c -> analyzeChild(c, new Context(false)))
                    .collect(toImmutableList());
            Entry last = analyzeChild(listLast(children), new Context(context.isUsed));
            ImMap<Name, Set<Type>> breakValueTypes = Stream.concat(init.stream(), Stream.of(last))
                    .map(Entry::getBreakValueTypes)
                    .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes);
            return new Entry(last.getType(),
                    init.isEmpty() && last.getInitialization() == Initialization.INLINE ? Initialization.INLINE
                            : !last.getType().isConcrete() ? Initialization.VOID : Initialization.SETUP,
                    last.getOwnership(), breakValueTypes, context);
        }

        @Override
        public Entry visitBreak(Break node, Context context) {
            // checkState(!context.isUsed);
            Entry value = analyzeChild(node.getValue(), new Context(true));
            return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, updateBreakValueTypes(
                    value.getBreakValueTypes(), ImmutableList.of(node.getTarget()), value.getType()), context);
        }

        @Override
        public Entry visitBreakTable(BreakTable node, Context context) {
            // checkState(!context.isUsed);
            Entry condition = analyzeChild(node.getCondition(), new Context(true));
            return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID,
                    updateBreakValueTypes(condition.getBreakValueTypes(), ImmutableList.<Name>builder()
                            .addAll(node.getTargets()).add(node.getDefaultTarget()).build(), Type.NONE),
                    context);
        }

        @Override
        public Entry visitCall(Call node, Context context) {
            // TODO: check operands?
            Call.Target target = node.getTarget();
            Type type = node.getSignature().getResult();
            requireNonNull(type);
            List<Entry> operands = node.getOperands().stream().map(o -> analyzeChild(o, new Context(true)))
                    .collect(toImmutableList());
            checkState(operands.stream().allMatch(o -> o.getType().isConcrete()));
            return new Entry(type,
                    mergeValueInitializations(operands.stream().map(Entry::getInitialization)
                            .collect(toImmutableList()).toArray(new Initialization[] {})),
                    Ownership.FREE, operands.stream().map(Entry::getBreakValueTypes)
                            .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes),
                    context);
        }

        @Override
        public Entry visitCallIndirect(CallIndirect node, Context context) {
            Entry target = analyzeChild(node.getTarget(), new Context(true));
            checkState(target.getType().isConcrete());
            List<Entry> operands = node.getOperands().stream().map(o -> analyzeChild(o, new Context(true)))
                    .collect(toImmutableList());
            checkState(operands.stream().allMatch(o -> o.getType().isConcrete()));
            return new Entry(node.getSignature().getResult(),
                    mergeValueInitializations(
                            Stream.concat(Stream.of(target), operands.stream()).map(Entry::getInitialization)
                                    .collect(toImmutableList()).toArray(new Initialization[] {})),
                    Ownership.FREE,
                    Stream.concat(Stream.of(target), operands.stream()).map(Entry::getBreakValueTypes)
                            .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes),
                    context);
        }

        @Override
        public Entry visitConst(Const node, Context context) {
            return new Entry(node.getLiteral().getType(), Initialization.INLINE, Ownership.FREE,
                    EMPTY_BREAK_VALUE_TYPES, context);
        }

        @Override
        public Entry visitGetLocal(GetLocal node, Context context) {
            return new Entry(node.getType(), Initialization.INLINE, Ownership.FREE, EMPTY_BREAK_VALUE_TYPES,
                    context);
        }

        @Override
        public Entry visitIf(If node, Context context) {
            Entry condition = analyzeChild(node.getCondition(), new Context(true));
            Entry ifTrue = analyzeChild(node.getIfTrue(), new Context(context.isUsed));
            Entry ifFalse = analyzeChild(node.getIfFalse(), new Context(context.isUsed));
            checkState(condition.getType().isConcrete());
            ImMap<Name, Set<Type>> breakValueTypes = Stream.of(condition, ifTrue, ifFalse)
                    .map(Entry::getBreakValueTypes)
                    .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes);
            if (context.isUsed) {
                checkState(ifTrue.getType() == ifFalse.getType());
                checkState(ifTrue.getType().isConcrete());
                return new Entry(ifTrue.getType(),
                        mergeValueInitializations(condition.getInitialization(), ifTrue.getInitialization(),
                                ifFalse.getInitialization()),
                        mergeValueOwnerships(ifTrue.getOwnership(), ifFalse.getOwnership()), breakValueTypes,
                        context);
            } else {
                return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, breakValueTypes, context);
            }
        }

        @Override
        public Entry visitLabel(Label node, Context context) {
            // FIXME CFA -> ignore unreachable tails? or expect removed?
            Entry body = analyzeChild(node.getBody(), new Context(context.isUsed));
            ImMap<Name, Set<Type>> breakValueTypes = body.getBreakValueTypes();
            Type type = body.getType();
            Initialization initialization = body.getInitialization();
            Ownership ownership = body.getOwnership();
            if (breakValueTypes.containsKey(node.getName())) {
                Type breakType = Iterables.getOnlyElement(breakValueTypes.get(node.getName()));
                if (breakType.isConcrete()) {
                    checkState(type == breakType || type == Type.NONE);
                    type = breakType;
                    initialization = Initialization.SETUP;
                    ownership = Ownership.TEMP;
                } else {
                    if (context.isUsed) {
                        checkState(type == Type.NONE);
                    } else {
                        type = Type.NONE;
                        initialization = Initialization.VOID;
                        ownership = Ownership.VOID;
                    }
                }
                breakValueTypes = breakValueTypes.without(node.getName());
            }
            return new Entry(type, initialization, ownership, breakValueTypes, context);
        }

        @Override
        public Entry visitLoad(Load node, Context context) {
            Entry ptr = analyzeChild(node.getPtr(), new Context(true));
            checkState(ptr.getType() == Type.I32);
            return new Entry(node.getType(), ptr.getInitialization(), Ownership.FREE, ptr.getBreakValueTypes(),
                    context);
        }

        @Override
        public Entry visitLoop(Loop node, Context context) {
            Entry body = analyzeChild(node.getBody(), new Context(context.isUsed));
            ImMap<Name, Set<Type>> breakValueTypes = body.getBreakValueTypes();
            if (breakValueTypes.containsKey(node.getName())) {
                checkState(breakValueTypes.get(node.getName()).equals(EnumSet.of(Type.NONE)));
                breakValueTypes = breakValueTypes.without(node.getName());
            }
            return new Entry(body.getType(), body.getInitialization(), body.getOwnership(), breakValueTypes,
                    context);
        }

        @Override
        public Entry visitNop(Nop node, Context context) {
            return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, EMPTY_BREAK_VALUE_TYPES, context);
        }

        @Override
        public Entry visitReturn(Return node, Context context) {
            checkState(!context.isUsed);
            Entry value = analyzeChild(node.getValue(), new Context(true));
            return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, value.getBreakValueTypes(),
                    context);
        }

        @Override
        public Entry visitSelect(Select node, Context context) {
            Entry ifTrue = analyzeChild(node.getIfTrue(), new Context(true));
            Entry ifFalse = analyzeChild(node.getIfFalse(), new Context(true));
            Entry condition = analyzeChild(node.getCondition(), new Context(true));
            checkState(ifTrue.getType() == ifFalse.getType());
            checkState(ifTrue.getType().isConcrete());
            checkState(condition.getType() == Type.I32);
            return new Entry(ifTrue.getType(), Initialization.SETUP, // FIXME? used check?
                    Ownership.TEMP, mergeBreakValueTypes(ImmutableList.of(ifTrue.getBreakValueTypes(),
                            ifFalse.getBreakValueTypes(), condition.getBreakValueTypes())),
                    context);
        }

        @Override
        public Entry visitSetLocal(SetLocal node, Context context) {
            Entry value = analyzeChild(node.getValue(), new Context(true));
            checkState(value.getType().isConcrete());
            checkState(value.getType() == node.getType());
            return new Entry(value.getType(), value.getInitialization(), value.getOwnership(),
                    value.getBreakValueTypes(), context);
        }

        @Override
        public Entry visitStore(Store node, Context context) {
            Entry ptr = analyzeChild(node.getPtr(), new Context(true));
            Entry value = analyzeChild(node.getValue(), new Context(true));
            checkState(ptr.getType() == Type.I32);
            checkState(value.getType() == node.getType());
            return new Entry(node.getType(),
                    mergeValueInitializations(ptr.getInitialization(), value.getInitialization()),
                    value.getOwnership(),
                    mergeBreakValueTypes(ptr.getBreakValueTypes(), value.getBreakValueTypes()), context);
        }

        @Override
        public Entry visitSwitch(Switch node, Context context) {
            List<Entry> cases = node.getEntries().stream().map(Switch.Entry::getBody)
                    .map(child -> analyzeChild(child, new Context(false))).collect(toImmutableList());
            Entry condition = analyzeChild(node.getCondition(), new Context(true));
            checkState(condition.getType().isConcrete() && !condition.getType().isFloat());
            return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID,
                    mergeBreakValueTypes(Stream.concat(Stream.of(condition.getBreakValueTypes()),
                            cases.stream().map(Entry::getBreakValueTypes)).iterator()),
                    context);
        }

        @Override
        public Entry visitUnary(Unary node, Context context) {
            Entry value = analyzeChild(node.getValue(), new Context(true));
            checkState(value.getType().isConcrete());
            Set<Type> resultTypes = requireNonNull(node.getOp().getTypeMap().get(value.getType()));
            checkState(resultTypes.contains(node.getType()));
            return new Entry(node.getType(), value.getInitialization(), value.getOwnership(),
                    value.getBreakValueTypes(), context);
        }

        @Override
        public Entry visitUnreachable(Unreachable node, Context context) {
            return new Entry(Type.UNREACHABLE, Initialization.VOID, Ownership.VOID, EMPTY_BREAK_VALUE_TYPES,
                    context);
        }
    }, new Context(isRootUsed));
    checkState(rootAnalysis.getBreakValueTypes().isEmpty());
    analyses.put(root, rootAnalysis);
    return new ValueTypeAnalysis(analyses);
}

From source file:edu.umass.cs.utils.Util.java

public static Object getRandomOtherThan(Set<?> all, Set<?> exclude) {
    Object[] allArray = all.toArray();
    int index = -1;
    if (exclude.containsAll(all))
        return null;
    while (exclude.contains(allArray[index = (int) (Math.random() * allArray.length)]))
        ;//from ww  w . java2 s  .  co  m
    return allArray[index];
}

From source file:com.diversityarrays.util.ClassPathExtender.java

public static void addDirectoryJarsToClassPath(Log logger, Consumer<File> jarChecker, File... dirs) {
    if (dirs == null || dirs.length <= 0) {
        if (logger != null) {
            logger.info("No directories provided for class path");
        }//from w ww  .  j  a va2 s .c  o m
        return;
    }

    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    if (ccl instanceof java.net.URLClassLoader) {
        try {
            Method m = java.net.URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            m.setAccessible(true);

            Set<URL> currentUrls = new HashSet<URL>(Arrays.asList(((URLClassLoader) ccl).getURLs()));
            if (VERBOSE) {
                info(logger, "=== Current URLS in ClassLoader: " + currentUrls.size());
                for (URL u : currentUrls) {
                    info(logger, "\t" + u.toString());
                }
            }

            for (File dir : dirs) {
                if (dir.isDirectory()) {
                    for (File f : dir.listFiles(JAR_OR_PROPERTIES)) {
                        try {
                            URL u = f.toURI().toURL();
                            if (!currentUrls.contains(u)) {
                                m.invoke(ccl, u);
                                if (VERBOSE) {
                                    info(logger, "[Added " + u + "] to CLASSPATH");
                                }
                                if (jarChecker != null) {
                                    jarChecker.accept(f);
                                }
                            }
                        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
                                | MalformedURLException e) {
                            warn(logger,
                                    "%Unable to add " + f.getPath() + " to CLASSPATH (" + e.getMessage() + ")");
                        }
                    }
                }
            }
        } catch (NoSuchMethodException e) {
            warn(logger, "%No method: " + java.net.URLClassLoader.class.getName() + ".addURL(URL)");
        }

    } else {
        warn(logger, "%currentThread.contextClassLoader is not an instance of "
                + java.net.URLClassLoader.class.getName());
    }
}

From source file:acromusashi.stream.ml.anomaly.lof.LofCalculator.java

/**
 * ??K????<br>/*from  www.  j a v a 2 s .c  om*/
 * ????????????????????????
 * 
 * @param kn K
 * @param max ??
 * @param addedPoint 
 * @param dataSet 
 * @return LOF
 */
public static double calculateLofWithUpdate(int kn, int max, LofPoint addedPoint, LofDataSet dataSet) {
    // ??????????????
    String deleteId = addPointToDataSet(max, addedPoint, dataSet);

    // K??K??????????
    Set<String> updateTargets = generateUpdateTargets(addedPoint, dataSet, deleteId);

    Collection<LofPoint> targetList = dataSet.getDataMap().values();
    // K??K??????????????2????
    for (LofPoint targetPoint : targetList) {
        if (updateTargets.contains(targetPoint.getDataId())) {
            // ?K??K???
            updateKDistance(kn, targetPoint, dataSet);
        }
    }

    // K?????K?????K????????/???
    // ???????????/????????????? 
    for (LofPoint targetPoint : targetList) {
        // ????
        updateLrd(targetPoint, dataSet);
    }

    // ??addedPoint???K??K?????????????????????
    double lof = calculateLof(addedPoint, dataSet);
    return lof;
}

From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java

/**
 * Returns the first row headers (field names) mapped to the column indexes
 * @return  Map<ColumnNumber, ColumnHeader>
 *///from  w w  w .  j  a va  2  s  .  c o m
static SortedMap<Integer, String> getFirstRowHeaders(Workbook hSSFWorkbook, Integer sheetID) {
    SortedMap<Integer, String> firstRowMap = new TreeMap<Integer, String>();
    if (hSSFWorkbook == null || sheetID == null) {
        return firstRowMap;
    }
    //first search for duplicate columns
    Set<String> sameColumnNames = new HashSet<String>();
    Set<String> columnNames = new HashSet<String>();
    Sheet sheet = hSSFWorkbook.getSheetAt(sheetID.intValue());
    Row firstRow = sheet.getRow(0);
    if (firstRow != null) {
        for (Cell cell : firstRow) {
            String columnHeader = ExcelImportBL.getStringCellValue(cell);
            if (columnHeader != null && !"".equals(columnHeader)) {
                if (columnNames.contains(columnHeader)) {
                    sameColumnNames.add(columnHeader);
                } else {
                    columnNames.add(columnHeader);
                }
            }
        }
    }
    sheet = hSSFWorkbook.getSheetAt(sheetID.intValue());
    firstRow = sheet.getRow(0);
    if (firstRow != null) {
        for (Cell cell : firstRow) {
            String columnHeader = ExcelImportBL.getStringCellValue(cell);
            if (columnHeader != null && !"".equals(columnHeader)) {
                if (sameColumnNames.contains(columnHeader)) {
                    //for duplicate columns add also the column index
                    columnHeader += " (" + cell.getColumnIndex() + ")";
                }
                firstRowMap.put(Integer.valueOf(cell.getColumnIndex()), columnHeader);
            }
        }
    }
    return firstRowMap;
}

From source file:com.igormaznitsa.charsniffer.CharSnifferMojo.java

static boolean checkForAbc(@Nonnull final String text, @Nonnull final CheckConfig config,
        @Nonnull final StringBuilder errorBuffer) {
    final String allowed = config.abc;
    final String disallowed = config.noAbc;

    final Set<Character> errorChars = new HashSet<Character>();

    if (allowed != null || disallowed != null) {
        for (int i = 0; i < text.length(); i++) {
            final char c = text.charAt(i);

            if (config.ignoreAbcForISOControl && Character.isISOControl(c)) {
                continue;
            }/*  w  ww  .j a v a  2 s .  c o m*/

            if (allowed != null) {
                if (allowed.indexOf(c) < 0) {
                    if (!errorChars.contains(c)) {
                        errorChars.add(c);
                        if (errorBuffer.length() > 0) {
                            errorBuffer.append(',');
                        }
                        errorBuffer.append('\'').append(c).append('\'');
                    }
                }
            }

            if (disallowed != null) {
                if (disallowed.indexOf(c) >= 0) {
                    if (!errorChars.contains(c)) {
                        errorChars.add(c);
                        if (errorBuffer.length() > 0) {
                            errorBuffer.append(',');
                        }
                        errorBuffer.append('\'').append(c).append('\'');
                    }
                }
            }
        }
    }

    return errorChars.isEmpty();
}

From source file:de.flashpixx.rrd_antlr4.CMain.java

/**
 * returns a list of grammar files//from  w  w  w .j  a  v a  2 s  .  co  m
 *
 * @param p_input grammar file or directory with grammar files
 * @param p_import imported files
 * @param p_exclude file names which are ignored
 * @return stream of file objects
 */
private static Stream<File> filelist(final File p_input, final Set<File> p_import,
        final Set<String> p_exclude) {
    if (!p_input.exists())
        throw new RuntimeException(CCommon.languagestring(CMain.class, "notexist", p_input));

    try {
        return (p_input.isFile() ? Stream.of(p_input)
                : Files.find(p_input.toPath(), Integer.MAX_VALUE,
                        (i, j) -> (j.isRegularFile()) && (!j.isSymbolicLink())).map(Path::toFile))
                                .filter(i -> i.getName().endsWith(GRAMMARFILEEXTENSION))
                                .filter(i -> !p_import.contains(i))
                                .filter(i -> !p_exclude.contains(i.getName()));
    } catch (final IOException l_exception) {
        throw new RuntimeException(l_exception);
    }
}

From source file:com.jaspersoft.studio.server.WSClientHelper.java

private static List<ResourceDescriptor> listFolder(ANode parent, int index, IConnection client,
        IProgressMonitor monitor, ResourceDescriptor rd, int depth) throws Exception {
    monitor.subTask("Listing " + rd.getUriString());
    depth++;/*from   w w w . ja  v  a2  s .  c o m*/

    List<ResourceDescriptor> children = client.list(monitor, rd);
    if (parent instanceof MServerProfile || (parent instanceof MResource
            && ((MResource) parent).getValue().getWsType().equals(ResourceDescriptor.TYPE_FOLDER))) {
        Collections.sort(children, new Comparator<ResourceDescriptor>() {

            @Override
            public int compare(ResourceDescriptor arg0, ResourceDescriptor arg1) {
                if (arg0.getLabel() == arg1.getLabel())
                    return 0;
                if (arg0.getLabel() == null)
                    return -1;
                if (arg1.getLabel() == null)
                    return 1;
                String wsType0 = arg0.getWsType();
                String wsType1 = arg1.getWsType();
                if (wsType0.equals(wsType1))
                    return arg0.getLabel().compareToIgnoreCase(arg1.getLabel());
                if (wsType0.equals(ResourceDescriptor.TYPE_FOLDER))
                    return -1;
                if (wsType1.equals(ResourceDescriptor.TYPE_FOLDER))
                    return 1;
                if (wsType0.equals(ResourceDescriptor.TYPE_REPORTUNIT))
                    return -1;
                if (wsType1.equals(ResourceDescriptor.TYPE_REPORTUNIT))
                    return 1;
                if (wsType0.equals(ResourceDescriptor.TYPE_DOMAIN_TOPICS))
                    return -1;
                if (wsType1.equals(ResourceDescriptor.TYPE_DOMAIN_TOPICS))
                    return 1;
                return wsType0.compareTo(wsType1);
            }
        });
    }

    Set<String> set = new HashSet<String>();
    for (ResourceDescriptor r : children) {
        if (!r.getWsType().equals(ResourceDescriptor.TYPE_INPUT_CONTROL) && set.contains(r.getUriString()))
            continue;
        set.add(r.getUriString());
        if (rd.getWsType().equals(ResourceDescriptor.TYPE_REPORTUNIT)
                || rd.getWsType().equals(ResourceDescriptor.TYPE_DOMAIN_TOPICS)) {
            if (SelectorDatasource.isDatasource(r))
                continue;
        }
        MResource node = ResourceFactory.getResource(parent, r, index);
        if (depth <= 0) {
            if (r.getWsType().equals(ResourceDescriptor.TYPE_FOLDER)) {
                listFolder(node, client, r.getUriString(), monitor, depth);
            } else if (r.getWsType().equals(ResourceDescriptor.TYPE_REPORTUNIT)
                    || rd.getWsType().equals(ResourceDescriptor.TYPE_DOMAIN_TOPICS)) {
                r = client.get(monitor, r, null);
                Set<String> setRU = new HashSet<String>();
                List<ResourceDescriptor> children2 = r.getChildren();
                for (ResourceDescriptor res : children2) {
                    if (setRU.contains(res.getUriString()))
                        continue;
                    setRU.add(res.getUriString());
                    if (SelectorDatasource.isDatasource(res))
                        continue;
                    if (res.getWsType().equals(ResourceDescriptor.TYPE_FOLDER))
                        listFolder(node, client, res.getUriString(), monitor, depth);
                    else
                        ResourceFactory.getResource(node, res, index);
                    if (monitor.isCanceled())
                        return children;
                }
            }
        }
        if (monitor.isCanceled())
            return children;
    }
    return children;
}

From source file:me.vertretungsplan.objects.SubstitutionSchedule.java

/**
 * Filter a set of substitutions by excluding a set of subjects
 *
 * @param excludedSubjects a set of subjects to exclude
 * @param substitutions    a set of {@link Substitution}s
 * @return the substitutions from the set that are not for one of the specified subjects
 *///from   ww  w . ja va  2  s  .  c  o  m
public static Set<Substitution> filterBySubject(Set<String> excludedSubjects, Set<Substitution> substitutions) {
    if (excludedSubjects == null || excludedSubjects.isEmpty())
        return substitutions;
    Set<Substitution> filteredSubstitutions = new HashSet<>();
    for (Substitution substitution : substitutions) {
        if (substitution.getPreviousSubject() != null) {
            if (!excludedSubjects.contains(substitution.getPreviousSubject())) {
                filteredSubstitutions.add(substitution);
            }
        } else if (substitution.getSubject() != null) {
            if (!excludedSubjects.contains(substitution.getSubject())) {
                filteredSubstitutions.add(substitution);
            }
        } else {
            filteredSubstitutions.add(substitution);
        }
    }
    return filteredSubstitutions;
}