Example usage for java.util TreeSet size

List of usage examples for java.util TreeSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:com.redhat.example.rules.unittest.RuleCoverageLogger.java

/**
 * print the coverage result of All RuleGroup
 *///from  ww w.  ja v  a  2 s.c o  m
public void printCoverage() {
    logger.debug("##### RULE COVERAGE - START #####");
    int sumExecuted = 0;
    int sumDefined = 0;
    TreeSet<String> sortedRuleGroupNames = new TreeSet<String>(ruleGroupToRulesMap.keySet());
    if (sortedRuleGroupNames.size() == 0) {
        logger.debug(
                "##### Rule Group is EMPTY!! : The coverage info. has just cleared or No rules has been executed since cleared. #####");
    }
    for (String ruleGroupName : sortedRuleGroupNames) {
        int nums[] = printCoverageOfRuleGroup(ruleGroupName);
        sumExecuted += nums[0];
        sumDefined += nums[1];
    }
    if (sumDefined > 0) {
        logger.debug("# All Rule Groups - Coverage {}% ( {} / {} )", 100 * sumExecuted / sumDefined,
                sumExecuted, sumDefined);
    }
    logger.debug("##### RULE COVERAGE -  END  #####");
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * get all views (viewId's) with Statistic
 * @return/* ww  w .j  av  a 2  s .  c o  m*/
 */
public static String[] getViews(Model model) {
    TreeSet<String> views = new TreeSet<String>();
    String[] ids = model.getStatistics().getAllIds();
    for (int i = 0; i < ids.length; i++) {
        Statistic statistic = model.getStatistics().get(ids[i]);
        StatisticGrafic statisticGrafic = (StatisticGrafic) statistic.getGrafic();
        if (statisticGrafic != null) {
            String viewId = statisticGrafic.getViewId();
            if (!views.contains(viewId))
                views.add(viewId);
        }
    }
    String[] out = new String[views.size()];
    int i = 0;
    for (Iterator<String> it = views.iterator(); it.hasNext();) {
        out[i] = it.next();
        i++;
    }
    return out;

}

From source file:crossspectrumapp.CrossSpectrumApp.java

private HashSet<Integer> getSelections() throws SQLException, LdvTableException, ViewConfigException {
    HashSet<Integer> ret = new HashSet<>();
    long strt = System.currentTimeMillis();
    getDbTables();/*from  w  ww  .  java  2 s.  co  m*/

    {
        int n;
        String[] channelNames = cscl.getChannelNames();
        if (channelNames == null || channelNames.length == 0) {
            throw new IllegalArgumentException("No Channel specified");
        }
        if (channelNames.length != 2) {
            throw new IllegalArgumentException("2 and only 2 channels need to be specified.");
        }
        String server = cscl.getServer();
        String cType = cscl.getcType();

        if ((server == null || server.isEmpty()) && (cType == null || cType.isEmpty())) {
            for (String channelName : channelNames) {
                n = chanTbl.getBestMatch(channelName);
                ret.add(n);
            }
        } else {
            if (cType == null || cType.isEmpty()) {
                cType = "raw";
            }
            for (String channelName : channelNames) {
                TreeSet<ChanInfo> chSet = chanTbl.getAsSet(server, channelName, cType, 10);
                if (chSet.size() > 1) {
                    System.err.println("Warning: more than one channel matches: " + channelName);
                }

                for (ChanInfo ci : chSet) {
                    Integer id = ci.getId();
                    ret.add(id);
                }
            }
        }
        if (ret.isEmpty()) {
            for (String channelName : channelNames) {
                System.err.println("Channel requested was not found: " + channelName);
            }
        }
    }
    return ret;

}

From source file:org.jasig.portlet.calendar.processor.ICalendarContentProcessorTest.java

@Test
public void test() throws IOException {

    Resource calendarFile = applicationContext.getResource("classpath:/sampleEvents.ics");

    DateMidnight start = new DateMidnight(2010, 1, 1, DateTimeZone.UTC);
    Interval interval = new Interval(start, start.plusYears(3));

    InputStream in = calendarFile.getInputStream();
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    IOUtils.copyLarge(in, buffer);//  ww  w .j  av a2 s .  c om

    TreeSet<VEvent> events = new TreeSet<VEvent>(new VEventStartComparator());
    net.fortuna.ical4j.model.Calendar c = processor.getIntermediateCalendar(interval,
            new ByteArrayInputStream(buffer.toByteArray()));
    events.addAll(processor.getEvents(interval, c));

    assertEquals(5, events.size());

    Iterator<VEvent> iterator = events.iterator();
    VEvent event = iterator.next();
    assertEquals("Independence Day", event.getSummary().getValue());
    assertNull(event.getStartDate().getTimeZone());

    event = iterator.next();
    assertEquals("Vikings @ Saints  [NBC]", event.getSummary().getValue());
    DateTime eventStart = new DateTime(event.getStartDate().getDate(), DateTimeZone.UTC);
    assertEquals(0, eventStart.getHourOfDay());
    assertEquals(30, eventStart.getMinuteOfHour());

    event = iterator.next();
    assertEquals("Independence Day", event.getSummary().getValue());
    assertNull(event.getStartDate().getTimeZone());

}

From source file:hudson.graph.jfreechart.JFreeChartSupport.java

@Override
public void setData(DataSet data) {

    TreeSet rowSet = new TreeSet(data.getRows());
    TreeSet colSet = new TreeSet(data.getColumns());

    Comparable[] _rows = (Comparable[]) rowSet.toArray(new Comparable[rowSet.size()]);
    Comparable[] _cols = (Comparable[]) colSet.toArray(new Comparable[colSet.size()]);

    // insert rows and columns in the right order
    for (Comparable r : _rows) {
        dataset.setValue(null, r, _cols[0]);
    }//from w w  w  .  ja va2s  .c o  m
    for (Comparable c : _cols) {
        dataset.setValue(null, _rows[0], c);
    }

    for (int i = 0; i < data.getValues().size(); i++) {
        dataset.addValue((Number) data.getValues().get(i), (Comparable) data.getRows().get(i),
                (Comparable) data.getColumns().get(i));
    }
}

From source file:org.apache.solr.client.solrj.io.eval.KnnEvaluator.java

@Override
public Object doWork(Object... values) throws IOException {

    if (values.length < 3) {
        throw new IOException("knn expects three parameters a Matrix, numeric array and k");
    }/*from w ww .  jav  a  2  s  .  co  m*/

    Matrix matrix = null;
    double[] vec = null;
    int k = 0;

    if (values[0] instanceof Matrix) {
        matrix = (Matrix) values[0];
    } else {
        throw new IOException("The first parameter for knn should be a matrix.");
    }

    if (values[1] instanceof List) {
        List<Number> nums = (List<Number>) values[1];
        vec = new double[nums.size()];
        for (int i = 0; i < nums.size(); i++) {
            vec[i] = nums.get(i).doubleValue();
        }
    } else {
        throw new IOException("The second parameter for knn should be a numeric array.");
    }

    if (values[2] instanceof Number) {
        k = ((Number) values[2]).intValue();
    } else {
        throw new IOException("The third parameter for knn should be k.");
    }

    double[][] data = matrix.getData();

    TreeSet<Neighbor> neighbors = new TreeSet();
    for (int i = 0; i < data.length; i++) {
        double distance = distanceMeasure.compute(vec, data[i]);
        neighbors.add(new Neighbor(i, distance));
        if (neighbors.size() > k) {
            neighbors.pollLast();
        }
    }

    double[][] out = new double[neighbors.size()][];
    List<String> rowLabels = matrix.getRowLabels();
    List<String> newRowLabels = new ArrayList();
    List<Number> distances = new ArrayList();
    int i = -1;

    while (neighbors.size() > 0) {
        Neighbor neighbor = neighbors.pollFirst();
        int rowIndex = neighbor.getRow();

        if (rowLabels != null) {
            newRowLabels.add(rowLabels.get(rowIndex));
        }

        out[++i] = data[rowIndex];
        distances.add(neighbor.getDistance());
    }

    Matrix knn = new Matrix(out);

    if (rowLabels != null) {
        knn.setRowLabels(newRowLabels);
    }

    knn.setColumnLabels(matrix.getColumnLabels());
    knn.setAttribute("distances", distances);
    return knn;
}

From source file:org.apache.solr.update.processor.UpdateIndexAuthorizationProcessorTest.java

/**
 * Ensure no new methods have been added to base class that are not invoking
 * Sentry/*from w  w  w.j  a v  a2s. co m*/
 */
@Test
public void testAllMethodsChecked() throws Exception {
    Method[] methods = UpdateRequestProcessor.class.getDeclaredMethods();
    TreeSet<String> foundNames = new TreeSet<String>();
    for (Method method : methods) {
        if (Modifier.isPublic(method.getModifiers())) {
            foundNames.add(method.getName());
        }
    }
    assertEquals(methodNames.size(), foundNames.size());
    assertTrue(foundNames.containsAll(methodNames));
}

From source file:org.openanzo.glitter.query.SPARQLAlgebra.java

/**
 * Conjoins two solution sets.//from   www.  ja v a 2 s.c o m
 * 
 * (A null list of solutions functions equivalently to a solution set with a single bindings-less solution. This is shorthand and is COMPLETELY different
 * from a solution set with zero solutions (which conjoins with any other solution set to the empty solution set).)
 * 
 * 
 * @param set1
 * @param set2
 * @return The conjunction of the two solution sets.
 */
static public SolutionSet join(SolutionSet set1, SolutionSet set2) {
    boolean isEnabled = RequestAnalysis.getAnalysisLogger().isDebugEnabled();
    log.trace(LogUtils.GLITTER_MARKER, "join");

    if (set1 == null) {
        if (isEnabled)
            RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                    "[glitter_SPARQLAlgebra_identityJoin-RHS] {}", Integer.toString(set2.size()));
        return set2;
    }
    if (set2 == null) {
        if (isEnabled)
            RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                    "[glitter_SPARQLAlgebra_identityJoin-LHS] {}", Integer.toString(set1.size()));
        return set1;
    }
    Comparator<Value> comparator = getComparator(set1, set2);

    if (set1.size() == 0 || set2.size() == 0) {
        if (isEnabled)
            RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                    "[glitter_SPARQLAlgebra_nullJoin]");
        return new SolutionList();
    }

    PatternSolution sol1[] = set1.toArray(new PatternSolution[0]);
    PatternSolution sol2[] = set2.toArray(new PatternSolution[0]);

    if (sol1.length == 1 && sol1[0].size() == 0) {
        if (isEnabled)
            RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                    "[glitter_SPARQLAlgebra_identityJoin-RHS] {}", Integer.toString(set2.size()));
        return set2;
    } else if (sol2.length == 1 && sol2[0].size() == 0) {
        if (isEnabled)
            RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                    "[glitter_SPARQLAlgebra_identityJoin-LHS] {}", Integer.toString(set1.size()));
        return set1;
    }

    SolutionSet newSolutions = new CustomCompareSolutionSet.ComparableSolutionList(comparator);

    long start = 0;

    if (isEnabled) {
        RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                "[glitter_SPARQLAlgebra_startJoin] {}:{}", Integer.toString(set1.size()),
                Integer.toString(set2.size()));
        start = System.currentTimeMillis();
    }

    TreeSet<Bindable> count = new TreeSet<Bindable>();
    for (PatternSolution element : sol1) {
        for (Bindable bindable : element.getBoundDomain(true)) {
            count.add(bindable);
        }
    }
    TreeSet<Bindable> count2 = new TreeSet<Bindable>();
    for (PatternSolution element : sol2) {
        for (Bindable bindable : element.getBoundDomain(true)) {
            count2.add(bindable);
        }
    }

    TreeSet<Bindable> matchSet = new TreeSet<Bindable>();
    if (count.size() < count2.size()) {
        for (Bindable bindable : count) {
            if (count2.contains(bindable))
                matchSet.add(bindable);
        }
    } else {
        for (Bindable bindable : count2) {
            if (count.contains(bindable)) {
                matchSet.add(bindable);
            }
        }
    }
    Bindable matchedBindables[] = matchSet.toArray(new Bindable[0]);

    if (isEnabled) {
        StringBuilder sb = new StringBuilder();
        for (Bindable bindable : matchSet) {
            sb.append(bindable.toString());
            sb.append(",");
        }
        RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                "[glitter_SPARQLAlgebra_matchingBindings] {}", sb.toString());
    }
    long startSort = 0;
    if (isEnabled) {
        startSort = System.currentTimeMillis();
    }
    Arrays.sort(sol1, 0, sol1.length, new PatternSolutionImpl.SetSolutionComparator(matchSet, comparator));
    if (isEnabled) {
        RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                "[glitter_SPARQLAlgebra_leftSortTime] {}",
                Long.toString(System.currentTimeMillis() - startSort));
        startSort = System.currentTimeMillis();
    }
    Arrays.sort(sol2, 0, sol2.length, new PatternSolutionImpl.SetSolutionComparator(matchSet, comparator));
    if (isEnabled) {
        RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                "[glitter_SPARQLAlgebra_rightSortTime] {}",
                Long.toString(System.currentTimeMillis() - startSort));
        startSort = System.currentTimeMillis();
    }
    //System.err.println("Joining:" + sol1.length + ":" + sol2.length);
    int j = 0;
    //long start = System.currentTimeMillis();
    if (matchSet.size() > 0) {
        for (PatternSolution solution : sol1) {
            Bindable sol1Bindables[] = solution.getBoundDomainArray();
            boolean done = false;
            for (int k = j; k < sol2.length && !done; k++) {
                if (sol1Bindables.length == 0) {
                    newSolutions.add(sol2[k]);
                } else {
                    boolean match = true;
                    boolean cloned = false;
                    PatternSolution solution2 = sol2[k];
                    boolean firstEmpty = true;
                    Bindable bindables2[] = solution2.getBoundDomainArray();
                    int m = 0;
                    if (bindables2.length > 0) {
                        boolean breaker = false;
                        for (Bindable element : matchedBindables) {
                            firstEmpty = false;
                            for (int mm = m; mm < bindables2.length && !breaker; mm++) {
                                int comp1 = element.compareTo(bindables2[mm]);
                                if (comp1 == 0) {
                                    Value term = solution.getBinding(element);
                                    Value term2 = solution2.getBinding(bindables2[mm]);
                                    //If term is null, this means that lh solution does not have a binding for a shared binding, so have to do slow conjoin
                                    if (term == null) {
                                        PatternSolution psNew = conjoin(solution, solution2);
                                        if (psNew != null) {
                                            newSolutions.add(psNew);
                                        }
                                        match = false;
                                        breaker = true;
                                    } else {
                                        int comp = comparator.compare(term, term2);
                                        if (comp > 0) {
                                            match = false;
                                            breaker = true;
                                            j = k;
                                            break;
                                        } else if (comp < 0) {
                                            match = false;
                                            done = true;
                                            breaker = true;
                                            break;
                                        } else {
                                            if (!cloned) {
                                                bindables2 = bindables2.clone();
                                                cloned = true;
                                            }
                                            // conjunction.put(bindables2[mm], term);
                                            bindables2[mm] = null;
                                            m = mm + 1;
                                            break;
                                        }
                                    }
                                } else if (comp1 > 0) {
                                    m = mm;
                                }
                            }
                            if (breaker)
                                break;
                        }
                        if (match) {
                            if (firstEmpty) {
                                newSolutions.add(solution2);
                            } else {
                                PatternSolutionImpl newSolution = new PatternSolutionImpl(solution);
                                for (Bindable element : bindables2) {
                                    if (element != null) {
                                        newSolution.setBinding(element, solution2.getBinding(element));
                                    }
                                }
                                newSolutions.add(new PatternSolutionImpl(newSolution));
                            }
                        }
                    } else {
                        newSolutions.add(solution);
                    }
                }
            }
        }
    } else {
        for (PatternSolution solution : sol1) {
            for (PatternSolution solution2 : sol2) {
                Bindable bindable[] = new Bindable[solution.getBoundDomainArray().length
                        + solution2.getBoundDomainArray().length];
                Value value[] = new Value[solution.getBoundDomainArray().length
                        + solution2.getBoundDomainArray().length];
                Bindable bs[] = solution.getBoundDomain(false);
                Value vs[] = solution.getBoundVariablesArray(false);

                System.arraycopy(bs, 0, bindable, 0, bs.length);
                System.arraycopy(vs, 0, value, 0, vs.length);
                int last = vs.length;
                bs = solution2.getBoundDomain(false);
                vs = solution2.getBoundVariablesArray(false);
                System.arraycopy(bs, 0, bindable, last, bs.length);
                System.arraycopy(vs, 0, value, last, vs.length);

                newSolutions.add(new PatternSolutionImpl(bindable, value));
            }
        }
    }
    //System.err.println("Join:" + (System.currentTimeMillis() - start) + ":" + newSolutions.size());
    if (isEnabled) {
        RequestAnalysis.getAnalysisLogger().debug(LogUtils.GLITTER_MARKER,
                "[glitter_SPARQLAlgebra_endJoin] {}:{}", Integer.toString(newSolutions.size()),
                Long.toString(System.currentTimeMillis() - start));
    }
    return newSolutions;
    /*   SolutionSet newSolutions2 = new SolutionList();
     for (PatternSolution ps1 : set1) {
     for (PatternSolution ps2 : set2) {
     PatternSolution psNew = ps1.conjoin(ps2);
     if (psNew != null)
     newSolutions2.add(psNew);
     }
     }
     return newSolutions;*/
}

