コード例 #1
0
 @Test
 public void rejectToTarget() {
   ImmutableBag<String> strings = this.newBag();
   Assert.assertEquals(
       strings, strings.reject(Predicates.lessThan("0"), FastList.<String>newList()).toBag());
   Verify.assertEmpty(strings.reject(Predicates.greaterThan("0"), FastList.<String>newList()));
 }
コード例 #2
0
  @Test
  public void retainAllFromEntrySet() {
    MutableMapIterable<String, Integer> map =
        this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3);
    Assert.assertFalse(
        map.entrySet()
            .retainAll(
                FastList.newListWith(
                    ImmutableEntry.of("One", 1),
                    ImmutableEntry.of("Two", 2),
                    ImmutableEntry.of("Three", 3),
                    ImmutableEntry.of("Four", 4))));

    Assert.assertTrue(
        map.entrySet()
            .retainAll(
                FastList.newListWith(
                    ImmutableEntry.of("One", 1),
                    ImmutableEntry.of("Three", 3),
                    ImmutableEntry.of("Four", 4))));
    Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map);

    MutableMapIterable<Integer, Integer> integers = this.newMapWithKeysValues(1, 1, 2, 2, 3, 3);
    Integer copy = new Integer(1);
    Assert.assertTrue(integers.entrySet().retainAll(mList(ImmutableEntry.of(copy, copy))));
    Assert.assertEquals(iMap(copy, copy), integers);
    Assert.assertNotSame(copy, Iterate.getOnly(integers.entrySet()).getKey());
    Assert.assertNotSame(copy, Iterate.getOnly(integers.entrySet()).getValue());
  }
コード例 #3
0
  @Test
  public void keySet_retainAll() {
    // a map with a null key
    MutableMap<Integer, Integer> map = this.newMapWithKeyValue(null, 0);

    MutableList<Object> retained = Lists.mutable.of();
    retained.add(null);
    Assert.assertFalse(map.keySet().retainAll(retained));
    Verify.assertContains(null, map.keySet());

    // a map with a chain containing empty slots
    MutableMap<Integer, Integer> map2 = this.mapWithCollisionsOfSize(5);
    Assert.assertFalse(map2.keySet().retainAll(FastList.<Integer>newListWith(0, 17, 34, 51, 68)));
    Verify.assertContainsAll(map2.keySet(), 0, 17, 34, 51, 68);

    // a map with no chaining, nothing retained
    MutableMap<Integer, String> map3 = this.newMapWithKeyValue(1, "One");
    Assert.assertTrue(map3.keySet().retainAll(FastList.<Integer>newListWith(9)));
    Verify.assertEmpty(map3);

    Set<Integer> keys =
        this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four").keySet();
    Assert.assertTrue(keys.retainAll(FastList.<Integer>newListWith(1, 2, 3)));
    Verify.assertContainsAll(keys, 1, 2, 3);
  }
コード例 #4
0
 public <V> MutableList<V> collect(BooleanToObjectFunction<? extends V> function) {
   FastList<V> target = FastList.newList(this.size);
   for (int i = 0; i < this.size; i++) {
     target.add(function.valueOf(this.items.get(i)));
   }
   return target;
 }
コード例 #5
0
 @Test
 public void selectWith() {
   Assert.assertEquals(
       FastList.newListWith(1, 2),
       this.lazyIterable.selectWith(
           Predicates2.<Integer>lessThan(), 3, FastList.<Integer>newList()));
 }
コード例 #6
0
 @Test
 public void keySet_containsAll() {
   MutableMap<Integer, String> map =
       this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
   Assert.assertFalse(map.keySet().containsAll(FastList.<Integer>newListWith(5)));
   Assert.assertTrue(map.keySet().containsAll(FastList.<Integer>newListWith(1, 2, 4)));
 }
コード例 #7
0
 @Test
 public void rejectWith() {
   Assert.assertEquals(
       FastList.newListWith(3, 4, 5, 6, 7),
       this.lazyIterable.rejectWith(
           Predicates2.<Integer>lessThan(), 3, FastList.<Integer>newList()));
 }
コード例 #8
0
  @Override
  @Test
  public void retainAllFromEntrySet() {
    super.retainAllFromEntrySet();

    for (int i = 1; i < COLLISIONS.size(); i++) {
      MutableMap<Integer, Integer> map = this.mapWithCollisionsOfSize(i);

      Assert.assertFalse(
          map.entrySet()
              .retainAll(
                  FastList.newList(map.entrySet())
                      .with(ImmutableEntry.of(COLLISION_10, COLLISION_10))));

      Assert.assertTrue(map.entrySet().retainAll(this.mapWithCollisionsOfSize(i - 1).entrySet()));
      Assert.assertEquals(this.mapWithCollisionsOfSize(i - 1), map);
    }

    // simple map, collection to retain contains non-entry element
    MutableMap<Integer, String> map4 = this.newMapWithKeysValues(1, "One", 2, "Two");
    FastList<Object> toRetain =
        FastList.<Object>newListWith(
            ImmutableEntry.of(1, "One"), "explosion!", ImmutableEntry.of(2, "Two"));
    Assert.assertFalse(map4.entrySet().retainAll(toRetain));
  }
