List of usage examples for java.util SortedSet iterator
Iterator<E> iterator();
From source file:org.apache.geronimo.console.repository.RepositoryViewPortlet.java
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { // i think generic portlet already does this if (WindowState.MINIMIZED.equals(request.getWindowState())) { return;/*from ww w .j a va2 s .com*/ } String mode = request.getParameter("mode"); if (mode != null && mode.equals("usage")) { String res = request.getParameter("res"); String[] parts = res.split("/"); request.setAttribute("res", res); request.setAttribute("groupId", parts[0]); request.setAttribute("artifactId", parts[1]); request.setAttribute("version", parts[2]); request.setAttribute("type", parts[3]); usageView.include(request, response); return; } try { List list = new ArrayList(); ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories(); for (int i = 0; i < repos.length; i++) { ListableRepository repo = repos[i]; final SortedSet artifacts = repo.list(); for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) { String fileName = iterator.next().toString(); list.add(fileName); } } Collections.sort(list); request.setAttribute("org.apache.geronimo.console.repo.list", list); } catch (Exception e) { throw new PortletException(e); } normalView.include(request, response); }
From source file:org.geoserver.security.iride.IrideRoleServiceTest.java
public void testGetRolesForSuperUser() throws IOException { IrideRoleService roleService = wrapRoleService(createRoleService(), "super"); SortedSet<GeoServerRole> roles = roleService.getRolesForUser(SUPER_SAMPLE_USER); assertNotNull(roles);/* www. ja va 2s . co m*/ assertEquals(1, roles.size()); assertEquals("SUPERUSER_SIIG", roles.iterator().next().toString()); //assertEquals(GeoServerRole.ADMIN_ROLE, roles.iterator().next()); RoleCalculator roleCalc = new RoleCalculator(roleService); roles = roleCalc.calculateRoles(SUPER_SAMPLE_USER); assertNotNull(roles); assertEquals(3, roles.size()); boolean foundAdmin = false; for (GeoServerRole role : roles) { if (role.equals(GeoServerRole.ADMIN_ROLE)) { foundAdmin = true; } } assertTrue(foundAdmin); }
From source file:org.LexGrid.LexBIG.example.ScoreTerm.java
/** * Returns a score providing a relative comparison of the first set of words * against the second./*from ww w. j a v a 2 s .co m*/ * <p> * Currently the score is evaluated as a simple percentage based on number * of words in the first set that are also in the second (order * independent). This could be enhanced to take order into account, etc. * * @param wordsToCompare * @param wordsToCompareAgainst * @return The score (a percentage); a higher value indicates a stronger * match. */ protected float score(SortedSet wordsToCompare, SortedSet wordsToCompareAgainst) { int totalWords = wordsToCompare.size(); int matchWords = 0; for (Iterator words = wordsToCompare.iterator(); words.hasNext();) { String word = words.next().toString(); if (wordsToCompareAgainst.contains(word)) matchWords++; } return ((float) matchWords / (float) totalWords) * 100; }
From source file:org.sakuli.services.receiver.gearman.model.builder.OutputBuilder.java
private String generateStepInformation(SortedSet<TestCaseStep> steps) { StringBuilder sb = new StringBuilder(); Iterator<TestCaseStep> it = steps.iterator(); while (it.hasNext()) { TestCaseStep step = it.next();//from ww w.j ava2 s . c o m if (TestCaseStepState.WARNING.equals(step.getState())) { sb.append("step \"").append(step.getName()).append("\" (").append(formatToSec(step.getDuration())) .append(" /warn at ").append(formatToSec(step.getWarningTime())).append(")"); } if (it.hasNext()) { sb.append(", "); } } return sb.toString(); }
From source file:it.geosolutions.geofence.gui.server.service.impl.ProfilesManagerServiceImpl.java
public PagingLoadResult<ProfileCustomProps> getProfileCustomProps(int offset, int limit, UserGroup profile) { int start = offset; Long t = new Long(0); List<ProfileCustomProps> customPropsDTO = new ArrayList<ProfileCustomProps>(); if ((profile != null) && (profile.getId() >= 0)) { try {// w w w. java2 s . c om logger.error("TODO: profile refactoring!!! custom props have been removed"); Map<String, String> customProperties = new HashMap<String, String>(); customProperties.put("NOTE", "Custom properties are no longer supported. Code is unstable"); // Map<String, String> customProperties = geofenceRemoteService.getUserGroupAdminService().getCustomProps(profile.getId()); if (customProperties == null) { if (logger.isErrorEnabled()) { logger.error("No property found on server"); } throw new ApplicationException("No rule found on server"); } long rulesCount = customProperties.size(); t = new Long(rulesCount); int page = (start == 0) ? start : (start / limit); SortedSet<String> sortedset = new TreeSet<String>(customProperties.keySet()); Iterator<String> it = sortedset.iterator(); while (it.hasNext()) { String key = it.next(); ProfileCustomProps property = new ProfileCustomProps(); property.setPropKey(key); property.setPropValue(customProperties.get(key)); customPropsDTO.add(property); } // for (String key : customProperties.keySet()) { // ProfileCustomProps property = new ProfileCustomProps(); // property.setPropKey(key); // property.setPropValue(customProperties.get(key)); // customPropsDTO.add(property); // } } catch (Exception e) { // do nothing! } } return new RpcPageLoadResult<ProfileCustomProps>(customPropsDTO, offset, t.intValue()); }
From source file:org.dbunit.util.search.DepthFirstSearch.java
/** * This is the real depth first search algorithm, which is called recursively. * /*from ww w.j a v a 2s . c o m*/ * @param node node where the search starts * @param currentSearchDepth the search depth in the recursion * @return true if the node has been already searched before * @throws Exception if an exception occurs while getting the edges */ private boolean search(Object node, int currentSearchDepth) throws SearchException { if (this.logger.isDebugEnabled()) { this.logger.debug("search:" + node); } if (this.scannedNodes.contains(node)) { if (this.logger.isDebugEnabled()) { this.logger.debug("already searched; returning true"); } return true; } if (!this.callback.searchNode(node)) { if (this.logger.isDebugEnabled()) { this.logger.debug("Callback handler blocked search for node " + node); } return true; } if (this.logger.isDebugEnabled()) { this.logger.debug("Pushing " + node); } this.scannedNodes.add(node); if (currentSearchDepth < this.searchDepth) { // first, search the nodes the node depends on SortedSet edges = this.callback.getEdges(node); if (edges != null) { Iterator iterator = edges.iterator(); while (iterator.hasNext()) { // and recursively search these nodes IEdge edge = (IEdge) iterator.next(); Object toNode = edge.getTo(); search(toNode, currentSearchDepth++); } } } // finally, add the node to the result if (this.logger.isDebugEnabled()) { this.logger.debug("Adding node " + node + " to the final result"); } // notify the callback a node was added this.callback.nodeAdded(node); result.add(node); return false; }
From source file:org.dbunit.util.search.DepthFirstSearch.java
/** * Do a reverse search (i.e, searching the other way of the edges) in order * to adjust the input before the real search. * @param node node where the search starts * @param currentSearchDepth the search depth in the recursion * @return true if the node has been already reverse-searched before * @throws Exception if an exception occurs while getting the edges *//*from w w w . jav a2 s .c o m*/ private boolean reverseSearch(Object node, int currentSearchDepth) throws SearchException { if (this.logger.isDebugEnabled()) { this.logger.debug("reverseSearch:" + node); } if (this.reverseScannedNodes.contains(node)) { if (this.logger.isDebugEnabled()) { this.logger.debug("already searched; returning true"); } return true; } if (!this.callback.searchNode(node)) { if (this.logger.isDebugEnabled()) { this.logger.debug("callback handler blocked reverse search for node " + node); } return true; } if (this.logger.isDebugEnabled()) { this.logger.debug("Pushing (reverse) " + node); } this.reverseScannedNodes.add(node); if (currentSearchDepth < this.searchDepth) { // first, search the nodes the node depends on SortedSet edges = this.callback.getEdges(node); if (edges != null) { Iterator iterator = edges.iterator(); while (iterator.hasNext()) { // and recursively search these nodes if we find a match IEdge edge = (IEdge) iterator.next(); Object toNode = edge.getTo(); if (toNode.equals(node)) { Object fromNode = edge.getFrom(); reverseSearch(fromNode, currentSearchDepth++); } } } } // finally, add the node to the input this.nodesFrom.add(node); return false; }
From source file:org.geoserver.geofence.gui.server.service.impl.ProfilesManagerServiceImpl.java
public PagingLoadResult<ProfileCustomProps> getProfileCustomProps(int offset, int limit, UserGroupModel profile) {//w w w .j av a 2 s .co m int start = offset; Long t = new Long(0); List<ProfileCustomProps> customPropsDTO = new ArrayList<ProfileCustomProps>(); if ((profile != null) && (profile.getId() >= 0)) { try { logger.error("TODO: profile refactoring!!! custom props have been removed"); Map<String, String> customProperties = new HashMap<String, String>(); customProperties.put("NOTE", "Custom properties are no longer supported. Code is unstable"); // Map<String, String> customProperties = geofenceRemoteService.getUserGroupAdminService().getCustomProps(profile.getId()); if (customProperties == null) { if (logger.isErrorEnabled()) { logger.error("No property found on server"); } throw new ApplicationException("No rule found on server"); } long rulesCount = customProperties.size(); t = new Long(rulesCount); int page = (start == 0) ? start : (start / limit); SortedSet<String> sortedset = new TreeSet<String>(customProperties.keySet()); Iterator<String> it = sortedset.iterator(); while (it.hasNext()) { String key = it.next(); ProfileCustomProps property = new ProfileCustomProps(); property.setPropKey(key); property.setPropValue(customProperties.get(key)); customPropsDTO.add(property); } // for (String key : customProperties.keySet()) { // ProfileCustomProps property = new ProfileCustomProps(); // property.setPropKey(key); // property.setPropValue(customProperties.get(key)); // customPropsDTO.add(property); // } } catch (Exception e) { // do nothing! } } return new RpcPageLoadResult<ProfileCustomProps>(customPropsDTO, offset, t.intValue()); }
From source file:com.medvision360.medrecord.spi.tck.RMTestBase.java
protected void assertEqualish(Archetype orig, Archetype other) { assertEquals(orig.getAdlVersion(), other.getAdlVersion()); assertEquals(orig.getArchetypeId(), other.getArchetypeId()); assertEquals(orig.getDescription(), other.getDescription()); SortedSet<String> origPaths = new TreeSet<>(orig.getPathNodeMap().keySet()); SortedSet<String> otherPaths = new TreeSet<>(other.getPathNodeMap().keySet()); assertEquals(origPaths.size(), otherPaths.size()); Iterator<String> origIt = origPaths.iterator(); Iterator<String> otherIt = otherPaths.iterator(); while (origIt.hasNext()) { String origPath = origIt.next(); String otherPath = otherIt.next(); assertEquals(origPath, otherPath); }/*from w ww . j ava 2s . co m*/ }
From source file:annis.visualizers.htmlvis.HTMLVis.java
private String createHTML(SDocumentGraph graph, VisualizationDefinition[] definitions) { SortedMap<Long, SortedSet<OutputItem>> outputStartTags = new TreeMap<Long, SortedSet<OutputItem>>(); SortedMap<Long, SortedSet<OutputItem>> outputEndTags = new TreeMap<Long, SortedSet<OutputItem>>(); StringBuilder sb = new StringBuilder(); EList<SToken> token = graph.getSortedSTokenByText(); for (SToken t : token) { for (VisualizationDefinition vis : definitions) { String matched = vis.getMatcher().matchedAnnotation(t); if (matched != null) { vis.getOutputter().outputHTML(t, matched, outputStartTags, outputEndTags); }/*from w ww .j a v a 2s .c o m*/ } } List<SSpan> spans = graph.getSSpans(); for (VisualizationDefinition vis : definitions) { for (SSpan span : spans) { String matched = vis.getMatcher().matchedAnnotation(span); if (matched != null) { vis.getOutputter().outputHTML(span, matched, outputStartTags, outputEndTags); } } } // get all used indexes Set<Long> indexes = new TreeSet<Long>(); indexes.addAll(outputStartTags.keySet()); indexes.addAll(outputEndTags.keySet()); for (Long i : indexes) { // output all strings belonging to this token position // first the start tags for this position SortedSet<OutputItem> itemsStart = outputStartTags.get(i); if (itemsStart != null) { Iterator<OutputItem> it = itemsStart.iterator(); boolean first = true; while (it.hasNext()) { OutputItem s = it.next(); if (!first) { sb.append("-->"); } first = false; sb.append(s.getOutputString()); if (it.hasNext()) { sb.append("<!--\n"); } } } // then the end tags for this position, but inverse their order SortedSet<OutputItem> itemsEnd = outputEndTags.get(i); if (itemsEnd != null) { List<OutputItem> itemsEndReverse = new LinkedList<OutputItem>(itemsEnd); Collections.reverse(itemsEndReverse); for (OutputItem s : itemsEndReverse) { sb.append(s.getOutputString()); } } } return sb.toString(); }