Interface MapDifference<K,V>

Type Parameters:
K - key type | 键类型
V - value type | 值类型

public interface MapDifference<K,V>
MapDifference - Result of comparing two maps MapDifference - 比较两个 Map 的结果

Represents the difference between two maps, including entries only in the left, only in the right, in common, and with differing values.

表示两个 Map 之间的差异,包括仅在左边的条目、仅在右边的条目、共同的条目和值不同的条目。

Features | 主要功能:

  • Entries only on left - 仅在左边的条目
  • Entries only on right - 仅在右边的条目
  • Entries in common - 共同的条目
  • Entries with differing values - 值不同的条目

Usage Examples | 使用示例:

MapDifference<String, Integer> diff = MapUtil.difference(map1, map2);

if (!diff.areEqual()) {
    Map<String, Integer> onlyLeft = diff.entriesOnlyOnLeft();
    Map<String, Integer> onlyRight = diff.entriesOnlyOnRight();
    Map<String, ValueDifference<Integer>> differing = diff.entriesDiffering();
}

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    ValueDifference - Represents different values for the same key ValueDifference - 表示相同键的不同值
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if the two maps are equal 是否相等
    Get entries where keys are the same but values differ 值不同的条目
    Get entries common to both maps (same key and value) 共同的条目
    Get entries only in the left map 仅在左边的条目
    Get entries only in the right map 仅在右边的条目
  • Method Details

    • areEqual

      boolean areEqual()
      Check if the two maps are equal 是否相等
      Returns:
      true if equal | 如果相等则返回 true
    • entriesOnlyOnLeft

      Map<K,V> entriesOnlyOnLeft()
      Get entries only in the left map 仅在左边的条目
      Returns:
      entries only on left | 仅在左边的条目
    • entriesOnlyOnRight

      Map<K,V> entriesOnlyOnRight()
      Get entries only in the right map 仅在右边的条目
      Returns:
      entries only on right | 仅在右边的条目
    • entriesInCommon

      Map<K,V> entriesInCommon()
      Get entries common to both maps (same key and value) 共同的条目
      Returns:
      common entries | 共同的条目
    • entriesDiffering

      Map<K, MapDifference.ValueDifference<V>> entriesDiffering()
      Get entries where keys are the same but values differ 值不同的条目
      Returns:
      differing entries | 值不同的条目