コード例 #9
0
 @Override
 @Test
 public void distinct() {
   super.distinct();
   Assert.assertEquals(
       FastList.newListWith(2, 3, 4, 5),
       new DropIterable<>(FastList.newListWith(1, 1, 2, 3, 3, 3, 4, 5), 2).distinct().toList());
 }
コード例 #10
0
 @Test
 public void testForEachWithIndexToArrayUsingFastList() {
   Integer[] array = new Integer[200];
   FastList<Integer> list = (FastList<Integer>) Interval.oneTo(200).toList();
   Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
   ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 10, 10);
   Assert.assertArrayEquals(array, list.toArray(new Integer[] {}));
 }
コード例 #11
0
 @Test
 public void keysAndValues_toString() {
   MutableMapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2");
   Verify.assertContains(map.keySet().toString(), FastList.newListWith("[1, 2]", "[2, 1]"));
   Verify.assertContains(map.values().toString(), FastList.newListWith("[1, 2]", "[2, 1]"));
   Verify.assertContains(map.keysView().toString(), FastList.newListWith("[1, 2]", "[2, 1]"));
   Verify.assertContains(map.valuesView().toString(), FastList.newListWith("[1, 2]", "[2, 1]"));
 }
コード例 #12
0
  @Test
  public void retainAllFromValues() {
    MutableMapIterable<String, Integer> map =
        this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3);
    Assert.assertFalse(map.values().retainAll(FastList.newListWith(1, 2, 3, 4)));

    Assert.assertTrue(map.values().retainAll(FastList.newListWith(1, 3)));
    Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map);
  }
コード例 #13
0
  @Test
  public void removeAllFromKeySet() {
    MutableMapIterable<String, Integer> map =
        this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3);
    Assert.assertFalse(map.keySet().removeAll(FastList.newListWith("Four")));

    Assert.assertTrue(map.keySet().removeAll(FastList.newListWith("Two", "Four")));
    Assert.assertEquals(UnifiedMap.newWithKeysValues("One", 1, "Three", 3), map);
  }
コード例 #14
0
 @Test
 public void toArray() {
   Assert.assertArrayEquals(
       FastList.newListWith(1, 2).toArray(),
       this.lazyIterable.select(Predicates.lessThan(3)).toArray());
   Assert.assertArrayEquals(
       FastList.newListWith(1, 2).toArray(),
       this.lazyIterable.select(Predicates.lessThan(3)).toArray(new Object[2]));
 }
コード例 #15
0
 @Test
 public void updateValue() {
   MutableMapIterable<Integer, Integer> map = this.newMap();
   Iterate.forEach(
       Interval.oneTo(1000), each -> map.updateValue(each % 10, () -> 0, integer -> integer + 1));
   Assert.assertEquals(Interval.zeroTo(9).toSet(), map.keySet());
   Assert.assertEquals(
       FastList.newList(Collections.nCopies(10, 100)), FastList.newList(map.values()));
 }
コード例 #16
0
 @Test
 public void injectInto() {
   ImmutableBag<Integer> integers = this.newBag().collect(Integer::valueOf);
   Integer result = integers.injectInto(0, AddFunction.INTEGER);
   Assert.assertEquals(
       FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result.intValue());
   String result1 = this.newBag().injectInto("0", String::concat);
   Assert.assertEquals(FastList.newList(this.newBag()).injectInto("0", String::concat), result1);
 }
コード例 #17
0
 @Test
 public void collectIfWithTarget() {
   Assert.assertEquals(
       FastList.newListWith("1", "2", "3"),
       this.newWith(1, 2, 3)
           .collectIf(
               Predicates.instanceOf(Integer.class),
               Functions.getToString(),
               FastList.<String>newList()));
 }
コード例 #18
0
 @Test
 public void keySetToArray() {
   MutableMapIterable<String, Integer> map =
       this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3);
   MutableList<String> expected = FastList.newListWith("One", "Two", "Three").toSortedList();
   Set<String> keySet = map.keySet();
   Assert.assertEquals(expected, FastList.newListWith(keySet.toArray()).toSortedList());
   Assert.assertEquals(
       expected, FastList.newListWith(keySet.toArray(new String[keySet.size()])).toSortedList());
 }
コード例 #19
0
 @Test
 public void testReject() {
   Assert.assertEquals(
       ArrayStack.newStackFromTopToBottom("2", "3"),
       this.unmodifiableStackString.reject(StringPredicates.contains("1")));
   Assert.assertEquals(
       FastList.newListWith("2", "3"),
       this.unmodifiableStackString.reject(
           StringPredicates.contains("1"), FastList.<String>newList()));
 }
コード例 #20
0
  @Test
  public void entrySet_containsAll() {
    // simple map, test for non-existent entries
    MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 3, "Three");
    Set<Map.Entry<Integer, String>> entries = map.entrySet();
    Assert.assertFalse(entries.containsAll(FastList.newListWith(ImmutableEntry.of(2, "Two"))));

    Assert.assertTrue(
        entries.containsAll(
            FastList.newListWith(ImmutableEntry.of(1, "One"), ImmutableEntry.of(3, "Three"))));
  }
