Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:com.hazelcast.config.ConfigCompatibilityChecker.java

private static <T> void checkCompatibleConfigs(String type, Config c1, Config c2, Map<String, T> configs1,
        Map<String, T> configs2, ConfigChecker<T> checker) {

    final Set<String> configNames = new HashSet<String>(configs1.keySet());
    configNames.addAll(configs2.keySet());

    for (final String name : configNames) {
        final T config1 = ConfigUtils.lookupByPattern(c1.getConfigPatternMatcher(), configs1, name);
        final T config2 = ConfigUtils.lookupByPattern(c2.getConfigPatternMatcher(), configs2, name);
        if (config1 != null && config2 != null && !checker.check(config1, config2)) {
            throw new HazelcastException(
                    format("Incompatible " + type + " config :\n{0}\n vs \n{1}", config1, config2));
        }//from w  w  w . jav a 2  s.com
    }
    final T config1 = checker.getDefault(c1);
    final T config2 = checker.getDefault(c2);
    if (!checker.check(config1, config2)) {
        throw new HazelcastException(
                format("Incompatible default " + type + " config :\n{0}\n vs \n{1}", config1, config2));
    }
}

From source file:com.fluidops.iwb.widget.SemWiki.java

/**
 * Extracts semantic links from the old and from the new wiki page and collects the diff
 * inside the addStmts and remStmts variables.
 * //  w  ww  .  jav a 2  s .  c  om
 * @param wikiPageOld the old wiki page text (may be null or empty)
 * @param wikiPageNew (may be null or empty)
 * @param subject the URI represented by the wiki page
 * @param context the context in which to store the diff
 */
