-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a Map<String, List<Integer> instead of Map<String, int[]> for sub…
…plans to facilitate serialization and comparison
- Loading branch information
Showing
7 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
api/src/main/java/datawave/microservice/querymetric/StringIntegerListMapAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package datawave.microservice.querymetric; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlValue; | ||
import javax.xml.bind.annotation.adapters.XmlAdapter; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Provides JAX-B marshalling/unmarshalling of {@link Map} of String to List of Integer. This allows the marshalled type to be in our own namespace rather than | ||
* in the "default" one, which when triggered will then assume the "" prefix and push all of our own elements into the "ns2" prefix. | ||
*/ | ||
public class StringIntegerListMapAdapter extends XmlAdapter<StringIntegerListMapAdapter.StringIntegerListMap,Map<String,List<Integer>>> { | ||
|
||
@Override | ||
public Map<String,List<Integer>> unmarshal(StringIntegerListMap v) throws Exception { | ||
HashMap<String,List<Integer>> map = new HashMap<>(); | ||
for (StringIntegerListMapEntry entry : v.entries) { | ||
map.put(entry.key, entry.value); | ||
} | ||
return map; | ||
} | ||
|
||
@Override | ||
public StringIntegerListMap marshal(Map<String,List<Integer>> v) throws Exception { | ||
StringIntegerListMap map = new StringIntegerListMap(); | ||
for (Map.Entry<String,List<Integer>> entry : v.entrySet()) { | ||
map.entries.add(new StringIntegerListMapEntry(entry.getKey(), entry.getValue())); | ||
} | ||
return map; | ||
} | ||
|
||
public static class StringIntegerListMap { | ||
@XmlElement(name = "entry") | ||
private List<StringIntegerListMapEntry> entries = new ArrayList<>(); | ||
} | ||
|
||
public static class StringIntegerListMapEntry { | ||
@XmlAttribute(name = "name") | ||
private String key; | ||
@XmlValue | ||
private List<Integer> value; | ||
|
||
public StringIntegerListMapEntry() {} | ||
|
||
public StringIntegerListMapEntry(String key, List<Integer> value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters