Example usage for java.util SortedSet addAll

List of usage examples for java.util SortedSet addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:org.broadinstitute.gatk.engine.recalibration.BQSRGatherer.java

/**
 * Gathers the input recalibration reports into a single report.
 *
 * @param inputs Input recalibration GATK reports
 * @return gathered recalibration GATK report
 *///w  w  w .  j a va 2  s  . c o  m
public static GATKReport gatherReport(final List<File> inputs) {
    final SortedSet<String> allReadGroups = new TreeSet<String>();
    final LinkedHashMap<File, Set<String>> inputReadGroups = new LinkedHashMap<File, Set<String>>();

    // Get the read groups from each input report
    for (final File input : inputs) {
        final Set<String> readGroups = RecalibrationReport.getReadGroups(input);
        inputReadGroups.put(input, readGroups);
        allReadGroups.addAll(readGroups);
    }

    // Log the read groups that are missing from specific inputs
    for (Map.Entry<File, Set<String>> entry : inputReadGroups.entrySet()) {
        final File input = entry.getKey();
        final Set<String> readGroups = entry.getValue();
        if (allReadGroups.size() != readGroups.size()) {
            // Since this is not completely unexpected, more than debug, but less than a proper warning.
            logger.info(MISSING_READ_GROUPS + ": " + input.getAbsolutePath());
            for (final Object readGroup : CollectionUtils.subtract(allReadGroups, readGroups)) {
                logger.info("  " + readGroup);
            }
        }
    }

    RecalibrationReport generalReport = null;
    for (File input : inputs) {
        final RecalibrationReport inputReport = new RecalibrationReport(input, allReadGroups);
        if (inputReport.isEmpty()) {
            continue;
        }

        if (generalReport == null)
            generalReport = inputReport;
        else
            generalReport.combine(inputReport);
    }
    if (generalReport == null)
        throw new ReviewedGATKException(EMPTY_INPUT_LIST);

    generalReport.calculateQuantizedQualities();

    return generalReport.createGATKReport();
}

From source file:net.dontdrinkandroot.utils.collections.CollectionUtils.java

public static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> entriesSortedByValuesInverse(
        Map<K, V> map) {//from ww  w.  j a  v a 2  s . c om

    SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<Map.Entry<K, V>>(new Comparator<Map.Entry<K, V>>() {

        @Override
        public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {

            int res = e2.getValue().compareTo(e1.getValue());
            /* Preserve items with equal values */
            return res != 0 ? res : -1;
        }
    });
    sortedEntries.addAll(map.entrySet());

    return sortedEntries;
}

From source file:com.tussle.main.Utility.java

public static Collection<ProjectionVector> prunedProjections(Collection<ProjectionVector> vectors) {
    SortedSet<ProjectionVector> sortedVectors = new ConcurrentSkipListSet<>(
            Comparator.comparingDouble((ProjectionVector p) -> -p.magnitude()));
    sortedVectors.addAll(vectors);
    if (isPruned(sortedVectors))
        return sortedVectors;
    double reduceMagnitude = 0;
    Iterator<ProjectionVector> i = sortedVectors.iterator();
    ProjectionVector p0 = i.next();//from w ww.j  a va  2 s  .c o  m
    ProjectionVector p1 = i.next();
    double cos0 = p0.xNorm();
    double sin0 = p0.yNorm();
    double cos1 = p1.xNorm();
    double sin1 = p1.yNorm();
    //zeroth on the right, first on the left
    if (cos0 * sin1 < cos1 * sin0) {
        double tmpcos = cos1;
        double tmpsin = sin1;
        cos1 = cos0;
        sin1 = sin0;
        cos0 = tmpcos;
        sin0 = tmpsin;
    }
    while (i.hasNext()) {
        ProjectionVector next = i.next();
        double nextcos = next.xNorm();
        double nextsin = next.yNorm();
        if (nextcos * sin0 >= cos0 * nextsin && cos1 * nextsin >= nextcos * sin1) {
            //Case 0: Within cross product bounds
        } else if (nextcos * sin0 >= cos0 * nextsin) {
            //Case 1: Over the left, extend those bounds
            cos1 = nextcos;
            sin1 = nextsin;
        } else if (cos1 * nextsin >= nextcos * sin1) {
            //Case 2: Over the right, extend those bounds
            cos0 = nextcos;
            sin0 = nextsin;
        } else {
            //Case 3: Opposite side, immediately return false
            reduceMagnitude = next.magnitude();
            break;
        }
    }
    //Now given reduceMagnitude, remove elements with lesser magnitude and
    //reduce the magnitude of remaining elements
    if (Double.isFinite(reduceMagnitude)) {
        for (Iterator<ProjectionVector> j = sortedVectors.iterator(); j.hasNext();) {
            ProjectionVector vec = j.next();
            if (vec.magnitude() <= reduceMagnitude)
                j.remove();
            else
                vec = new ProjectionVector(vec.xNorm(), vec.yNorm(), vec.magnitude() - reduceMagnitude);
        }
    }
    return sortedVectors;
}

