Ejemplo n.º 1
0
  @Test
  public void entryBasicTests() {
    Map.Entry<String, String> kvh1 = Maps2.entry("xyzzy", "plugh");
    Map.Entry<String, String> kvh2 = Maps2.entry("foobar", "blurfl");
    @SuppressWarnings({"unchecked", "rawtypes"})
    Map.Entry<String, String> sie = new AbstractMap.SimpleImmutableEntry("xyzzy", "plugh");

    assertTrue(kvh1.equals(sie));
    assertTrue(sie.equals(kvh1));
    assertFalse(kvh2.equals(sie));
    assertFalse(sie.equals(kvh2));
    assertEquals(sie.hashCode(), kvh1.hashCode());
    assertEquals(sie.toString(), kvh1.toString());
  }
  public static void setReferenceMap(ICConfigurationDescription cfg, Map<String, String> map) {
    Map<String, String> oldRefs = getReferenceMap(cfg);
    Map<String, String> newRefs = new LinkedHashMap<String, String>(map);

    // We need to preserve order. The API we have with the external settings manager allows us to
    // add and remove individual items.
    // In the future this could be fixed, but for the moment, remove and replace all the referenced
    // items
    // from the first item that doens't match.

    Iterator<Map.Entry<String, String>> oldIter = oldRefs.entrySet().iterator();
    Iterator<Map.Entry<String, String>> newIter = newRefs.entrySet().iterator();

    while (oldIter.hasNext() && newIter.hasNext()) {
      Map.Entry<String, String> oldEntry = oldIter.next();
      Map.Entry<String, String> newEntry = newIter.next();
      if (!oldEntry.equals(newEntry)) break;
      oldIter.remove();
      newIter.remove();
    }

    // Now remove all the remaining old entries
    for (Map.Entry<String, String> entry : oldRefs.entrySet())
      removeReference(cfg, entry.getKey(), entry.getValue());
    // And add the new entries
    for (Map.Entry<String, String> entry : newRefs.entrySet())
      createReference(cfg, entry.getKey(), entry.getValue());
  }
Ejemplo n.º 3
0
    @Override
    public boolean equals(final Object o) {
      if (this == o) {
        return true;
      }
      if (!(o instanceof PageCacheKeyImpl)) {
        return false;
      }
      final PageCacheKeyImpl cacheKey = (PageCacheKeyImpl) o;
      if (hashCode() != cacheKey.hashCode()) {
        return false;
      }

      // we *cannot* use LinkedHashMap equals impl here because the Cache key equals SHOULD involve
      // the ORDER of the entries. Two LinkedHashMap's that contain the same entries in a different
      // order
      // return TRUE, which we do not want! For the cachekey, the ORDER DOES MATTER

      final Set<Map.Entry<String, Serializable>> entries = linkedKeyFragments.entrySet();
      final Set<Map.Entry<String, Serializable>> otherEntries =
          ((PageCacheKeyImpl) o).linkedKeyFragments.entrySet();

      if (entries.size() != otherEntries.size()) {
        return false;
      }

      final Iterator<Map.Entry<String, Serializable>> iterator = entries.iterator();
      final Iterator<Map.Entry<String, Serializable>> otherIterator = otherEntries.iterator();

      while (iterator.hasNext()) {
        final Map.Entry<String, Serializable> next = iterator.next();
        final Map.Entry<String, Serializable> otherNext = otherIterator.next();
        if (!next.equals(otherNext)) {
          return false;
        }
      }

      return true;
    }
Ejemplo n.º 4
0
 public boolean equals(Object o) {
   return entry.equals(o);
 }