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:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testMatchingCollections() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    Collection<String> coll = new HashSet<String>();
    coll.add("coll1");
    bw.setPropertyValue("collection", coll);
    Set<String> set = new HashSet<String>();
    set.add("set1");
    bw.setPropertyValue("set", set);
    SortedSet<String> sortedSet = new TreeSet<String>();
    sortedSet.add("sortedSet1");
    bw.setPropertyValue("sortedSet", sortedSet);
    List<String> list = new LinkedList<String>();
    list.add("list1");
    bw.setPropertyValue("list", list);
    assertSame(coll, tb.getCollection());
    assertSame(set, tb.getSet());/*from   w w  w  .  j  a  va  2  s .c  o m*/
    assertSame(sortedSet, tb.getSortedSet());
    assertSame(list, tb.getList());
}

From source file:com.collabnet.ccf.teamforge.TFWriter.java

private TrackerDO updateTrackerMetaData(GenericArtifact ga, String trackerId, Connection connection) {
    Map<String, SortedSet<String>> fieldsToBeChanged = new HashMap<String, SortedSet<String>>();
    // retrieve all fields that should be changed
    List<GenericArtifactField> fields = ga.getAllGenericArtifactFields();
    for (GenericArtifactField genericArtifactField : fields) {
        String fieldName = genericArtifactField.getFieldName();
        Object fieldValue = genericArtifactField.getFieldValue();
        SortedSet<String> values = fieldsToBeChanged.get(fieldName);
        if (values == null) {
            values = new TreeSet<String>();
            fieldsToBeChanged.put(fieldName, values);
        }//from  w  w  w  .ja  v  a  2s. c  om
        if (fieldValue != null) {
            values.add(fieldValue.toString());
        }
    }
    TrackerDO result = null;
    try {
        result = trackerHandler.updateTrackerMetaData(ga, trackerId, fieldsToBeChanged, connection);
    } catch (RemoteException e) {
        String cause = "Could not update meta data of tracker " + trackerId + e.getMessage();
        log.error(cause, e);
        ga.setErrorCode(GenericArtifact.ERROR_META_DATA_WRITE);
        throw new CCFRuntimeException(cause, e);
    }
    if (result != null) {
        log.info("Successfully updated meta data of tracker " + result.getId());
    }
    return result;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.scientificCouncil.thesis.ManageSecondCycleThesisSearchBean.java

public SortedSet<Enrolment> findEnrolments() {
    thesisPresentationStateCountMap = new ThesisPresentationStateCountMap();

    final SortedSet<Enrolment> result = new TreeSet<Enrolment>(Enrolment.COMPARATOR_BY_STUDENT_NUMBER);

    final Set<CurricularCourse> curricularCourses = new HashSet<CurricularCourse>();

    for (final ExecutionDegree executionDegree : executionYear.getExecutionDegreesSet()) {
        final DegreeCurricularPlan degreeCurricularPlan = executionDegree.getDegreeCurricularPlan();
        degreeCurricularPlan.applyToCurricularCourses(executionYear,
                new org.apache.commons.collections.Predicate() {
                    @Override//from   w ww  .  j a  va  2  s.c  o  m
                    public boolean evaluate(final Object arg0) {
                        final CurricularCourse curricularCourse = (CurricularCourse) arg0;
                        if (curricularCourse.isDissertation()) {
                            if (!curricularCourses.contains(curricularCourse)) {
                                curricularCourses.add(curricularCourse);
                                for (final CurriculumModule curriculumModule : curricularCourse
                                        .getCurriculumModulesSet()) {
                                    if (curriculumModule.isEnrolment()) {
                                        final Enrolment enrolment = (Enrolment) curriculumModule;
                                        if (enrolment.getExecutionYear() == executionYear) {
                                            final ThesisPresentationState state = ThesisPresentationState
                                                    .getThesisPresentationState(enrolment);
                                            if (presentationState == null || state == presentationState) {
                                                result.add(enrolment);
                                            }
                                            thesisPresentationStateCountMap.count(state);
                                        }
                                    }
                                }
                            }
                        }
                        return false;
                    }
                });
    }

    return result;
}

From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java

public static ExecutionCourse readLastBySigla(final String sigla) {
    SortedSet<ExecutionCourse> result = new TreeSet<ExecutionCourse>(
            EXECUTION_COURSE_EXECUTION_PERIOD_COMPARATOR);
    for (ExecutionCourse executionCourse : Bennu.getInstance().getExecutionCoursesSet()) {
        if (sigla.equalsIgnoreCase(executionCourse.getSigla())) {
            result.add(executionCourse);
        }/*from  w  ww  .j a v  a  2s . co  m*/
    }
    return result.isEmpty() ? null : result.last();
}

From source file:net.firejack.platform.core.cache.CacheProcessor.java

private Map<String, SortedSet<Action>> retrieveActionsByPackage() {
    //process actions
    Map<String, List<ActionModel>> actionList = actionStore.findAllWithPermissionsByPackage();
    Map<String, SortedSet<Action>> actionsMap = new HashMap<String, SortedSet<Action>>();
    for (Map.Entry<String, List<ActionModel>> packageActions : actionList.entrySet()) {
        if (packageActions.getValue() != null) {
            SortedSet<Action> actionSet = new TreeSet<Action>(new ActionComparator());
            for (ActionModel action : packageActions.getValue()) {
                Action actionInfo = modelFactory.convertTo(Action.class, action);
                actionSet.add(actionInfo);
            }/*from   w w  w  .ja v  a2s  . com*/
            actionsMap.put(packageActions.getKey(), actionSet);
        }
    }
    return actionsMap;
}

From source file:org.openmrs.module.rheapocadapter.impl.HL7MessageTransformer.java

private Person getProviderORUR01(OBR encObr) throws HL7Exception {
    XCN hl7Provider = encObr.getOrderingProvider(0);

    Person p = service.getPersonByNID(hl7Provider.getIDNumber().getValue());
    // Integer providerId = service.getPersonByNID(NID);

    if (p == null) {
        log.info(//from w w w .java  2  s. c  o  m
                "ID extracted from the HL7 message does not match with PoC records, a basic patient will be created...");
        Person providerCandidate = new Person();
        providerCandidate.setGender("N/A");
        PersonName name = new PersonName();

        if (hl7Provider.getGivenName().getValue() != null) {
            name.setGivenName(hl7Provider.getGivenName().getValue());
        } else {
            name.setGivenName("BLANK");
        }

        if (hl7Provider.getFamilyName().getSurname().getValue() != null) {
            name.setFamilyName(hl7Provider.getFamilyName().getSurname().getValue());
        } else {
            name.setFamilyName("BLANK");
        }

        SortedSet<PersonName> names = new TreeSet<PersonName>();

        names.add(name);
        providerCandidate.setNames(names);

        PersonAttributeType NIDAttributeType = Context.getPersonService().getPersonAttributeTypeByName("NID");

        if (NIDAttributeType == null) {
            log.info("Creating a PersonAttributeType for NID since it does not exsist");
            NIDAttributeType = new PersonAttributeType();
            NIDAttributeType.setName("NID");
            NIDAttributeType.setDescription("Stores the NID of the Person object");
            Context.getPersonService().savePersonAttributeType(NIDAttributeType);
        }

        PersonAttribute NIDAtrribute = new PersonAttribute();
        NIDAtrribute.setAttributeType(NIDAttributeType);
        NIDAtrribute.setValue(hl7Provider.getIDNumber().getValue());

        PersonAttributeType roleAttributeType = Context.getPersonService().getPersonAttributeType("Role");

        // We need to mark this patient as a potential provider.
        // The ideal way to do this would be to create a user object and set
        // its Role to Provider.
        // However, this would result in the creation and storage of an
        // additional object in the database.
        // Furthermore, we would be forced to define an username and
        // password for each of the new users.
        // Therefore, I am merely creating a person attribute of type Role,
        // and setting it to "Provider" (for now).

        if (roleAttributeType == null) {
            log.info("Creating a PersonAttributeType for Role since it does not exsist");
            roleAttributeType = new PersonAttributeType();
            roleAttributeType.setName("Role");
            roleAttributeType.setDescription("Stores the Role of the Person object");
            Context.getPersonService().savePersonAttributeType(roleAttributeType);
        }

        PersonAttribute roledAtrribute = new PersonAttribute();
        roledAtrribute.setAttributeType(roleAttributeType);
        roledAtrribute.setValue("Provider");

        SortedSet<PersonAttribute> attributes = new TreeSet<PersonAttribute>();
        attributes.add(NIDAtrribute);
        attributes.add(roledAtrribute);

        providerCandidate.setAttributes(attributes);

        Person candidate = Context.getPersonService().savePerson(providerCandidate);

        p = candidate;
    }
    return p;
}

From source file:net.firejack.platform.core.cache.CacheProcessor.java

@Override
public void addActions(List<Action> actions) {
    if (actions != null && !actions.isEmpty()) {
        Map<String, SortedSet<Action>> packageActions = new HashMap<String, SortedSet<Action>>();
        for (Action action : actions) {
            String packageLookup = getPackageLookup(action.getPath());
            SortedSet<Action> voList = packageActions.get(packageLookup);
            if (voList == null) {
                voList = new TreeSet<Action>(new ActionComparator());
                packageActions.put(packageLookup, voList);
            }//from   w  w w.  j a va 2  s.c  om
            voList.add(action);
        }
        CacheManager cacheManager = CacheManager.getInstance();
        for (Map.Entry<String, SortedSet<Action>> packageActionsEntry : packageActions.entrySet()) {

            List<Action> cachedActions = cacheManager.getActions(packageActionsEntry.getKey());
            if (cachedActions == null) {
                cachedActions = new LinkedList<Action>();
            }
            for (Action action : packageActionsEntry.getValue()) {
                cachedActions.add(action);
            }
            cacheManager.setActions(packageActionsEntry.getKey(), cachedActions);
        }
    }
}

From source file:main.java.workload.Workload.java

public static Set<Integer> getTrDataSet(Database db, Cluster cluster, WorkloadBatch wb,
        Set<Integer> trTupleSet) {

    Set<Integer> trDataSet = new TreeSet<Integer>();
    SortedSet<Integer> deletedTuples = new TreeSet<Integer>();

    int s_id = 1;
    for (int tpl_id : trTupleSet) {

        if (!deletedTuples.contains(tpl_id)) {

            String[] parts = Cluster.breakDataIdWithoutReplicaId(tpl_id);
            int tpl_pk = Integer.parseInt(parts[0]);
            int tbl_id = Integer.parseInt(parts[1]);

            Tuple tpl = db.getTupleById(tbl_id, tpl_id);
            int _id = -1;

            if (tpl.getTuple_action().equals(WorkloadConstants.TPL_INSERT)) {

                tpl.setTuple_action(WorkloadConstants.TPL_INITIAL);

                // Insert into Cluster, already in the Database               
                switch (Global.setup) {
                case "range":
                    Server s = cluster.getServer(s_id);
                    int p_id = cluster.getRangePartition(s, tbl_id);

                    _id = cluster.insertData_RangePartitioning(tpl_id, s_id, p_id);

                    ++s_id;/*from ww w. j  a v a  2  s .c om*/
                    if (s_id > Global.servers)
                        s_id = 1;

                    break;

                case "consistenthash":
                    _id = cluster.insertData_ConsistentHash(tpl_id);
                    break;

                default:
                    Global.LOGGER.error(
                            "Wrong cluster setup method is specified !!! Choose either 'range' or 'consistenthash'");
                    break;
                }

                trDataSet.add(_id);

            } else if (tpl.getTuple_action().equals("delete")) {
                // Remove from Cluster
                switch (Global.setup) {
                case "range":
                    cluster.deleteDataRangePartitioning(tpl_id);
                    break;

                case "consistenthash":
                    cluster.deleteDataConsistentHashing(tpl_id);
                    break;

                default:
                    Global.LOGGER.error(
                            "Wrong cluster setup method is specified !!! Choose either 'range' or 'consistenthash'");
                    break;
                }

                // Remove from Database
                db.deleteTupleByPk(tbl_id, tpl_pk);

                _id = Cluster.getDataIdFromTupleId(tpl_id);

                // Remove from Workload Batch                                    
                // Removing vertex in Workload Batch graph and hypergraph                  
                wb.deleteTrDataFromWorkload(_id);

                SimpleVertex v = wb.hgr.getVertex(_id);
                if (v != null) {
                    wb.hgr.removeVertex(v);
                }

                deletedTuples.add(tpl_id);

            } else {

                _id = Cluster.getDataIdFromTupleId(tpl_id);
                trDataSet.add(_id);
            }
        } // end--if()
    } // Tuple

    return trDataSet;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

private SortedSet<YearMonthDay> getAllValidLessonDatesWithoutInstancesDates(YearMonthDay startDateToSearch,
        YearMonthDay endDateToSearch) {//w  w  w  . ja  v a 2  s.  c o m

    SortedSet<YearMonthDay> result = new TreeSet<YearMonthDay>();
    startDateToSearch = startDateToSearch != null ? getValidBeginDate(startDateToSearch) : null;

    if (!wasFinished() && startDateToSearch != null && endDateToSearch != null
            && !startDateToSearch.isAfter(endDateToSearch)) {
        Space lessonCampus = getLessonCampus();
        final int dayIncrement = getFrequency() == FrequencyType.BIWEEKLY
                ? FrequencyType.WEEKLY.getNumberOfDays()
                : getFrequency().getNumberOfDays();
        boolean shouldAdd = true;
        while (true) {
            if (isDayValid(startDateToSearch, lessonCampus)) {
                if (getFrequency() != FrequencyType.BIWEEKLY || shouldAdd) {
                    if (!isHoliday(startDateToSearch, lessonCampus)) {
                        result.add(startDateToSearch);
                    }
                }
                shouldAdd = !shouldAdd;
            }
            startDateToSearch = startDateToSearch.plusDays(dayIncrement);
            if (startDateToSearch.isAfter(endDateToSearch)) {
                break;
            }
        }
    }
    return result;
}

From source file:net.sourceforge.fenixedu.domain.Teacher.java

public SortedSet<ExecutionCourse> getCurrentExecutionCourses() {
    final SortedSet<ExecutionCourse> executionCourses = new TreeSet<ExecutionCourse>(
            ExecutionCourse.EXECUTION_COURSE_COMPARATOR_BY_EXECUTION_PERIOD_AND_NAME);
    final ExecutionSemester currentExecutionPeriod = ExecutionSemester.readActualExecutionSemester();
    final ExecutionSemester previousExecutionPeriod = currentExecutionPeriod.getPreviousExecutionPeriod();
    for (final Professorship professorship : getProfessorshipsSet()) {
        final ExecutionCourse executionCourse = professorship.getExecutionCourse();
        final ExecutionSemester executionSemester = executionCourse.getExecutionPeriod();
        if (executionSemester == currentExecutionPeriod || executionSemester == previousExecutionPeriod) {
            executionCourses.add(executionCourse);
        }//from ww  w.  j av a 2  s.co m
    }
    return executionCourses;
}