Example usage for java.util SortedSet add

List of usage examples for java.util SortedSet add

Introduction

In this page you can find the example usage for java.util SortedSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.aurel.track.admin.customize.category.filter.execute.loadItems.LoadItemLinksUtil.java

/**
 * Gets all linked workItems// ww  w.  jav  a2  s .  co  m
 * @param itemBeanList
 * @param itemLinkBeans
 * @param personID
 * @param locale
 * @param ganntMSProjectReportBeanLinksMap out parameter for "reversed" (gantt compatible MS Project links)
 * @return
 */
public static Map<Integer, SortedSet<ReportBeanLink>> getAllLinkedWorkItems(List<TWorkItemBean> itemBeanList,
        List<TWorkItemLinkBean> itemLinkBeans, Integer personID, Locale locale,
        Map<Integer, SortedSet<ReportBeanLink>> ganntMSProjectReportBeanLinksMap) {
    Map<Integer, SortedSet<ReportBeanLink>> allLinkedWorkItems = new HashMap<Integer, SortedSet<ReportBeanLink>>();
    Set<Integer> baseWorkItemIDsSet = new HashSet<Integer>();
    Map<Integer, TWorkItemBean> itemBeanMap = new HashMap<Integer, TWorkItemBean>();
    if (itemBeanList != null) {
        for (TWorkItemBean workItemBean : itemBeanList) {
            Integer workItemID = workItemBean.getObjectID();
            baseWorkItemIDsSet.add(workItemID);
            itemBeanMap.put(workItemID, workItemBean);
        }
    }
    if (itemLinkBeans == null) {
        return allLinkedWorkItems;
    }
    Map<Integer, ILinkType> linkTypeIDToLinkTypeMap = LinkTypeBL.getLinkTypeIDToLinkTypeMap();
    //if project specificID is active gather the linked workItems not included in the reportBeanList
    Map<Integer, TWorkItemBean> linkedWorkItemsMap = new HashMap<Integer, TWorkItemBean>();
    Set<Integer> links = new HashSet<Integer>();
    boolean projectSpecificIDsActive = ApplicationBean.getInstance().getSiteBean().getProjectSpecificIDsOn();
    for (TWorkItemLinkBean workItemLinkBean : itemLinkBeans) {
        Integer linkPred = workItemLinkBean.getLinkPred();
        Integer linkSucc = workItemLinkBean.getLinkSucc();
        if (linkPred != null && !baseWorkItemIDsSet.contains(linkPred)) {
            links.add(linkPred);
        }
        if (linkSucc != null && !baseWorkItemIDsSet.contains(linkSucc)) {
            links.add(linkSucc);
        }
    }
    if (!links.isEmpty()) {
        List<TWorkItemBean> linkedWorkItemBeans = LoadItemIDListItems.getWorkItemBeansByWorkItemIDs(
                GeneralUtils.createIntArrFromIntegerCollection(links), personID, false, false, false);
        for (TWorkItemBean workItemBean : linkedWorkItemBeans) {
            linkedWorkItemsMap.put(workItemBean.getObjectID(), workItemBean);
        }
    }
    Map<String, String> linkTypeNames = LinkTypeBL.getLinkTypeNamesMap(locale);
    Map<Integer, TLinkTypeBean> allLinkTypesMap = GeneralUtils.createMapFromList(LinkTypeBL.loadAll());
    List<Integer> msProjectLinkTypes = null;
    //gather the MSProject link types if Gantt MSProject links are needed
    if (ganntMSProjectReportBeanLinksMap != null) {
        MsProjectLinkType msProjectLinkType = MsProjectLinkType.getInstance();
        msProjectLinkTypes = LinkTypeBL.getLinkTypesByPluginClass(msProjectLinkType);
    }
    for (TWorkItemLinkBean workItemLinkBean : itemLinkBeans) {
        Integer linkID = workItemLinkBean.getObjectID();
        Integer linkTypeID = workItemLinkBean.getLinkType();
        Integer linkDirection = workItemLinkBean.getLinkDirection();
        Integer linkPred = workItemLinkBean.getLinkPred();
        Integer linkSucc = workItemLinkBean.getLinkSucc();
        if (linkSucc == null) {
            //link to a non-workItem
            continue;
        }
        TLinkTypeBean linkTypeBean = allLinkTypesMap.get(linkTypeID);
        if (linkTypeBean != null) {
            SortedSet<ReportBeanLink> allLinksForWorkItem;
            Integer linkTypeDirection = linkTypeBean.getLinkDirection();
            ILinkType linkType = null;
            switch (linkTypeDirection) {
            case LINK_DIRECTION.UNIDIRECTIONAL_OUTWARD:
                allLinksForWorkItem = allLinkedWorkItems.get(linkPred);
                if (allLinksForWorkItem == null) {
                    allLinksForWorkItem = new TreeSet<ReportBeanLink>();
                    allLinkedWorkItems.put(linkPred, allLinksForWorkItem);
                }
                TWorkItemBean linkedItemBeanOutward = getLinkedReportBean(itemBeanMap, linkSucc);
                String outwardLinkTitle = getLinkedItemTitle(linkedItemBeanOutward, linkedWorkItemsMap,
                        linkSucc);
                ReportBeanLink reportBeanLinkOutward = new ReportBeanLink(linkID, linkSucc, outwardLinkTitle,
                        linkedItemBeanOutward != null, linkTypeID, linkDirection,
                        linkTypeNames.get(MergeUtil.mergeKey(linkTypeID, linkDirection)));
                if (projectSpecificIDsActive && linkSucc != null) {
                    reportBeanLinkOutward.setProjectSpecificIssueNo(
                            getProjectSpecificIssueNo(linkedItemBeanOutward, linkedWorkItemsMap, linkSucc));
                }
                linkType = linkTypeIDToLinkTypeMap.get(linkTypeID);
                if (linkType != null) {
                    reportBeanLinkOutward
                            .setLinkSpecificData(linkType.getItemLinkSpecificData(workItemLinkBean));
                }
                allLinksForWorkItem.add(reportBeanLinkOutward);
                break;
            case LINK_DIRECTION.UNIDIRECTIONAL_INWARD:
                allLinksForWorkItem = allLinkedWorkItems.get(linkSucc);
                if (allLinksForWorkItem == null) {
                    allLinksForWorkItem = new TreeSet<ReportBeanLink>();
                    allLinkedWorkItems.put(linkSucc, allLinksForWorkItem);
                }
                TWorkItemBean linkedItemBeanInward = getLinkedReportBean(itemBeanMap, linkPred);
                String inwardLinkTitle = getLinkedItemTitle(linkedItemBeanInward, linkedWorkItemsMap, linkPred);
                ReportBeanLink reportBeanLinkInward = new ReportBeanLink(linkID, linkPred, inwardLinkTitle,
                        linkedItemBeanInward != null, linkTypeID, linkDirection,
                        linkTypeNames.get(MergeUtil.mergeKey(linkTypeID, linkDirection)));
                if (projectSpecificIDsActive && linkPred != null) {
                    reportBeanLinkInward.setProjectSpecificIssueNo(
                            getProjectSpecificIssueNo(linkedItemBeanInward, linkedWorkItemsMap, linkPred));
                }
                linkType = linkTypeIDToLinkTypeMap.get(linkTypeID);
                if (linkType != null) {
                    reportBeanLinkInward
                            .setLinkSpecificData(linkType.getItemLinkSpecificData(workItemLinkBean));
                }
                allLinksForWorkItem.add(reportBeanLinkInward);
                if (ganntMSProjectReportBeanLinksMap != null && msProjectLinkTypes != null
                        && msProjectLinkTypes.contains(linkTypeID)) {
                    //for Gantt chart the predecessors should contain the successors: same as it would be UNIDIRECTIONAL_OUTWARD, but only for msProject link types
                    SortedSet<ReportBeanLink> ganntMSProjectReportBeanLinkSet = ganntMSProjectReportBeanLinksMap
                            .get(linkPred);
                    if (ganntMSProjectReportBeanLinkSet == null) {
                        ganntMSProjectReportBeanLinkSet = new TreeSet<ReportBeanLink>();
                        ganntMSProjectReportBeanLinksMap.put(linkPred, ganntMSProjectReportBeanLinkSet);
                    }
                    reportBeanLinkInward = new ReportBeanLink(linkID, linkSucc, inwardLinkTitle,
                            linkedItemBeanInward != null, linkTypeID, linkDirection,
                            linkTypeNames.get(MergeUtil.mergeKey(linkTypeID, linkDirection)));
                    //now only the MsProject links for the gantt chart need this specific data
                    reportBeanLinkInward.setLinkSpecificData(
                            MsProjectLinkType.getInstance().getItemLinkSpecificData(workItemLinkBean));
                    if (projectSpecificIDsActive && linkPred != null) {
                        reportBeanLinkInward.setProjectSpecificIssueNo(
                                getProjectSpecificIssueNo(linkedItemBeanInward, linkedWorkItemsMap, linkSucc));
                    }
                    ganntMSProjectReportBeanLinkSet.add(reportBeanLinkInward);
                }
                break;
            case LINK_DIRECTION.BIDIRECTIONAL:
                allLinksForWorkItem = allLinkedWorkItems.get(linkPred);
                if (allLinksForWorkItem == null) {
                    allLinksForWorkItem = new TreeSet<ReportBeanLink>();
                    allLinkedWorkItems.put(linkPred, allLinksForWorkItem);
                }
                TWorkItemBean succLinkedItemBean = getLinkedReportBean(itemBeanMap, linkSucc);
                String succLinkTitle = getLinkedItemTitle(succLinkedItemBean, linkedWorkItemsMap, linkSucc);
                ReportBeanLink reportBeanLinkSucc = new ReportBeanLink(linkID, linkSucc, succLinkTitle,
                        succLinkedItemBean != null, linkTypeID, linkDirection,
                        linkTypeNames.get(MergeUtil.mergeKey(linkTypeID, linkDirection)));
                if (projectSpecificIDsActive && linkSucc != null) {
                    reportBeanLinkSucc.setProjectSpecificIssueNo(
                            getProjectSpecificIssueNo(succLinkedItemBean, linkedWorkItemsMap, linkSucc));
                }
                linkType = linkTypeIDToLinkTypeMap.get(linkTypeID);
                if (linkType != null) {
                    reportBeanLinkSucc.setLinkSpecificData(linkType.getItemLinkSpecificData(workItemLinkBean));
                }
                allLinksForWorkItem.add(reportBeanLinkSucc);
                if (linkDirection != null) {
                    int reverseDirection = LinkTypeBL.getReverseDirection(linkDirection.intValue());
                    allLinksForWorkItem = allLinkedWorkItems.get(linkSucc);
                    if (allLinksForWorkItem == null) {
                        allLinksForWorkItem = new TreeSet<ReportBeanLink>();
                        allLinkedWorkItems.put(linkSucc, allLinksForWorkItem);
                    }
                    TWorkItemBean predLinkedItemBean = getLinkedReportBean(itemBeanMap, linkPred);
                    String predLinkTitle = getLinkedItemTitle(predLinkedItemBean, linkedWorkItemsMap, linkPred);
                    ReportBeanLink reportBeanLinkPred = new ReportBeanLink(linkID, linkPred, predLinkTitle,
                            predLinkedItemBean != null, linkTypeID, Integer.valueOf(reverseDirection),
                            linkTypeNames
                                    .get(MergeUtil.mergeKey(linkTypeID, Integer.valueOf(reverseDirection))));
                    if (projectSpecificIDsActive && linkPred != null) {
                        reportBeanLinkPred.setProjectSpecificIssueNo(
                                getProjectSpecificIssueNo(predLinkedItemBean, linkedWorkItemsMap, linkPred));
                    }
                    if (linkType != null) {
                        reportBeanLinkPred
                                .setLinkSpecificData(linkType.getItemLinkSpecificData(workItemLinkBean));
                    }
                    allLinksForWorkItem.add(reportBeanLinkPred);
                }
                break;
            default:
                break;
            }
        }
    }
    return allLinkedWorkItems;
}

From source file:io.wcm.caconfig.editor.impl.ConfigNamesServlet.java

private JSONArray getConfigNames(Resource contextResource) throws JSONException {
    JSONArray output = new JSONArray();

    SortedSet<String> configNames = configManager.getConfigurationNames();
    SortedSet<JSONObject> sortedResult = new TreeSet<>(new Comparator<JSONObject>() {
        @Override/*from w  w  w.j  a va 2s  . c  om*/
        public int compare(JSONObject o1, JSONObject o2) {
            String label1 = o1.optString("label");
            String label2 = o2.optString("label");
            if (StringUtils.equals(label1, label2)) {
                String configName1 = o1.optString("configName");
                String configName2 = o2.optString("configName");
                return configName1.compareTo(configName2);
            }
            return label1.compareTo(label2);
        }
    });
    for (String configName : configNames) {
        ConfigurationMetadata metadata = configManager.getConfigurationMetadata(configName);
        if (metadata != null) {
            JSONObject item = new JSONObject();
            item.put("configName", configName);
            item.putOpt("label", metadata.getLabel());
            item.putOpt("description", metadata.getDescription());
            item.put("collection", metadata.isCollection());
            item.put("exists", hasConfig(contextResource, configName, metadata.isCollection()));
            item.put("allowAdd", allowAdd(contextResource, configName));
            sortedResult.add(item);
        }
    }

    sortedResult.forEach(output::put);

    return output;
}

