Beispiel #1
0
  @Test
  public void randomAccess() {
    SingletonHList<String> spiedTail = spy(singletonHList("second"));
    Tuple2<String, String> tuple2 = new Tuple2<>("first", spiedTail);

    verify(spiedTail, only()).head();
    tuple2._1();
    tuple2._2();
    verifyNoMoreInteractions(spiedTail);
  }
  protected void handleKeyValues(
      final Iterator<Tuple2<K, V>> itr, IKeyValueConsumer<K, V>... consumer) {
    if (first == null) return;
    final K key = first._1();

    final Iterator<V> itx =
        new Iterator<V>() {
          Tuple2<K, V> current = first;

          @Override
          public boolean hasNext() {
            return current != null;
          }

          @Override
          public V next() {
            V ret = current._2();
            if (itr.hasNext()) {
              current = itr.next();
              if (!current._1().equals(key)) {
                first = current;
                current = null;
              }
            } else current = null;
            return ret;
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException("Fix This"); // ToDo
          }
        };
  }
  @Override
  public Iterable<KeyValueObject<KOUT, VOUT>> call(final Iterator<Tuple2<K, V>> itr)
      throws Exception {
    first = null;
    final List<KeyValueObject<KOUT, VOUT>> holder = new ArrayList<KeyValueObject<KOUT, VOUT>>();
    if (!itr.hasNext()) return holder;

    first = itr.next();

    final Iterator<V> itx =
        new Iterator<V>() {
          Tuple2<K, V> current = first;

          @Override
          public boolean hasNext() {
            if (current == null) return false;
            return true;
          }

          @Override
          public V next() {
            V ret = current._2();
            if (itr.hasNext()) {
              Tuple2<K, V> test = itr.next();
              if (test._1().equals(first._1())) current = test;
              else {
                first = test; // different key
                current = null;
              }
            } else current = null;
            return ret;
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException("Fix This"); // ToDo
          }
        };

    final Iterable<V> vals =
        new Iterable<V>() {
          @Override
          public Iterator<V> iterator() {
            return itx;
          }
        };
    final IKeyValueConsumer<KOUT, VOUT> consumer =
        new IKeyValueConsumer<KOUT, VOUT>() {
          @Override
          public void consume(final KeyValueObject<KOUT, VOUT> kv) {
            holder.add(kv);
          }
        };
    K key = (K) first._1();
    reducer.handleValues(key, vals, consumer);
    return holder;
  }
Beispiel #4
0
  @Test
  public void staticFactoryMethodFromMapEntry() {
    Map.Entry<String, Integer> stringIntEntry =
        new HashMap<String, Integer>() {
          {
            put("string", 1);
          }
        }.entrySet().iterator().next();

    assertEquals(tuple("string", 1), Tuple2.fromEntry(stringIntEntry));
  }
Beispiel #5
0
 @Test(expected = UnsupportedOperationException.class)
 public void setValueIsNotSupported() {
   tuple2.setValue(3);
 }
Beispiel #6
0
 @Test
 public void mapEntryProperties() {
   assertEquals((Integer) 1, tuple2.getKey());
   assertEquals((Integer) 2, tuple2.getValue());
 }
Beispiel #7
0
 @Test
 public void bifunctorProperties() {
   assertEquals(
       new Tuple2<>("1", new SingletonHList<>("2")),
       tuple2.biMap(Object::toString, Object::toString));
 }
Beispiel #8
0
 @Test
 public void accessors() {
   assertEquals((Integer) 1, tuple2._1());
   assertEquals((Integer) 2, tuple2._2());
 }
Beispiel #9
0
 @Test
 public void cons() {
   assertEquals(new Tuple3<>(0, tuple2), tuple2.cons(0));
 }
Beispiel #10
0
 @Test
 public void tail() {
   assertEquals(new SingletonHList<>(2), tuple2.tail());
 }
Beispiel #11
0
 @Test
 public void head() {
   assertEquals((Integer) 1, tuple2.head());
 }
Beispiel #12
0
/*    */   public void testTuple()
/*    */   {
/* 12 */     Tuple2 person = new Tuple2("tom", BoxesRunTime.boxToInteger(25));
/* 13 */     Predef..MODULE$.println(person._1());
/* 14 */     Predef..MODULE$.println(BoxesRunTime.boxToInteger(person._2$mcI$sp()));
/*    */   }