mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
Merge origin/master
This commit is contained in:
commit
8195b9eaa7
3 changed files with 161 additions and 16 deletions
|
|
@ -110,7 +110,6 @@ public class ScryfallImageSupportTokens {
|
||||||
put("AKH/Anointer Priest", "https://api.scryfall.com/cards/takh/2/en?format=image");
|
put("AKH/Anointer Priest", "https://api.scryfall.com/cards/takh/2/en?format=image");
|
||||||
put("AKH/Aven Initiate", "https://api.scryfall.com/cards/takh/3/en?format=image");
|
put("AKH/Aven Initiate", "https://api.scryfall.com/cards/takh/3/en?format=image");
|
||||||
put("AKH/Aven Wind Guide", "https://api.scryfall.com/cards/takh/4/en?format=image");
|
put("AKH/Aven Wind Guide", "https://api.scryfall.com/cards/takh/4/en?format=image");
|
||||||
put("AKH/Gideon of the Trials Emblem", "https://api.scryfall.com/cards/takh/25/en?format=image");
|
|
||||||
put("AKH/Glyph Keeper", "https://api.scryfall.com/cards/takh/5/en?format=image");
|
put("AKH/Glyph Keeper", "https://api.scryfall.com/cards/takh/5/en?format=image");
|
||||||
put("AKH/Heart-Piercer Manticore", "https://api.scryfall.com/cards/takh/6/en?format=image");
|
put("AKH/Heart-Piercer Manticore", "https://api.scryfall.com/cards/takh/6/en?format=image");
|
||||||
put("AKH/Honored Hydra", "https://api.scryfall.com/cards/takh/7/en?format=image");
|
put("AKH/Honored Hydra", "https://api.scryfall.com/cards/takh/7/en?format=image");
|
||||||
|
|
@ -204,9 +203,6 @@ public class ScryfallImageSupportTokens {
|
||||||
put("BFZ/Octopus", "https://api.scryfall.com/cards/tbfz/7/en?format=image");
|
put("BFZ/Octopus", "https://api.scryfall.com/cards/tbfz/7/en?format=image");
|
||||||
put("BFZ/Plant", "https://api.scryfall.com/cards/tbfz/10/en?format=image");
|
put("BFZ/Plant", "https://api.scryfall.com/cards/tbfz/10/en?format=image");
|
||||||
|
|
||||||
// C17
|
|
||||||
|
|
||||||
|
|
||||||
// WAR
|
// WAR
|
||||||
put("WAR/Angel", "https://api.scryfall.com/cards/twar/2/en?format=image");
|
put("WAR/Angel", "https://api.scryfall.com/cards/twar/2/en?format=image");
|
||||||
put("WAR/Assassin", "https://api.scryfall.com/cards/twar/6/en?format=image");
|
put("WAR/Assassin", "https://api.scryfall.com/cards/twar/6/en?format=image");
|
||||||
|
|
|
||||||
|
|
@ -115,18 +115,38 @@ public abstract class Watcher implements Serializable {
|
||||||
((Set) field.get(watcher)).clear();
|
((Set) field.get(watcher)).clear();
|
||||||
((Set) field.get(watcher)).addAll((Set) field.get(this));
|
((Set) field.get(watcher)).addAll((Set) field.get(this));
|
||||||
} else if (field.getType() == Map.class) {
|
} else if (field.getType() == Map.class) {
|
||||||
Map target = ((Map) field.get(watcher));
|
|
||||||
target.clear();
|
|
||||||
Map source = (Map) field.get(this);
|
|
||||||
|
|
||||||
ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
|
ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
|
||||||
Type valueType = parameterizedType.getActualTypeArguments()[1];
|
Type valueType = parameterizedType.getActualTypeArguments()[1];
|
||||||
if (valueType.getClass().getSimpleName().contains("Set")) {
|
if (valueType.getTypeName().contains("Set")) {
|
||||||
source.entrySet().forEach(kv -> {
|
Map<Object, Set<Object>> source = (Map<Object, Set<Object>>) field.get(this);
|
||||||
Object key = ((Map.Entry) kv).getKey();
|
Map<Object, Set<Object>> target = (Map<Object, Set<Object>>) field.get(watcher);
|
||||||
Set value = (Set) ((Map.Entry) kv).getValue();
|
target.clear();
|
||||||
target.put(key, new HashSet<>(value));
|
for (Map.Entry<Object, Set<Object>> e : source.entrySet()) {
|
||||||
});
|
Set<Object> set = new HashSet<>();
|
||||||
|
set.addAll(e.getValue());
|
||||||
|
target.put(e.getKey(), set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (valueType.getTypeName().contains("List")) {
|
||||||
|
Map<Object, List<Object>> source = (Map<Object, List<Object>>) field.get(this);
|
||||||
|
Map<Object, List<Object>> target = (Map<Object, List<Object>>) field.get(watcher);
|
||||||
|
target.clear();
|
||||||
|
for (Map.Entry<Object, List<Object>> e : source.entrySet()) {
|
||||||
|
List<Object> list = new ArrayList<>();
|
||||||
|
list.addAll(e.getValue());
|
||||||
|
target.put(e.getKey(), list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (valueType.getTypeName().contains("Map")) {
|
||||||
|
Map<Object, Map<Object, Object>> source = (Map<Object, Map<Object, Object>>) field.get(this);
|
||||||
|
Map<Object, Map<Object, Object>> target = (Map<Object, Map<Object, Object>>) field.get(watcher);
|
||||||
|
target.clear();
|
||||||
|
for (Map.Entry<Object, Map<Object, Object>> e : source.entrySet()) {
|
||||||
|
Map<Object, Object> map = new HashMap<>();
|
||||||
|
map.putAll(e.getValue());
|
||||||
|
target.put(e.getKey(), map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
((Map) field.get(watcher)).putAll((Map) field.get(this));
|
((Map) field.get(watcher)).putAll((Map) field.get(this));
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
package mage;
|
package mage;
|
||||||
|
|
||||||
import static mage.constants.WatcherScope.GAME;
|
import static mage.constants.WatcherScope.GAME;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
|
|
@ -19,7 +23,7 @@ import org.junit.Test;
|
||||||
public class WatcherTest {
|
public class WatcherTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void testShallowCopy() {
|
||||||
// Given
|
// Given
|
||||||
Map<String, String> mapField = new HashMap<>();
|
Map<String, String> mapField = new HashMap<>();
|
||||||
mapField.put("mapFieldKey1", "mapFieldValue1");
|
mapField.put("mapFieldKey1", "mapFieldValue1");
|
||||||
|
|
@ -43,6 +47,104 @@ public class WatcherTest {
|
||||||
assertEquals(ImmutableMap.of("mapFieldKey1", "mapFieldValue1", "mapFieldKey2", "mapFieldValue2"), copy.getMapField());
|
assertEquals(ImmutableMap.of("mapFieldKey1", "mapFieldValue1", "mapFieldKey2", "mapFieldValue2"), copy.getMapField());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeepCopyMapOfList() {
|
||||||
|
// Given
|
||||||
|
Map<String, List<String>> listInMapField = new HashMap<>();
|
||||||
|
List<String> list1 = new ArrayList<>();
|
||||||
|
list1.add("v1");
|
||||||
|
list1.add("v1.1");
|
||||||
|
List<String> list2 = new ArrayList<>();
|
||||||
|
list2.add("v2");
|
||||||
|
listInMapField.put("k1", list1);
|
||||||
|
listInMapField.put("k2", list2);
|
||||||
|
|
||||||
|
TestWatcher testWatcher = new TestWatcher(GAME);
|
||||||
|
testWatcher.setListInMapField(listInMapField);
|
||||||
|
|
||||||
|
// When
|
||||||
|
TestWatcher copy = testWatcher.copy();
|
||||||
|
|
||||||
|
// And
|
||||||
|
testWatcher.getListInMapField().get("k1").add("v1.2");
|
||||||
|
List<String> list3 = new ArrayList<>();
|
||||||
|
list3.add("v5");
|
||||||
|
testWatcher.getListInMapField().put("k5", list3);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Map<String, List<String>> copyListInMap = copy.getListInMapField();
|
||||||
|
assertEquals(2, copyListInMap.size());
|
||||||
|
assertTrue(copyListInMap.containsKey("k1"));
|
||||||
|
assertEquals(ImmutableList.of("v1", "v1.1"), copyListInMap.get("k1"));
|
||||||
|
assertTrue(copyListInMap.containsKey("k2"));
|
||||||
|
assertEquals(ImmutableList.of("v2"), copyListInMap.get("k2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeepCopyMapOfSet() {
|
||||||
|
// Given
|
||||||
|
Map<String, Set<String>> setInMapField = new HashMap<>();
|
||||||
|
Set<String> set1 = new HashSet<>();
|
||||||
|
set1.add("v3");
|
||||||
|
Set<String> set2 = new HashSet<>();
|
||||||
|
set2.add("v4");
|
||||||
|
set2.add("v4.1");
|
||||||
|
setInMapField.put("k3", set1);
|
||||||
|
setInMapField.put("k4", set2);
|
||||||
|
setInMapField.put("k", new HashSet<String>());
|
||||||
|
|
||||||
|
TestWatcher testWatcher = new TestWatcher(GAME);
|
||||||
|
testWatcher.setSetInMapField(setInMapField);
|
||||||
|
|
||||||
|
// When
|
||||||
|
TestWatcher copy = testWatcher.copy();
|
||||||
|
|
||||||
|
// And
|
||||||
|
testWatcher.getSetInMapField().get("k3").add("v3.1");
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Map<String, Set<String>> copySetInMap = copy.getSetInMapField();
|
||||||
|
assertEquals(3, copySetInMap.size());
|
||||||
|
assertTrue(copySetInMap.containsKey("k3"));
|
||||||
|
assertEquals(ImmutableSet.of("v3"), copySetInMap.get("k3"));
|
||||||
|
assertTrue(copySetInMap.containsKey("k4"));
|
||||||
|
assertEquals(ImmutableSet.of("v4", "v4.1"), copySetInMap.get("k4"));
|
||||||
|
assertTrue(copySetInMap.containsKey("k"));
|
||||||
|
assertEquals(ImmutableSet.of(), copySetInMap.get("k"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeepCopyMapOfMap() {
|
||||||
|
// Given
|
||||||
|
Map<String, Map<String, String>> mapInMapField = new HashMap<>();
|
||||||
|
Map<String, String> map1 = new HashMap<>();
|
||||||
|
map1.put("k1.1", "v1.1");
|
||||||
|
map1.put("k1.2", "v1.2");
|
||||||
|
Map<String, String> map2 = new HashMap<>();
|
||||||
|
map2.put("k2.1", "v2.1");
|
||||||
|
mapInMapField.put("k1", map1);
|
||||||
|
mapInMapField.put("k2", map2);
|
||||||
|
|
||||||
|
TestWatcher testWatcher = new TestWatcher(GAME);
|
||||||
|
testWatcher.setMapInMapField(mapInMapField);
|
||||||
|
|
||||||
|
// When
|
||||||
|
TestWatcher copy = testWatcher.copy();
|
||||||
|
|
||||||
|
// And
|
||||||
|
testWatcher.getMapInMapField().get("k2").put("k2.2", "v2.2");
|
||||||
|
testWatcher.getMapInMapField().put("k3", new HashMap<>());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Map<String, Map<String, String>> copyMapInMap = copy.getMapInMapField();
|
||||||
|
assertEquals(2, copyMapInMap.size());
|
||||||
|
assertTrue(copyMapInMap.containsKey("k1"));
|
||||||
|
assertEquals(ImmutableMap.of("k1.1", "v1.1", "k1.2", "v1.2"), copyMapInMap.get("k1"));
|
||||||
|
assertTrue(copyMapInMap.containsKey("k2"));
|
||||||
|
assertEquals(ImmutableMap.of("k2.1", "v2.1"), copyMapInMap.get("k2"));
|
||||||
|
assertFalse(copyMapInMap.containsKey("k3"));
|
||||||
|
}
|
||||||
|
|
||||||
private Set<String> set(String... values) {
|
private Set<String> set(String... values) {
|
||||||
return Stream.of(values).collect(Collectors.toSet());
|
return Stream.of(values).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +153,9 @@ public class WatcherTest {
|
||||||
private String stringField;
|
private String stringField;
|
||||||
private Set<String> setField = new HashSet<>();
|
private Set<String> setField = new HashSet<>();
|
||||||
private Map<String, String> mapField = new HashMap<>();
|
private Map<String, String> mapField = new HashMap<>();
|
||||||
|
private Map<String, List<String>> listInMapField = new HashMap<>();
|
||||||
|
private Map<String, Set<String>> setInMapField = new HashMap<>();
|
||||||
|
private Map<String, Map<String, String>> mapInMapField = new HashMap<>();
|
||||||
|
|
||||||
public TestWatcher(WatcherScope scope) {
|
public TestWatcher(WatcherScope scope) {
|
||||||
super(scope);
|
super(scope);
|
||||||
|
|
@ -84,5 +189,29 @@ public class WatcherTest {
|
||||||
public void setMapField(Map<String, String> mapField) {
|
public void setMapField(Map<String, String> mapField) {
|
||||||
this.mapField = mapField;
|
this.mapField = mapField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, List<String>> getListInMapField() {
|
||||||
|
return listInMapField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListInMapField(Map<String, List<String>> listInMapField) {
|
||||||
|
this.listInMapField = listInMapField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Set<String>> getSetInMapField() {
|
||||||
|
return setInMapField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetInMapField(Map<String, Set<String>> setInMapField) {
|
||||||
|
this.setInMapField = setInMapField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Map<String, String>> getMapInMapField() {
|
||||||
|
return mapInMapField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMapInMapField(Map<String, Map<String, String>> mapInMapField) {
|
||||||
|
this.mapInMapField = mapInMapField;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue