java.util.AbstractMap.equals()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中java.util.AbstractMap.equals()方法的一些代码示例,展示了AbstractMap.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractMap.equals()方法的具体详情如下:
包路径:java.util.AbstractMap
类名称:AbstractMap
方法名:equals

AbstractMap.equals介绍

[英]This implementation first checks the structure of object. If it is not a map or of a different size, this returns false. Otherwise it iterates its own entry set, looking up each entry's key in object. If any value does not equal the other map's value for the same key, this returns false. Otherwise it returns true.
[中]此实现首先检查对象的结构。如果不是贴图或大小不同,则返回false。否则,它将迭代自己的条目集,在对象中查找每个条目的键。如果任何值不等于同一个键的其他贴图的值,则返回false。否则返回true。

代码示例

代码示例来源:origin: stackoverflow.com

public static void main(String args[]) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("2", "whatever2");
map.put("1", "whatever1");
TreeMap<String, Object> map2 = new TreeMap<String, Object>();
map2.put("2", "whatever2");
map2.put("1", "whatever1");

System.out.println("Are maps equal (using equals):" + map.equals(map2));
System.out.println("Are maps equal (using toString().equals()):"
    + map.toString().equals(map2.toString()));

System.out.println("Map1:"+map.toString());
System.out.println("Map2:"+map2.toString());
}

代码示例来源:origin: apache/geode

@Override
public boolean equals(final Object o) {
 if (this == o) {
  return true;
 }
 if (o == null || getClass() != o.getClass()) {
  return false;
 }
 if (!super.equals(o)) {
  return false;
 }
 final BucketTargetingMap<?, ?> that = (BucketTargetingMap<?, ?>) o;
 if (!region.getFullPath().equals(that.region.getFullPath())) {
  return false;
 }
 return callbackArg.equals(that.callbackArg);
}

代码示例来源:origin: robovm/robovm

