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:gov.nih.nci.caarray.dao.ProjectDaoTest.java

@Test
public void testGetTermsForExperiment() {
    Transaction tx = null;/*ww w  .  j  a  v  a 2  s.c  o m*/
    try {
        tx = this.hibernateHelper.beginTransaction();
        final Organism org = new Organism();
        org.setScientificName("Foo");
        org.setTermSource(DUMMY_TERM_SOURCE);
        Project p = new Project();
        Experiment e = p.getExperiment();
        e.setProject(p);
        e.setTitle("test title");
        final SortedSet<AssayType> assayTypes = new TreeSet<AssayType>();
        assayTypes.add(DUMMY_ASSAYTYPE_1);
        e.setAssayTypes(assayTypes);
        e.setManufacturer(new Organization());
        e.setOrganism(org);
        daoObject.save(p);
        daoObject.save(DUMMY_ASSAYTYPE_1);
        daoObject.save(DUMMY_ASSAYTYPE_2);
        assertEquals(0, daoObject.getCellTypesForExperiment(e).size());
        assertEquals(0, daoObject.getDiseaseStatesForExperiment(e).size());
        assertEquals(0, daoObject.getTissueSitesForExperiment(e).size());
        assertEquals(0, daoObject.getMaterialTypesForExperiment(e).size());
        tx.commit();
    } catch (final DAOException e) {
        this.hibernateHelper.rollbackTransaction(tx);
        throw e;
    }
}

From source file:Arguments.java

/**
 * Returns a verbose String that documents this Arguments instance. It summarizes your options
 * into required, non-required, and positional fields. For long args it also tells you which
 * fields should have a value if it is present.
 *//*from ww  w .j  av  a2s  .c  o  m*/
