コード例 #1
0
  @Test
  public void setKeyPreservation() {
    Key key = new Key("key");

    Key duplicateKey1 = new Key("key");
    MutableSet<Key> set1 =
        UnifiedSetWithHashingStrategy.newSet(HashingStrategies.<Key>defaultStrategy())
            .with(key, duplicateKey1);
    Verify.assertSize(1, set1);
    Verify.assertContains(key, set1);
    Assert.assertSame(key, set1.getFirst());

    Key duplicateKey2 = new Key("key");
    MutableSet<Key> set2 =
        UnifiedSetWithHashingStrategy.newSet(HashingStrategies.<Key>defaultStrategy())
            .with(key, duplicateKey1, duplicateKey2);
    Verify.assertSize(1, set2);
    Verify.assertContains(key, set2);
    Assert.assertSame(key, set2.getFirst());

    Key duplicateKey3 = new Key("key");
    MutableSet<Key> set3 =
        UnifiedSetWithHashingStrategy.newSet(HashingStrategies.<Key>defaultStrategy())
            .with(key, new Key("not a dupe"), duplicateKey3);
    Verify.assertSize(2, set3);
    Verify.assertContainsAll(set3, key, new Key("not a dupe"));
    Assert.assertSame(key, set3.detect(key::equals));
  }
コード例 #2
0
 @Test
 public void getFirstGetLast() {
   MutableSet<String> list5 = Sets.fixedSize.of("1", "2", "3", "4");
   Assert.assertEquals("1", list5.getFirst());
   Assert.assertEquals("4", list5.getLast());
 }