Example usage for java.util ListIterator hasNext

List of usage examples for java.util ListIterator hasNext

Introduction

In this page you can find the example usage for java.util ListIterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the forward direction.

Usage

From source file:com.innoventsolutions.pentaho.birtrptdocplugin.BIRTContentGenerator.java

@Override
public void createContent() throws Exception {
    this.session = PentahoSessionHolder.getSession();
    this.repository = PentahoSystem.get(IUnifiedRepository.class, session);
    final RepositoryFile BIRTfile = (RepositoryFile) parameterProviders.get("path").getParameter("file");
    final String ExecBIRTFilePath = "../webapps/birt/" + BIRTfile.getId() + ".rptdocument";
    /*/*w  w w.  j av  a2  s  .co m*/
     * Get BIRT report design from repository
     */
    final File ExecBIRTFile = new File(ExecBIRTFilePath);
    if (!ExecBIRTFile.exists()) {
        final FileOutputStream fos = new FileOutputStream(ExecBIRTFilePath);
        try {
            final SimpleRepositoryFileData data = repository.getDataForRead(BIRTfile.getId(),
                    SimpleRepositoryFileData.class);
            final InputStream inputStream = data.getInputStream();
            final byte[] buffer = new byte[0x1000];
            int bytesRead = inputStream.read(buffer);
            while (bytesRead >= 0) {
                fos.write(buffer, 0, bytesRead);
                bytesRead = inputStream.read(buffer);
            }
        } catch (final Exception e) {
            Logger.error(getClass().getName(), e.getMessage());
        } finally {
            fos.close();
        }
    }
    /*
     * Redirect to BIRT Viewer
     */
    try {
        // Get informations about user context
        final IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class);
        String roles = "";
        final ListIterator<String> li = service.getRolesForUser(null, session.getName()).listIterator();
        while (li.hasNext()) {
            roles = roles + li.next().toString() + ",";
        }
        // Redirect
        final HttpServletResponse response = (HttpServletResponse) this.parameterProviders.get("path")
                .getParameter("httpresponse");
        response.sendRedirect(
                "/birt/frameset?__document=" + BIRTfile.getId() + ".rptdocument&__showtitle=false&username="
                        + session.getName() + "&userroles=" + roles + "&reportname=" + BIRTfile.getTitle());
    } catch (final Exception e) {
        Logger.error(getClass().getName(), e.getMessage());
    }
}

From source file:com.liferay.maven.arquillian.internal.tasks.ToolsClasspathTask.java

@Override
public URLClassLoader execute(MavenWorkingSession session) {

    final Logger log = LoggerFactory.getLogger(ToolsClasspathTask.class);

    final ParsedPomFile pomFile = session.getParsedPomFile();

    LiferayPluginConfiguration configuration = new LiferayPluginConfiguration(pomFile);

    System.setProperty("liferayVersion", configuration.getLiferayVersion());

    File appServerLibGlobalDir = new File(configuration.getAppServerLibGlobalDir());

    File appServerLibPortalDir = new File(configuration.getAppServerLibPortalDir());

    List<URI> liferayToolArchives = new ArrayList<URI>();

    if (appServerLibGlobalDir != null && appServerLibGlobalDir.exists()) {

        // app server global libraries
        Collection<File> appServerLibs = FileUtils.listFiles(appServerLibGlobalDir, new String[] { "jar" },
                true);// w  ww  .  j  a v  a  2 s.  c o  m

        for (File file : appServerLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // All Liferay Portal Lib jars
        Collection<File> liferayPortalLibs = FileUtils.listFiles(appServerLibPortalDir, new String[] { "jar" },
                true);

        for (File file : liferayPortalLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // Util jars
        File[] utilJars = Maven.resolver().loadPomFromClassLoaderResource("liferay-tool-deps.xml")
                .importCompileAndRuntimeDependencies().resolve().using(AcceptAllStrategy.INSTANCE).asFile();

        for (int i = 0; i < utilJars.length; i++) {
            liferayToolArchives.add(utilJars[i].toURI());
        }

    }

    log.trace("Jars count in Tools classpath Archive:" + liferayToolArchives.size());

    List<URL> classpathUrls = new ArrayList<URL>();

    try {
        if (!liferayToolArchives.isEmpty()) {

            ListIterator<URI> toolsJarItr = liferayToolArchives.listIterator();
            while (toolsJarItr.hasNext()) {
                URI jarURI = toolsJarItr.next();
                classpathUrls.add(jarURI.toURL());
            }

        }
    } catch (MalformedURLException e) {
        log.error("Error building Tools classpath", e);
    }

    return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), null);
}

From source file:com.liferay.arquillian.maven.internal.tasks.ToolsClasspathTask.java

