OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 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 53... Line 53...
53
 
53
 
54
    public TextSearchSpec(String filterString, final Mode mode) {
54
    public TextSearchSpec(String filterString, final Mode mode) {
55
        this.mode = mode;
55
        this.mode = mode;
56
        this.filterString = filterString;
56
        this.filterString = filterString;
57
        this.normalizedFilterString = normalize(filterString);
57
        this.normalizedFilterString = normalize(filterString);
58
        this.formats = new HashMap<Class<?>, FormatGroup>();
58
        this.formats = new HashMap<>();
59
        this.parsedFilter = new HashMap<Format, Object>();
59
        this.parsedFilter = new HashMap<>();
60
    }
60
    }
61
 
61
 
62
    private String normalize(String s) {
62
    private String normalize(String s) {
63
        if (this.mode == Mode.CONTAINS_STRICT || this.mode == Mode.EQUALS_STRICT) {
63
        if (this.mode == Mode.CONTAINS_STRICT || this.mode == Mode.EQUALS_STRICT) {
64
            return s.trim();
64
            return s.trim();
Line 86... Line 86...
86
    }
86
    }
87
 
87
 
88
    private final String format(final Format fmt, final Object cell) {
88
    private final String format(final Format fmt, final Object cell) {
89
        try {
89
        try {
90
            return fmt.format(cell);
90
            return fmt.format(cell);
91
        } catch (Exception e) {
91
        } catch (final Exception e) {
92
            throw new IllegalStateException("Couldn't format " + cell + '(' + getClass(cell) + ") with " + fmt, e);
92
            throw new IllegalStateException("Couldn't format " + cell + '(' + getClass(cell) + ") with " + fmt, e);
93
        }
93
        }
94
    }
94
    }
95
 
95
 
96
    static private String getClass(Object cell) {
96
    static private String getClass(Object cell) {
Line 99... Line 99...
99
 
99
 
100
    private final Double getDouble() {
100
    private final Double getDouble() {
101
        if (!this.parsedFilterD_tried) {
101
        if (!this.parsedFilterD_tried) {
102
            try {
102
            try {
103
                this.parsedFilterD = Double.valueOf(this.filterString);
103
                this.parsedFilterD = Double.valueOf(this.filterString);
104
            } catch (NumberFormatException e) {
104
            } catch (final NumberFormatException e) {
105
                this.parsedFilterD = null;
105
                this.parsedFilterD = null;
106
            }
106
            }
107
            this.parsedFilterD_tried = true;
107
            this.parsedFilterD_tried = true;
108
        }
108
        }
109
        return this.parsedFilterD;
109
        return this.parsedFilterD;