/**
 * Compares the argument to the receiver, and returns {@code true} if the
 * specified {@code Object} is an {@code EnumMap} and both {@code EnumMap}s contain the same mappings.
 *
 * @param object
 *            the {@code Object} to compare with this {@code EnumMap}.
 * @return boolean {@code true} if {@code object} is the same as this {@code EnumMap},
 *         {@code false} otherwise.
 * @see #hashCode()
 * @see #entrySet()
 */
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object object) {
  if (this == object) {
    return true;
  }
  if (!(object instanceof EnumMap)) {
    return super.equals(object);
  }
  EnumMap<K, V> enumMap = (EnumMap<K, V>) object;
  if (keyType != enumMap.keyType || size() != enumMap.size()) {
    return false;
  }
  return Arrays.equals(hasMapping, enumMap.hasMapping)
      && Arrays.equals(values, enumMap.values);
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@Override
public boolean equals(Object o) {
 if (this == o) {
  return true;
 }
 if (!(o instanceof SmallSortedMap)) {
  return super.equals(o);
 }
 SmallSortedMap<?, ?> other = (SmallSortedMap<?, ?>) o;
 final int size = size();
 if (size != other.size()) {
  return false;
 }
 // Best effort try to avoid allocating an entry set.
 final int numArrayEntries = getNumArrayEntries();
 if (numArrayEntries != other.getNumArrayEntries()) {
  return entrySet().equals(other.entrySet());
 }
 for (int i = 0; i < numArrayEntries; i++) {
  if (!getArrayEntryAt(i).equals(other.getArrayEntryAt(i))) {
   return false;
  }
 }
 if (numArrayEntries != size) {
  return overflowEntries.equals(other.overflowEntries);
 }
 return true;
}

代码示例来源:origin: geotools/geotools

/**
 * Compares the specified object with this map for equality.
 *
 * @param object The object to compare with this map for equality.
 */
@Override
public boolean equals(final Object object) {
  return super.equals(object);
}

代码示例来源:origin: org.geotools/gt2-metadata

/**
 * Compares the specified object with this map for equality.
 */
public boolean equals(final Object object) {
  synchronized (hash) {
    return super.equals(object);
  }
}

代码示例来源:origin: org.geotools/gt-metadata

/**
 * Compares the specified object with this map for equality.
 *
 * @param object The object to compare with this map for equality.
 */
@Override
public boolean equals(final Object object) {
  synchronized (hash) {
    return super.equals(object);
  }
}

代码示例来源:origin: javax.faces/jsf-impl

@Override
public boolean equals(Object obj) {
  return !(obj == null || !(obj instanceof ApplicationMap))
      && super.equals(obj);
}

代码示例来源:origin: it.geosolutions.imageio-ext/imageio-ext-utilities

/**
 * Compares the specified object with this map for equality.
 *
 * @param object The object to compare with this map for equality.
 */
@Override
public boolean equals(final Object object) {
  synchronized (hash) {
    return super.equals(object);
  }
}

代码示例来源:origin: geosolutions-it/imageio-ext

/**
 * Compares the specified object with this map for equality.
 *
 * @param object The object to compare with this map for equality.
 */
@Override
public boolean equals(final Object object) {
  synchronized (hash) {
    return super.equals(object);
  }
}

代码示例来源:origin: peter-lawrey/Performance-Examples

@Override
public boolean equals(Object o) {
  return super.equals(o);
}

代码示例来源:origin: com.metamx/extendedset

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(Object obj) {
  if (this == obj)
    return true;
  if (!super.equals(obj))
    return false;
  if (!(obj instanceof ArrayMap<?>))
    return false;
  return Arrays.equals(array, ((ArrayMap<?>) obj).array);
}

代码示例来源:origin: com.n3twork.druid/extendedset

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(Object obj) {
  if (this == obj)
    return true;
  if (!super.equals(obj))
    return false;
  if (!(obj instanceof ArrayMap<?>))
    return false;
  return Arrays.equals(array, ((ArrayMap<?>) obj).array);
}

代码示例来源:origin: metamx/extendedset

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(Object obj) {
  if (this == obj)
    return true;
  if (!super.equals(obj))
    return false;
  if (!(obj instanceof ArrayMap<?>))
    return false;
  return Arrays.equals(array, ((ArrayMap<?>) obj).array);
}

代码示例来源:origin: stackoverflow.com

HashMap<String, String> m = new HashMap<>();
// Populate map...

// Save the state:
HashMap<String, String> saved = new HashMap<>(m);

// Clients might modify map here...

// Test if the map was modified:
boolean modified = saved.equals(m);

代码示例来源:origin: com.ibm.sbt/com.ibm.commons.runtime

@Override
public boolean equals(Object obj) {
  if (obj.getClass()==this.getClass()) {
    return super.equals(obj);
  }
  return false;
}

代码示例来源:origin: stackoverflow.com

public void injectArrayIntoHashMap() {
   HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
   ArrayList<String> l1 = new ArrayList<String>();
   l1.add("hello");
   l1.add("howdy");
   map.put("hi", l1);

   HashMap<String, ArrayList<String>> newMap = new HashMap<String, ArrayList<String>>();
   ArrayList<String> l2 = new ArrayList<String>();
   l2.add("hello");
   l2.add("howdy");
   newMap.put("hi", l2);

   System.out.println(map.equals(newMap));
}

代码示例来源:origin: stackoverflow.com

HashMap<String, String> map = new HashMap<String, String>(){
  @Override
  public boolean equals(Object o) {
    // TODO comparison here
    return super.equals(o);
  }
};
map.equals(new HashMap<String, String>());

代码示例来源:origin: org.arakhne.afc.core/references

@Pure
@Override
public final boolean equals(Object obj) {
  expurgeNow();
  return super.equals(obj);
}

代码示例来源:origin: com.linkedin.pegasus/data

@Override
public boolean equals(Object object)
{
 if (this == object)
 {
  return true;
 }
 if (object != null && object instanceof AbstractMapTemplate)
 {
  return ((AbstractMapTemplate<?>) object).data().equals(_map);
 }
 return super.equals(object);
}

相关文章