Changeset 4727


Ignore:
Timestamp:
03/17/14 10:57:22 (11 years ago)
Author:
Twan Goosen
Message:

specialised map entry model towards collection values and ensured serialisability

Location:
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/CollectionMapEntryModel.java

    r4725 r4727  
    1717package eu.clarin.cmdi.vlo.wicket.model;
    1818
     19import com.google.common.collect.Lists;
    1920import com.google.common.collect.Maps;
    2021import java.io.Serializable;
    21 import java.util.AbstractMap;
    22 import java.util.HashMap;
    23 import java.util.Map;
     22import java.util.Collection;
    2423import java.util.Map.Entry;
    2524import org.apache.wicket.model.LoadableDetachableModel;
     
    3332 * @param <V> value type
    3433 */
    35 public class MapEntryModel<K extends Serializable, V extends Serializable> extends LoadableDetachableModel<Entry<K, V>> {
     34public class CollectionMapEntryModel<K extends Serializable, V extends Serializable> extends LoadableDetachableModel<Entry<K, Collection<V>>> {
    3635
    3736    private final K key;
    38     private final V value;
     37    private final Collection<V> value;
    3938
    40     public MapEntryModel(Entry<K, V> entry) {
     39    public CollectionMapEntryModel(Entry<K, Collection<V>> entry) {
    4140        super(entry);
    4241        key = entry.getKey();
    43         value = entry.getValue();
     42
     43        final Collection<V> entryValue = entry.getValue();
     44        if (entryValue instanceof Serializable) {
     45            value = entryValue;
     46        } else {
     47            // copy to a serialisable collection
     48            value = Lists.newArrayList(entryValue);
     49        }
    4450    }
    4551
    4652    @Override
    47     protected Entry<K, V> load() {
     53    protected Entry<K, Collection<V>> load() {
    4854        return Maps.immutableEntry(key, value);
    4955    }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/FacetSelectionProvider.java

    r4693 r4727  
    1919
    2020import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    21 import eu.clarin.cmdi.vlo.wicket.model.MapEntryModel;
     21import eu.clarin.cmdi.vlo.wicket.model.CollectionMapEntryModel;
    2222import java.util.Collection;
    2323import java.util.Iterator;
     
    4949    @Override
    5050    public IModel<Map.Entry<String, Collection<String>>> model(Map.Entry<String, Collection<String>> object) {
    51         return new MapEntryModel<String, Collection<String>>(object);
     51        return new CollectionMapEntryModel<String, String>(object);
    5252    }
    5353
Note: See TracChangeset for help on using the changeset viewer.