/**
 * (non-Javadoc)/*  www  . ja v  a 2 s  . c o  m*/
 * @see
 * org.jboss.shrinkwrap.resolver.impl.maven.task.MavenWorkingSessionTask
 * #execute(org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession)
 */
@Override
public URLClassLoader execute(MavenWorkingSession session) {
    final ParsedPomFile pomFile = session.getParsedPomFile();

    LiferayPluginConfiguration configuration = new LiferayPluginConfiguration(pomFile);

    System.setProperty("liferayVersion", configuration.getLiferayVersion());

    File appServerLibGlobalDir = new File(configuration.getAppServerLibGlobalDir());

    File appServerLibPortalDir = new File(configuration.getAppServerLibPortalDir());

    List<URI> liferayToolArchives = new ArrayList<>();

    if ((appServerLibGlobalDir != null) && appServerLibGlobalDir.exists()) {

        // app server global libraries

        Collection<File> appServerLibs = FileUtils.listFiles(appServerLibGlobalDir, new String[] { "jar" },
                true);

        for (File file : appServerLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // All Liferay Portal Lib jars

        Collection<File> liferayPortalLibs = FileUtils.listFiles(appServerLibPortalDir, new String[] { "jar" },
                true);

        for (File file : liferayPortalLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // Util jars

        File[] utilJars = Maven.resolver().loadPomFromClassLoaderResource("liferay-tool-deps.xml")
                .importCompileAndRuntimeDependencies().resolve().using(AcceptAllStrategy.INSTANCE).asFile();

        for (int i = 0; i < utilJars.length; i++) {
            liferayToolArchives.add(utilJars[i].toURI());
        }
    }

    if (_log.isTraceEnabled()) {
        _log.trace("Jars count in Tools classpath Archive:" + liferayToolArchives.size());
    }

    List<URL> classpathUrls = new ArrayList<>();

    try {
        if (!liferayToolArchives.isEmpty()) {
            ListIterator<URI> toolsJarItr = liferayToolArchives.listIterator();
            while (toolsJarItr.hasNext()) {
                URI jarURI = toolsJarItr.next();
                classpathUrls.add(jarURI.toURL());
            }
        }
    } catch (MalformedURLException e) {
        _log.error("Error building Tools classpath", e);
    }

    return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), null);
}

From source file:biz.c24.io.spring.integration.selectors.ValidatingMessageSelectorTests.java

@Test
public void testInvalid() {
    Employee employee = new Employee();
    employee.setSalutation("Mr");
    // Should fail due to non-capitalised first letter
    employee.setFirstName("andy");
    employee.setLastName("Acheson");
    // No job title set - should also cause a validation failure
    //employee.setJobTitle("Software Developer");

    C24ValidatingMessageSelector selector = new C24ValidatingMessageSelector();
    selector.setFailFast(true);/*from  www .  j a v a 2  s .co  m*/
    selector.setThrowExceptionOnRejection(false);
    assertThat(selector.accept(MessageBuilder.withPayload(employee).build()), is(false));

    selector.setFailFast(false);
    assertThat(selector.accept(MessageBuilder.withPayload(employee).build()), is(false));

    selector.setFailFast(true);
    selector.setThrowExceptionOnRejection(true);
    try {
        selector.accept(MessageBuilder.withPayload(employee).build());
        fail("Selector failed to throw an exception on invalid CDO");
    } catch (MessageRejectedException ex) {
        // Expected behaviour
        assertThat(ex.getCause(), is(ValidationException.class));
    }

    selector.setFailFast(false);
    try {
        selector.accept(MessageBuilder.withPayload(employee).build());
        fail("Selector failed to throw an exception on invalid CDO");
    } catch (C24AggregatedMessageValidationException ex) {
        // Expected behaviour
        ListIterator<ValidationEvent> failures = ex.getFailEvents();
        int failureCount = 0;
        while (failures.hasNext()) {
            failureCount++;
            failures.next();
        }
        assertThat(failureCount, is(2));

    }
}

From source file:io.bibleget.VersionsSelect.java

