Example usage for org.apache.commons.collections Bag uniqueSet

List of usage examples for org.apache.commons.collections Bag uniqueSet

Introduction

In this page you can find the example usage for org.apache.commons.collections Bag uniqueSet.

Prototype

Set uniqueSet();

Source Link

Document

Returns a Set of unique elements in the Bag.

Usage

From source file:org.lockss.crawler.FuncWarcExploder.java

public void runTest(boolean good) throws Exception {
    log.debug3("About to create content");
    createContent();//  w ww.  j  av a  2 s.c o m

    // get the root of the simContent
    String simDir = sau.getSimRoot();

    log.debug3("About to crawl content");
    boolean res = crawlContent(good ? null : url[url.length - 1]);
    if (good) {
        assertTrue("Crawl failed", res);
        if (false)
            assertTrue(
                    "Crawl should succeed but got " + lastCrawlResult
                            + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage),
                    lastCrawlResult == Crawler.STATUS_SUCCESSFUL);
    } else {
        assertFalse("Crawl succeeded", res);
        if (false)
            assertTrue(
                    "Crawl should get STATUS_PLUGIN_ERROR but got " + lastCrawlResult
                            + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage),
                    lastCrawlResult == Crawler.STATUS_PLUGIN_ERROR);
        return;
    }

    // read all the files links from the root of the simcontent
    // check the link level of the file and see if it contains
    // in myCUS (check if the crawler crawl within the max. depth)
    CachedUrlSet myCUS = sau.getAuCachedUrlSet();
    File dir = new File(simDir);
    if (dir.isDirectory()) {
        File f[] = dir.listFiles();
        log.debug("Checking simulated content.");
        checkThruFileTree(f, myCUS);
        log.debug("Checking simulated content done.");
        checkExplodedUrls();
        checkUnExplodedUrls();

        log.debug("Check finished.");
    } else {
        log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory");
    }

    // Test PluginManager.getAuContentSize(), just because this is a
    // convenient place to do it.  If the simulated AU params are changed, or
    // SimulatedContentGenerator is changed, this number may have to
    // change.  NB - because the WARC files are compressed,  their
    // size varies randomly by a small amount.
    long expected = 9394;
    long actual = AuUtil.getAuContentSize(sau, true);
    long error = expected - actual;
    log.debug("Expected " + expected + " actual " + actual);
    long absError = (error < 0 ? -error : error);
    assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60);

    List sbc = ((MySimulatedArchivalUnit) sau).sbc;
    Bag b = new HashBag(sbc);
    Set uniq = new HashSet(b.uniqueSet());
    for (Iterator iter = uniq.iterator(); iter.hasNext();) {
        b.remove(iter.next(), 1);
    }
    // Permission pages get checked twice.  Hard to avoid that, so allow it
    b.removeAll(sau.getPermissionUrls());
    // archives get checked twice - from checkThruFileTree & checkExplodedUrls
    b.remove(url2[url2.length - 1]);
    // This test is screwed up by the use of shouldBeCached() in
    // WarcExploder() to find the AU to store the URL in.
    //assertEmpty("shouldBeCached() called multiple times on same URLs.", b);

    // Test getUrlStems
    checkGetUrlStems();
    // Test crawl rules
    checkCrawlRules();
    // Test getPermissionPage
    //checkGetPermissionPages();

}

From source file:org.lockss.crawler.FuncWarcExploder2.java

