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.gopivotal.cla.web.CorporateSignatoryController.java

private SortedSet<String> domains(Set<Email> emails) {
    SortedSet<String> domains = new TreeSet<>();

    for (Email email : emails) {
        Matcher matcher = DOMAIN.matcher(email.getAddress());
        if (matcher.find()) {
            domains.add(matcher.group(1));
        }/*  w  w w .  j a  va2s.c o  m*/
    }

    return domains;
}

From source file:com.github.lindenb.jvarkit.util.vcf.VCFUtils.java

public static SortedSet<VCFContigHeaderLine> samSequenceDictToVCFContigHeaderLine(SAMSequenceDictionary dict) {
    SortedSet<VCFContigHeaderLine> meta2 = new TreeSet<VCFContigHeaderLine>();
    for (SAMSequenceRecord ssr : dict.getSequences()) {
        Map<String, String> mapping = new HashMap<String, String>();
        mapping.put("ID", ssr.getSequenceName());
        mapping.put("length", String.valueOf(ssr.getSequenceLength()));
        String as = ssr.getAssembly();
        if (as != null && !as.trim().isEmpty())
            mapping.put("assembly", as);
        VCFContigHeaderLine h = new VCFContigHeaderLine(mapping, ssr.getSequenceIndex());
        meta2.add(h);
    }//from w  ww .j a v  a2s . c o  m
    return meta2;
}

From source file:org.cleverbus.admin.web.msg.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 {//from  www. ja v a 2 s  .  c  o  m
            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()));
            }

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

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

    return "msgLog";
}

From source file:org.jmxtrans.embedded.samples.cocktail.cocktail.CocktailRepository.java

/**
 * @param ingredientName//from   w  w  w.  j  a  v a  2s  .c om
 * @param cocktailName
 * @return
 */
public Collection<Cocktail> find(@Nullable String ingredientName, @Nullable String cocktailName) {
    SortedSet<Cocktail> result = new TreeSet<Cocktail>();
    for (Cocktail cocktail : cocktails.values()) {
        if (cocktailName == null && ingredientName == null) {
            result.add(cocktail);
        }
        if (StringUtils.hasLength(cocktailName)) {
            if (cocktail.getName().toLowerCase().contains(cocktailName.toLowerCase())) {
                result.add(cocktail);
                break;
            }
        }
        if (ingredientName != null) {
            for (String cocktailIngredient : cocktail.getIngredientNames()) {
                if (cocktailIngredient.toLowerCase().contains(ingredientName.toLowerCase())) {
                    result.add(cocktail);
                    break;
                }
            }
        }

    }
    return result;
}

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

/**
 * Test method for {@link User#setUserRights(SortedSet)}.
 *///  w w w. j  a  va2 s. c o  m
@Test
public final void testSetUserRights() {
    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);

    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:org.tonguetied.usermanagement.UserTest.java

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

    UserRight userRight2 = new UserRight(Permission.ROLE_ADMIN, tamil, india, bundle);
    user1.addUserRight(userRight2);

    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:org.tonguetied.usermanagement.UserTest.java

/**
 * Test method for {@link User#addUserRight(UserRight)}.
 *//*from   w  w w. j  av a 2 s .c om*/
@Test
public final void testAddExistingUserRight() {
    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);

    user1.addUserRight(userRight1);

    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:org.tonguetied.usermanagement.UserTest.java

/**
 * Test method for {@link User#removeUserRight(UserRight)}.
 *///from  w ww. j a v  a 2  s.  c om
@Test
public final void testRemoveExistingUserRight() {
    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);

    user1.removeUserRight(new UserRight(Permission.ROLE_ADMIN, null, null, null));

    GrantedAuthority[] authorities = user1.getAuthorities();
    assertEquals(1, authorities.length);
    GrantedAuthority[] expectedAuthorities = new GrantedAuthority[] {
            new GrantedAuthorityImpl(Permission.ROLE_USER.name()) };
    assertArrayEquals(expectedAuthorities, authorities);
}

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

/**
 * Test method for {@link User#removeUserRight(UserRight)}.
 *///from   w ww  .  j av  a  2  s .  c  o  m
@Test
public final void testRemoveNonExistentUserRight() {
    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);

    user1.removeUserRight(new UserRight(Permission.ROLE_VERIFIER, tamil, india, bundle));

    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:com.github.springtestdbunit.entity.EntityAssert.java

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