List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testAddFilter() { final Checker checker = new Checker(); final DebugFilter filter = new DebugFilter(); checker.addFilter(filter);//www. j ava2 s . co m filter.resetFilter(); final SortedSet<LocalizedMessage> messages = Sets.newTreeSet(); messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null)); checker.fireErrors("Some File Name", messages); assertTrue("Checker.fireErrors() doesn't call filter", filter.wasCalled()); }
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testRemoveFilter() { final Checker checker = new Checker(); final DebugFilter filter = new DebugFilter(); final DebugFilter f2 = new DebugFilter(); checker.addFilter(filter);/*from w ww. j a v a 2s. co m*/ checker.addFilter(f2); checker.removeFilter(filter); f2.resetFilter(); final SortedSet<LocalizedMessage> messages = Sets.newTreeSet(); messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null)); checker.fireErrors("Some File Name", messages); assertTrue("Checker.fireErrors() doesn't call filter", f2.wasCalled()); assertFalse("Checker.fireErrors() does call removed filter", filter.wasCalled()); }
From source file:dom.usuario.UsuarioShiroRepositorio.java
@Programmatic @MemberOrder(sequence = "10") @Named("Agregar Usuario") public UsuarioShiro addUsuarioShiro(final @Named("Nick") String nick, final @Named("Password") String password, final @Named("Rol") Rol rol) { final UsuarioShiro obj = container.newTransientInstance(UsuarioShiro.class); final SortedSet<Rol> rolesList = new TreeSet<Rol>(); if (rol != null) { rolesList.add(rol); obj.setRolesList(rolesList);// w w w . j av a 2s.co m } obj.setNick(nick); obj.setPassword(password); container.persistIfNotAlready(obj); return obj; }
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testDestroy() throws Exception { final Checker checker = new Checker(); final DebugAuditAdapter auditAdapter = new DebugAuditAdapter(); checker.addListener(auditAdapter);//from www. ja v a2 s . c o m final DebugFilter filter = new DebugFilter(); checker.addFilter(filter); // should remove al listeners and filters checker.destroy(); // Let's try fire some events getFireAuditStartedMethod().invoke(checker); getFireAuditFinished().invoke(checker); checker.fireFileStarted("Some File Name"); checker.fireFileFinished("Some File Name"); final SortedSet<LocalizedMessage> messages = Sets.newTreeSet(); messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null)); checker.fireErrors("Some File Name", messages); assertFalse("Checker.destroy() doesn't remove listeners.", auditAdapter.wasCalled()); assertFalse("Checker.destroy() doesn't remove filters.", filter.wasCalled()); }
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testAddListener() throws Exception { final Checker checker = new Checker(); final DebugAuditAdapter auditAdapter = new DebugAuditAdapter(); checker.addListener(auditAdapter);//from w ww.j av a 2 s .co m // Let's try fire some events getFireAuditStartedMethod().invoke(checker); assertTrue("Checker.fireAuditStarted() doesn't call listener", auditAdapter.wasCalled()); auditAdapter.resetListener(); getFireAuditFinished().invoke(checker); assertTrue("Checker.fireAuditFinished() doesn't call listener", auditAdapter.wasCalled()); auditAdapter.resetListener(); checker.fireFileStarted("Some File Name"); assertTrue("Checker.fireFileStarted() doesn't call listener", auditAdapter.wasCalled()); auditAdapter.resetListener(); checker.fireFileFinished("Some File Name"); assertTrue("Checker.fireFileFinished() doesn't call listener", auditAdapter.wasCalled()); auditAdapter.resetListener(); final SortedSet<LocalizedMessage> messages = Sets.newTreeSet(); messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null)); checker.fireErrors("Some File Name", messages); assertTrue("Checker.fireErrors() doesn't call listener", auditAdapter.wasCalled()); }
From source file:com.jd.survey.web.settings.QuestionController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String create(@RequestParam(value = "_proceed", required = false) String proceed, @Valid Question question, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {/*from w w w.j a v a 2 s .c o m*/ String login = principal.getName(); User user = userService.user_findByLogin(login); //SurveyDefinitionPage surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_findById(surveyDefinitionPageId); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( question.getPage().getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } //User user = userService.user_findByLogin(principal.getName()); if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, question, user); return "settings/questions/create"; } if (!surveySettingsService.question_ValidateDateRange(question)) { populateEditForm(uiModel, question, user); bindingResult.rejectValue("dateMinimum", "date_format_validation_range"); return "settings/questions/create"; } //validate Double min max if (!surveySettingsService.question_ValidateMinMaxDoubleValues(question)) { populateEditForm(uiModel, question, user); bindingResult.rejectValue("decimalMinimum", "field_min_invalid"); return "settings/questions/create"; } //validate Integer min max if (!surveySettingsService.question_ValidateMinMaxValues(question)) { populateEditForm(uiModel, question, user); bindingResult.rejectValue("integerMinimum", "field_min_invalid"); return "settings/questions/create"; } if (question.getType().getIsRating()) { SortedSet<QuestionOption> options = new TreeSet<QuestionOption>(); options.add(new QuestionOption(question, (short) 1, "1", messageSource .getMessage(EXTREMELY_UNSATISFIED_LABEL, null, LocaleContextHolder.getLocale()))); options.add(new QuestionOption(question, (short) 2, "2", messageSource.getMessage(UNSATISFIED_LABEL, null, LocaleContextHolder.getLocale()))); options.add(new QuestionOption(question, (short) 3, "3", messageSource.getMessage(NEUTRAL_LABEL, null, LocaleContextHolder.getLocale()))); options.add(new QuestionOption(question, (short) 4, "4", messageSource.getMessage(SATISFIED_LABEL, null, LocaleContextHolder.getLocale()))); options.add(new QuestionOption(question, (short) 5, "5", messageSource .getMessage(EXTREMELY_SATISFIED_LABEL, null, LocaleContextHolder.getLocale()))); question = surveySettingsService.question_merge(question, options); } // if (question.getPublishToSocrata().equals(true)){ // bindingResult.rejectValue("socrataColumnName", "field_min_invalid"); // return "settings/questions/create"; // } else { Policy questionTextPolicy = Policy .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy emailAs = new AntiSamy(); CleanResults crQuestionText = emailAs.scan(question.getQuestionText(), questionTextPolicy); question.setQuestionText(crQuestionText.getCleanHTML()); Policy questionTipPolicy = Policy .getInstance(this.getClass().getResource(POLICY_FILE_LOCATION)); AntiSamy completedSurveyAs = new AntiSamy(); CleanResults crQuestionTip = completedSurveyAs.scan(question.getTip(), questionTipPolicy); question.setTip(crQuestionTip.getCleanHTML()); question = surveySettingsService.question_merge(question); } uiModel.asMap().clear(); return "settings/questions/saved"; } else { return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( question.getPage().getSurveyDefinition().getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java
/** * Retrieve ALL {@link AvailableBlock}s for an owner in a {@link SortedSet}. * /*ww w .j av a 2 s . c o m*/ * The blocks are returned as-is (no expansion). * * @param owner * @return */ protected SortedSet<AvailableBlock> internalRetrieveSchedule(final IScheduleOwner owner) { List<PersistenceAvailableBlock> scheduleRows = this.simpleJdbcTemplate.query( "select * from schedules where owner_id = ?", new PersistenceAvailableBlockRowMapper(), owner.getId()); SortedSet<AvailableBlock> availableBlocks = new TreeSet<AvailableBlock>(); for (PersistenceAvailableBlock row : scheduleRows) { availableBlocks.add(AvailableBlockBuilder.createBlock(row.getStartTime(), row.getEndTime(), row.getVisitorLimit(), row.getMeetingLocation())); } return availableBlocks; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.department.PublicDepartmentSiteDA.java
public ActionForward degrees(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {/*from ww w . ja v a 2 s. c o m*/ Unit unit = getUnit(request); Department department = unit.getDepartment(); if (department == null) { return presentation(mapping, actionForm, request, response); } Map<DegreeType, SortedSet<Degree>> degreeAndTypes = new HashMap<DegreeType, SortedSet<Degree>>(); SortedSet<DegreeType> activeTypes = new TreeSet<DegreeType>(); SortedSet<DegreeType> inactiveTypes = new TreeSet<DegreeType>(); for (Degree degree : department.getDegreesSet()) { DegreeType type = degree.getDegreeType(); if (degree.isActive()) { activeTypes.add(type); } else { inactiveTypes.add(type); } SortedSet<Degree> current = degreeAndTypes.get(type); if (current == null) { current = new TreeSet<Degree>(Degree.COMPARATOR_BY_NAME_AND_ID); degreeAndTypes.put(type, current); } current.add(degree); } request.setAttribute("inactive-types", inactiveTypes); request.setAttribute("active-types", activeTypes); for (DegreeType type : inactiveTypes) { request.setAttribute(type.getName(), degreeAndTypes.get(type)); } for (DegreeType type : activeTypes) { request.setAttribute(type.getName(), degreeAndTypes.get(type)); } return mapping.findForward("department-degrees"); }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java
/** * {@link AvailableBlock}s are combined before storage. The purpose of this method is to provide a consistent mechanism * for retrieving the block data for a specific day and expand them to the owner's preferred min duration. * /* w ww. ja va2 s .c o m*/ * @param owner * @param referenceDay * @return a possibly empty but never null {@link SortedSet} of {@link AvailableBlock}s with minimum preferred duration for the specified owner and calendar day. */ protected SortedSet<AvailableBlock> retrieveBlocksForDayInternal(IScheduleOwner owner, Date referenceDay) { // retrieve all blocks for the day. Date startOfDay = DateUtils.truncate(referenceDay, Calendar.DATE); Date endOfDay = DateUtils.addDays(startOfDay, 1); List<PersistenceAvailableBlock> scheduleRows = this.simpleJdbcTemplate.query( "select * from schedules where owner_id = ? and start_time >= ? and end_time < ?", new PersistenceAvailableBlockRowMapper(), owner.getId(), startOfDay, endOfDay); SortedSet<AvailableBlock> availableBlocks = new TreeSet<AvailableBlock>(); for (PersistenceAvailableBlock row : scheduleRows) { availableBlocks.add(AvailableBlockBuilder.createBlock(row.getStartTime(), row.getEndTime(), row.getVisitorLimit(), row.getMeetingLocation())); } int ownerPreferredMinDuration = owner.getPreferredMeetingDurations().getMinLength(); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(availableBlocks, ownerPreferredMinDuration); return expanded; }
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testRemoveListener() throws Exception { final Checker checker = new Checker(); final DebugAuditAdapter auditAdapter = new DebugAuditAdapter(); final DebugAuditAdapter aa2 = new DebugAuditAdapter(); checker.addListener(auditAdapter);/*w w w . j av a2 s .c om*/ checker.addListener(aa2); checker.removeListener(auditAdapter); // Let's try fire some events getFireAuditStartedMethod().invoke(checker); assertTrue("Checker.fireAuditStarted() doesn't call listener", aa2.wasCalled()); assertFalse("Checker.fireAuditStarted() does call removed listener", auditAdapter.wasCalled()); aa2.resetListener(); getFireAuditFinished().invoke(checker); assertTrue("Checker.fireAuditFinished() doesn't call listener", aa2.wasCalled()); assertFalse("Checker.fireAuditFinished() does call removed listener", auditAdapter.wasCalled()); aa2.resetListener(); checker.fireFileStarted("Some File Name"); assertTrue("Checker.fireFileStarted() doesn't call listener", aa2.wasCalled()); assertFalse("Checker.fireFileStarted() does call removed listener", auditAdapter.wasCalled()); aa2.resetListener(); checker.fireFileFinished("Some File Name"); assertTrue("Checker.fireFileFinished() doesn't call listener", aa2.wasCalled()); assertFalse("Checker.fireFileFinished() does call removed listener", auditAdapter.wasCalled()); aa2.resetListener(); final SortedSet<LocalizedMessage> messages = Sets.newTreeSet(); messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null)); checker.fireErrors("Some File Name", messages); assertTrue("Checker.fireErrors() doesn't call listener", aa2.wasCalled()); assertFalse("Checker.fireErrors() does call removed listener", auditAdapter.wasCalled()); }