public void runTest(boolean good) throws Exception {
    log.debug3("About to create content");
    createContent();/*from w  w w .  ja v  a 2  s.c  o  m*/

    // get the root of the simContent
    String simDir = sau.getSimRoot();

    log.debug3("About to crawl content");
    boolean res = crawlContent(good ? null : url[url.length - 1]);
    if (good) {
        assertTrue("Crawl failed", res);
        if (false)
            assertTrue(
                    "Crawl should succeed but got " + lastCrawlResult
                            + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage),
                    lastCrawlResult == Crawler.STATUS_SUCCESSFUL);
    } else {
        assertFalse("Crawl succeeded", res);
        if (false)
            assertTrue(
                    "Crawl should get STATUS_PLUGIN_ERROR but got " + lastCrawlResult
                            + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage),
                    lastCrawlResult == Crawler.STATUS_PLUGIN_ERROR);
        return;
    }

    // read all the files links from the root of the simcontent
    // check the link level of the file and see if it contains
    // in myCUS (check if the crawler crawl within the max. depth)
    CachedUrlSet myCUS = sau.getAuCachedUrlSet();
    File dir = new File(simDir);
    if (dir.isDirectory()) {
        checkExplodedUrls();
        checkUnExplodedUrls();

        log.debug("Check finished.");
    } else {
        log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory");
    }

    // Test PluginManager.getAuContentSize(), just because this is a
    // convenient place to do it.  If the simulated AU params are changed, or
    // SimulatedContentGenerator is changed, this number may have to
    // change.  NB - because the WARC files are compressed,  their
    // size varies randomly by a small amount.
    long expected = 35775;
    long actual = AuUtil.getAuContentSize(sau, true);
    long error = expected - actual;
    long absError = (error < 0 ? -error : error);
    assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60);

    List sbc = ((MySimulatedArchivalUnit) sau).sbc;
    Bag b = new HashBag(sbc);
    Set uniq = new HashSet(b.uniqueSet());
    for (Iterator iter = uniq.iterator(); iter.hasNext();) {
        b.remove(iter.next(), 1);
    }
    // Permission pages get checked twice.  Hard to avoid that, so allow it
    b.removeAll(sau.getPermissionUrls());
    // archives get checked twice - from checkThruFileTree & checkExplodedUrls
    b.remove(url2[url2.length - 1]);
    // This test is screwed up by the use of shouldBeCached() in
    // WarcExploder() to find the AU to store the URL in.
    //assertEmpty("shouldBeCached() called multiple times on same URLs.", b);

}

From source file:org.lockss.crawler.FuncZipExploder.java

public void runTest(boolean good) throws Exception {
    log.debug3("About to create content");
    createContent();//  ww  w  . ja v a2  s .c  o m

    // get the root of the simContent
    String simDir = sau.getSimRoot();

    log.debug3("About to crawl content");
    boolean res = crawlContent(good ? null : "002file.bin");
    if (good) {
        assertTrue("Crawl failed", res);
        if (false)
            assertTrue(
                    "Crawl should succeed but got " + lastCrawlResult
                            + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage),
                    lastCrawlResult == Crawler.STATUS_SUCCESSFUL);
    } else {
        assertFalse("Crawl succeeded", res);
        if (false)
            assertTrue(
                    "Crawl should get STATUS_PLUGIN_ERROR but got " + lastCrawlResult
                            + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage),
                    lastCrawlResult == Crawler.STATUS_PLUGIN_ERROR);
        return;
    }

    // read all the files links from the root of the simcontent
    // check the link level of the file and see if it contains
    // in myCUS (check if the crawler crawl within the max. depth)
    CachedUrlSet myCUS = sau.getAuCachedUrlSet();
    File dir = new File(simDir);
    if (dir.isDirectory()) {
        File f[] = dir.listFiles();
        log.debug("Checking simulated content.");
        checkThruFileTree(f, myCUS);
        log.debug("Checking simulated content done.");
        checkExplodedUrls();
        checkUnExplodedUrls();

        log.debug("Check finished.");
    } else {
        log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory");
    }

    // Test PluginManager.getAuContentSize(), just because this is a
    // convenient place to do it.  If the simulated AU params are changed, or
    // SimulatedContentGenerator is changed, this number may have to
    // change.  NB - because the ZIP files are compressed,  their
    // size varies randomly by a small amount.
    long expected = 2615;
    long actual = AuUtil.getAuContentSize(sau, true);
    long error = expected - actual;
    long absError = (error < 0 ? -error : error);
    assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60);

    List sbc = ((MySimulatedArchivalUnit) sau).sbc;
    Bag b = new HashBag(sbc);
    Set uniq = new HashSet(b.uniqueSet());
    for (Iterator iter = uniq.iterator(); iter.hasNext();) {
        b.remove(iter.next(), 1);
    }
    // Permission pages get checked twice.  Hard to avoid that, so allow it
    b.removeAll(sau.getPermissionUrls());
    // archives get checked twice - from checkThruFileTree & checkExplodedUrls
    b.remove("http://www.example.com/content.zip");
    // This test is screwed up by the use of shouldBeCached() in
    // ZipExploder() to find the AU to store the URL in.
    //assertEmpty("shouldBeCached() called multiple times on same URLs.", b);

}

