I am trying to implement a method that replaces all values inside a Hashmap with all the values inside a document.
The idea behind that is that I loop through all items
that I get from Document.getItems()
and simply use the Item.getType()
method so I can decide what type I use for which field.
Something like that:
private void replace(SomeClass model, Document document) {
Map<String, Object> objectsMap = model.getObjectsMap();
Vector<Item> items = document.getItems();
for(Item item : items) {
if(item.getType() == Item.TEXT) {
model.add(item.getName(), item.getValueString()); // model.add(...) is basically a Map.put(String key, Object value);
} else if(item.getType() == Item.AUTHORS) {
// ...
} else if(/*...*/) {
// ...
}
}
}
Now my problem is that I cannot distinguish between a Text
and a TextList
because getType()
returns 1280 for both.
Has anyone tried something like that already or maybe can give me a hint of what approach might be a workaround?
EDIT
Regarding the idea from one of the comments, to use a TextList
when item.getValues().size() > 1
and Text
otherwise:
As mentioned in the comment the problem is, that I want to be able to use the field later as well.
For example:
If I have a TextList
field with one item in the document, and I would use the approach described above, I would put a String inside the Map
for this field.
If I want to add more Items to this field (which should be a Vector
since originally it was a TextList
) I wouldn't be able to - at least not in a straight forward way.