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.jaspersoft.jasperserver.api.common.service.impl.BeanForInterfaceFactoryImpl.java

public String getBeanName(Map interfaceToBeanMappings, Class itfClass) {
    if (interfaceToBeanMappings == null) {
        return null;
    }/*from   w  w  w  .  j ava 2s. c o m*/

    //TODO cache
    try {
        SortedSet interfaces = new TreeSet(itfComparator);

        for (Iterator it = interfaceToBeanMappings.keySet().iterator(); it.hasNext();) {
            String itfName = (String) it.next();
            Class itf = Class.forName(itfName, true, Thread.currentThread().getContextClassLoader());
            if (itf.isAssignableFrom(itfClass)) {
                interfaces.add(itf);
            }
        }

        if (!interfaces.isEmpty()) {
            Class itf = (Class) interfaces.iterator().next();
            return (String) interfaceToBeanMappings.get(itf.getName());
        }
        return null;
    } catch (ClassNotFoundException e) {
        log.error(e, e);
        throw new JSExceptionWrapper(e);
    }
}

From source file:com.espertech.esper.filter.TestStringRangeComparator.java

public void testComparator() {
    SortedSet<StringRange> sorted = new TreeSet<StringRange>(new StringRangeComparator());

    final String[][] TEST_SET = { { "B", "G" }, { "B", "F" }, { null, "E" }, { "A", "F" }, { "A", "G" }, };

    final int[] EXPECTED_INDEX = { 2, 3, 4, 1, 0 };

    // Sort// w  w  w . ja va 2 s.  co  m
    StringRange ranges[] = new StringRange[TEST_SET.length];
    for (int i = 0; i < TEST_SET.length; i++) {
        ranges[i] = new StringRange(TEST_SET[i][0], TEST_SET[i][1]);
        sorted.add(ranges[i]);
    }
    System.out.println("sorted=" + sorted);

    // Check results
    int count = 0;
    for (Iterator<StringRange> i = sorted.iterator(); i.hasNext();) {
        StringRange range = i.next();
        int indexExpected = EXPECTED_INDEX[count];
        StringRange expected = ranges[indexExpected];

        log.debug(".testComparator count=" + count + " range=" + range + " expected=" + expected);

        assertEquals("failed at count " + count, range, expected);
        count++;
    }
    assertEquals(count, TEST_SET.length);
}

From source file:gov.nih.nci.caintegrator.domain.genomic.Platform.java

/**
 *
 *///from  w w w  .  j  ava2  s .co m
private void createTypeToReporterListMap() {
    typeToReporterListMap = new HashMap<ReporterTypeEnum, SortedSet<ReporterList>>();
    for (ReporterList reporterList : getReporterListsInternal()) {
        SortedSet<ReporterList> listsForType = typeToReporterListMap.get(reporterList.getReporterType());
        if (listsForType == null) {
            listsForType = new TreeSet<ReporterList>();
            typeToReporterListMap.put(reporterList.getReporterType(), listsForType);
        }
        listsForType.add(reporterList);
    }
}

From source file:net.sourceforge.fenixedu.domain.organizationalStructure.DepartmentUnit.java

public List<ScientificAreaUnit> getScientificAreaUnits() {
    final SortedSet<ScientificAreaUnit> result = new TreeSet<ScientificAreaUnit>(
            ScientificAreaUnit.COMPARATOR_BY_NAME_AND_ID);
    for (Unit unit : getSubUnits()) {
        if (unit.isScientificAreaUnit()) {
            result.add((ScientificAreaUnit) unit);
        }//from w w  w  .  j  a v  a 2  s.  c om
    }
    return new ArrayList<ScientificAreaUnit>(result);
}

From source file:ca.travelagency.components.fields.TravelDocumentField.java

@Override
protected Iterator<String> getChoices(String input) {
    if (StringUtils.isEmpty(input)) {
        return Collections.<String>emptyList().iterator();
    }//from   w  ww .ja  v a  2s  .c  om
    SortedSet<String> choices = new TreeSet<String>();
    Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
        String country = locale.getDisplayCountry().toUpperCase();
        if (country.startsWith(input.toUpperCase())) {
            String value = getLocalizer().getString(country, this, country);
            if (StringUtils.isBlank(value)) {
                value = country;
            }
            choices.add(WordUtils.capitalize(StringUtils.lowerCase(value + " " + suffix)));
            if (choices.size() == DISPLAY_MAX_SIZE) {
                break;
            }
        }
    }
    return choices.iterator();
}