From source file:org.lockss.crawler.FuncZipExploder2.java

public void testRunSelf() throws Exception {
    log.debug3("About to create content");
    createContent();/*w  w w . j  a v a  2s .c o  m*/

    // get the root of the simContent
    String simDir = sau.getSimRoot();

    log.debug3("About to crawl content");
    crawlContent();

    // read all the files links from the root of the simcontent
    // check the link level of the file and see if it contains
    // in myCUS (check if the crawler crawl within the max. depth)
    CachedUrlSet myCUS = sau.getAuCachedUrlSet();
    File dir = new File(simDir);
    if (dir.isDirectory()) {
        File f[] = dir.listFiles();
        log.debug("Checking simulated content.");
        checkThruFileTree(f, myCUS);
        log.debug("Checking simulated content done.");
        checkUnExplodedUrls();
        checkExplodedUrls();

        log.debug("Check finished.");
    } else {
        log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory");
    }

    // Test PluginManager.getAuContentSize(), just because this is a
    // convenient place to do it.  If the simulated AU params are changed, or
    // SimulatedContentGenerator is changed, this number may have to
    // change.  NB - because the ZIP files are compressed,  their
    // size varies randomly by a small amount.
    long expected = 285227;
    long actual = AuUtil.getAuContentSize(sau, true);
    long error = expected - actual;
    long absError = (error < 0 ? -error : error);
    assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60);

    if (false) {
        List sbc = ((MySimulatedArchivalUnit) sau).sbc;
        Bag b = new HashBag(sbc);
        Set uniq = new HashSet(b.uniqueSet());
        for (Iterator iter = uniq.iterator(); iter.hasNext();) {
            b.remove(iter.next(), 1);
        }
        // Permission pages get checked twice.  Hard to avoid that, so allow it
        b.removeAll(sau.getPermissionUrls());
        // archives get checked twice - from checkThruFileTree & checkExplodedUrls
        b.remove("http://www.example.com/content.zip");
        // This test is screwed up by the use of shouldBeCached() in
        // ZipExploder() to find the AU to store the URL in.
        //assertEmpty("shouldBeCached() called multiple times on same URLs.", b);
    }
    // Now check the DOIs
    checkDOIs();
}

From source file:org.rzo.yajsw.os.ms.win.w32.Pdh.java

/**
 * Enum object items./*from w  w  w  . j av  a  2  s  .c  o m*/
 * 
 * @param objectName
 *            the object name
 * @param english
 *            the english
 * 
 * @return the list
 */