public VersionsSelect() throws ClassNotFoundException {
    biblegetDB = BibleGetDB.getInstance();
    String bibleVersionsStr = biblegetDB.getMetaData("VERSIONS");
    JsonReader jsonReader = Json.createReader(new StringReader(bibleVersionsStr));
    JsonObject bibleVersionsObj = jsonReader.readObject();
    Set<String> versionsabbrev = bibleVersionsObj.keySet();
    bibleVersions = new BasicEventList<>();
    if (!versionsabbrev.isEmpty()) {
        for (String s : versionsabbrev) {
            String versionStr = bibleVersionsObj.getString(s); //store these in an array
            String[] array;/*from  ww w.ja  va  2s .c  o m*/
            array = versionStr.split("\\|");
            bibleVersions.add(new BibleVersion(s, array[0], array[1],
                    StringUtils.capitalize(new Locale(array[2]).getDisplayLanguage())));
        }
    }

    versionsByLang = new SeparatorList<>(bibleVersions, new VersionComparator(), 1, 1000);

    int listLength = versionsByLang.size();
    enabledFlags = new boolean[listLength];

    ListIterator itr = versionsByLang.listIterator();
    while (itr.hasNext()) {
        int idx = itr.nextIndex();
        Object next = itr.next();
        enabledFlags[idx] = !(next.getClass().getSimpleName().equals("GroupSeparator"));
        if (enabledFlags[idx]) {
            versionCount++;
        } else {
            versionLangs++;
        }
    }

    this.setModel(new DefaultEventListModel<>(versionsByLang));
    this.setCellRenderer(new VersionCellRenderer());
    this.setSelectionModel(new DisabledItemSelectionModel());
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheEntryUpdater.java

private void removeCacheEntry1xxWarnings(List<Header> cacheEntryHeaderList, HttpCacheEntry entry) {
    ListIterator<Header> cacheEntryHeaderListIter = cacheEntryHeaderList.listIterator();

    while (cacheEntryHeaderListIter.hasNext()) {
        String cacheEntryHeaderName = cacheEntryHeaderListIter.next().getName();

        if (HeaderConstants.WARNING.equals(cacheEntryHeaderName)) {
            for (Header cacheEntryWarning : entry.getHeaders(HeaderConstants.WARNING)) {
                if (cacheEntryWarning.getValue().startsWith("1")) {
                    cacheEntryHeaderListIter.remove();
                }//www.  java2s.  c o  m
            }
        }
    }
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheEntryUpdater.java

private void removeCacheHeadersThatMatchResponse(List<Header> cacheEntryHeaderList, HttpResponse response) {
    for (Header responseHeader : response.getAllHeaders()) {
        ListIterator<Header> cacheEntryHeaderListIter = cacheEntryHeaderList.listIterator();

        while (cacheEntryHeaderListIter.hasNext()) {
            String cacheEntryHeaderName = cacheEntryHeaderListIter.next().getName();

            if (cacheEntryHeaderName.equals(responseHeader.getName())) {
                cacheEntryHeaderListIter.remove();
            }//from   ww w  . j a  v a 2s  .c  om
        }
    }
}

From source file:mimir.ControlChart.java

public void newValue(double value) {
    //add value to data
    this.data.addValue(value);
    //System.out.println("Added Value: "+value+" to dataset");
    //iterate through patterns to catch signals
    ListIterator<PatternRule> patternChecker = this.patterns.listIterator(0);
    while (patternChecker.hasNext()) {
        PatternRule p = patternChecker.next();
        //System.out.println("Checking for: " + p.name);
        boolean flag = p.check(value);
        if (flag) {
            this.signals.add(p.name);
            //System.out.println(" -- caught flag -- ");
        }/*from w  ww  . j a  v  a 2  s. co  m*/
    }
    //handle signals in other scope
    return;
}

From source file:com.offbynull.voip.kademlia.model.NodeLeastRecentSet.java

public Node get(Id id) {
    InternalValidate.matchesLength(baseId.getBitLength(), id);

    ListIterator<Activity> it = entries.listIterator();
    while (it.hasNext()) {
        Activity entry = it.next();//from ww w.java 2 s.c  o  m

        Id entryId = entry.getNode().getId();

        if (entryId.equals(id)) {
            return entry.getNode();
        }
    }

    return null;
}

From source file:biz.c24.io.spring.integration.config.ValidatingSelectorTests.java

@Test
public void testThrowingInvalid() {
    Employee employee = new Employee();
    employee.setSalutation("Mr");
    // Invalid as first char not capitalised
    employee.setFirstName("andy");
    employee.setLastName("Acheson");
    // Invalid as no job title
    //employee.setJobTitle("Software Developer");

    try {//from   w w  w.jav a  2 s  . c  o m
        template.convertAndSend(exceptionThrowingInputChannel, employee);
        fail("Selector failed to throw exception on invalid message");
    } catch (MessageHandlingException ex) {
        // Expected behaviour
        assertThat(ex.getCause(), is(C24AggregatedMessageValidationException.class));
        C24AggregatedMessageValidationException vEx = (C24AggregatedMessageValidationException) ex.getCause();
        ListIterator<ValidationEvent> failures = vEx.getFailEvents();
        int failureCount = 0;
        while (failures.hasNext()) {
            failureCount++;
            failures.next();
        }
        assertThat(failureCount, is(2));

    }

    // Make sure there are no other messages floating around
    assertThat(validChannel.receive(1), is(nullValue()));
    assertThat(invalidChannel.receive(1), is(nullValue()));

}