From source file:carskit.data.processor.DataDAO.java

/**
 * @param rawId/*from  w w  w  .j  av a2  s.c o  m*/
 *            raw context id as String
 * @return inner context id as int
 */
public int getContextId(String rawId) {
    //System.out.println(rawId);
    int id;
    if (rawId.contains(":")) { // in shape of dim:c, dim:c
        String[] ccs = rawId.toLowerCase().split(",");
        SortedSet<Integer> set = new TreeSet<Integer>();
        for (int i = 0; i < ccs.length; ++i)
            set.add(this.getContextConditionId(ccs[i].trim()));
        StringBuilder sb = new StringBuilder();
        Iterator<Integer> itor = set.iterator();
        while (itor.hasNext()) {
            if (sb.length() > 0)
                sb.append(",");
            sb.append(itor.next());
        }
        return getContextId(sb.toString());
    } else // in shape of 1,2,3,
        id = ctxIds.get(rawId);
    return id;
}

From source file:org.sakaiproject.lessonbuildertool.service.ForumEntity.java

public List<LessonEntity> getEntitiesInSite(SimplePageBean bean) {

    List<LessonEntity> ret = new ArrayList<LessonEntity>();

    // LSNBLDR-21. If the tool is not in the current site we shouldn't query
    // for topics owned by the tool.
    Site site = null;/*www.  j a v  a2  s .  c o m*/
    try {
        site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext());
    } catch (Exception impossible) {
        return ret;
    }

    ToolConfiguration tool = site.getToolForCommonId("sakai.forums");

    if (tool == null) {

        // Forums is not in this site. Move on to the next provider.

        if (nextEntity != null)
            ret.addAll(nextEntity.getEntitiesInSite());

        return ret;
    }

    //ForumEntity e = new ForumEntity(TYPE_FORUM_TOPIC, 3L, 2);

    //e.setGroups(Arrays.asList("1c24287b-b880-43da-8cdd-c6cdc1249c5c", "75184424-853e-4dd4-9e92-980c851f0580"));
    //e.setGroups(Arrays.asList("75184424-853e-4dd4-9e92-980c851f0580"));

    SortedSet<DiscussionForum> forums = new TreeSet<DiscussionForum>(
            new ForumBySortIndexAscAndCreatedDateDesc());
    for (DiscussionForum forum : forumManager.getForumsForMainPage())
        forums.add(forum);

    // security. assume this is only used in places where it's OK, so skip security checks
    for (DiscussionForum forum : forums) {
        if (!forum.getDraft()) {
            ForumEntity entity = new ForumEntity(TYPE_FORUM_FORUM, forum.getId(), 1);
            entity.forum = forum;
            ret.add(entity);
            for (Object o : forum.getTopicsSet()) {
                DiscussionTopic topic = (DiscussionTopic) o;
                if (topic.getDraft().equals(Boolean.FALSE)) {
                    entity = new ForumEntity(TYPE_FORUM_TOPIC, topic.getId(), 2);
                    entity.topic = topic;
                    ret.add(entity);
                }
            }
        }
    }

    if (nextEntity != null)
        ret.addAll(nextEntity.getEntitiesInSite(bean));

    return ret;
}