public static List enumObjectItems(String objectName, boolean english) {
    if (english)
        objectName = translate(objectName);
    Bag bag = new HashBag();
    int pdhStatus = Pdhdll.ERROR_SUCCESS;
    Memory szCounterListBuffer = null;
    IntByReference dwCounterListSize = new IntByReference();
    Memory szInstanceListBuffer = null;
    IntByReference dwInstanceListSize = new IntByReference();
    String szThisInstance = null;

    // Determine the required buffer size for the data.
    pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real time
            // source
            null, // local machine
            objectName, // object to enumerate
            szCounterListBuffer, // pass NULL and 0
            dwCounterListSize, // to get length required
            szInstanceListBuffer, // buffer size
            dwInstanceListSize, // 
            Pdhdll.PERF_DETAIL_WIZARD, // counter detail level
            0);

    if (pdhStatus == Pdhdll.PDH_MORE_DATA) {
        // Allocate the buffers and try the call again.
        szCounterListBuffer = new Memory(dwCounterListSize.getValue() * 4);
        szInstanceListBuffer = new Memory((dwInstanceListSize.getValue() * 4));

        if ((szCounterListBuffer != null) && (szInstanceListBuffer != null)) {
            pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real
                    // time
                    // source
                    null, // local machine
                    objectName, // object to enumerate
                    szCounterListBuffer, // buffer to receive counter
                    // list
                    dwCounterListSize, szInstanceListBuffer, // buffer to
                    // receive
                    // instance
                    // list
                    dwInstanceListSize, Pdhdll.PERF_DETAIL_WIZARD, // counter
                    // detail
                    // level
                    0);

            if (pdhStatus == Pdhdll.ERROR_SUCCESS) {
                // System.out.println ("Enumerating Processes:");

                // Walk the instance list. The list can contain one
                // or more null-terminated strings. The last string
                // is followed by a second null-terminator.
                int i = 0;
                for (szThisInstance = szInstanceListBuffer.getString(0); szThisInstance != null
                        && szThisInstance.length() > 0; i += szThisInstance.length()
                                + 1, szThisInstance = szInstanceListBuffer.getString(i)) {
                    // System.out.println( szThisInstance);
                    bag.add(szThisInstance);

                }
            } else {
                System.out.println("PdhEnumObjectItems failed with " + Integer.toHexString(pdhStatus));
            }
        } else {
            System.out.println("Unable to allocate buffers");
            // pdhStatus = ERROR_OUTOFMEMORY;
        }

    } else {
        System.out.println("PdhEnumObjectItems failed with " + Integer.toHexString(pdhStatus));
    }

    List result = new ArrayList();
    for (Iterator it = bag.uniqueSet().iterator(); it.hasNext();) {
        String str = (String) it.next();
        result.add(str);
        // System.out.println(str);
        for (int i = 1; i < bag.getCount(str); i++) {
            result.add(str + "#" + i);
            // System.out.println(str+"#"+i);
        }
    }

    return result;
}

From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java

private List<CdrGraphBean> getCallDirectionGraphData(List<CdrCallDirectionDecorator> cdrdecorated) {
    List<CdrGraphBean> directionCalls = new ArrayList<CdrGraphBean>();
    Bag directionCallsBag = new HashBag();
    for (CdrCallDirectionDecorator cdr : cdrdecorated) {
        directionCallsBag.add(cdr.getCallDirection());
    }// w w  w .  j  a va 2  s  .c  o  m
    Set uniqueSetDirection = directionCallsBag.uniqueSet();
    for (Object key : uniqueSetDirection) {
        CdrGraphBean bean = new CdrGraphBean((String) key, directionCallsBag.getCount(key));
        directionCalls.add(bean);
    }
    return directionCalls;
}

From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java

private List<CdrGraphBean> getTerminationCallsData(List<Cdr> cdrs, Locale locale) {
    List<CdrGraphBean> terminationCalls = new ArrayList<CdrGraphBean>();
    Bag terminationCallsBag = new HashBag();
    for (Cdr cdr : cdrs) {
        CdrDecorator cdrDecorator = new CdrDecorator(cdr, locale, getMessages());
        terminationCallsBag.add(cdrDecorator.getTermination());
    }//from w  w w.j  av  a 2 s  . c om
    Set uniqueSetTermination = terminationCallsBag.uniqueSet();
    for (Object key : uniqueSetTermination) {
        CdrGraphBean bean = new CdrGraphBean((String) key, terminationCallsBag.getCount(key));
        terminationCalls.add(bean);
    }
    return terminationCalls;
}

From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java

private List<CdrGraphBean> mostActiveExtensions(Bag bagExtensions) {
    List<CdrGraphBean> activeExtensions = new ArrayList<CdrGraphBean>();
    Set uniqueSetCallers = bagExtensions.uniqueSet();
    for (Object key : uniqueSetCallers) {
        CdrGraphBean bean = new CdrGraphBean((String) key, bagExtensions.getCount(key));
        activeExtensions.add(bean);/*from   www  .j a v  a2s . c  om*/
    }
    Collections.sort(activeExtensions, Collections.reverseOrder());
    if (activeExtensions.size() > 10) {
        activeExtensions = activeExtensions.subList(0, 10);
    }

    return activeExtensions;
}

