Example usage for java.util TreeSet add

List of usage examples for java.util TreeSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java

/**
 * Test search tag.//from  w  w w  .  ja  v  a 2s  .  co m
 */
@Test
public void testSearchTag() {
    final TreeSet<String> tags = new TreeSet<>();
    tags.add("java");
    tags.add("coding");

    DateTime t = new DateTime();
    clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/1", "Blog de Fabien Vauchelles n1",
            "Du coooodde rahhh::!!!!! #", tags, false);

    t = t.plusSeconds(1);
    final TreeSet<String> tags2 = new TreeSet<>();
    tags2.add("coding");
    tags2.add("blogging");

    clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/2", "Blog de Fabien Vauchelles n2",
            "Du code, du vrai", tags2, false);

    assertEquals("2 links should have been created", 2, clientAuth.getLinksCount());

    final Iterator<ShaarliLink> it = clientAuth.searchTagsIterator("java");
    assertTrue("Search should work", it.hasNext());

    final ShaarliLink link = it.next();
    assertEquals("Search should find the good result", "Blog de Fabien Vauchelles n1", link.getTitle());
}

From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java

/**
 * Test setLinksByPage./*w w w . ja v  a  2  s  .  c  o  m*/
 */
@Test
public void testSetLinksByPage() {
    // Create
    DateTime t = new DateTime();
    for (int i = 0; i < 10; i++) {
        final TreeSet<String> tags = new TreeSet<>();
        tags.add("tagfix");
        tags.add("tag" + i);

        clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/" + i,
                "Blog de Fabien Vauchelles n" + i, "du java quoi! #" + i, tags, false);

        t = t.plusSeconds(1);
    }

    for (int i = 1; i <= 10; i++) {
        clientAuth.setLinksByPage(i);

        final List<ShaarliLink> links = clientAuth.searchAll(1);

        assertEquals("Links set and count must match", i, links.size());
    }

}

From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java

/**
 * Test tags creation./*from  ww w.  ja v a 2s .  c  om*/
 */
@Test
public void testTags() {
    // Create link 1
    final TreeSet<String> tags = new TreeSet<>();
    tags.add("java");
    tags.add("coding");

    final String ID = clientAuth.createLink("http://fabien.vauchelles.com/", "Blog de Fabien Vauchelles n",
            "Du coooodde rahhh::!!!!! #", tags, false);

    assertTrue("ID should be assigned", ID != null && !ID.isEmpty());

    // Create link 2
    final TreeSet<String> tags2 = new TreeSet<>();
    tags2.add("java");
    tags2.add("blogging");

    final String ID2 = clientAuth.createLink("http://www.vauchelles.com/", "Site Vauchelles n", "Stout",
            tags2, false);

    assertTrue("ID should be assigned", ID2 != null && !ID2.isEmpty());

    final Map<String, Integer> atags = clientAuth.getTags();
    assertEquals("Tags count must be 3", 3, atags.size());

    assertEquals("Keyword 'blogging' must exists 1 time", 1, (int) atags.get("blogging"));
    assertEquals("Keyword 'coding' must exists 1 time", 1, (int) atags.get("coding"));
    assertEquals("Keyword 'java' must exists 2 times", 2, (int) atags.get("java"));
}

From source file:com.thoughtworks.go.domain.DirectoryScannerTest.java

private void compareFiles(DirectoryScanner ds, String[] expectedFiles, String[] expectedDirectories) {
    String includedFiles[] = ds.getIncludedFiles();
    String includedDirectories[] = ds.getIncludedDirectories();
    assertThat("expected " + Arrays.asList(expectedFiles) + " but " + Arrays.asList(includedFiles),
            includedFiles.length, is(expectedFiles.length));
    assertThat("directories present: ", includedDirectories.length, is(expectedDirectories.length));

    TreeSet files = new TreeSet();
    for (int counter = 0; counter < includedFiles.length; counter++) {
        files.add(includedFiles[counter].replace(File.separatorChar, '/'));
    }// ww w  . jav a2s  . co  m

    TreeSet directories = new TreeSet();
    for (int counter = 0; counter < includedDirectories.length; counter++) {
        directories.add(includedDirectories[counter].replace(File.separatorChar, '/'));
    }

    String currentfile;
    Iterator i = files.iterator();
    int counter = 0;
    while (i.hasNext()) {
        currentfile = (String) i.next();
        assertThat(currentfile, is(expectedFiles[counter]));
        counter++;
    }
    String currentdirectory;
    Iterator dirit = directories.iterator();
    counter = 0;
    while (dirit.hasNext()) {
        currentdirectory = (String) dirit.next();
        assertThat(currentdirectory, is(expectedDirectories[counter]));
        counter++;
    }
}

From source file:com.miz.mizuu.fragments.CoverSearchFragment.java

private void showContent() {
    mProgressBar.setVisibility(View.GONE);
    mAdapter.notifyDataSetChanged();// ww  w .j a v a 2s .c o m

    TreeSet<String> languages = new TreeSet<String>();
    for (int i = 0; i < mCovers.size(); i++)
        if (!mCovers.get(i).getLanguage().equals("Null"))
            languages.add(mCovers.get(i).getLanguage());

    mItems = new String[languages.size() + 1];
    mItems[0] = getString(R.string.stringShowAllLanguages);
    Iterator<String> itr = languages.iterator();
    int i = 1;
    while (itr.hasNext()) {
        mItems[i] = itr.next();
        i++;
    }

    getActivity().invalidateOptionsMenu();
}

From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java

/**
 * Test search all.//from  w w w .  jav a 2 s  . com
 */
@Test
public void testSearchAll() {
    // Create
    DateTime t = new DateTime();
    for (int i = 0; i < 10; i++) {
        final TreeSet<String> tags = new TreeSet<>();
        tags.add("tagfix");
        tags.add("tag" + i);

        clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/" + i,
                "Blog de Fabien Vauchelles n" + i, "du java quoi! #" + i, tags, false);

        t = t.plusSeconds(1);
    }

    // Check
    assertEquals("10 links should have been created", 10, clientAuth.getLinksCount());

    clientUnauth.setLinksByPage(3);

    int num = 9;
    final Iterator<ShaarliLink> it = clientUnauth.searchAllIterator();
    while (it.hasNext()) {
        final ShaarliLink link = it.next();

        assertEquals("URLs must be the same", "http://fabien.vauchelles.com/" + num, link.getUrl());
        assertEquals("Titles must be the same", "Blog de Fabien Vauchelles n" + num, link.getTitle());
        assertEquals("Descriptions must be the same", "du java quoi! #" + num, link.getDescription());
        assertFalse("Link must be public", link.isRestricted());

        final TreeSet<String> tags = new TreeSet<>();
        tags.add("tagfix");
        tags.add("tag" + num);
        assertArrayEquals("Tags must be the same", tags.toArray(), link.getTags().toArray());

        --num;
    }
}

From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java

/**
 * Test search all reverse.// www .j ava 2  s.  co  m
 */
@Test
public void testSearchAllReverse() {
    // Create
    DateTime t = new DateTime();
    for (int i = 0; i < 10; i++) {
        final TreeSet<String> tags = new TreeSet<>();
        tags.add("tagfix");
        tags.add("tag" + i);

        clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/" + i,
                "Blog de Fabien Vauchelles n" + i, "du java quoi! #" + i, tags, false);

        t = t.plusSeconds(1);
    }

    // Check
    assertEquals("10 links should have been created", 10, clientAuth.getLinksCount());

    clientUnauth.setLinksByPage(3);

    int num = 0;
    final Iterator<ShaarliLink> it = clientUnauth.searchAllReverseIterator();
    while (it.hasNext()) {
        final ShaarliLink link = it.next();

        assertEquals("URLs must be the same", "http://fabien.vauchelles.com/" + num, link.getUrl());
        assertEquals("Titles must be the same", "Blog de Fabien Vauchelles n" + num, link.getTitle());
        assertEquals("Descriptions must be the same", "du java quoi! #" + num, link.getDescription());
        assertFalse("Link must be public", link.isRestricted());

        final TreeSet<String> tags = new TreeSet<>();
        tags.add("tagfix");
        tags.add("tag" + num);
        assertArrayEquals("Tags must be the same", tags.toArray(), link.getTags().toArray());

        ++num;
    }
}

From source file:org.apilytic.currency.service.impl.DefaultTwitterService.java

/** {@inheritDoc} */
@Override/*  ww  w  .j ava2 s. c om*/
public SortedSet<TwitterMessage> getTwitterMessages(Long tweetId, SortOrder sortOrder) {

    final TreeSet<TwitterMessage> tweets = new TreeSet<TwitterMessage>();

    if (tweetId != null) {

        final Map<Long, TwitterMessage> twitterMessagesAsMap = twitterMessages.asMap();

        for (Long id : twitterMessagesAsMap.keySet()) {
            if (id.compareTo(tweetId) > 0) {
                tweets.add(twitterMessages.getIfPresent(id));
            }
        }

    } else {
        tweets.addAll(this.twitterMessages.asMap().values());
    }

    if (SortOrder.DESCENDING.equals(sortOrder)) {
        return tweets.descendingSet();
    }

    return tweets;
}

From source file:com.miz.mizuu.fragments.CollectionCoverSearchFragment.java

private void showContent() {
    mProgressBar.setVisibility(View.GONE);
    mAdapter.notifyDataSetChanged();//  w ww. ja v  a 2s  . c  o  m

    TreeSet<String> languages = new TreeSet<String>();
    for (int i = 0; i < mCovers.size(); i++) {
        if (!mCovers.get(i).getLanguage().equals("Null"))
            languages.add(mCovers.get(i).getLanguage());
    }

    mItems = new String[languages.size() + 1];
    mItems[0] = getString(R.string.stringShowAllLanguages);
    Iterator<String> itr = languages.iterator();
    int i = 1;
    while (itr.hasNext()) {
        mItems[i] = itr.next();
        i++;
    }

    getActivity().invalidateOptionsMenu();
}

From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java

/**
 * Test CRUD./*from   w  ww.j av  a2  s.co m*/
 */
@Test
public void testCRUD() {
    // Create
    final TreeSet<String> tags = new TreeSet<>();
    tags.add("java");
    tags.add("coding");

    final String ID = clientAuth.createLink("http://fabien.vauchelles.com/", "Blog de Fabien Vauchelles n",
            "Du coooodde rahhh::!!!!! #", tags, false);

    // Create check
    assertTrue("ID should be assigned", ID != null && !ID.isEmpty());

    List<ShaarliLink> links = clientUnauth.searchAll(1);
    assertEquals("Only 1 links should be created", 1, links.size());
    ShaarliLink link = links.get(0);

    assertEquals("IDs must be the same", ID, link.getID());
    assertEquals("URLs must be the same", "http://fabien.vauchelles.com/", link.getUrl());
    assertEquals("Titles must be the same", "Blog de Fabien Vauchelles n", link.getTitle());
    assertEquals("Descriptions must be the same", "Du coooodde rahhh::!!!!! #", link.getDescription());
    assertFalse("Link must not be restricted", link.isRestricted());
    assertArrayEquals("Tags must be the same", tags.toArray(), link.getTags().toArray());

    // Modify
    final TreeSet<String> tags2 = new TreeSet<>();
    tags2.add("codding");
    tags2.add("blogging");
    clientAuth.createOrUpdateLink(ID, "http://ma.nouvelle.url.com/", "Nouveau titre", "Nouvelle description",
            tags2, true);

    // Modify check
    links = clientUnauth.searchAll(1);
    assertEquals("Link must have disappear from public view", 0, links.size());
    links = clientAuth.searchAll(1);
    assertEquals("A modification shouldn't create another link", 1, links.size());
    link = links.get(0);

    assertEquals("IDs must be the same", ID, link.getID());
    assertEquals("URIs must be the same", "http://ma.nouvelle.url.com/", link.getUrl());
    assertEquals("Titles must be the same", "Nouveau titre", link.getTitle());
    assertEquals("Descriptions must be the same", "Nouvelle description", link.getDescription());
    assertTrue("Link must be private", link.isRestricted());
    assertArrayEquals("Tags must be the same", tags2.toArray(), link.getTags().toArray());

    // Delete
    clientAuth.delete(ID);

    assertEquals("Link shouldn't exist here", 0, clientAuth.getLinksCount());
}