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(SortedSet<E> s) 

Source Link

Document

Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.

Usage

From source file:org.traccar.web.CsvBuilder.java

private SortedSet<Method> getSortedMethods(Object object) {
    Method[] methodArray = object.getClass().getMethods();
    SortedSet<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
        @Override//  w  w w  .j a  v a 2s  .com
        public int compare(Method m1, Method m2) {
            if (m1.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
                return 1;
            }
            if (m2.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
                return -1;
            }
            return m1.getName().compareTo(m2.getName());
        }
    });
    methods.addAll(Arrays.asList(methodArray));
    return methods;
}

From source file:eu.itesla_project.modules.rules.ListSecurityRulesTool.java

@Override
public void run(CommandLine line) throws Exception {
    OfflineConfig config = OfflineConfig.load();
    String rulesDbName = line.hasOption("rules-db-name") ? line.getOptionValue("rules-db-name")
            : OfflineConfig.DEFAULT_RULES_DB_NAME;
    RulesDbClient rulesDb = config.getRulesDbClientFactoryClass().newInstance().create(rulesDbName);
    String workflowId = line.getOptionValue("workflow");
    boolean addInfos = line.hasOption("add-infos");
    double purityThreshold = CheckSecurityCommand.DEFAULT_PURITY_THRESHOLD;
    if (line.hasOption("purity-threshold")) {
        purityThreshold = Double.parseDouble(line.getOptionValue("purity-threshold"));
    }/*from  ww w  .ja  v a 2 s.  com*/
    Set<RuleId> ruleIds = new TreeSet<>(rulesDb.listRules(workflowId, null));
    Table table = new Table(addInfos ? 7 : 3, BorderStyle.CLASSIC_WIDE);
    table.addCell("Contingency ID");
    table.addCell("Security index type");
    table.addCell("Attribute Set");
    if (addInfos) {
        table.addCell("Status");
        table.addCell("Attribute count");
        table.addCell("Convex set count");
        table.addCell("Inequality count");
    }
    for (RuleId ruleId : ruleIds) {
        SecurityIndexId securityIndexId = ruleId.getSecurityIndexId();
        table.addCell(securityIndexId.getContingencyId());
        table.addCell(securityIndexId.getSecurityIndexType().toString());
        table.addCell(ruleId.getAttributeSet().toString());
        if (addInfos) {
            SecurityRule rule = rulesDb.getRules(workflowId, ruleId.getAttributeSet(),
                    securityIndexId.getContingencyId(), securityIndexId.getSecurityIndexType()).get(0);
            SecurityRuleExpression ruleExpr = rule.toExpression(purityThreshold);
            table.addCell(ruleExpr.getStatus().toString());
            if (ruleExpr.getStatus() == SecurityRuleStatus.SECURE_IF) {
                ExpressionStatistics statistics = ExpressionStatistics.compute(ruleExpr.getCondition());
                table.addCell(Integer.toString(statistics.getAttributeCount()));
                table.addCell(Integer.toString(statistics.getConvexSetCount()));
                table.addCell(Integer.toString(statistics.getInequalityCount()));
            } else {
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    }
    System.out.println(table.render());
}

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

public ColumnConditionAnd(TreeSet<ColumnCondition> treeSet) {
    this.columnValues = new TreeSet<>(treeSet);
}

From source file:org.apache.solr.client.solrj.impl.DelegationTokenHttpSolrClient.java

public DelegationTokenHttpSolrClient(String baseURL, HttpClient client, ResponseParser parser,
        boolean allowCompression, String delegationToken) {
    super(baseURL, client, parser, allowCompression);
    if (delegationToken == null) {
        throw new IllegalArgumentException("Delegation token cannot be null");
    }// w w  w.  j  a  v a2s  . c  o  m
    this.delegationToken = delegationToken;
    setQueryParams(new TreeSet<>(Arrays.asList(DELEGATION_TOKEN_PARAM)));
    invariantParams = new ModifiableSolrParams();
    invariantParams.set(DELEGATION_TOKEN_PARAM, delegationToken);
}

From source file:com.qwazr.extractor.ExtractorServiceImpl.java

@Override
public Set<String> list() {
    return new TreeSet<>(extractorManager.getList());
}

From source file:com.github.qwazer.markdown.confluence.gradle.plugin.ConfluenceGradleTask.java

protected static void validateNoDuplicates(Collection<ConfluenceConfig.Page> pages) {

    Set<ConfluenceConfig.Page> set = new TreeSet<>(new Comparator<ConfluenceConfig.Page>() {
        @Override// w  ww .  j a  v  a  2 s  . co  m
        public int compare(ConfluenceConfig.Page o1, ConfluenceConfig.Page o2) {
            return o1.getTitle().compareTo(o2.getTitle());
        }
    });

    set.addAll(pages);

    if (set.size() < pages.size()) {
        throw new IllegalArgumentException("Found duplicate pageTitle in confluence pages");
    }
}

From source file:api.behindTheName.BehindTheNameApi.java

private void Search(final HashSet<String> set, int counter, final PeopleNameOption option,
        final ProgressCallback callback) {
    final int c = counter;
    callback.onProgressUpdate(behindTheNameProgressValues[c]);
    if (!set.isEmpty())
        callback.onProgress(new TreeSet<>(set));

    Platform.runLater(new Runnable() {

        @Override//  ww w . j av a2  s  .c  om
        public void run() {
            String nation = genres.get(option.genre);
            String gender = getGenderKey(option.gender);
            String url = "http://www.behindthename.com/api/random.php?number=6&usage=" + nation + "&gender="
                    + gender + "&key=" + BEHIND_THE_NAME_KEY;

            final File file = new File("Temp.xml");
            try {
                URL u = new URL(url);
                FileUtils.copyURLToFile(u, file);

                List<String> lines = FileUtils.readLines(file);
                for (String s : lines) {
                    if (s.contains("<name>")) {
                        s = s.substring(s.indexOf(">") + 1, s.lastIndexOf("</"));
                        set.add(s);
                    }
                }

            } catch (MalformedURLException ex) {
                Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
            }

            try {
                Thread.sleep(250);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (set.size() == MAX_SIZE || c == MAX_SEARCH - 1 || set.isEmpty()) {
                callback.onProgressUpdate(1.0f);

                return;
            }

            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    Search(set, c + 1, option, callback);
                }
            });

        }
    });

}

From source file:com.vrem.wifianalyzer.wifi.band.WiFiChannelCountryGHZ5Test.java

@Test
public void testChannelsAustraliaCanada() throws Exception {
    final SortedSet<Integer> exclude = new TreeSet<>(Arrays.asList(120, 124, 128));
    final int expectedSize = CHANNELS_SET1.size() + CHANNELS_SET2.size() + CHANNELS_SET3.size()
            - exclude.size();/*  w ww  .ja va2s . co m*/
    List<String> countries = Arrays.asList("AU", "CA");
    IterableUtils.forEach(countries, new Closure<String>() {
        @Override
        public void execute(String country) {
            Set<Integer> actual = fixture.findChannels(country);
            assertEquals(expectedSize, actual.size());
            assertTrue(actual.containsAll(CHANNELS_SET1));
            assertTrue(actual.containsAll(CHANNELS_SET3));
            assertFalse(actual.containsAll(exclude));
        }
    });
}

From source file:com.github.springtestdbunit.entity.OtherEntityAssert.java

public void assertValues(String... values) {
    SortedSet<String> expected = new TreeSet<String>(Arrays.asList(values));
    SortedSet<String> actual = new TreeSet<String>();
    TypedQuery<OtherSampleEntity> query = this.entityManager.createQuery(this.criteriaQuery);
    List<OtherSampleEntity> results = query.getResultList();
    for (OtherSampleEntity sampleEntity : results) {
        actual.add(sampleEntity.getValue());
        this.entityManager.detach(sampleEntity);
    }/*from  ww w .j  a v  a 2s. c  o m*/
    assertEquals(expected, actual);
}