From source file:ru.org.linux.tag.TagDao.java

public SortedSet<String> getTopTags() {
    final SortedSet<String> set = new TreeSet<>();

    jdbcTemplate.query("SELECT counter,value FROM tags_values WHERE counter>1 ORDER BY counter DESC LIMIT "
            + TOP_TAGS_COUNT, new RowCallbackHandler() {
                @Override//www.  j  a  va  2s  .  c om
                public void processRow(ResultSet rs) throws SQLException {
                    set.add(rs.getString("value"));
                }
            });

    return set;
}

From source file:cerrla.ElitesData.java

@Override
public String toString() {
    StringBuffer buffer = new StringBuffer();

    buffer.append("Slot counts: \n");
    MultiMap<Integer, Slot> orderedMap = MultiMap.createSortedSetMultiMap();
    SortedSet<Integer> keys = new TreeSet<Integer>();
    for (Slot slot : slotData_.keySet()) {
        int count = (int) slotData_.get(slot).getCount();
        orderedMap.put(count, slot);/*from   ww  w.j  a va 2  s  .  c  om*/
        keys.add(count);
    }
    for (Integer count : keys) {
        for (Slot slot : orderedMap.get(count)) {
            SlotData slotData = slotData_.get(slot);
            if (slot.getSlotSplitFacts().isEmpty())
                buffer.append("\tSlot " + slot.getAction() + ":\n" + slotData + "\n");
            else
                buffer.append("\tSlot " + slot.getSlotSplitFacts() + " => " + slot.getAction() + ":\n"
                        + slotData_.get(slot) + "\n");
        }
    }

    return buffer.toString();
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ShowClassesDispatchAction.java

private Table organizeClassViews(final Degree degree, final ExecutionSemester executionSemester) {
    final Table classViewsTable = new Table(degree.buildFullCurricularYearList().size());

    final DegreeCurricularPlan degreeCurricularPlan = findMostRecentDegreeCurricularPlan(degree,
            executionSemester);/*from   w w w .  j  a va2  s  .  co  m*/

    final SortedSet<SchoolClass> schoolClasses = new TreeSet<SchoolClass>(new BeanComparator("nome"));
    for (final SchoolClass schoolClass : executionSemester.getSchoolClassesSet()) {
        final ExecutionDegree executionDegree = schoolClass.getExecutionDegree();
        if (executionDegree.getDegreeCurricularPlan() == degreeCurricularPlan) {
            schoolClasses.add(schoolClass);
        }
    }

    for (final SchoolClass schoolClass : schoolClasses) {
        classViewsTable.appendToColumn(schoolClass.getAnoCurricular().intValue() - 1,
                newClassView(schoolClass));
    }

    return classViewsTable;
}

From source file:io.selendroid.common.SelendroidCapabilities.java

private String getDefaultVersion(Set<String> keys, String appName) {
    SortedSet<String> listOfApps = new TreeSet<String>();
    for (String key : keys) {
        if (key.split(":")[0].contentEquals(appName)) {
            listOfApps.add(key);
        }//w ww . j  a v a 2 s.  c om
    }
    return listOfApps.size() > 0 ? listOfApps.last() : null;
}

From source file:com.gtwm.pb.model.manageData.WordCloud.java

private void recordStemOrigin(String wordString, String stem) {
    // Record words which have the same stem so they can be expanded
    // back when returning the cloud
    SortedSet<WordInfo> stemOrigins = this.stemOriginMap.get(stem);
    if (stemOrigins == null) {
        // Comparator so most common words are first
        stemOrigins = new TreeSet<WordInfo>(new WordWeightComparator());
        WordInfo newStemOrigin = new Word(wordString, 1);
        stemOrigins.add(newStemOrigin);
        this.stemOriginMap.put(stem, stemOrigins);
    } else {/*from  ww  w  .  j  ava2s .c  o m*/
        SortedSet<WordInfo> newStemOrigins = new TreeSet<WordInfo>(new WordWeightComparator());
        boolean wordFound = false;
        for (WordInfo stemOrigin : stemOrigins) {
            if (stemOrigin.getName().equals(wordString)) {
                WordInfo newStemOrigin = new Word(wordString, stemOrigin.getWeight() + 1);
                newStemOrigins.add(newStemOrigin);
                wordFound = true;
            } else {
                newStemOrigins.add(stemOrigin);
            }
        }
        if (!wordFound) {
            newStemOrigins.add(new Word(wordString, 1));
        }
        this.stemOriginMap.put(stem, newStemOrigins);
    }
}