コード例 #21
0
 @Test
 public void distinct() {
   ArrayList<Integer> list = new ArrayList<Integer>();
   list.addAll(FastList.newListWith(9, 4, 7, 7, 5, 6, 2, 4));
   List<Integer> result = ArrayListIterate.distinct(list);
   Verify.assertListsEqual(FastList.newListWith(9, 4, 7, 5, 6, 2), result);
   ArrayList<Integer> target = new ArrayList<Integer>();
   ArrayListIterate.distinct(list, target);
   Verify.assertListsEqual(FastList.newListWith(9, 4, 7, 5, 6, 2), target);
   Verify.assertSize(8, list);
 }
コード例 #22
0
 @Test
 public void updateValue_collisions() {
   MutableMapIterable<Integer, Integer> map = this.newMap();
   MutableList<Integer> list = Interval.oneTo(2000).toList();
   Collections.shuffle(list);
   Iterate.forEach(list, each -> map.updateValue(each % 1000, () -> 0, integer -> integer + 1));
   Assert.assertEquals(Interval.zeroTo(999).toSet(), map.keySet());
   Assert.assertEquals(
       HashBag.newBag(map.values()).toStringOfItemToCount(),
       FastList.newList(Collections.nCopies(1000, 2)),
       FastList.newList(map.values()));
 }
コード例 #23
0
 @Test
 public void makeString() {
   Assert.assertEquals(
       FastList.newList(this.classUnderTest()).toString(),
       '[' + this.classUnderTest().makeString() + ']');
   Assert.assertEquals(
       FastList.newList(this.classUnderTest()).toString(),
       '[' + this.classUnderTest().makeString(", ") + ']');
   Assert.assertEquals(
       FastList.newList(this.classUnderTest()).toString(),
       this.classUnderTest().makeString("[", ", ", "]"));
 }
コード例 #24
0
 @Test
 public void collectWith() {
   Assert.assertEquals(
       FastList.newListWith("1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 "),
       this.lazyIterable.collectWith(
           new Function2<Integer, String, String>() {
             public String value(Integer argument1, String argument2) {
               return argument1.toString() + argument2;
             }
           },
           " ",
           FastList.<String>newList()));
 }
コード例 #25
0
 @Test
 public void groupByEachWithOptimisedList() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 105));
   Function<Integer, Iterable<String>> function =
       new Function<Integer, Iterable<String>>() {
         public Iterable<String> valueOf(Integer object) {
           return FastList.newListWith(object.toString(), object.toString() + '*');
         }
       };
   MutableMultimap<String, Integer> target = new FastListMultimap<String, Integer>();
   MutableMultimap<String, Integer> result = ArrayListIterate.groupByEach(list, function, target);
   Assert.assertEquals(result.get("105"), FastList.newListWith(105));
   Assert.assertEquals(result.get("105*"), FastList.newListWith(105));
 }
コード例 #26
0
 @Test
 public void collectWith() {
   Function2<String, String, String> function =
       new Function2<String, String, String>() {
         public String value(String band, String parameter) {
           return parameter + band.charAt(0);
         }
       };
   Assert.assertEquals(
       FastList.newListWith(">M", ">B", ">E", ">S"),
       this.unmodifiableCollection.collectWith(function, ">"));
   Assert.assertEquals(
       FastList.newListWith("*M", "*B", "*E", "*S"),
       this.unmodifiableCollection.collectWith(function, "*", FastList.<String>newList()));
 }
コード例 #27
0
  @Test
  public void appendString() {
    Appendable builder1 = new StringBuilder();
    this.classUnderTest().appendString(builder1);
    Assert.assertEquals(
        FastList.newList(this.classUnderTest()).toString(), '[' + builder1.toString() + ']');

    Appendable builder2 = new StringBuilder();
    this.classUnderTest().appendString(builder2, ", ");
    Assert.assertEquals(
        FastList.newList(this.classUnderTest()).toString(), '[' + builder2.toString() + ']');

    Appendable builder3 = new StringBuilder();
    this.classUnderTest().appendString(builder3, "[", ", ", "]");
    Assert.assertEquals(FastList.newList(this.classUnderTest()).toString(), builder3.toString());
  }
コード例 #28
0
 @Test
 public void injectInto() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Integer result = integers.injectInto(0, AddFunction.INTEGER);
   Assert.assertEquals(
       FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result.intValue());
 }
コード例 #29
0
 @Test
 public void forEachWith() {
   MutableList<String> result = Lists.mutable.of();
   MutableSet<String> source = Sets.fixedSize.of("1", "2", "3", "4");
   source.forEachWith(Procedures2.fromProcedure(CollectionAddProcedure.on(result)), null);
   Assert.assertEquals(FastList.newListWith("1", "2", "3", "4"), result);
 }
コード例 #30
0
 @Test
 public void testRejectWith() {
   Verify.assertSize(
       3,
       this.unmodifiableStackString.rejectWith(
           Predicates2.equal(), 3, FastList.<String>newList()));
 }