From source file:org.jenkins.ci.plugins.jobimport.RemoteJobUtils.java

protected static SortedSet<RemoteJob> fromHudsonXml(final String xml)
        throws SAXException, IOException, ParserConfigurationException, XPathExpressionException {
    final SortedSet<RemoteJob> remoteJobs = new TreeSet<RemoteJob>();

    if (StringUtils.isEmpty(xml)) {
        return remoteJobs;
    }// ww w  . j a  va  2 s. c om

    if (!xml.startsWith("<hudson>")) {
        return remoteJobs;
    }

    final Document document = XPathUtils.parse(xml);

    for (final String jobUrl : XPathUtils.evaluateNodeListTextXPath(document,
            XPATH_EXPRESSION_HUDSON_JOB_URL)) {
        remoteJobs.addAll(fromXml(URLUtils.fetchUrl(jobUrl + "/api/xml")));
    }

    return remoteJobs;
}

From source file:org.jbosson.plugins.amq.ArtemisMBeanDiscoveryComponent.java

protected static String formatMessage(String messageTemplate, Map<String, String> variableValues) {

    StringBuffer result = new StringBuffer();

    // collect keys and values to determine value size limit if needed
    final Map<String, String> replaceMap = new HashMap<String, String>();

    final Matcher matcher = PROPERTY_NAME_PATTERN.matcher(messageTemplate);
    int count = 0;
    while (matcher.find()) {
        final String key = matcher.group(1);
        final String value = variableValues.get(key);

        if (value != null) {
            replaceMap.put(key, value);//w  w  w.j a v a2  s.  c  om
            matcher.appendReplacement(result, Matcher.quoteReplacement(value));
        } else {
            matcher.appendReplacement(result, Matcher.quoteReplacement(matcher.group()));
        }

        count++;
    }
    matcher.appendTail(result);

    // check if the result exceeds MAX_LENGTH for formatted properties
    if (!replaceMap.isEmpty() && result.length() > MAX_LENGTH) {
        // sort values according to size
        final SortedSet<String> values = new TreeSet<String>(new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        });
        values.addAll(replaceMap.values());

        // find total value characters allowed
        int available = MAX_LENGTH - PROPERTY_NAME_PATTERN.matcher(messageTemplate).replaceAll("").length();

        // fit values from small to large in the allowed size to determine the maximum average
        int averageLength = available / count;
        for (String value : values) {
            final int length = value.length();
            if (length > averageLength) {
                break;
            }
            available -= length;
            count--;
            averageLength = available / count;
        }

        // replace values
        matcher.reset();
        result.delete(0, result.length());
        while (matcher.find()) {
            String value = replaceMap.get(matcher.group(1));
            if (value != null && value.length() > averageLength) {
                value = value.substring(0, averageLength);
            }
            matcher.appendReplacement(result, value != null ? value : matcher.group());
        }
        matcher.appendTail(result);
    }

    return result.toString();
}

From source file:org.jenkins.ci.plugins.jobimport.RemoteJobUtils.java

