Example usage for org.apache.commons.collections CollectionUtils exists

List of usage examples for org.apache.commons.collections CollectionUtils exists

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils exists.

Prototype

public static boolean exists(Collection collection, Predicate predicate) 

Source Link

Document

Answers true if a predicate is true for at least one element of a collection.

Usage

From source file:org.apache.carbondata.datamap.bloom.BloomDataMapWriter.java

BloomDataMapWriter(String tablePath, String dataMapName, List<CarbonColumn> indexColumns, Segment segment,
        String shardName, SegmentProperties segmentProperties, int bloomFilterSize, double bloomFilterFpp,
        boolean compressBloom) throws IOException {
    super(tablePath, dataMapName, indexColumns, segment, shardName, segmentProperties, bloomFilterSize,
            bloomFilterFpp, compressBloom);

    columnarSplitter = segmentProperties.getFixedLengthKeySplitter();
    this.indexCol2MdkIdx = new HashMap<>();
    int idx = 0;//from  w w w .j a va 2  s .  c o m
    for (final CarbonDimension dimension : segmentProperties.getDimensions()) {
        if (!dimension.isGlobalDictionaryEncoding() && !dimension.isDirectDictionaryEncoding()) {
            continue;
        }
        boolean isExistInIndex = CollectionUtils.exists(indexColumns, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                return ((CarbonColumn) object).getColName().equalsIgnoreCase(dimension.getColName());
            }
        });
        if (isExistInIndex) {
            this.indexCol2MdkIdx.put(dimension.getColName(), idx);
        }
        idx++;
    }
}

From source file:org.apache.flink.streaming.runtime.tasks.StreamTask.java

@Override
public void triggerCheckpoint(long checkpointId, long timestamp) throws Exception {

    LOG.debug("Starting checkpoint {} on task {}", checkpointId, getName());

    synchronized (checkpointLock) {
        if (isRunning) {
            try {
                // We wrap the states of the chained operators in a list, marking non-stateful operators with null
                List<Tuple2<StateHandle<Serializable>, Map<String, OperatorStateHandle>>> chainedStates = new ArrayList<Tuple2<StateHandle<Serializable>, Map<String, OperatorStateHandle>>>();

                // A wrapper handle is created for the List of statehandles
                WrapperStateHandle stateHandle;
                try {

                    // We construct a list of states for chained tasks
                    for (StreamOperator<?> chainedOperator : outputHandler.getChainedOperators()) {
                        if (chainedOperator instanceof StatefulStreamOperator) {
                            chainedStates.add(((StatefulStreamOperator<?>) chainedOperator)
                                    .getStateSnapshotFromFunction(checkpointId, timestamp));
                        } else {
                            chainedStates.add(null);
                        }/*from   w w w.  ja v a 2  s  . c om*/
                    }

                    stateHandle = CollectionUtils.exists(chainedStates, NotNullPredicate.INSTANCE)
                            ? new WrapperStateHandle(chainedStates)
                            : null;
                } catch (Exception e) {
                    throw new Exception("Error while drawing snapshot of the user state.", e);
                }

                // now emit the checkpoint barriers
                outputHandler.broadcastBarrier(checkpointId, timestamp);

                // now confirm the checkpoint
                if (stateHandle == null) {
                    getEnvironment().acknowledgeCheckpoint(checkpointId);
                } else {
                    getEnvironment().acknowledgeCheckpoint(checkpointId, stateHandle);
                }
            } catch (Exception e) {
                if (isRunning) {
                    throw e;
                }
            }
        }
    }
}

From source file:org.archive.crawler.extractor.ExtractorHTMLTest.java

/**
 * HER-1728 //from  w w  w  . j a  v a 2s .  c  om
 * @throws URIException 
 */
public void testFlashvarsParamValue() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com/"));
    CharSequence cs = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "    <param name=\"flashvars\" value=\"zoomifyXMLPath=ParamZoomifySlideshowViewer.xml\">\n"
            + "    <param name=\"menu\" value=\"false\">\n" + "    <param name=\"bgcolor\" value=\"#000000\">\n"
            + "    <param name=\"src\" value=\"ZoomifySlideshowViewer.swf\">\n"
            + "    <embed flashvars=\"zoomifyXMLPath=EmbedZoomifySlideshowViewer.xml\" src=\"ZoomifySlideshowViewer.swf\" menu=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" name=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "</object> ";
    this.extractor.extract(curi, cs);
    String expected = "http://www.example.com/ParamZoomifySlideshowViewer.xml";
    assertTrue("outlinks should contain: " + expected,
            CollectionUtils.exists(curi.getOutLinks(), destinationsIsPredicate(expected)));
}

From source file:org.archive.crawler.extractor.ExtractorHTMLTest.java

/**
 * HER-1728 /* w  w  w.  ja v  a  2 s  .c o  m*/
 * @throws URIException 
 */
public void testFlashvarsEmbedAttribute() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com/"));
    CharSequence cs = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "    <param name=\"flashvars\" value=\"zoomifyXMLPath=ParamZoomifySlideshowViewer.xml\">\n"
            + "    <param name=\"menu\" value=\"false\">\n" + "    <param name=\"bgcolor\" value=\"#000000\">\n"
            + "    <param name=\"src\" value=\"ZoomifySlideshowViewer.swf\">\n"
            + "    <embed flashvars=\"zoomifyXMLPath=EmbedZoomifySlideshowViewer.xml\" src=\"ZoomifySlideshowViewer.swf\" menu=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" name=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "</object> ";
    this.extractor.extract(curi, cs);
    String expected = "http://www.example.com/EmbedZoomifySlideshowViewer.xml";
    assertTrue("outlinks should contain: " + expected,
            CollectionUtils.exists(curi.getOutLinks(), destinationsIsPredicate(expected)));
}

From source file:org.archive.modules.extractor.ExtractorHTMLTest.java

/**
 * Test that relative URIs with late colons aren't misinterpreted
 * as absolute URIs with long, illegal scheme components. 
 * //  ww w . j  a va 2  s .  com
 * See http://webteam.archive.org/jira/browse/HER-1268
 * 
 * @throws URIException
 */
public void testBadRelativeLinks() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com"));
    CharSequence cs = "<a href=\"example.html;jsessionid=deadbeef:deadbeed?parameter=this:value\"/>"
            + "<a href=\"example.html?parameter=this:value\"/>";
    getExtractor().extract(curi, cs);

    assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            return ((CrawlURI) object).getURI()
                    .indexOf("/example.html;jsessionid=deadbeef:deadbeed?parameter=this:value") >= 0;
        }
    }));

    assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            return ((CrawlURI) object).getURI().indexOf("/example.html?parameter=this:value") >= 0;
        }
    }));
}

From source file:org.archive.modules.extractor.ExtractorHTMLTest.java

/**
 * Test if scheme is maintained by speculative hops onto exact 
 * same host//from  ww  w.j  a va2 s. c  o m
 * 
 * [HER-1524] speculativeFixup in ExtractorJS should maintain URL scheme
 */
public void testSpeculativeLinkExtraction() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("https://www.example.com"));
    CharSequence cs = "<script type=\"text/javascript\">_parameter=\"www.anotherexample.com\";"
            + "_anotherparameter=\"www.example.com/index.html\"" + ";</script>";
    getExtractor().extract(curi, cs);

    assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            System.err.println(
                    "comparing: " + ((CrawlURI) object).getURI() + " and https://www.anotherexample.com/");
            return ((CrawlURI) object).getURI().equals("http://www.anotherexample.com/");
        }
    }));
    assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            return ((CrawlURI) object).getURI().equals("https://www.example.com/index.html");
        }
    }));
}

From source file:org.archive.modules.extractor.ExtractorHTMLTest.java

/**
 * HER-1728 /*from w w  w  .j a  v  a2  s .c om*/
 * @throws URIException 
 */
public void testFlashvarsParamValue() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com/"));
    CharSequence cs = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "    <param name=\"flashvars\" value=\"zoomifyXMLPath=ParamZoomifySlideshowViewer.xml\">\n"
            + "    <param name=\"menu\" value=\"false\">\n" + "    <param name=\"bgcolor\" value=\"#000000\">\n"
            + "    <param name=\"src\" value=\"ZoomifySlideshowViewer.swf\">\n"
            + "    <embed flashvars=\"zoomifyXMLPath=EmbedZoomifySlideshowViewer.xml\" src=\"ZoomifySlideshowViewer.swf\" menu=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" name=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "</object> ";
    getExtractor().extract(curi, cs);
    String expected = "http://www.example.com/ParamZoomifySlideshowViewer.xml";
    assertTrue("outlinks should contain: " + expected,
            CollectionUtils.exists(curi.getOutLinks(), destinationsIsPredicate(expected)));
}

