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.glaf.core.util.AnnotationUtils.java

public static Collection<String> findJPAEntity(String packagePrefix) {
    AnnotationDB db = getAnnotationDB(packagePrefix);
    Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
    Set<String> entities = annotationIndex.get("javax.persistence.Entity");
    Collection<String> sortSet = new TreeSet<String>();
    if (entities != null && !entities.isEmpty()) {
        for (String str : entities) {
            if (packagePrefix != null && str.contains(packagePrefix)) {
                sortSet.add(str);//from  w  ww  .  j  a  v  a 2 s . c  om
            }
        }
    }
    return sortSet;
}

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

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

    filters.stream().flatMap(f -> f.optimize().visit(new Visitor<Stream<Filter>>() {
        @Override/*from w w  w  .ja va2  s  .c  om*/
        public Stream<Filter> visitOr(final OrFilter or) {
            return or.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> visitAnd(final AndFilter and) {
                    return and.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);
        }
    })).forEach(result::add);

    return result;
}

From source file:mangotiger.io.RecursiveFileIteratorTest.java

private static Set<File> files(final File root, final FileFilter filter) {
    final Set<File> files = new TreeSet<File>();
    final StringBuffer info = new StringBuffer("Files:");
    final Iterator<File> iterator = new RecursiveFileIterator(root, filter);
    while (iterator.hasNext()) {
        final File file = iterator.next();
        info.append("\n\t").append(file);
        files.add(file);//w  ww  .  j  a va 2  s.  com
    }
    log().info(info);
    return files;
}

From source file:net.leegorous.jsc.TestJavaScriptDocument.java

private void _testFindImport() throws Exception {
    File file = new File(getFileName("/scripts/test/pkg/b.js"));
    Set classPaths = new TreeSet();
    classPaths.add(new File(getFileName("/scripts")));
    JavaScriptDocument jsdoc = new JavaScriptDocument(null, file, classPaths);
    jsdoc.findImports();//from   w w w. j a  va  2 s . co m

    assertNotNull(jsdoc.getImportedDocs());
    assertEquals("b.js only imported 2 file.", 2, jsdoc.getImportedDocs().size());
    assertEquals("It should be 3 documents imported in total.", 3, jsdoc.getImportedFiles().size());

    String content = jsdoc.getImportedContent().toString();
    assertTrue("a.js should be imported.", content.indexOf("var A;") > 0);
    assertTrue("c.js should be imported.", content.indexOf("var C;") > 0);
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.subject.ScheduleDay.java

public ScheduleDay(Date date, Date today) {
    this.date = date;
    this.today = today;
    activities = new TreeSet<ScheduledActivity>();
}

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

@Override
public ModelAndView doRequest() throws Throwable {
    final TreeSet<Registration> regs = new TreeSet<>();

    for (final Registration reg : sessMan.getRegistrationsByUser(sessMan.getCurrentUser())) {
        final Event ev = sessMan.retrieveEvent(reg);

        if ((ev == null) || // TODO Event deleted - should delete registration?
                (ev.getMaxTickets() < 0)) {
            // XXX Warn? - not registrable any more
            continue;
        }/*w w  w.  ja va2  s. c om*/

        reg.setEvent(ev);

        regs.add(reg);
    }

    return objModel("agenda", "regs", regs);
}

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

public static Instances createDataset(final Collection<Document> documents) {

    // Key = feature name | Value = number representing NUMERIC, NOMINAL, etc.
    final Map<String, Integer> featureType = new TreeMap<String, Integer>();

    // Key = feature name | Values = distinct values for NOMINAL values
    final Map<String, Set<String>> nominalFeatureMap = new HashMap<String, Set<String>>();

    final Set<String> labels = new TreeSet<String>();
    final Set<String> docIds = new TreeSet<String>();

    // First scan -- determine attribute values
    for (Document document : documents) {
        processFeatures(document.getFeatures(), featureType, nominalFeatureMap);
        docIds.add(document.getName());//from ww w . j av  a2s  . co m

        for (Line line : document.getLines()) {
            processFeatures(line.getFeatures(), featureType, nominalFeatureMap);

            labels.add(line.getLabel());
        }
    }

    final ArrayList<Attribute> attributes = new ArrayList<Attribute>();

    // Add Document and Line IDs as first two attributes
    //final Attribute docId = new Attribute(DOC_ID, (ArrayList<String>) null);
    final Attribute docId = new Attribute(DOC_ID, new ArrayList<String>(docIds));
    final Attribute lineId = new Attribute(LINE_ID);

    attributes.add(docId);
    attributes.add(lineId);

    // Build attributes
    for (String feature : featureType.keySet()) {
        final int type = featureType.get(feature);

        if (type == Attribute.NUMERIC) {
            attributes.add(new Attribute(feature));
        } else {
            if (nominalFeatureMap.containsKey(feature)) {
                attributes.add(new Attribute(feature, new ArrayList<String>(nominalFeatureMap.get(feature))));
            }
        }
    }

    // Add class attribute
    Attribute classAttr = new Attribute(LABEL, new ArrayList<String>(labels));
    attributes.add(classAttr);

    final Instances instances = new Instances("train", attributes, documents.size());

    // Second scan -- add data
    for (Document document : documents) {
        final Map<String, Object> docFeatures = document.getFeatures();

        for (Line line : document.getLines()) {
            final Instance instance = new DenseInstance(attributes.size());

            final Map<String, Object> lineFeatures = line.getFeatures();
            lineFeatures.putAll(docFeatures);

            instance.setValue(docId, document.getName());
            instance.setValue(lineId, line.getLineId());
            instance.setValue(classAttr, line.getLabel());

            for (Attribute attribute : attributes) {
                if (!attribute.equals(docId) && !attribute.equals(lineId) && !attribute.equals(classAttr)) {
                    final String name = attribute.name();
                    final Object obj = lineFeatures.get(name);

                    if (obj instanceof Double) {
                        instance.setValue(attribute, ((Double) obj).doubleValue());
                    } else if (obj instanceof Integer) {
                        instance.setValue(attribute, ((Integer) obj).doubleValue());
                    } else {
                        instance.setValue(attribute, obj.toString());
                    }
                }
            }

            instances.add(instance);
        }
    }

    // Set last attribute as class
    instances.setClassIndex(attributes.size() - 1);

    return instances;
}

From source file:com.kdgregory.pomutil.dependency.TestDependencyCheck.java

private Set<String> extractArtifactIds(Collection<Artifact> artifacts) {
    Set<String> result = new TreeSet<String>();
    for (Artifact artifact : artifacts)
        result.add(artifact.getArtifactId());
    return result;
}

From source file:edu.cmu.sphinx.speakerid.SpeakerCluster.java

public SpeakerCluster(Segment s, Array2DRowRealMatrix featureMatrix, double bicValue) {
    this.segmentSet = new TreeSet<Segment>();
    this.featureMatrix = new Array2DRowRealMatrix(featureMatrix.getData());
    this.bicValue = bicValue;
    addSegment(s);//from w  ww.  j av a 2 s  .  com
}

From source file:org.killbill.billing.plugin.meter.timeline.categories.CategoryAndMetricsForSources.java

public CategoryAndMetricsForSources(final String eventCategory) {
    this(new CategoryAndMetrics(eventCategory), new TreeSet<String>());
}