Example usage for java.util TreeSet TreeSet

List of usage examples for java.util TreeSet TreeSet

Introduction

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

Prototype

public TreeSet() 

Source Link

Document

Constructs a new, empty tree set, sorted according to the natural ordering of its elements.

Usage

From source file:com.jdom.word.playdough.model.BaseGamePackResolver.java

public SortedSet<String> getGamePackNames() {
    SortedSet<String> names = new TreeSet<String>();
    for (File file : gamePacksDirectory.listFiles()) {
        if (file.getName().startsWith(GAME_PACK_PREFIX)) {
            names.add(file.getName());//  www.ja  va 2s . co  m
        }
    }

    return names;
}

From source file:org.bedework.eventreg.web.OutputCSVController.java

@Override
public ModelAndView doRequest() throws Throwable {
    if (sessMan.getCurrentCalsuite() == null) {
        return errorReturn("No calsuite");
    }/*from ww  w .j a v a 2 s  . c o  m*/

    final String formName = sessMan.getCurrentFormName();

    final FormDef form = sessMan.getFormDef(formName);

    final TreeSet<Registration> regs = new TreeSet<>();

    for (final Registration reg : sessMan.getRegistrationsByHref(req.getHref())) {
        reg.setEvent(sessMan.retrieveEvent(reg));

        regs.add(reg);
    }

    final CSVOutputter csv = new CSVOutputter(sessMan.getCurrEvent(), form, regs);

    req.getResponse().setHeader("Content-Disposition",
            "Attachment; Filename=\"" + req.getFilename("eventreg.csv") + "\"");
    //response.setContentType("application/vnd.ms-excel; charset=UTF-8");

    return objModel(getForwardSuccess(), "csv", csv);
}

From source file:gov.va.chir.tagline.dao.DatasetFeatureSaver.java

public DatasetFeatureSaver(final File file) throws IOException {
    this.file = file;

    docFeatures = new TreeSet<String>();
    lineFeatures = new TreeSet<String>();

    headerWritten = false;/*from w  ww . j a v a2 s.c o m*/
}

From source file:com.spotify.heroic.filter.impl.AndFilterImpl.java

private static SortedSet<Filter> flatten(final Collection<Filter> statements) {
    final SortedSet<Filter> result = new TreeSet<>();

    for (final Filter f : statements) {
        final Filter o = f.optimize();

        if (o == null) {
            continue;
        }/*from ww  w  . j  a va  2 s .co m*/

        if (o instanceof Filter.And) {
            result.addAll(((Filter.And) o).terms());
            continue;
        }

        if (o instanceof Filter.Not) {
            final Filter.Not not = (Filter.Not) o;

            if (not.first() instanceof Filter.Or) {
                result.addAll(collapseNotOr((Filter.Or) not.first()));
                continue;
            }
        }

        result.add(o);
    }

    return result;
}

From source file:edu.harvard.med.screensaver.util.CollectionUtils.java

public static SortedSet<String> toUniqueStrings(Collection<?> c) {
    SortedSet<String> result = new TreeSet<String>();
    for (Object e : c) {
        result.add(e.toString());//from  w w  w .  java 2 s. c o m
    }
    return result;
}

From source file:com.spotify.heroic.filter.AndFilter.java

static SortedSet<Filter> flatten(final Collection<Filter> filters) {
    final SortedSet<Filter> result = new TreeSet<>();

    filters.stream().flatMap(f -> f.optimize().visit(new Filter.Visitor<Stream<Filter>>() {
        @Override/*  ww w .  j a v a  2  s .  com*/
        public Stream<Filter> visitAnd(final AndFilter and) {
            return and.terms().stream().map(Filter::optimize);
        }

        @Override
        public Stream<Filter> visitNot(final NotFilter not) {
            // check for De Morgan's
            return not.getFilter().visit(new Filter.Visitor<Stream<Filter>>() {
                @Override
                public Stream<Filter> visitOr(final OrFilter or) {
                    return or.terms().stream().map(f -> NotFilter.of(f).optimize());
                }

                @Override
                public Stream<Filter> defaultAction(final Filter filter) {
                    return Stream.of(not.optimize());
                }
            });
        }

        @Override
        public Stream<Filter> defaultAction(final Filter filter) {
            return Stream.of(filter.optimize());
        }
    })).forEach(result::add);

    return result;
}

From source file:de.metanome.algorithm_integration.ColumnConditionOr.java

/**
 * Exists for Gwt serialization
 */
protected ColumnConditionOr() {
    this.columnValues = new TreeSet<>();
}

From source file:org.openmrs.module.spreadsheetimport.SpreadsheetImportUtil.java