public static void saveSemanticLinkDiff(String wikiPageOld, String wikiPageNew, URI subject, Context context) {
    try {
        List<Statement> oldStmts = Wikimedia.getSemanticRelations(wikiPageOld, subject);
        List<Statement> newStmts = Wikimedia.getSemanticRelations(wikiPageNew, subject);

        // calculate stmts to remove
        Set<Statement> remStmts = new HashSet<Statement>();
        remStmts.addAll(oldStmts);
        remStmts.removeAll(newStmts);

        // calculate stmts to add
        Set<Statement> addStmts = new HashSet<Statement>();
        addStmts.addAll(newStmts);
        // Note msc: 
        // strictly speaking, we should do the following now:
        //
        // addStmts.removeAll(oldStmts);
        // 
        // , to add only those statements that were definitely added. Though we
        // encountered problems with this (e.g. when pressing the Save button
        // twice), resulting in statements that are visible in the Wiki as sem
        // links, but not contained in the DB. Given that the addToContext() 
        // will not create duplicates anyway, we write all statements, to avoid
        // the above-mentioned problems.

        ReadWriteDataManager dm = null;
        try {
            dm = ReadWriteDataManagerImpl.openDataManager(Global.repository);
            if (remStmts.size() > 0)
                dm.removeInEditableContexts(remStmts, context);

            if (addStmts.size() > 0)
                dm.addToContextNoDuplicates(addStmts, context);
        } finally {
            ReadWriteDataManagerImpl.closeQuietly(dm);
        }

        // update statements in keyword index
        KeywordIndexAPI.replaceKeywordIndexEntry(subject);
    } catch (Exception e) {
        String message = e.getMessage();
        if (e instanceof UnsupportedOperationException)
            message = "Write operations to the repository not supported (read only).";
        logger.debug("Error while saving semantic links: " + message);
        throw new RuntimeException("Error while saving semantic links: " + message, e);
    }
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

/** 
 * Get a list of calculators based on the property requested by the user
 * //  w w w . ja  va 2  s. co  m
 * getCalculators() calls itself in case the requiredCalculator list is not
 * empty.
 * 
 * @param prop
 *           Name of the requested properties
 * @param availCALCS
 *           is the full list of calculators defined by the XML files
 * @return  a set of calculators 
 */
private static Set<Calculator> getCalculators(String prop, Set<Calculator> availCALCS) {
    Set<Calculator> myCalcs = new LinkedHashSet<Calculator>();
    for (Calculator calc : availCALCS) {
        if (calc.getName().equals(prop)) {
            myCalcs.add(calc);
            for (String dep : calc.getRequiredCalculators()) {
                //recursively get all dependent calculators
                myCalcs.addAll(getCalculators(dep, availCALCS));
            }
        }
    }
    return myCalcs;
}

From source file:models.NotificationEvent.java

public static void afterNewCommitComment(Project project, ReviewComment comment, String commitId)
        throws IOException, SVNException, ServletException {
    Commit commit = RepositoryService.getRepository(project).getCommit(commitId);
    Set<User> watchers = commit.getWatchers(project);
    watchers.addAll(getMentionedUsers(comment.getContents()));
    watchers.remove(UserApp.currentUser());

    NotificationEvent notiEvent = createFromCurrentUser(comment);
    notiEvent.title = formatReplyTitle(project, commit);
    notiEvent.receivers = watchers;//  w  w w  .ja v a  2 s. com
    notiEvent.eventType = NEW_REVIEW_COMMENT;
    notiEvent.oldValue = null;
    notiEvent.newValue = comment.getContents();

    NotificationEvent.add(notiEvent);
}

From source file:models.NotificationEvent.java

public static void afterNewSVNCommitComment(Project project, CommitComment codeComment)
        throws IOException, SVNException, ServletException {
    Commit commit = RepositoryService.getRepository(project).getCommit(codeComment.commitId);
    Set<User> watchers = commit.getWatchers(project);
    watchers.addAll(getMentionedUsers(codeComment.contents));
    watchers.remove(UserApp.currentUser());

    NotificationEvent notiEvent = createFromCurrentUser(codeComment);
    notiEvent.title = formatReplyTitle(project, commit);
    notiEvent.receivers = watchers;//from   w w w .j  ava2s . c  o  m
    notiEvent.eventType = NEW_COMMENT;
    notiEvent.oldValue = null;
    notiEvent.newValue = codeComment.contents;

    NotificationEvent.add(notiEvent);
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <T extends Element> Set<T> removeInvisibleElements(Set<T> elements,
        HighlightConditionList highlightConditions) {
    Set<T> removed = new LinkedHashSet<>();

    highlightConditions.getConditions().stream().filter(c -> c.isInvisible()).forEach(c -> {
        Set<T> toRemove = c.getValues(elements).entrySet().stream().filter(e -> e.getValue() != 0.0)
                .map(e -> e.getKey()).collect(Collectors.toCollection(LinkedHashSet::new));

        elements.removeAll(toRemove);//from w  ww  . j  a v  a 2s . co  m
        removed.addAll(toRemove);
    });

    return removed;
}

From source file:com.evolveum.midpoint.repo.sql.data.common.RObject.java

public static void copyFromJAXB(PrismContainerValue containerValue, RObject repo, PrismContext prismContext,
        RObjectExtensionType ownerType) throws DtoTranslationException {
    RAnyConverter converter = new RAnyConverter(prismContext);

    Set<RAnyValue> values = new HashSet<RAnyValue>();
    try {//w ww  .  ja  v a  2s  .  c o  m
        List<Item<?, ?>> items = containerValue.getItems();
        //TODO: is this ehought??should we try items without definitions??
        if (items != null) {
            for (Item item : items) {
                values.addAll(converter.convertToRValue(item, false));
            }
        }
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }

    for (RAnyValue value : values) {
        ROExtValue ex = (ROExtValue) value;
        ex.setOwner(repo);
        ex.setOwnerType(ownerType);

        if (value instanceof ROExtDate) {
            repo.getDates().add(value);
        } else if (value instanceof ROExtLong) {
            repo.getLongs().add(value);
        } else if (value instanceof ROExtReference) {
            repo.getReferences().add(value);
        } else if (value instanceof ROExtString) {
            repo.getStrings().add(value);
        } else if (value instanceof ROExtPolyString) {
            repo.getPolys().add(value);
        } else if (value instanceof ROExtBoolean) {
            repo.getBooleans().add(value);
        }
    }

    repo.setStringsCount((short) repo.getStrings().size());
    repo.setDatesCount((short) repo.getDates().size());
    repo.setPolysCount((short) repo.getPolys().size());
    repo.setReferencesCount((short) repo.getReferences().size());
    repo.setLongsCount((short) repo.getLongs().size());
    repo.setBooleansCount((short) repo.getBooleans().size());
}

From source file:com.streamsets.pipeline.lib.util.ProtobufTypeUtil.java

/**
 * Loads a Protobuf file descriptor set into an ubermap of file descriptors.
 *
 * @param set               FileDescriptorSet
 * @param dependenciesMap   FileDescriptor dependency map
 * @param fileDescriptorMap The populated map of FileDescriptors
 * @throws StageException/*  www.j a  v a 2 s . c o  m*/
 */
public static void getAllFileDescriptors(DescriptorProtos.FileDescriptorSet set,
        Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
        Map<String, Descriptors.FileDescriptor> fileDescriptorMap) throws StageException {
    List<DescriptorProtos.FileDescriptorProto> fileList = set.getFileList();
    try {
        for (DescriptorProtos.FileDescriptorProto fdp : fileList) {
            if (!fileDescriptorMap.containsKey(fdp.getName())) {
                Set<Descriptors.FileDescriptor> dependencies = dependenciesMap.get(fdp.getName());
                if (dependencies == null) {
                    dependencies = new LinkedHashSet<>();
                    dependenciesMap.put(fdp.getName(), dependencies);
                    dependencies.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fdp, set));
                }
                Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom(fdp,
                        dependencies.toArray(new Descriptors.FileDescriptor[dependencies.size()]));
                fileDescriptorMap.put(fdp.getName(), fileDescriptor);
            }
        }
    } catch (Descriptors.DescriptorValidationException e) {
        throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
    }
}