From source file:com.google.gwt.emultest.java.util.TreeSetTest.java

/**
 * Test method for 'java.util.SortedSet.first()'.
 *
 * @see java.util.SortedSet#first()//from www  .  ja  v  a  2s.c o  m
 */
public void testFirst() {
    SortedSet<E> sortedSet = createNavigableSet();
    // test with a single entry set
    sortedSet.add(getKeys()[0]);
    assertEquals(getKeys()[0], sortedSet.first());
    // is it consistent with other methods
    assertEquals(sortedSet.toArray()[0], sortedSet.first());
    assertEquals(getKeys()[0], sortedSet.last());
    assertEquals(sortedSet.last(), sortedSet.first());

    // test with two entry set
    sortedSet.add(getKeys()[1]);
    assertEquals(getKeys()[0], sortedSet.first());
    assertFalse(getKeys()[1].equals(sortedSet.first()));
    // is it consistent with other methods
    assertEquals(sortedSet.toArray()[0], sortedSet.first());
    assertFalse(getKeys()[0].equals(sortedSet.last()));
    assertFalse(sortedSet.last().equals(sortedSet.first()));
}

From source file:com.google.gwt.emultest.java.util.TreeSetTest.java

/**
 * Test method for 'java.util.SortedSet.last()'.
 *
 * @see java.util.SortedSet#last()/*from w  w  w.j a  v  a  2  s . c om*/
 */
