svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / RecentUsedsAttributesImpl.java @ 47499
History | View | Annotate | Download (2.25 KB)
1 |
package org.gvsig.fmap.dal.feature.impl; |
---|---|
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 |
if( store == null ) { |
29 |
return Collections.EMPTY_LIST; |
30 |
} |
31 |
CircularFifoQueue<String> recents = this.recentsForStore.get(store.getFullName()); |
32 |
if( recents==null ) { |
33 |
return Collections.EMPTY_LIST; |
34 |
} |
35 |
return recents;
|
36 |
} |
37 |
|
38 |
public List<FeatureAttributeDescriptor> getAttributes(FeatureType featureType) { |
39 |
List<FeatureAttributeDescriptor> r = new ArrayList<>(); |
40 |
for (String name : this.getNames(featureType)) { |
41 |
FeatureAttributeDescriptor attrRecendUsed = featureType.getAttributeDescriptor(name); |
42 |
if (attrRecendUsed != null) { |
43 |
r.add(attrRecendUsed); |
44 |
} |
45 |
} |
46 |
return r;
|
47 |
} |
48 |
|
49 |
public void add(FeatureAttributeDescriptor attribute) { |
50 |
this.add(attribute.getFeatureType(), attribute.getName());
|
51 |
} |
52 |
|
53 |
public void add(FeatureType featureType, FeatureAttributeDescriptor attribute) { |
54 |
this.add(featureType, attribute.getName());
|
55 |
} |
56 |
|
57 |
public void add(FeatureType featureType, String name) { |
58 |
String storeFullName = featureType.getStore().getFullName();
|
59 |
CircularFifoQueue<String> recents = this.recentsForStore.get(storeFullName); |
60 |
if( recents==null ) { |
61 |
recents = new CircularFifoQueue(this.getMaxSize()); |
62 |
this.recentsForStore.put(storeFullName, recents);
|
63 |
} |
64 |
recents.remove(name); |
65 |
recents.add(name); |
66 |
} |
67 |
|
68 |
public int getMaxSize() { |
69 |
return 6; |
70 |
} |
71 |
} |