From source file:models.NotificationEvent.java

/**
 * @see {@link controllers.PullRequestApp#newComment(String, String, Long, String)}
 *//*w w  w .ja v  a2s.  co m*/
public static void afterNewComment(User sender, PullRequest pullRequest, ReviewComment newComment,
        String urlToView) {
    NotificationEvent notiEvent = createFrom(sender, newComment);
    notiEvent.title = formatReplyTitle(pullRequest);
    Set<User> receivers = getMentionedUsers(newComment.getContents());
    receivers.addAll(getReceivers(sender, pullRequest));
    receivers.remove(User.findByLoginId(newComment.author.loginId));
    notiEvent.receivers = receivers;
    notiEvent.eventType = NEW_REVIEW_COMMENT;
    notiEvent.oldValue = null;
    notiEvent.newValue = newComment.getContents();

    NotificationEvent.add(notiEvent);
}

From source file:com.telefonica.iot.perseo.RulesManager.java

/**
 * Add all rules from a JSON representation of an array of objects with a
 * name field and a text field. If the rule exists with the same EPL text, it
 * is not re-created. Pre-existing rules not in the passed array and older
 * than a threshold (maxAge) will be deleted
 *
 * @param epService Esper provider containing rules
 * @param text JSON text of the rule/* ww  w.  j ava  2  s  .c  o  m*/
 *
 * @return Result object with a code and a JSON response
 */
public static synchronized Result updateAll(EPServiceProvider epService, String text) {
    try {
        long maxAge = Configuration.getMaxAge();
        logger.debug("rule block text: " + text);
        org.json.JSONArray ja = new JSONArray(text);
        logger.debug("rules as JSONArray: " + ja);
        logger.info("put rules+contexts: " + ja.length());
        Map<String, String> newOnes = new LinkedHashMap<String, String>();
        Set<String> oldOnesNames = new HashSet<String>();

        long now = System.currentTimeMillis();
        for (int i = 0; i < ja.length(); i++) {
            JSONObject jo = ja.getJSONObject(i);
            String name = jo.optString("name", "");
            if ("".equals(name.trim())) {
                return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing name\"}");
            }
            String newEpl = jo.optString("text", "");
            if ("".equals(newEpl.trim())) {
                return new Result(HttpServletResponse.SC_BAD_REQUEST, "{\"error\":\"missing text\"}");
            }
            newOnes.put(name, newEpl);
        }

        oldOnesNames.addAll(Arrays.asList(epService.getEPAdministrator().getStatementNames()));

        for (String n : newOnes.keySet()) {
            String newEpl = newOnes.get(n);
            if (!oldOnesNames.contains(n)) {
                logger.debug("found new statement: " + n);
                EPStatement statement = epService.getEPAdministrator().createEPL(newEpl, n);
                logger.debug("statement json: " + Utils.Statement2JSONObject(statement));
                statement.addListener(new GenericListener());
            } else {
                EPStatement prevStmnt = epService.getEPAdministrator().getStatement(n);
                String oldEPL = prevStmnt.getText();
                if (!oldEPL.equals(newOnes.get(n))) {
                    logger.debug("found changed statement: " + n);
                    prevStmnt.destroy();
                    logger.debug("deleted statement: " + n);
                    EPStatement statement = epService.getEPAdministrator().createEPL(newEpl, n);
                    logger.debug("re-created statement: " + n);
                    logger.debug("statement json: " + Utils.Statement2JSONObject(statement));
                    statement.addListener(new GenericListener());
                } else {
                    logger.debug("identical statement: " + n);
                }
                oldOnesNames.remove(n);
            }
        }
        //Delete oldOnes if they are old enough
        for (String o : oldOnesNames) {
            EPStatement prevStmnt = epService.getEPAdministrator().getStatement(o);
            logger.debug("unexpected statement: " + o);
            if (prevStmnt.getTimeLastStateChange() < now - maxAge) {
                logger.debug("unexpected statement, too old: " + o);
                prevStmnt.destroy();
                logger.debug("deleted garbage statement: " + o);
            }
        }
        return new Result(HttpServletResponse.SC_OK, "{}");
    } catch (EPException epe) {
        logger.error("creating statement " + epe);
        return new Result(HttpServletResponse.SC_BAD_REQUEST,
                String.format("{\"error\":%s}\n", JSONObject.valueToString(epe.getMessage())));
    } catch (JSONException je) {
        logger.error("creating statement " + je);
        return new Result(HttpServletResponse.SC_BAD_REQUEST,
                String.format("{\"error\":%s}\n", JSONObject.valueToString(je.getMessage())));
    }
}