OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
17 ilm 5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.sql.view.search;
15
 
16
import org.openconcerto.utils.OrderedSet;
17
 
18
import java.util.List;
19
 
20
public class SearchList implements SearchSpec {
21
 
22
    public static SearchList singleton(SearchSpec item) {
23
        final SearchList res = new SearchList();
24
        res.addSearchItem(item);
25
        return res;
26
    }
27
 
28
    // *** instance
29
 
30
    private final List<SearchSpec> items;
31
 
32
    public SearchList() {
33
        super();
182 ilm 34
        this.items = new OrderedSet<>();
17 ilm 35
    }
36
 
93 ilm 37
    public void addSearchItem(SearchSpec item) {
17 ilm 38
        this.items.add(item);
39
    }
40
 
93 ilm 41
    public void removeSearchItem(SearchSpec item) {
17 ilm 42
        this.items.remove(item);
43
    }
44
 
182 ilm 45
    @Override
17 ilm 46
    public boolean isEmpty() {
47
        for (final SearchSpec s : this.items)
48
            if (!s.isEmpty())
49
                return false;
50
        return true;
51
    }
52
 
182 ilm 53
    @Override
17 ilm 54
    public boolean match(Object line) {
182 ilm 55
        return this.match((List<?>) line);
17 ilm 56
    }
57
 
58
    // fait un AND de tous les éléments
182 ilm 59
    private boolean match(List<?> line) {
17 ilm 60
        // List de String, cad 1 String par colonne
61
 
62
        boolean result = false;
63
        final int stop = this.items.size();
64
        for (int i = 0; i < stop; i++) {
65
            final SearchSpec item = this.items.get(i);
66
            if (!item.match(line)) {
67
                return false;
68
            }
69
            result = true;
70
        }
71
        return result;
72
    }
73
 
182 ilm 74
    @Override
17 ilm 75
    public String toString() {
76
        final StringBuffer sb = new StringBuffer(this.items.size() * 32);
77
        sb.append("SearchList:" + this.items.size() + " items");
78
        for (final SearchSpec item : this.items) {
79
            sb.append("\n");
80
            sb.append(item);
81
        }
82
        return sb.toString();
83
    }
84
 
85
}