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 @ 44340
History | View | Annotate | Download (2.12 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 |
r.add(featureType.getAttributeDescriptor(name)); |
42 |
} |
43 |
return r;
|
44 |
} |
45 |
|
46 |
public void add(FeatureAttributeDescriptor attribute) { |
47 |
this.add(attribute.getFeatureType(), attribute.getName());
|
48 |
} |
49 |
|
50 |
public void add(FeatureType featureType, FeatureAttributeDescriptor attribute) { |
51 |
this.add(featureType, attribute.getName());
|
52 |
} |
53 |
|
54 |
public void add(FeatureType featureType, String name) { |
55 |
String storeFullName = featureType.getStore().getFullName();
|
56 |
CircularFifoQueue<String> recents = this.recentsForStore.get(storeFullName); |
57 |
if( recents==null ) { |
58 |
recents = new CircularFifoQueue(this.getMaxSize()); |
59 |
this.recentsForStore.put(storeFullName, recents);
|
60 |
} |
61 |
recents.remove(name); |
62 |
recents.add(name); |
63 |
} |
64 |
|
65 |
public int getMaxSize() { |
66 |
return 6; |
67 |
} |
68 |
} |