List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:io.wcm.handler.url.suffix.SuffixBuilder.java
/** * Build complete suffix.//from ww w . j a v a 2 s. c o m * @return the suffix */ public String build() { SortedMap<String, Object> sortedParameterMap = new TreeMap<>(parameterMap); // gather resource paths in a treeset (having them in a defined order helps with caching) SortedSet<String> resourcePathsSet = new TreeSet<>(); // iterate over all parts that should be kept from the current request for (String nextPart : initialSuffixParts) { // if this is a key-value-part: if (nextPart.indexOf(KEY_VALUE_DELIMITER) > 0) { String key = decodeKey(nextPart); // decode and keep the part if it is not overridden in the given parameter-map if (!sortedParameterMap.containsKey(key)) { String value = decodeValue(nextPart); sortedParameterMap.put(key, value); } } else { // decode and keep the resource paths (unless they are specified again in resourcePaths) String path = decodeResourcePathPart(nextPart); if (!resourcePaths.contains(path)) { resourcePathsSet.add(path); } } } // copy the resources specified as parameters to the sorted set of paths if (resourcePaths != null) { resourcePathsSet.addAll(ImmutableList.copyOf(resourcePaths)); } // gather all suffix parts in this list List<String> suffixParts = new ArrayList<>(); // now encode all resource paths for (String path : resourcePathsSet) { suffixParts.add(encodeResourcePathPart(path)); } // now encode all entries from the parameter map for (Entry<String, Object> entry : sortedParameterMap.entrySet()) { Object value = entry.getValue(); if (value == null) { // don't add suffix part if value is null continue; } String encodedKey = encodeKeyValuePart(entry.getKey()); String encodedValue = encodeKeyValuePart(value.toString()); suffixParts.add(encodedKey + KEY_VALUE_DELIMITER + encodedValue); } // finally join these parts to a single string return StringUtils.join(suffixParts, SUFFIX_PART_DELIMITER); }
From source file:net.rrm.ehour.report.service.AggregateReportServiceImpl.java
@Override public ProjectManagerReport getProjectManagerDetailedReport(Project project) { ProjectManagerReport report = new ProjectManagerReport(); // get the project report.setProject(project);/*from w w w. j a va2 s .co m*/ // get a proper report range DateRange reportRange = getReportRangeForProject(project); report.setReportRange(reportRange); // get all aggregates List<Project> projects = Arrays.asList(project); SortedSet<AssignmentAggregateReportElement> aggregates = new TreeSet<AssignmentAggregateReportElement>( reportAggregatedDAO.getCumulatedHoursPerAssignmentForProjects(projects, reportRange)); // filter out just the id's List<Integer> assignmentIds = new ArrayList<>(); for (AssignmentAggregateReportElement aggregate : aggregates) { assignmentIds.add(aggregate.getProjectAssignment().getAssignmentId()); } // get all assignments for this period regardless whether they booked hours on it List<ProjectAssignment> allAssignments = projectAssignmentService.getProjectAssignments(project, reportRange); for (ProjectAssignment assignment : allAssignments) { if (!assignmentIds.contains(assignment.getAssignmentId())) { AssignmentAggregateReportElement emptyAggregate = new AssignmentAggregateReportElement(); emptyAggregate.setProjectAssignment(assignment); aggregates.add(emptyAggregate); } } report.setAggregates(aggregates); report.deriveTotals(); return report; }
From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java
/** * Ensures that the {@link Set} for the given * {@link DeviceProtocolInfoSource} contains the specified element. Returns * {@code true} if {@code protocolInfo} was added a result of the call, or * {@code false} the {@link Set} for the given * {@link DeviceProtocolInfoSource} already contains the specified element. * * @param type the {@link DeviceProtocolInfoSource} type. * @param protocolInfo element whose presence is to be ensured. * @return {@code true} if the {@link Set} for {@code type} changed as a * result of the call, {@code false} otherwise. */// ww w . j av a 2s . com public boolean add(DeviceProtocolInfoSource<?> type, ProtocolInfo protocolInfo) { setsLock.writeLock().lock(); try { SortedSet<ProtocolInfo> currentSet; if (protocolInfoSets.containsKey(type)) { currentSet = protocolInfoSets.get(type); } else { currentSet = new TreeSet<ProtocolInfo>(); protocolInfoSets.put(type, currentSet); } if (currentSet.add(protocolInfo)) { updateImageProfiles(); return true; } return false; } finally { setsLock.writeLock().unlock(); } }
From source file:com.palantir.atlasdb.sweep.SweepTaskRunner.java
private Set<Long> getTimestampsToSweep(Cell cell, Collection<Long> timestamps /* start timestamps */, @Modified Map<Long, Long> startTsToCommitTs, @Output Set<Cell> sentinelsToAdd, long sweepTimestamp, boolean sweepLastCommitted, SweepStrategy sweepStrategy) { Set<Long> uncommittedTimestamps = Sets.newHashSet(); SortedSet<Long> committedTimestampsToSweep = Sets.newTreeSet(); long maxStartTs = TransactionConstants.FAILED_COMMIT_TS; boolean maxStartTsIsCommitted = false; for (long startTs : timestamps) { long commitTs = ensureCommitTimestampExists(startTs, startTsToCommitTs); if (startTs > maxStartTs && commitTs < sweepTimestamp) { maxStartTs = startTs;//from w ww . j a v a 2s . c o m maxStartTsIsCommitted = commitTs != TransactionConstants.FAILED_COMMIT_TS; } // Note: there could be an open transaction whose start timestamp is equal to // sweepTimestamp; thus we want to sweep all cells such that: // (1) their commit timestamp is less than sweepTimestamp // (2) their start timestamp is NOT the greatest possible start timestamp // passing condition (1) if (commitTs > 0 && commitTs < sweepTimestamp) { committedTimestampsToSweep.add(startTs); } else if (commitTs == TransactionConstants.FAILED_COMMIT_TS) { uncommittedTimestamps.add(startTs); } } if (committedTimestampsToSweep.isEmpty()) { return uncommittedTimestamps; } if (sweepStrategy == SweepStrategy.CONSERVATIVE && committedTimestampsToSweep.size() > 1) { // We need to add a sentinel if we are removing a committed value sentinelsToAdd.add(cell); } if (sweepLastCommitted && maxStartTsIsCommitted) { return Sets.union(uncommittedTimestamps, committedTimestampsToSweep); } return Sets.union(uncommittedTimestamps, committedTimestampsToSweep.subSet(0L, committedTimestampsToSweep.last())); }
From source file:de.knowwe.defi.usermanager.XMLUserDatabase.java
/** * Returns all WikiNames that are stored in the UserDatabase * as an array of WikiPrincipal objects. If the database does not * contain any profiles, this method will return a zero-length * array./*from w w w . ja v a 2 s . c om*/ * @return the WikiNames * @throws org.apache.wiki.auth.WikiSecurityException In case things fail. */ @Override public Principal[] getWikiNames() throws WikiSecurityException { if (c_dom == null) { throw new IllegalStateException("FATAL: database does not exist"); } SortedSet<Principal> principals = new TreeSet<>(); NodeList users = c_dom.getElementsByTagName(USER_TAG); for (int i = 0; i < users.getLength(); i++) { Element user = (Element) users.item(i); String wikiName = user.getAttribute(WIKI_NAME); if (wikiName == null) { Log.warning("Detected null wiki name in XMLUserDataBase. Check your user database."); } else { Principal principal = new WikiPrincipal(wikiName, WikiPrincipal.WIKI_NAME); principals.add(principal); } } return principals.toArray(new Principal[principals.size()]); }
From source file:controllers.Statistics.java
private static void getElapsedTimeStatisticsForSeconds(long secondInMillis, int previousSeconds, String target, ObjectNode objectNode) {//from w w w. ja v a 2s . c o m TitanGraph g = Global.getGraph(); long second = (secondInMillis / 1000) * 1000; SortedSet<Integer> numSet = new TreeSet<Integer>(); int value = 0; int sum = 0; int count = 0; for (int i = (previousSeconds - 1); i > -1; i--) { //Logger.info("previousSeconds=" + (second - (i * 1000))); Iterator<Vertex> it = g.getVertices("second", second - (i * 1000)).iterator(); Vertex v = null; //if(it.hasNext()) { while (it.hasNext()) { v = it.next(); for (Vertex vertex : v.query().labels("include").has("event", target).vertices()) { if (vertex == null) { continue; } value = (Integer) vertex.getProperty("elapsedTime"); count++; sum += value; numSet.add(value); } } } objectNode.put("cnt", count); if (count > 0) { objectNode.put("avg", sum / count); objectNode.put("min", numSet.first()); objectNode.put("max", numSet.last()); } else { objectNode.put("avg", 0); objectNode.put("min", 0); objectNode.put("max", 0); } }
From source file:org.openmrs.module.privilegehelper.web.controller.PrivilegeAssignerController.java
@RequestMapping(value = "/assignPrivileges") public String assignPrivileges(final @ModelAttribute(PRIVILEGES) SortedSet<PrivilegeLogEntry> privileges, final @ModelAttribute(MISSING_PRIVILEGES) SortedSet<PrivilegeLogEntry> missingPrivileges, final User user, @RequestParam final Integer loggedUserId, final ModelMap model) { User loggedUser = Context.getUserService().getUser(loggedUserId); if (loggedUser == null) { throw new IllegalArgumentException("User with id " + loggedUserId + " does not exist!"); }//from w w w .jav a 2s . c o m privileges.clear(); missingPrivileges.clear(); final List<PrivilegeLogEntry> loggedPrivileges = logger.getLoggedPrivileges(loggedUser); for (PrivilegeLogEntry privilege : loggedPrivileges) { if (StringUtils.isBlank(privilege.getPrivilege())) { continue; } final Privilege existingPrivilege = Context.getUserService().getPrivilege(privilege.getPrivilege()); if (existingPrivilege != null) { privileges.add(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(), privilege.isRequired(), !user.hasPrivilege(privilege.getPrivilege()))); } else { missingPrivileges.add(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(), privilege.isRequired(), !user.hasPrivilege(privilege.getPrivilege()))); } } model.addAttribute("userId", user.getUserId()); return "redirect:assignRoles.form"; }
From source file:com.okta.swagger.codegen.AbstractOktaJavaClientCodegen.java
private SortedSet<String> parentPathParams(ObjectNode n) { SortedSet<String> result = new TreeSet<>(); ArrayNode argNodeList = (ArrayNode) n.get("arguments"); if (argNodeList != null) { for (JsonNode argNode : argNodeList) { if (argNode.has("parentSrc")) { String src = argNode.get("parentSrc").textValue(); String dest = argNode.get("dest").textValue(); if (src != null) { result.add(dest); }/*from w ww .j ava 2 s .c om*/ } } } return result; }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java
@Test public void testDoHandleListPage05() throws IOException, ServletException { this.setUpSecurity(); SharedBuildNumber bn1 = new SharedBuildNumber(12); bn1.setName("hello"); SharedBuildNumber bn2 = new SharedBuildNumber(22); bn2.setName("world"); SortedSet<SharedBuildNumber> set = new TreeSet<SharedBuildNumber>(new Comparator<SharedBuildNumber>() { @Override// w ww .j a v a2 s. c o m public int compare(SharedBuildNumber left, SharedBuildNumber right) { return left.getName().compareTo(right.getName()); } }); set.add(bn1); set.add(bn2); expect(this.request.getParameter("action")).andReturn("list"); expect(this.request.getMethod()).andReturn("POST"); expect(this.request.getParameter("direction")).andReturn("asc"); expect(this.request.getParameter("sort")).andReturn("name"); expect(this.service.getAllSharedBuildNumbersSortedByName(false)).andReturn(set); replay(this.service, this.request, this.response); ModelAndView modelAndView = this.controller.doHandle(this.request, this.response); assertNotNull("The model and view should not be null.", modelAndView); assertEquals("The view is not correct.", "/plugin/" + testNum + "/jsp/list.jsp", modelAndView.getViewName()); Map<String, Object> model = modelAndView.getModel(); assertNotNull("The model should not be null.", model); assertEquals("sortedBy is not correct.", "name", model.get("sortedBy")); assertEquals("sortClass is not correct.", "sortedAsc", model.get("sortClass")); assertEquals("sortChange is not correct.", "desc", model.get("sortChange")); assertEquals("sbnParameterPrefix is not correct.", BuildNumberPropertiesProvider.PARAMETER_PREFIX, model.get("sbnParameterPrefix")); assertEquals("numResults is not correct.", 2, model.get("numResults")); assertSame("buildNumbers is not correct.", set, model.get("buildNumbers")); }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java
@Test public void testDoHandleListPage06() throws IOException, ServletException { this.setUpSecurity(); SortedSet<SharedBuildNumber> set = new TreeSet<SharedBuildNumber>(new Comparator<SharedBuildNumber>() { @Override/*from w w w. j a va 2s. c o m*/ public int compare(SharedBuildNumber left, SharedBuildNumber right) { return NumberUtils.compare(left.getId(), right.getCounter()); } }); set.add(new SharedBuildNumber(12)); set.add(new SharedBuildNumber(22)); set.add(new SharedBuildNumber(15)); expect(this.request.getParameter("action")).andReturn("list"); expect(this.request.getMethod()).andReturn("POST"); expect(this.request.getParameter("direction")).andReturn("desc"); expect(this.request.getParameter("sort")).andReturn("name"); expect(this.service.getAllSharedBuildNumbersSortedByName(true)).andReturn(set); replay(this.service, this.request, this.response); ModelAndView modelAndView = this.controller.doHandle(this.request, this.response); assertNotNull("The model and view should not be null.", modelAndView); assertEquals("The view is not correct.", "/plugin/" + testNum + "/jsp/list.jsp", modelAndView.getViewName()); Map<String, Object> model = modelAndView.getModel(); assertNotNull("The model should not be null.", model); assertEquals("sortedBy is not correct.", "name", model.get("sortedBy")); assertEquals("sortClass is not correct.", "sortedDesc", model.get("sortClass")); assertEquals("sortChange is not correct.", "asc", model.get("sortChange")); assertEquals("sbnParameterPrefix is not correct.", BuildNumberPropertiesProvider.PARAMETER_PREFIX, model.get("sbnParameterPrefix")); assertEquals("numResults is not correct.", 3, model.get("numResults")); assertSame("buildNumbers is not correct.", set, model.get("buildNumbers")); }