protected static SortedSet<RemoteJob> fromListViewXml(final String xml)
        throws SAXException, IOException, ParserConfigurationException, XPathExpressionException {
    final SortedSet<RemoteJob> remoteJobs = new TreeSet<RemoteJob>();

    if (StringUtils.isEmpty(xml)) {
        return remoteJobs;
    }//from   ww  w .  j  a v  a2  s  .c o m

    if (!xml.startsWith("<listView>")) {
        return remoteJobs;
    }

    final Document document = XPathUtils.parse(xml);

    for (final String jobUrl : XPathUtils.evaluateNodeListTextXPath(document,
            XPATH_EXPRESSION_LIST_VIEW_JOB_URL)) {
        remoteJobs.addAll(fromXml(URLUtils.fetchUrl(jobUrl + "/api/xml")));
    }

    return remoteJobs;
}

From source file:com.bluexml.side.form.clazz.utils.ClassDiagramUtils.java

/**
 * Get all class from the model/* ww w  .j  a v a  2 s.  c om*/
 * 
 * @param c
 * @return
 */
public static SortedSet<AbstractClass> getAllClazzs(AbstractClass c) {
    SortedSet<AbstractClass> s = new TreeSet<AbstractClass>(new ClazzComparator());
    List<ClassPackage> l = findAllPackage(c);
    for (ClassPackage p2 : l) {
        EList<Clazz> Clazzs = p2.getClassSet();
        s.addAll(Clazzs);
    }

    return s;
}

From source file:org.jasig.schedassist.model.AvailableBlockBuilder.java

/**
 * Expand a {@link Set} of {@link AvailableBlock} into a {@link SortedSet} of {@link AvailableBlock}s with a duration equal
 * to the meetingLengthMinutes argument in minutes.
 * /*from  w w  w .jav a  2 s  . c o m*/
 * @param largeBlocks
 * @return the new set
 */
public static SortedSet<AvailableBlock> expand(Set<AvailableBlock> largeBlocks,
        final int meetingLengthMinutes) {
    SortedSet<AvailableBlock> smallBlocks = new TreeSet<AvailableBlock>();
    for (AvailableBlock sourceBlock : largeBlocks) {
        smallBlocks.addAll(expand(sourceBlock, meetingLengthMinutes));
    }
    return smallBlocks;
}

From source file:org.opennms.netmgt.dao.NodeDaoIT.java

private static <T> void assertSetsEqual(Set<T> expectedSet, Set<T> actualSet, String orderProperty,
        AssertEquals<T> comparer) throws Exception {
    SortedSet<T> expectedSorted = new TreeSet<T>(new PropertyComparator(orderProperty));
    expectedSorted.addAll(expectedSet);
    SortedSet<T> actualSorted = new TreeSet<T>(new PropertyComparator(orderProperty));
    actualSorted.addAll(actualSet);//w  w w .java 2  s.  c om

    Iterator<T> expected = expectedSorted.iterator();
    Iterator<T> actual = actualSorted.iterator();

    while (expected.hasNext() && actual.hasNext()) {
        comparer.assertEqual(expected.next(), actual.next());
    }

    if (expected.hasNext())
        fail("Missing item " + expected.next() + " in the actual list");

    if (actual.hasNext())
        fail("Unexpected item " + actual.next() + " in the actual list");
}

From source file:gov.nih.nci.cananolab.util.StringUtils.java

/**
 * Parse the text into an array of words using white space as delimiter.
 * Keeping words in quotes together./*from w  ww.  j  av  a  2 s.co  m*/
 *
 * @param texts
 * @return
 */
public static List<String> parseToWords(String text) {
    if (isEmpty(text)) {
        return null;
    }
    SortedSet<String> wordList = new TreeSet<String>();

    // extract words in quotes first
    String patternStr = "\\B[\"']([^\"']*)[\"']\\B";
    String[] nonQuotedTexts = text.split(patternStr);
    for (String txt : nonQuotedTexts) {
        String[] nonQuotedWords = txt.split("\\s");
        wordList.addAll(Arrays.asList(nonQuotedWords));
    }
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(text);

    List<String> quotedWords = new ArrayList<String>();
    int start = 0;
    while (matcher.find(start)) {
        String quotedWord = matcher.group(1).trim();
        quotedWords.add(quotedWord);
        start = matcher.end(1);
    }
    wordList.addAll(quotedWords);

    return new ArrayList<String>(wordList);
}