コード例 #1
0
 @Test
 public void testFirst() throws Exception {
   List<String> mList = new ArrayList<>();
   mList.add("x");
   mList.add("y");
   mList.add("z");
   mList.add("w");
   ImmutableList<String> l = new ArrayBackedImmutableList<String>(mList);
   Assert.assertEquals("x", l.first());
   Assert.assertEquals("y", l.tail(1).first());
   Assert.assertEquals("z", l.subList(2, 1).first());
 }
コード例 #2
0
 @Test
 public void testSublist() throws Exception {
   List<String> mList = new ArrayList<>();
   mList.add("x");
   mList.add("y");
   mList.add("z");
   mList.add("w");
   ImmutableList<String> l = new ArrayBackedImmutableList<String>(mList);
   Assert.assertEquals("[]", l.subList(0, 0).toString());
   Assert.assertEquals("[x]", l.subList(0, 1).toString());
   Assert.assertEquals("[x, y]", l.subList(0, 2).toString());
   Assert.assertEquals("[x, y, z]", l.subList(0, 3).toString());
   Assert.assertEquals("[x, y, z, w]", l.subList(0, 4).toString());
   Assert.assertEquals("[y, z, w]", l.subList(1, 3).toString());
   Assert.assertEquals("[y, z]", l.subList(1, 2).toString());
   Assert.assertEquals("[y, z]", l.subList(1, 2).toString());
   Assert.assertEquals("[y]", l.subList(1, 1).toString());
   Assert.assertEquals("[z]", l.subList(2, 1).toString());
 }