public String getDocumentation() {
    StringBuilder buf = new StringBuilder("\n");
    int maxFlagSize = 0;
    SortedSet<String> reqList = new TreeSet<String>();
    SortedSet<String> nonReqList = new TreeSet<String>();

    if (programName.length() > 0) {
        buf.append(programName + ": ");
    }
    if (shortProgramDoc.length() > 0) {
        buf.append(shortProgramDoc + "\n");
    } else {
        buf.append("Complete documentation...\n");
    }

    // add flags to required/non-required sets
    for (String docMe : docs.keySet()) {
        maxFlagSize = Math.max(maxFlagSize, docMe.length());
        if (requireFlag.contains(docMe)) {
            reqList.add(docMe);
        } else {
            nonReqList.add(docMe);
        }
    }

    // add positional fields to required/non-required sets
    for (int i = 0; i < positionalDocs.size(); i++) {
        List<String> posDoc = positionalDocs.get(i);
        String pseudoFlag = getPseudoFlag(i, posDoc.get(0));
        maxFlagSize = Math.max(maxFlagSize, pseudoFlag.length());
    }
    if (reqList.size() > 0) {
        buf.append("codeTitle>Required flags:\n\n");
        buf.append(getDocumentation(reqList, maxFlagSize));
    }
    if (nonReqList.size() > 0) {
        buf.append("\n  Non-required flags:\n\n");
        buf.append(getDocumentation(nonReqList, maxFlagSize));
    }
    if (positionalDocs.size() > 0) {
        buf.append("\n   Positional fields:\n\n");
        for (int i = 0; i < positionalDocs.size(); i++) {
            List<String> posDoc = positionalDocs.get(i);
            String pseudoFlag = getPseudoFlag(i, posDoc.get(0));
            buf.append(formatDocumentation(pseudoFlag, space, maxFlagSize, posDoc.get(1), 70));
        }
    }
    return buf.toString();
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityApplicationProcess.java

private void addCandidacy(final Map<Degree, SortedSet<SecondCycleIndividualCandidacyProcess>> result,
        final SecondCycleIndividualCandidacyProcess process) {
    SortedSet<SecondCycleIndividualCandidacyProcess> values = result.get(process.getCandidacySelectedDegree());
    if (values == null) {
        result.put(process.getCandidacySelectedDegree(),
                values = new TreeSet<SecondCycleIndividualCandidacyProcess>(
                        SecondCycleIndividualCandidacyProcess.COMPARATOR_BY_CANDIDACY_PERSON));
    }/*from www . j  a v a2 s  . com*/
    values.add(process);
}

From source file:io.wcm.config.core.impl.ParameterProviderBridge.java

@SuppressWarnings("unchecked")
private ConfigurationMetadata toConfigMetadata(List<Parameter<?>> parameters) {
    SortedSet<PropertyMetadata<?>> properties = new TreeSet<>(new Comparator<PropertyMetadata<?>>() {
        @Override//from   w ww  .ja  v  a  2  s. com
        public int compare(PropertyMetadata<?> o1, PropertyMetadata<?> o2) {
            String sort1 = StringUtils.defaultString(o1.getLabel(), o1.getName());
            String sort2 = StringUtils.defaultString(o2.getLabel(), o2.getName());
            return sort1.compareTo(sort2);
        }
    });

    for (Parameter<?> parameter : parameters) {
        PropertyMetadata<?> property;
        if (parameter.getType().equals(Map.class)) {
            property = toPropertyStringArray((Parameter<Map>) parameter);
        } else {
            property = toProperty(parameter);
        }
        String label = (String) parameter.getProperties().get(EditorProperties.LABEL);
        String description = (String) parameter.getProperties().get(EditorProperties.DESCRIPTION);
        String group = (String) parameter.getProperties().get(EditorProperties.GROUP);
        if (group != null) {
            label = group + ": " + StringUtils.defaultString(label, parameter.getName());
        }
        properties.add(property.label(label).description(description));
    }

    return new ConfigurationMetadata(DEFAULT_CONFIG_NAME, properties, false)
            .label("wcm.io Configuration Parameters");
}

From source file:org.openmrs.module.hl7output.util.RHEA_ORU_R01Handler.java

private Person getProvider(PV1 pv1) throws HL7Exception {
    XCN hl7Provider = pv1.getAttendingDoctor(0);
    Integer providerId = Context.getHL7Service().resolvePersonId(hl7Provider);
    if (providerId == null) {
        log.info(//www  .ja v a2s  .c o m
                "ID extracted from the HL7 message does not match with SHR 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 ECIDAttributeType = Context.getPersonService().getPersonAttributeType("ECID");

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

        PersonAttribute ecidAtrribute = new PersonAttribute();
        ecidAtrribute.setAttributeType(ECIDAttributeType);
        ecidAtrribute.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(ecidAtrribute);
        attributes.add(roledAtrribute);

        providerCandidate.setAttributes(attributes);

        Person candidate = Context.getPersonService().savePerson(providerCandidate);
        log.info("Created person id :" + candidate.getId() + " as a basic person for the missing provider");
        providerId = candidate.getId();
    }
    Person provider = new Person(providerId);
    return provider;
}

From source file:jp.zippyzip.web.ListServlet.java

String toJsonZips(ParentChild data, String zip, PersistenceManager pm) throws JSONException {

    String zip2 = zip.substring(3);
    SortedSet<String> keys = new TreeSet<String>();
    boolean start = true;
    StringBuilder ret = new StringBuilder("{\"zip1\":\"");

    ret.append(data.getParents().getFirst());
    ret.append("\",\"zip2\":\"");
    ret.append(zip2);//from  ww  w  .  j  a v  a  2  s . c om
    ret.append("\",\"zips\":[");

    for (String json : data.getChildren()) {

        JSONObject jo = new JSONObject(json);

        if (!jo.optString("zip2", "").equals(zip2)) {
            continue;
        }
        keys.add(jo.optString("key", ""));
    }

    for (String key : keys) {

        try {

            ParentChild zips = pm.getObjectById(ParentChild.class, key);
            City city = City.fromJson(zips.getParents().getLast());

            for (String json : zips.getChildren()) {

                JSONObject jo = new JSONObject(json);

                if (!jo.optString("code", "").equals(zip)) {
                    continue;
                }

                if (start) {
                    start = false;
                } else {
                    ret.append(",");
                }

                jo.put("x0402", city.getCode());
                jo.put("city", city.getName());
                jo.remove("add1Yomi");
                jo.remove("add2Yomi");
                jo.remove("corpYomi");
                ret.append(jo.toString());
            }

        } catch (JDOObjectNotFoundException e) {
        }
    }

    return ret.append("]}").toString();
}

From source file:org.bedework.timezones.common.leveldb.LdbCachedData.java

private AliasMaps buildAliasMaps() throws TzException {
    try {/*from w  ww.j av a2 s.c  om*/
        open();

        final AliasMaps maps = new AliasMaps();

        maps.byTzid = new HashMap<>();
        maps.byAlias = new HashMap<>();
        maps.aliases = new Properties();

        final StringBuilder aliasStr = new StringBuilder();

        try (DBIterator it = db.iterator()) {
            for (it.seekToFirst(); it.hasNext(); it.next()) {
                final String key = Iq80DBFactory.asString(it.peekNext().getKey());

                if (!key.startsWith(aliasPrefix)) {
                    continue;
                }

                final TzAlias alias = getJson(it.peekNext().getValue(), TzAlias.class);

                final String aliasId = alias.getAliasId();
                final StringBuilder ids = new StringBuilder();
                String delim = "";

                for (final String s : alias.getTargetIds()) {
                    ids.append(delim);

                    final String id = escape(s);
                    ids.append(id);
                    delim = ",";

                    SortedSet<String> as = maps.byTzid.get(id);

                    if (as == null) {
                        as = new TreeSet<>();
                        maps.byTzid.put(id, as);
                    }

                    as.add(aliasId);
                }

                aliasStr.append(escape(aliasId));
                aliasStr.append('=');
                aliasStr.append(ids.toString());
                aliasStr.append('\n');

                maps.aliases.setProperty(aliasId, ids.toString());

                maps.byAlias.put(aliasId, alias);
            }
        }

        maps.aliasesStr = aliasStr.toString();

        return maps;
    } catch (final Throwable t) {
        throw new TzException(t);
    } finally {
        close();
    }
}

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

public SortedSet<YearMonthDay> getAllLessonInstanceDates() {
    SortedSet<YearMonthDay> dates = new TreeSet<YearMonthDay>();
    for (LessonInstance instance : getLessonInstancesSet()) {
        dates.add(instance.getDay());
    }//  w  w  w . j  a v  a2  s.c  om
    return dates;
}

From source file:edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.java

public SortedSet<Text> getSplits() {
    String[] val = conf.getStringArray(Keys.SPLITS);
    if ((val == null) || (val.length == 0)) {
        return null;
    }/*from   w  ww .  ja v  a  2s  .  co m*/
    SortedSet<Text> splits = new TreeSet<Text>();
    for (String s : val) {
        splits.add(new Text(s));
    }
    return splits;
}

From source file:gov.nih.nci.caarray.web.action.project.ProjectFilesActionTest.java

private SortedSet<CaArrayFile> getImportedFileSet() throws IOException {
    final SortedSet<CaArrayFile> fileSet = new TreeSet<CaArrayFile>();

    final CaArrayFile file1 = new CaArrayFile();
    file1.setName("file1");
    file1.setType(AFFYMETRIX_CDF.getName());
    file1.setFileStatus(FileStatus.IMPORTED);
    fileSet.add(file1);

    final CaArrayFile file2 = new CaArrayFile();
    file2.setName("file2");
    file2.setType(AGILENT_CSV.getName());
    file2.setFileStatus(FileStatus.VALIDATED);
    fileSet.add(file2);/*  w  ww . j  a  v a  2 s. c  om*/

    final CaArrayFile file3 = new CaArrayFile();
    file3.setName("file3");
    file3.setType(null);
    file3.setFileStatus(FileStatus.VALIDATED);
    fileSet.add(file3);
    return fileSet;
}