/**
 * Resolve template dependencies: 1. Generate pre-specified values which are necessary for
 * template to be imported. 2. Create import indices which describe the order in which columns
 * must be imported. 3. Generated dependencies between columns being imported and other columns
 * which be must imported first./* ww  w .  ja  v a 2 s .c o  m*/
 * 
 * @param template
 * @throws Exception
 */
public static void resolveTemplateDependencies(SpreadsheetImportTemplate template) throws Exception {

    Set<SpreadsheetImportTemplatePrespecifiedValue> prespecifiedValues = new TreeSet<SpreadsheetImportTemplatePrespecifiedValue>();

    Map<String, Set<UniqueImport>> mapTnToUi = template.getMapOfColumnTablesToUniqueImportSet();
    Map<UniqueImport, Set<SpreadsheetImportTemplateColumn>> mapUiToCs = template
            .getMapOfUniqueImportToColumnSet();

    List<String> tableNamesSortedByImportIdx = new ArrayList<String>();

    //      // special treatment: when there's a reference to person_id, but 
    //      //  1) the current table is not encounter and 
    //      //  2) there's no column of table person to be added
    //      // then we should still add a person implicitly. This person record will use all default values
    //      boolean hasToAddPerson = false;
    //      for (UniqueImport key : mapUiToCs.keySet()) {
    //         String tableName = key.getTableName();         
    //         if (!("encounter".equals(tableName) || mapTnToUi.keySet().contains("person"))) {
    //            hasToAddPerson = true;
    //            break;
    //         }
    //      }
    //      if (hasToAddPerson) {
    //         UniqueImport ui = new UniqueImport("person", new Integer(-1));
    //         mapTnToUi.put("person", new TreeSet<UniqueImport>());
    //         mapUiToCs.put(ui, new TreeSet<SpreadsheetImportTemplateColumn>());
    //      }

    // Find requirements
    for (UniqueImport key : mapUiToCs.keySet()) {
        String tableName = key.getTableName();

        Map<String, String> mapIkTnToCn = DatabaseBackend
                .getMapOfImportedKeyTableNameToColumnNamesForTable(tableName);

        if ("patient_identifier".equals(tableName))
            mapIkTnToCn.put("patient", "patient_id");

        // encounter_id is optional, so it won't be part of mapIkTnToCn
        // if we need to create new encounter for this row, then force it to be here
        if (template.isEncounter() && "obs".equals(tableName))
            mapIkTnToCn.put("encounter", "encounter_id");

        // we need special treatment for provider_id of Encounter
        // provider_id is of type person, but the meaning is different. During import, reference to person is considered patient,
        // but for provider_id of Encounter, it refers to a health practitioner
        if ("encounter".equals(tableName)) {
            //            mapIkTnToCn.put("person", "provider_id");          // UPDATE: provider_id is no longer a foreign key for encounter
            mapIkTnToCn.put("location", "location_id");
            mapIkTnToCn.put("form", "form_id");

            //            // if this is an encounter-based import, then pre-specify the form_id for the encounter
            //            // 1. search for encounter column
            //            SpreadsheetImportTemplateColumn encounterColumn = mapUiToCs.get(key).iterator().next();
            //            // 2. prespecify form             
            //            SpreadsheetImportTemplatePrespecifiedValue v = new SpreadsheetImportTemplatePrespecifiedValue();
            //            v.setTemplate(template);
            //            v.setTableDotColumn("form.form_id");
            //            v.setValue(template.getTargetForm());
            //            SpreadsheetImportTemplateColumnPrespecifiedValue cpv = new SpreadsheetImportTemplateColumnPrespecifiedValue();
            //            cpv.setColumn(encounterColumn);
            //            cpv.setPrespecifiedValue(v);
            //            prespecifiedValues.add(v);
        }

        // Ignore users tableName 
        mapIkTnToCn.remove("users");

        for (String necessaryTableName : mapIkTnToCn.keySet()) {

            String necessaryColumnName = mapIkTnToCn.get(necessaryTableName);

            // TODO: I believe patient and person are only tables with this relationship, if not, then this
            // needs to be generalized
            if (necessaryTableName.equals("patient") && !mapTnToUi.containsKey("patient")
                    && mapTnToUi.containsKey("person")) {
                necessaryTableName = "person";
            }

            if (mapTnToUi.containsKey(necessaryTableName)
                    && !("encounter".equals(tableName) && ("provider_id".equals(necessaryColumnName)))) {

                // Not already imported? Add
                if (!tableNamesSortedByImportIdx.contains(necessaryTableName)) {
                    tableNamesSortedByImportIdx.add(necessaryTableName);
                }

                // Add column dependencies
                // TODO: really _table_ dependencies - for simplicity only use _first_ column
                // of each unique import
                Set<SpreadsheetImportTemplateColumn> columnsImportFirst = new TreeSet<SpreadsheetImportTemplateColumn>();
                for (UniqueImport uniqueImport : mapTnToUi.get(necessaryTableName)) {
                    // TODO: hacky cast
                    columnsImportFirst.add(
                            ((TreeSet<SpreadsheetImportTemplateColumn>) mapUiToCs.get(uniqueImport)).first());
                }
                for (SpreadsheetImportTemplateColumn columnImportNext : mapUiToCs.get(key)) {
                    for (SpreadsheetImportTemplateColumn columnImportFirst : columnsImportFirst) {
                        SpreadsheetImportTemplateColumnColumn cc = new SpreadsheetImportTemplateColumnColumn();
                        cc.setColumnImportFirst(columnImportFirst);
                        cc.setColumnImportNext(columnImportNext);
                        cc.setColumnName(necessaryColumnName);
                        columnImportNext.getColumnColumnsImportBefore().add(cc);
                    }
                }

            } else {

                // Add pre-specified value
                SpreadsheetImportTemplatePrespecifiedValue v = new SpreadsheetImportTemplatePrespecifiedValue();
                v.setTemplate(template);
                v.setTableDotColumn(necessaryTableName + "." + necessaryTableName + "_id");
                for (SpreadsheetImportTemplateColumn column : mapUiToCs.get(key)) {
                    SpreadsheetImportTemplateColumnPrespecifiedValue cpv = new SpreadsheetImportTemplateColumnPrespecifiedValue();
                    cpv.setColumn(column);
                    cpv.setPrespecifiedValue(v);

                    //                  System.out.println("SpreadsheetImportUtils: " + v.getTableDotColumn() + " ==> " + v.getValue());

                    cpv.setColumnName(necessaryColumnName);
                    v.getColumnPrespecifiedValues().add(cpv);
                }
                prespecifiedValues.add(v);
            }
        }

        // Add this tableName if not already added
        if (!tableNamesSortedByImportIdx.contains(tableName)) {
            tableNamesSortedByImportIdx.add(tableName);
        }
    }

    // Add all pre-specified values      
    template.getPrespecifiedValues().addAll(prespecifiedValues);

    // Set column import indices based on tableNameSortedByImportIdx
    int importIdx = 0;
    for (String tableName : tableNamesSortedByImportIdx) {
        for (UniqueImport uniqueImport : mapTnToUi.get(tableName)) {
            for (SpreadsheetImportTemplateColumn column : mapUiToCs.get(uniqueImport)) {
                column.setImportIdx(importIdx);
                importIdx++;
            }
        }
    }
}

