Browse Source
* commit 'b17206a3f9e41f5a19960c4102ec063989f305d8': REPORT-68607 数据连接全量保存改为增量保存 11 REPORT-68780 BeforeSwicth要等stash做完 REPORT-68062 单元格数据列高级设置-格式设置不生效 REPORT-68062 单元格数据列高级设置-格式设置不生效 REPORT-68555 【视觉验收】新建画布/加载动画 REPORT-65854 资源释放没有在finally 代码段中进行 REPORT-68175 release合并final REPORT-68127 【专题】jdk11的设计器用bat脚本启动失败,exe启动正常 REPORT-68062 单元格数据列高级设置-格式设置不生效 CHART-21969 fix: fvs.cpt屏蔽场景地图新建入口 REPORT-68061 单元格元素-数据设置-自定义分组设置无法点击确定 REPORT-68161 填报-模板web属性-切换设置时,编辑行背景设置的点击逻辑确认 REPORT-68127 【专题】jdk11的设计器用bat脚本启动失败,exe启动正常 REPORT-68062 单元格数据列高级设置-格式设置不生效 CHART-22972 HyperlinkProvider接口对图表超链不起作用 CHART-23227 钻取点地图&钻取区域地图切换类型,预览无法展示bugfix/11.0
Henry.Wang
3 years ago
15 changed files with 333 additions and 92 deletions
@ -0,0 +1,53 @@
|
||||
package com.fr.design.data; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author rinoux |
||||
* @version 10.0 |
||||
* Created by rinoux on 2022/3/28 |
||||
*/ |
||||
public final class MapCompareUtils { |
||||
|
||||
|
||||
/** |
||||
* 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 |
||||
* |
||||
* @param orig 原始map |
||||
* @param other 参考的新map |
||||
* @param eventHandler 有区别时的事件处理器 |
||||
* @param <K> K |
||||
* @param <V> V |
||||
*/ |
||||
public static <K, V> void contrastMapEntries(@NotNull Map<K, V> orig, @NotNull Map<K, V> other, @NotNull EventHandler<K, V> eventHandler) { |
||||
|
||||
Map<K, V> copiedOrig = new LinkedHashMap<>(orig); |
||||
|
||||
other.forEach((k, v) -> { |
||||
V existedV = copiedOrig.remove(k); |
||||
if (existedV != null) { |
||||
if (!v.equals(existedV)) { |
||||
eventHandler.on(EntryEventKind.UPDATED, k, v); |
||||
} |
||||
} else { |
||||
eventHandler.on(EntryEventKind.ADDED, k, v); |
||||
} |
||||
}); |
||||
|
||||
copiedOrig.forEach((k, v) -> eventHandler.on(EntryEventKind.REMOVED, k, v)); |
||||
} |
||||
|
||||
|
||||
public interface EventHandler<K, V> { |
||||
void on(EntryEventKind entryEventKind, K k, V v); |
||||
} |
||||
|
||||
public enum EntryEventKind { |
||||
ADDED, |
||||
REMOVED, |
||||
UPDATED; |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.data; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author rinoux |
||||
* @version 10.0 |
||||
* Created by rinoux on 2022/3/28 |
||||
*/ |
||||
public class MapCompareUtilsTest { |
||||
|
||||
@Test |
||||
public void contrastMapEntries() { |
||||
|
||||
|
||||
Map<String, String> orig = new LinkedHashMap<>(); |
||||
|
||||
orig.put("aaa", "aaa"); |
||||
orig.put("bbb", "bbb"); |
||||
orig.put("ccc", "ccc"); |
||||
orig.put("ddd", "ddd"); |
||||
|
||||
|
||||
Map<String, String> other = new LinkedHashMap<>(); |
||||
|
||||
other.put("aaa", "111"); |
||||
other.put("bbb", "bbb"); |
||||
other.put("ccc", "ccc"); |
||||
other.put("eee", "eee"); |
||||
|
||||
|
||||
MapCompareUtils.contrastMapEntries(orig, other, new MapCompareUtils.EventHandler<String, String>() { |
||||
@Override |
||||
public void on(MapCompareUtils.EntryEventKind entryEventKind, String s, String s2) { |
||||
switch (entryEventKind) { |
||||
case UPDATED: |
||||
Assert.assertEquals(s, "aaa"); |
||||
Assert.assertEquals(s2, "111"); |
||||
break; |
||||
case REMOVED: |
||||
Assert.assertEquals(s, "ddd"); |
||||
break; |
||||
case ADDED: |
||||
Assert.assertEquals(s, "eee"); |
||||
Assert.assertEquals(s2, "eee"); |
||||
break; |
||||
default: |
||||
Assert.fail(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue