コード例 #1
0
ファイル: LinkedSetTest.java プロジェクト: navis/ncache
  @Test
  public void testBasic() {
    LinkedSet<String> set = new LinkedSet<String>(true);
    Assert.assertNull(set.put("navis"));
    Assert.assertEquals("navis", set.get("navis"));
    Assert.assertEquals("navis", set.remove("navis"));

    set.put("navis1");
    set.put("navis2");
    set.put("navis3");
    set.put("navis4");

    Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis2", "navis3", "navis4"));
    Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis3", "navis4"));

    Assert.assertEquals("navis2", set.get("navis2"));

    Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2"));
    Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis3", "navis4"));

    Assert.assertEquals("navis3", set.removeMark("navis3"));

    Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2"));
    Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis3"));

    set.put("navis5");

    Assert.assertTrue(
        TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2", "navis5"));
    Assert.assertTrue(
        TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis3", "navis5"));

    Assert.assertNull(set.get("navis3"));

    Assert.assertTrue(
        TestUtils.equals(set.values(), "navis1", "navis3", "navis4", "navis2", "navis5"));
    Assert.assertTrue(
        TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis3", "navis5"));

    Assert.assertEquals("navis3", set.put("navis3"));

    Assert.assertTrue(
        TestUtils.equals(set.values(), "navis1", "navis4", "navis2", "navis5", "navis3"));
    Assert.assertTrue(
        TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis5", "navis3"));

    Assert.assertEquals("navis3", set.remove("navis3"));

    Assert.assertTrue(TestUtils.equals(set.values(), "navis1", "navis4", "navis2", "navis5"));
    Assert.assertTrue(TestUtils.equals(set.cvalues(), "navis1", "navis2", "navis4", "navis5"));
  }
コード例 #2
0
ファイル: Message.java プロジェクト: stee11/newsgroups
 public String[] getEmail() {
   LinkedSet<String> ls = new LinkedSet<String>();
   int counter = 0;
   String bod = this.getBody();
   String from = this.getFrom();
   Scanner f = new Scanner(from);
   Scanner b = new Scanner(bod);
   String pattern =
       "^[A-Za-z0-9]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
   while (b.hasNext()) {
     String newString = b.next();
     String finalString = newString.replaceAll(pattern, "");
     if (newString.matches(pattern)) {
       ls.add(newString);
       counter++;
     }
   }
   while (f.hasNext()) {
     String newString = f.next();
     String finalString = newString.replaceAll(pattern, "");
     if (newString.matches(pattern)) {
       ls.add(newString);
       counter++;
     }
   }
   String[] Lastemails = new String[ls.size()];
   if (ls.size() > 0) {
     for (int i = 0; i < ls.size(); i++) {
       Lastemails[i] = ls.get(i + 1);
     }
   }
   return Lastemails;
 }