Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / searchpanel / RecentUsedsAttributesImpl.java @ 44259

History | View | Annotate | Download (2.06 KB)

1
package org.gvsig.fmap.dal.swing.impl.searchpanel;
2

    
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.Collections;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import org.apache.commons.collections4.queue.CircularFifoQueue;
10
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
11
import org.gvsig.fmap.dal.feature.FeatureStore;
12
import org.gvsig.fmap.dal.feature.FeatureType;
13

    
14
/**
15
 *
16
 * @author jjdelcerro
17
 */
18
public class RecentUsedsAttributesImpl {
19

    
20
    private final Map<String,CircularFifoQueue<String>> recentsForStore;
21
    
22
    public RecentUsedsAttributesImpl() {
23
        this.recentsForStore = new HashMap<>();
24
    }
25
    
26
    public Collection<String> getNames(FeatureType featureType) {
27
        FeatureStore store = featureType.getStore();
28
        CircularFifoQueue<String> recents = this.recentsForStore.get(store.getFullName());
29
        if( recents==null ) {
30
            return Collections.EMPTY_LIST;
31
        }
32
        return recents;
33
    }
34
    
35
    public Collection<FeatureAttributeDescriptor> getAttributes(FeatureType featureType) {
36
        List<FeatureAttributeDescriptor> r = new ArrayList<>();
37
        for (String name : this.getNames(featureType)) {
38
            r.add(featureType.getAttributeDescriptor(name));
39
        }
40
        return r;
41
    }
42

    
43
    public void add(FeatureAttributeDescriptor attribute) {
44
        this.add(attribute.getFeatureType(), attribute.getName());
45
    }
46
    
47
    public void add(FeatureType featureType, FeatureAttributeDescriptor attribute) {
48
        this.add(featureType, attribute.getName());
49
    }
50
    
51
    public void add(FeatureType featureType, String name) {
52
        String storeFullName = featureType.getStore().getFullName();
53
        CircularFifoQueue<String> recents = this.recentsForStore.get(storeFullName);
54
        if( recents==null ) {
55
            recents = new CircularFifoQueue(this.getMaxSize());
56
            this.recentsForStore.put(storeFullName, recents);
57
        }
58
        recents.remove(name);
59
        recents.add(name);
60
    }
61

    
62
    public int getMaxSize() {
63
        return 6;
64
    }
65
}