Example usage for java.util SortedSet add

List of usage examples for java.util SortedSet add

Introduction

In this page you can find the example usage for java.util SortedSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.jd.survey.web.settings.QuestionOptionController.java

@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String updateForm(@PathVariable("id") Long questionId, Principal principal, Model uiModel) {
    log.info("updateForm(): questionId=" + questionId);
    try {//w  w  w  .j ava2 s.  co m
        Question question = surveySettingsService.question_findById(questionId);
        SortedSet<QuestionOption> options = question.getOptions();

        for (int i = 1; i <= EMPTY_OPTIONS_COUNT; i++) {
            options.add(new QuestionOption(question, (short) (question.getOptions().size() + i)));
        }
        question.setOptions(options);
        uiModel.addAttribute("question", question);
        return "settings/questionOptions/update";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:org.tonguetied.usermanagement.UserTest.java

/**
 * Test method for {@link User#addUserRight(UserRight)}.
 *///from  ww  w.  j a v a 2  s  .c o m
@Test
public final void testAddNullUserRightToExistingUserRights() {
    UserRight userRight1 = new UserRight(Permission.ROLE_USER, tamil, india, bundle);
    UserRight userRight2 = new UserRight(Permission.ROLE_ADMIN, tamil, india, bundle);
    SortedSet<UserRight> userRights = new TreeSet<UserRight>();
    userRights.add(userRight1);
    userRights.add(userRight2);
    user1.setUserRights(userRights);

    try {
        user1.addUserRight(null);
        fail("adding null userright should throw exception");
    } catch (IllegalArgumentException iae) {
        GrantedAuthority[] authorities = user1.getAuthorities();
        assertEquals(2, authorities.length);
        GrantedAuthority[] expectedAuthorities = new GrantedAuthority[] {
                new GrantedAuthorityImpl(Permission.ROLE_ADMIN.name()),
                new GrantedAuthorityImpl(Permission.ROLE_USER.name()) };
        assertArrayEquals(expectedAuthorities, authorities);
    }
}

From source file:$.MessageController.java

@RequestMapping(value = "/{msgId}/log", method = RequestMethod.GET)
    public String getLogOfMsgByMsgId(@PathVariable("msgId") Long msgId, Model model) {
        Message msg = messageService.findMessageById(msgId);

        model.addAttribute("requestMsgId", msgId);

        if (msg != null) {
            String correlationId = msg.getCorrelationId();

            model.addAttribute("correlationId", correlationId);

            List<String> logLines = new ArrayList<String>();
            try {
                long start = System.currentTimeMillis();
                SortedSet<LocalDate> logDates = getMsgDates(msg);
                logDates.add(new LocalDate()); // adding today just in case

                Log.debug("Starts searching log for correlationId = " + correlationId);

                for (LocalDate logDate : logDates) {
                    logLines.addAll(messageLogParser.getLogLines(correlationId, logDate.toDate()));
                }/*from   www.  ja v  a 2  s.  c  o  m*/

                Log.debug("Finished searching log in " + (System.currentTimeMillis() - start) + " ms.");

                model.addAttribute("log", StringUtils.join(logLines, "${symbol_escape}n"));
            } catch (IOException ex) {
                model.addAttribute("logErr", "Error occurred during reading log file: " + ex.getMessage());
            }
        }

        return "msgLog";
    }

From source file:ch.silviowangler.dox.web.DocumentControllerTest.java

@Test
@SuppressWarnings("unchecked")
public void edit() throws Exception {

    final DocumentClass documentClass = new DocumentClass("hello");
    final DocumentReference documentReference = newDocumentReference("hello.txt")
            .withDocumentClass(documentClass).build();

    when(documentService.findDocumentReference(1L)).thenReturn(documentReference);
    SortedSet<Attribute> attributes = new TreeSet<>();
    attributes.add(new Attribute("a", false, AttributeDataType.CURRENCY));
    attributes.add(new Attribute("b", false, AttributeDataType.STRING));
    when(documentService.findAttributes(documentClass)).thenReturn(attributes);

    final ModelAndView modelAndView = controller.editDocument(1L);

    assertThat(modelAndView.getViewName(), is("edit.doc"));
    assertThat(modelAndView.getModel().size(), is(2));
    assertThat(modelAndView.getModel().containsKey("doc"), is(true));
    assertThat((DocumentReference) modelAndView.getModel().get("doc"), is(documentReference));
    assertThat(modelAndView.getModel().containsKey("attributes"), is(true));
    assertThat(((SortedSet<Attribute>) modelAndView.getModel().get("attributes")).size(), is(2));

    InOrder order = inOrder(documentService);
    order.verify(documentService).findDocumentReference(1L);
    order.verify(documentService).findAttributes(documentReference.getDocumentClass());
    order.verifyNoMoreInteractions();//from  w w  w.  jav  a2 s .c  om
}

From source file:com.temenos.interaction.core.rim.TestHeaderHelper.java

@Test
public void testOptionsAllowHeader() {
    SortedSet<String> validNextStates = new TreeSet<String>();
    validNextStates.add("SEE");
    validNextStates.add("HISTORY");
    validNextStates.add("AUTHORISE");
    validNextStates.add("REVERSE");
    validNextStates.add("DELETE");
    validNextStates.add("INPUT");
    validNextStates.add("GET");
    validNextStates.add("HEAD");
    validNextStates.add("OPTIONS");

    Response r = HeaderHelper.allowHeader(Response.ok(), validNextStates).build();
    assertEquals("AUTHORISE, DELETE, GET, HEAD, HISTORY, INPUT, OPTIONS, REVERSE, SEE",
            r.getMetadata().getFirst("Allow"));
}

From source file:org.opennms.ng.dao.support.BottomNAttributeStatisticVisitor.java

/**
 * <p>getResults</p>/*from  www.j a  v  a 2  s  .co m*/
 *
 * @return top attribute statistics (up to getCount() number)
 */
@Override
public SortedSet<AttributeStatistic> getResults() {
    SortedSet<AttributeStatistic> top = new TreeSet<AttributeStatistic>(new AttributeStatisticComparator());

    for (AttributeStatistic stat : m_results) {
        top.add(stat);

        if (top.size() >= m_count) {
            break;
        }
    }

    return top;
}

From source file:org.opennms.ng.services.eventconfig.DefaultEventConfDao.java

@Override
public List<Event> getEventsByLabel() {
    SortedSet<Event> events = m_events.forEachEvent(new TreeSet<Event>(new EventLabelComparator()),
            new EventCallback<SortedSet<Event>>() {

                @Override/*w w  w  .j  av  a2 s.  c om*/
                public SortedSet<Event> process(SortedSet<Event> accum, Event event) {
                    accum.add(event);
                    return accum;
                }
            });
    return new ArrayList<Event>(events);
}

From source file:jenkins.metrics.util.NameRewriterMetricRegistry.java

private <T> SortedSet<String> rewrite(SortedSet<String> original) {
    if (StringUtils.isBlank(prefix) && StringUtils.isBlank(postfix)) {
        return original;
    }//from w w  w.j  a v a  2 s .c  o  m
    SortedSet<String> result = new TreeSet<String>(original.comparator());
    for (String name : original) {
        result.add(name(prefix, name, postfix));
    }
    return result;
}

From source file:com.github.springtestdbunit.entity.OtherEntityAssert.java

public void assertValues(String... values) {
    SortedSet<String> expected = new TreeSet<String>(Arrays.asList(values));
    SortedSet<String> actual = new TreeSet<String>();
    TypedQuery<OtherSampleEntity> query = this.entityManager.createQuery(this.criteriaQuery);
    List<OtherSampleEntity> results = query.getResultList();
    for (OtherSampleEntity sampleEntity : results) {
        actual.add(sampleEntity.getValue());
        this.entityManager.detach(sampleEntity);
    }/*from w w  w.  jav  a 2 s  .c o  m*/
    assertEquals(expected, actual);
}

From source file:com.trenako.web.controllers.form.RollingStockForm.java

/**
 * Returns the tags set built parsing a comma separated string.
 *
 * @return the tags/*from w ww .  j a v a  2 s .c o m*/
 */
public SortedSet<String> getTagsSet() {
    if (StringUtils.isBlank(getTags())) {
        return null;
    }

    String[] tags = getTags().split(",");
    SortedSet<String> tagsList = new TreeSet<String>();
    for (String tag : tags) {
        tagsList.add(Slug.encode(tag.trim()));
    }
    return tagsList;
}