mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 04:25:29 -04:00
Typename fix for collection types.
This commit is contained in:
parent
aff252f278
commit
ee002dfc87
@ -30,6 +30,10 @@ package com.twelvemonkeys.imageio.metadata.xmp;
|
|||||||
|
|
||||||
import com.twelvemonkeys.imageio.metadata.AbstractEntry;
|
import com.twelvemonkeys.imageio.metadata.AbstractEntry;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XMPEntry
|
* XMPEntry
|
||||||
*
|
*
|
||||||
@ -63,6 +67,23 @@ final class XMPEntry extends AbstractEntry {
|
|||||||
return fieldName != null ? fieldName : XMP.DEFAULT_NS_MAPPING.get(getIdentifier());
|
return fieldName != null ? fieldName : XMP.DEFAULT_NS_MAPPING.get(getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeName() {
|
||||||
|
// Special handling for collections
|
||||||
|
Object value = getValue();
|
||||||
|
if (value instanceof List) {
|
||||||
|
return "List";
|
||||||
|
}
|
||||||
|
else if (value instanceof Set) {
|
||||||
|
return "Set";
|
||||||
|
}
|
||||||
|
else if (value instanceof Map) {
|
||||||
|
return "Map";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to class name
|
||||||
|
return super.getTypeName();
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String type = getTypeName();
|
String type = getTypeName();
|
||||||
|
@ -30,6 +30,11 @@ package com.twelvemonkeys.imageio.metadata.xmp;
|
|||||||
|
|
||||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||||
import com.twelvemonkeys.imageio.metadata.EntryAbstractTest;
|
import com.twelvemonkeys.imageio.metadata.EntryAbstractTest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XMPEntryTest
|
* XMPEntryTest
|
||||||
@ -43,4 +48,25 @@ public class XMPEntryTest extends EntryAbstractTest {
|
|||||||
protected Entry createEntry(Object value) {
|
protected Entry createEntry(Object value) {
|
||||||
return new XMPEntry(XMP.NS_XAP + ":foo", value);
|
return new XMPEntry(XMP.NS_XAP + ":foo", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeNameMap() {
|
||||||
|
assertEquals("Map", createEntry(new HashMap<>()).getTypeName());
|
||||||
|
assertEquals("Map", createEntry(Collections.emptyMap()).getTypeName());
|
||||||
|
assertEquals("Map", createEntry(Collections.singletonMap("foo", "bar")).getTypeName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeNameSet() {
|
||||||
|
assertEquals("Set", createEntry(new HashSet<>()).getTypeName());
|
||||||
|
assertEquals("Set", createEntry(Collections.singleton("foo")).getTypeName());
|
||||||
|
assertEquals("Set", createEntry(Collections.unmodifiableSet(Collections.singleton("foo"))).getTypeName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTypeNameList() {
|
||||||
|
assertEquals("List", createEntry(new ArrayList<>()).getTypeName());
|
||||||
|
assertEquals("List", createEntry(Collections.emptyList()).getTypeName());
|
||||||
|
assertEquals("List", createEntry(Arrays.asList("foo", "bar")).getTypeName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user