svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.impl / src / main / java / org / gvsig / export / impl / service / ExportEntriesHistoric.java @ 44386
History | View | Annotate | Download (1.99 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.impl.service; |
7 |
|
8 |
import java.util.ArrayList; |
9 |
import java.util.Collections; |
10 |
import java.util.List; |
11 |
import org.apache.commons.lang3.StringUtils; |
12 |
import org.gvsig.export.ExportEntries; |
13 |
import org.gvsig.export.ExportEntry; |
14 |
import org.gvsig.expressionevaluator.Bookmark; |
15 |
import org.gvsig.expressionevaluator.Expression; |
16 |
|
17 |
/**
|
18 |
*
|
19 |
* @author osc
|
20 |
*/
|
21 |
public class ExportEntriesHistoric implements ExportEntries { |
22 |
|
23 |
public List<ExportEntry> history; |
24 |
public int maxsize = 10; |
25 |
|
26 |
public ExportEntriesHistoric() {
|
27 |
this.history = new ArrayList<>(); |
28 |
} |
29 |
|
30 |
@Override
|
31 |
public List<ExportEntry> toList() { |
32 |
return Collections.unmodifiableList(this.history); |
33 |
} |
34 |
|
35 |
@Override
|
36 |
public boolean add(ExportEntry element) { |
37 |
if (element == null) { |
38 |
return true; |
39 |
} |
40 |
if (!this.history.isEmpty()) { |
41 |
ExportEntry last = this.history.get(0); |
42 |
String lastPhrase = StringUtils.normalizeSpace(last.getName());
|
43 |
String curPhrase = StringUtils.normalizeSpace(element.getName());
|
44 |
if (StringUtils.equals(curPhrase, lastPhrase)) {
|
45 |
return true; |
46 |
} |
47 |
} |
48 |
this.history.add(0, element); |
49 |
if (this.history.size() > this.maxsize) { |
50 |
this.history.remove(this.history.size() - 1); |
51 |
} |
52 |
return true; |
53 |
} |
54 |
|
55 |
@Override
|
56 |
public boolean remove(String entry) { |
57 |
for (int i = 0; i < this.history.size(); i++) { |
58 |
ExportEntry bookmark = this.history.get(i);
|
59 |
if( StringUtils.equalsIgnoreCase(entry, bookmark.getName()) ) {
|
60 |
this.history.remove(i);
|
61 |
return true; |
62 |
} |
63 |
} |
64 |
return false; |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public boolean remove(ExportEntry entry) { |
69 |
return this.history.remove(entry); |
70 |
} |
71 |
} |