From source file:org.archive.modules.extractor.ExtractorHTMLTest.java

/**
 * HER-1728 /*from  w w  w  . j  a  v a2s  .com*/
 * @throws URIException 
 */
public void testFlashvarsEmbedAttribute() throws URIException {
    CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com/"));
    CharSequence cs = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" id=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "    <param name=\"flashvars\" value=\"zoomifyXMLPath=ParamZoomifySlideshowViewer.xml\">\n"
            + "    <param name=\"menu\" value=\"false\">\n" + "    <param name=\"bgcolor\" value=\"#000000\">\n"
            + "    <param name=\"src\" value=\"ZoomifySlideshowViewer.swf\">\n"
            + "    <embed flashvars=\"zoomifyXMLPath=EmbedZoomifySlideshowViewer.xml\" src=\"ZoomifySlideshowViewer.swf\" menu=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" name=\"ZoomifySlideshowViewer\" height=\"372\" width=\"590\">\n"
            + "</object> ";
    getExtractor().extract(curi, cs);
    String expected = "http://www.example.com/EmbedZoomifySlideshowViewer.xml";
    assertTrue("outlinks should contain: " + expected,
            CollectionUtils.exists(curi.getOutLinks(), destinationsIsPredicate(expected)));
}

From source file:org.archive.modules.extractor.JerichoExtractorHTMLTest.java

/**
 * Test a GET FORM ACTION extraction/*w w  w  . j a v a 2 s. com*/
 * 
 * @throws URIException
 */
public void testFormsLinkGet() throws URIException {
    UURI uuri = UURIFactory.getInstance("http://www.example.org");
    CrawlURI curi = new CrawlURI(uuri);
    CharSequence cs = "<form name=\"testform\" method=\"GET\" action=\"redirect_me?form=true\"> "
            + "  <INPUT TYPE=CHECKBOX NAME=\"checked[]\" VALUE=\"1\" CHECKED> "
            + "  <INPUT TYPE=CHECKBOX NAME=\"unchecked[]\" VALUE=\"1\"> " + "  <select name=\"selectBox\">"
            + "    <option value=\"selectedOption\" selected>option1</option>"
            + "    <option value=\"nonselectedOption\">option2</option>" + "  </select>"
            + "  <input type=\"submit\" name=\"test\" value=\"Go\">" + "</form>";
    getExtractor().extract(curi, cs);
    curi.getOutLinks();
    assertTrue(CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            return ((CrawlURI) object).getURI().indexOf(
                    "/redirect_me?form=true&checked[]=1&unchecked[]=&selectBox=selectedOption&test=Go") >= 0;
        }
    }));
}

From source file:org.archive.modules.extractor.JerichoExtractorHTMLTest.java

/**
 * Test a POST FORM ACTION being properly ignored 
 * //w ww .  ja  v a2s.c  om
 * @throws URIException
 */
public void testFormsLinkIgnorePost() throws URIException {
    UURI uuri = UURIFactory.getInstance("http://www.example.org");
    CrawlURI curi = new CrawlURI(uuri);
    CharSequence cs = "<form name=\"testform\" method=\"POST\" action=\"redirect_me?form=true\"> "
            + "  <INPUT TYPE=CHECKBOX NAME=\"checked[]\" VALUE=\"1\" CHECKED> "
            + "  <INPUT TYPE=CHECKBOX NAME=\"unchecked[]\" VALUE=\"1\"> " + "  <select name=\"selectBox\">"
            + "    <option value=\"selectedOption\" selected>option1</option>"
            + "    <option value=\"nonselectedOption\">option2</option>" + "  </select>"
            + "  <input type=\"submit\" name=\"test\" value=\"Go\">" + "</form>";
    getExtractor().extract(curi, cs);
    curi.getOutLinks();
    assertTrue(!CollectionUtils.exists(curi.getOutLinks(), new Predicate() {
        public boolean evaluate(Object object) {
            return ((CrawlURI) object).getURI().indexOf(
                    "/redirect_me?form=true&checked[]=1&unchecked[]=&selectBox=selectedOption&test=Go") >= 0;
        }
    }));
}