From source file:org.sonar.api.utils.KeyValueFormat.java

/**
 * @since 1.11// w  ww  .j  a v a  2  s .  c o  m
 * @deprecated use Multiset from google collections instead of commons-collections bags
 */
@Deprecated
public static String format(Bag bag, int var) {
    StringBuilder sb = new StringBuilder();
    if (bag != null) {
        boolean first = true;
        for (Object obj : bag.uniqueSet()) {
            if (!first) {
                sb.append(PAIR_SEPARATOR);
            }
            sb.append(obj.toString());
            sb.append(FIELD_SEPARATOR);
            sb.append(bag.getCount(obj) + var);
            first = false;
        }
    }
    return sb.toString();
}

From source file:org.squashtest.tm.service.internal.testcase.TestCaseCallTreeFinder.java

/**
 * returns an extended graph of ALL the test cases that can be reached by the source test cases, navigating on the call test steps
 * in both directions. This graph include the callers and the called test cases, recursively including their callers and test cases
 * etc until all relevant test cases are included in the resulting graph.
 *
 * @param calledIds/*from  w  w w.  j  a  va 2s  .  c  o m*/
 * @return
 */
// note :  for each node, call steps are searched both upward and downward. As a result every edge will
// be found twice (once on the up, once on the down). We then must build the graph by using only one edge over two
// that's why we use a bag here, and then we halve the cardinality.
public LibraryGraph<NamedReference, SimpleNode<NamedReference>> getExtendedGraph(List<Long> sourceIds) {

    // remember which nodes were processed (so that we can spare less DB calls in the worst cases scenarios)
    Set<Long> treated = new HashSet<>();
    treated.addAll(sourceIds);

    // the temporary result variable
    Bag allpairs = new HashBag();

    // a temporary buffer variable
    List<Long> currentNodes = new LinkedList<>(sourceIds);

    // phase 1 : data collection

    while (!currentNodes.isEmpty()) {

        List<NamedReferencePair> currentPair = testCaseDao.findTestCaseCallsUpstream(currentNodes);
        currentPair.addAll(testCaseDao.findTestCaseCallsDownstream(currentNodes));

        allpairs.addAll(currentPair);

        /*
         * collect the caller ids in the currentPair for the next loop, with the following restrictions :
         * 1) if the "caller" slot of the Object[] is not null,
         * 2) if the "called" slot is not null,
         * 2) if that node was not already processed
         *
         * then we can add that id.
         */

        List<Long> nextNodes = new LinkedList<>();

        for (NamedReferencePair pair : currentPair) {

            // no caller or no called -> no need for further processing
            if (pair.getCaller() == null || pair.getCalled() == null) {
                continue;
            }

            Long callerkey = pair.getCaller().getId();
            if (!treated.contains(callerkey)) {
                nextNodes.add(callerkey);
                treated.add(callerkey);
            }

            Long calledkey = pair.getCalled().getId();
            if (!treated.contains(calledkey)) {
                nextNodes.add(calledkey);
                treated.add(calledkey);
            }

        }

        currentNodes = nextNodes;

    }

    // phase 2 : halve the number of edges as explained in the comment above the method
    // every edges will appear two times, except for "boundaries" (ie caller is null or called is null),
    // for which the cardinality is 1.
    for (NamedReferencePair pair : (Set<NamedReferencePair>) allpairs.uniqueSet()) {
        int cardinality = allpairs.getCount(pair);
        if (cardinality > 1) {
            allpairs.remove(pair, cardinality / 2);
        }
    }

    // phase 3 : make that graph
    LibraryGraph<NamedReference, SimpleNode<NamedReference>> graph = new LibraryGraph<>();

    for (NamedReferencePair pair : (Iterable<NamedReferencePair>) allpairs) {
        graph.addEdge(node(pair.getCaller()), node(pair.getCalled()));
    }

    return graph;

}