From source file:eu.ggnet.dwoss.report.assist.ReportUtil.java

/**
 * Returns all Lines of the Report for Category Invoiced.
 * This consists of:/*from   ww  w.  j a v  a 2 s.c  om*/
 * <ul>
 * <li>Position of Type Capital Asset</li>
 * <li>Position of Type Invoice, with no References</li>
 * <li>Position of Type UNIT_ANNEX in DocumentType CREDIT_MEMO/ANNULATIION_INVOICE and a Referencing Invoice in the same report.</li>
 * </ul>
 * <p>
 * It's not allowed to have a null value in the collection.
 * <p>
 * @param lines
 * @return all Lines of the Report for Category Invoiced.
 */
//TODO: We could also substract the value of a unitannex from the invoice and not return the unit annex at all.
//But consider the impact in the ui, especially if we allow selection of such a "combined" line.
public static NavigableSet<ReportLine> filterInvoiced(Collection<ReportLine> lines) {
    NavigableSet<ReportLine> result = new TreeSet<>();
    for (ReportLine line : lines) {
        if (line.getDocumentType() == CAPITAL_ASSET)
            result.add(line);
        if (line.getDocumentType() == INVOICE && !line.isFullRepayedIn(lines))
            result.add(line);
        if (line.isPartialRepayment() && !line.isFullRepayedIn(lines)) {
            ReportLine invoiceRef = line.getSingleReference(INVOICE);
            if (invoiceRef == null)
                /*  No Invoice exists, probably before 2014 */ result.add(line);
            else if (lines.contains(invoiceRef))
                result.add(line);
        }
    }
    return result;
}

From source file:de.metanome.algorithm_integration.ColumnConditionAnd.java

/**
 * Exists for Gwt serialization
 */
protected ColumnConditionAnd() {
    this.columnValues = new TreeSet<>();
}