public void testLastKey() {
    SortedSet<E> sortedSet = createNavigableSet();

    // test with a single entry set
    sortedSet.add(getKeys()[0]);
    assertEquals(getKeys()[0], sortedSet.last());
    // is it consistent with other methods
    assertEquals(sortedSet.toArray()[0], sortedSet.last());
    assertEquals(getKeys()[0], sortedSet.first());
    assertEquals(sortedSet.first(), sortedSet.last());

    // test with two entry set
    sortedSet.add(getKeys()[1]);
    assertEquals(getKeys()[1], sortedSet.last());
    assertFalse(getKeys()[0].equals(sortedSet.last()));
    // is it consistent with other methods
    assertEquals(sortedSet.toArray()[1], sortedSet.last());
    assertEquals(getKeys()[0], sortedSet.first());
    assertFalse(sortedSet.first().equals(sortedSet.last()));
}

From source file:cerrla.modular.ModularPolicy.java

/**
 * Creates a new modular policy from an existing basic relational policy.
 * //from  ww  w. jav a 2s . com
 * @param basicPolicy
 *            The basic policy with rules to transfer to this policy.
 * @param policyGenerator
 *            The generator that created this policy.
 */
public ModularPolicy(RelationalPolicy newPol, LocalCrossEntropyDistribution policyGenerator) {
    this(policyGenerator);
    policySize_ = newPol.size();
    isEvaluated_ = false;

    // Add the rules, creating ModularHoles where appropriate.
    SortedSet<GoalCondition> subGoals = new TreeSet<GoalCondition>(new GoalConditionComparator());
    for (PolicyItem reo : newPol.getRules()) {
        if (reo instanceof RelationalRule) {
            RelationalRule rule = (RelationalRule) reo;
            policyRules_.add(reo);

            // Checking for sub-goals
            // Only have each sub-goal once
            if (ProgramArgument.USE_MODULES.booleanValue()) {
                Collection<SpecificGoalCondition> goalConds = rule.getSpecificSubGoals();
                for (GoalCondition gc : goalConds) {
                    if (!subGoals.contains(gc)) {
                        ModularSubGoal subGoal = new ModularSubGoal(gc, rule);
                        subGoals.add(gc);
                        policyRules_.add(subGoal);
                        childrenPolicies_.put(rule, subGoal);
                    }
                }
            }

            // General sub-goals
            if (ProgramArgument.USE_GENERAL_MODULES.booleanValue()) {
                Collection<GeneralGoalCondition>[] generalisedConds = rule.getGeneralisedConditions();
                // Add all general conditions, and fill in the blanks
                // when necessary.
                for (GoalCondition gc : generalisedConds[0]) {
                    if (!subGoals.contains(gc)) {
                        ModularSubGoal subGoal = new ModularSubGoal(gc, rule);
                        subGoals.add(gc);
                        policyRules_.add(subGoal);
                        childrenPolicies_.put(rule, subGoal);
                    }
                }
                for (GoalCondition gc : generalisedConds[1]) {
                    if (!subGoals.contains(gc)) {
                        ModularSubGoal subGoal = new ModularSubGoal(gc, rule);
                        subGoals.add(gc);
                        policyRules_.add(subGoal);
                        childrenPolicies_.put(rule, subGoal);
                    }
                }
            }
        }
    }
}

