OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 16... Line 16...
16
import java.util.Date;
16
import java.util.Date;
17
import java.util.List;
17
import java.util.List;
18
 
18
 
19
public class DateSearchSpec implements SearchSpec {
19
public class DateSearchSpec implements SearchSpec {
20
    // include or exclude filterString
20
    // include or exclude filterString
21
    private boolean excludeFilterString;
21
    private final boolean excludeFilterString;
22
    private int columnIndex;
22
    private final int columnIndex;
23
    private Date fromDate;
23
    private final Date fromDate;
24
    private Date toDate;
24
    private final Date toDate;
25
 
25
 
26
    public DateSearchSpec(Date from, Date to, int columnIndex) {
26
    public DateSearchSpec(Date from, Date to, int columnIndex) {
27
        this(false, from, to, columnIndex);
27
        this(false, from, to, columnIndex);
28
    }
28
    }
29
 
29
 
Line 42... Line 42...
42
     * @param toDate la date de fin.
42
     * @param toDate la date de fin.
43
     * @param index l'index de la colonne, -1 pour toute la ligne.
43
     * @param index l'index de la colonne, -1 pour toute la ligne.
44
     * @return <code>true</code> si la ligne contient.
44
     * @return <code>true</code> si la ligne contient.
45
     */
45
     */
46
    static private boolean contains(Object line, Date startDate, Date stopDate, int index) {
46
    static private boolean contains(Object line, Date startDate, Date stopDate, int index) {
47
 
-
 
48
        List list = (List) line;
47
        final List<?> list = (List<?>) line;
49
        final int start;
48
        final int start;
50
        final int stop;
49
        final int stop;
51
        if (index < 0) {
50
        if (index < 0) {
52
            // Cas ou on cherche sur tout
51
            // Cas ou on cherche sur tout
53
            start = 0;
52
            start = 0;
Line 60... Line 59...
60
 
59
 
61
        for (int i = start; i < stop; i++) {
60
        for (int i = start; i < stop; i++) {
62
            final Object cell = list.get(i);
61
            final Object cell = list.get(i);
63
            if (cell != null) {
62
            if (cell != null) {
64
                if (cell instanceof Date) {
63
                if (cell instanceof Date) {
65
                    Date date = (Date) cell;
64
                    final Date date = (Date) cell;
66
                    if (date.after(startDate) && date.before(stopDate)) {
65
                    if (date.after(startDate) && date.before(stopDate)) {
67
                        return true;
66
                        return true;
68
                    }
67
                    }
69
                } else {
68
                } else {
70
                    throw new IllegalArgumentException("The value is not a Date:" + cell + " index:" + index);
69
                    throw new IllegalArgumentException("The value is not a Date:" + cell + " index:" + index);
Line 73... Line 72...
73
            }
72
            }
74
        }
73
        }
75
        return false;
74
        return false;
76
    }
75
    }
77
 
76
 
-
 
77
    @Override
78
    public boolean match(Object line) {
78
    public boolean match(Object line) {
79
        return this.excludeFilterString ^ contains(line, this.fromDate, this.toDate, this.columnIndex);
79
        return this.excludeFilterString ^ contains(line, this.fromDate, this.toDate, this.columnIndex);
80
    }
80
    }
81
 
81
 
82
    public void dump() {
82
    public void dump() {
83
        System.out.println(this.excludeFilterString + ":" + this.fromDate + "->" + this.toDate + " col:" + this.columnIndex);
83
        System.out.println(this.excludeFilterString + ":" + this.fromDate + "->" + this.toDate + " col:" + this.columnIndex);
84
    }
84
    }
85
 
85
 
-
 
86
    @Override
86
    public boolean isEmpty() {
87
    public boolean isEmpty() {
87
        return true;
88
        return true;
88
    }
89
    }
89
 
90
 
90
}
91
}