From source file:com.qspin.qtaste.testsuite.impl.TestDataImpl.java

@Override
public String dump() {
    TreeSet<String> sortedKeys = new TreeSet<String>(hash.keySet());
    String result = new String("{");
    Iterator<String> iKey = sortedKeys.iterator();
    for (int i = 0; i < sortedKeys.size(); i++) {
        if (i > 0) {
            result += ", ";
        }//from  ww  w .j  a  v a2 s . c o m
        String key = iKey.next();
        result += key + "=" + hash.get(key);
    }
    result += "}";
    return result;
}

From source file:org.apache.hadoop.hbase.backup.impl.RestoreTablesClient.java

/**
 * Restore operation. Stage 2: resolved Backup Image dependency
 * @param backupManifestMap : tableName, Manifest
 * @param sTableArray The array of tables to be restored
 * @param tTableArray The array of mapping tables to restore to
 * @throws IOException exception/*from  w w w  .  ja v a 2 s.co  m*/
 */
private void restore(HashMap<TableName, BackupManifest> backupManifestMap, TableName[] sTableArray,
        TableName[] tTableArray, boolean isOverwrite) throws IOException {
    TreeSet<BackupImage> restoreImageSet = new TreeSet<>();

    for (int i = 0; i < sTableArray.length; i++) {
        TableName table = sTableArray[i];

        BackupManifest manifest = backupManifestMap.get(table);
        // Get the image list of this backup for restore in time order from old
        // to new.
        List<BackupImage> list = new ArrayList<>();
        list.add(manifest.getBackupImage());
        TreeSet<BackupImage> set = new TreeSet<>(list);
        List<BackupImage> depList = manifest.getDependentListByTable(table);
        set.addAll(depList);
        BackupImage[] arr = new BackupImage[set.size()];
        set.toArray(arr);
        restoreImages(arr, table, tTableArray[i], isOverwrite);
        restoreImageSet.addAll(list);
        if (restoreImageSet != null && !restoreImageSet.isEmpty()) {
            LOG.info("Restore includes the following image(s):");
            for (BackupImage image : restoreImageSet) {
                LOG.info("Backup: " + image.getBackupId() + " "
                        + HBackupFileSystem.getTableBackupDir(image.getRootDir(), image.getBackupId(), table));
            }
        }
    }
    LOG.debug("restoreStage finished");
}