Beispiel #1
1
  @Test
  public void splitLookup() {
    // do the split
    int pivot = 4;
    int max = 5;
    List<Integer> l = List.range(1, max + 1);
    TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
    P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>> p3 =
        m2.splitLookup(pivot);

    // create expected output
    List<Integer> leftList = List.range(1, pivot);
    TreeMap<Integer, String> leftMap =
        TreeMap.treeMap(Ord.intOrd, leftList.zip(leftList.map(i -> i.toString())));
    List<Integer> rightList = List.range(pivot + 1, max + 1);
    TreeMap<Integer, String> rightMap =
        TreeMap.treeMap(Ord.intOrd, rightList.zip(rightList.map(i -> i.toString())));

    // debug info
    if (true) {
      Show<TreeMap<Integer, String>> st = Show.treeMapShow(Show.intShow, Show.stringShow);
      Show<P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>>> sp3 =
          Show.p3Show(st, Show.optionShow(Show.stringShow), st);
      sp3.println(p3);
    }

    // do the assert
    Equal<TreeMap<Integer, String>> tme = Equal.treeMapEqual(Equal.intEqual, Equal.stringEqual);
    Equal<P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>>> eq =
        Equal.p3Equal(tme, Equal.optionEqual(Equal.stringEqual), tme);
    assertTrue(eq.eq(p3, p(leftMap, some(Integer.toString(pivot)), rightMap)));
  }
Beispiel #2
1
  @Test
  public void split() {
    // do the split
    int pivot = 4;
    int max = 5;
    List<Integer> l = List.range(1, max + 1);
    TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
    P3<Set<String>, Option<String>, Set<String>> p = m2.split(Ord.stringOrd, pivot);

    // print debug info
    Show<TreeMap<Integer, String>> st = Show.treeMapShow(Show.intShow, Show.stringShow);
    Show<Set<String>> ss = Show.setShow(Show.stringShow);
    Show<Option<String>> so = Show.optionShow(Show.stringShow);
    Show<P3<Set<String>, Option<String>, Set<String>>> sp3 = Show.p3Show(ss, so, ss);
    if (true) {
      st.println(m2);
      sp3.println(p);
    }

    // assert equals
    Equal<Set<String>> seq = Equal.setEqual(Equal.stringEqual);
    Set<String> left = toSetString(List.range(1, pivot));
    Set<String> right = toSetString(List.range(pivot + 1, max + 1));
    P3<Set<String>, Option<String>, Set<String>> expected =
        p(left, some(Integer.toString(pivot)), right);
    assertTrue(Equal.p3Equal(seq, Equal.optionEqual(Equal.stringEqual), seq).eq(p, expected));
  }
Beispiel #3
0
 public HashMap(java.util.Map<K, V> map) {
   this(map, Equal.anyEqual(), Hash.anyHash());
 }
Beispiel #4
0
 /** Converts the Iterable to a HashMap */
 public static <K, V> HashMap<K, V> iterableHashMap(final Iterable<P2<K, V>> entries) {
   return iterableHashMap(Equal.anyEqual(), Hash.anyHash(), entries);
 }
Beispiel #5
0
 public static <K, V> HashMap<K, V> fromMap(java.util.Map<K, V> map) {
   return fromMap(Equal.anyEqual(), Hash.anyHash(), map);
 }
Beispiel #6
0
 public <A> HashMap<A, V> mapKeys(F<K, A> function) {
   return mapKeys(function, Equal.anyEqual(), Hash.anyHash());
 }
Beispiel #7
0
 public <A, B> HashMap<A, B> map(F<K, A> keyFunction, F<V, B> valueFunction) {
   return map(keyFunction, valueFunction, Equal.anyEqual(), Hash.anyHash());
 }
Beispiel #8
0
 /**
  * Compare two key values for equality using the underlying equality strategy.
  *
  * @param k1 One key value to compare.
  * @param k2 The other key value to compare.
  * @return <code>true</code> if the two key values are equal, <code>false</code> otherwise.
  */
 public boolean eq(final K k1, final K k2) {
   return e.eq(k1, k2);
 }
Beispiel #9
0
 /**
  * Construct a hash map that uses {@link Object#equals} and {@link Object#hashCode}.
  *
  * @return A new hash map that uses {@link Object#equals} and {@link Object#hashCode}.
  */
 public static <K, V> HashMap<K, V> hashMap() {
   return hashMap(Equal.anyEqual(), Hash.anyHash());
 }
Beispiel #10
0
 @Override
 public boolean equals(Object other) {
   return Equal.equals0(Tree.class, this, other, () -> Equal.treeEqual(Equal.anyEqual()));
 }
 /**
  * Perform an equality test on this list which delegates to the .equals() method of the member
  * instances. This is implemented with Equal.nonEmptyListEqual using the anyEqual rule.
  *
  * @param obj the other object to check for equality against.
  * @return true if this list is equal to the provided argument
  */
 @Override
 public boolean equals(final Object obj) {
   return Equal.equals0(
       NonEmptyList.class, this, obj, () -> Equal.nonEmptyListEqual(Equal.<A>anyEqual()));
 }