From source file:com.google.gwt.emultest.java.util.TreeSetTest.java

/**
 * Test method for 'java.util.TreeSet.TreeSet(SortedSet)'.
 *
 * @see java.util.TreeSet#TreeSet(SortedSet)
 */// w w  w  .j  a  va  2s. com
public void testConstructor_SortedSet() {
    SortedSet<E> sourceMap = new TreeSet<E>();
    _assertEmpty(sourceMap);

    // populate the source set
    sourceMap.add(getKeys()[0]);
    sourceMap.add(getKeys()[1]);
    sourceMap.add(getKeys()[2]);

    TreeSet<E> copyConstructed = new TreeSet<E>(sourceMap);
    _assertEquals(sourceMap, copyConstructed);
}

From source file:org.guicerecipes.spring.support.AutowiredMemberProvider.java

protected Set<Binding<?>> getSortedBindings(Class<?> type, Predicate<Binding> filter) {
    SortedSet<Binding<?>> answer = new TreeSet<Binding<?>>(new Comparator<Binding<?>>() {
        public int compare(Binding<?> b1, Binding<?> b2) {

            int answer = typeName(b1).compareTo(typeName(b2));
            if (answer == 0) {
                // TODO would be nice to use google colletions here but its excluded from guice
                String n1 = annotationName(b1);
                String n2 = annotationName(b2);
                if ((n1 != null) || (n2 != null)) {
                    if (n1 == null) {
                        return -1;
                    }//from  w  w w  .  j  a va 2  s .  c o  m
                    if (n2 == null) {
                        return 1;
                    }
                    return n1.compareTo(n2);
                }
            }
            return answer;
        }
    });
    Set<Binding<?>> bindings = Injectors.getBindingsOf(injector, type);
    for (Binding<?> binding : bindings) {
        if (isValidAutowireBinding(binding) && filter.matches(binding)) {
            answer.add(binding);
        }
    }
    /*
     * if (answer.isEmpty() && bindings.size() == 1) { // if we have no matches on the filter, but we have a single static value, lets return it return bindings; }
     */
    return answer;
}

From source file:com.atlassian.jira.bc.group.DefaultGroupService.java

@Override
public Collection<String> getChildGroupNames(com.atlassian.crowd.embedded.api.Group group) {
    final com.atlassian.crowd.search.query.membership.MembershipQuery<com.atlassian.crowd.embedded.api.Group> membershipQuery = QueryBuilder
            .queryFor(com.atlassian.crowd.embedded.api.Group.class, EntityDescriptor.group())
            .childrenOf(EntityDescriptor.group()).withName(group.getName())
            .returningAtMost(EntityQuery.ALL_RESULTS);

    final SortedSet<String> setOfGroups = new TreeSet<String>();

    Iterable<com.atlassian.crowd.embedded.api.Group> children = crowdService.search(membershipQuery);
    for (com.atlassian.crowd.embedded.api.Group child : children) {
        if (crowdService.isGroupDirectGroupMember(child, group)) {
            setOfGroups.add(child.getName());
        }//from  w  w  w . jav a2 s . c o m
    }
    return Collections.unmodifiableSortedSet(setOfGroups);
}