OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 28 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 org.openconcerto.utils.i18n.I18nUtils;
16
import org.openconcerto.utils.i18n.I18nUtils;
17
 
17
 
18
import java.text.FieldPosition;
18
import java.text.FieldPosition;
19
import java.text.Format;
19
import java.text.Format;
20
import java.text.ParsePosition;
20
import java.text.ParsePosition;
-
 
21
import java.util.Arrays;
21
import java.util.Locale;
22
import java.util.Locale;
22
import java.util.ResourceBundle;
23
import java.util.ResourceBundle;
23
 
24
 
-
 
25
import net.jcip.annotations.Immutable;
-
 
26
 
-
 
27
@Immutable
24
public class BooleanFormat extends Format {
28
public class BooleanFormat extends Format {
25
    static private final boolean[] BOOLEAN_VALUES = new boolean[] { false, true };
29
    static private final boolean[] BOOLEAN_VALUES = new boolean[] { false, true };
26
    static private final BooleanFormat NUMBER_INSTANCE = new BooleanFormat("0", "1");
30
    static private final BooleanFormat NUMBER_INSTANCE = new BooleanFormat("0", "1");
27
 
31
 
28
    static private String[] getFormattedBooleans(final Locale l, final boolean yesNo) {
32
    static private String[] getFormattedBooleans(final Locale l, final boolean yesNo) {
Line 37... Line 41...
37
 
41
 
38
    static public BooleanFormat createYesNo(final Locale l) {
42
    static public BooleanFormat createYesNo(final Locale l) {
39
        return new BooleanFormat(getFormattedBooleans(l, true));
43
        return new BooleanFormat(getFormattedBooleans(l, true));
40
    }
44
    }
41
 
45
 
-
 
46
    static public BooleanFormat createTrueFalse(final Locale l) {
-
 
47
        return new BooleanFormat(getFormattedBooleans(l, false));
-
 
48
    }
-
 
49
 
42
    static public final BooleanFormat getNumberInstance() {
50
    static public final BooleanFormat getNumberInstance() {
43
        return NUMBER_INSTANCE;
51
        return NUMBER_INSTANCE;
44
    }
52
    }
45
 
53
 
-
 
54
    static public final BooleanFormat[] getAll(final Locale l) {
-
 
55
        return new BooleanFormat[] { createTrueFalse(l), createYesNo(l), getNumberInstance() };
-
 
56
    }
-
 
57
 
46
    private final String[] formattedValues;
58
    private final String[] formattedValues;
47
 
59
 
48
    public BooleanFormat() {
60
    public BooleanFormat() {
49
        this(getFormattedBooleans(Locale.getDefault(), false));
61
        this(getFormattedBooleans(Locale.getDefault(), false));
50
    }
62
    }
51
 
63
 
52
    public BooleanFormat(final String falseValue, final String trueValue) {
64
    public BooleanFormat(final String falseValue, final String trueValue) {
53
        this(new String[] { falseValue, trueValue });
65
        this(new String[] { falseValue, trueValue });
54
    }
66
    }
55
 
67
 
-
 
68
    // not public because parameter isn't copied
56
    private BooleanFormat(final String[] formattedValues) {
69
    private BooleanFormat(final String[] formattedValues) {
57
        this.formattedValues = formattedValues;
70
        this.formattedValues = formattedValues;
58
    }
71
    }
59
 
72
 
60
    public final String format(boolean b) {
73
    public final String format(boolean b) {
Line 86... Line 99...
86
            }
99
            }
87
        }
100
        }
88
        pos.setErrorIndex(pos.getIndex());
101
        pos.setErrorIndex(pos.getIndex());
89
        return null;
102
        return null;
90
    }
103
    }
-
 
104
 
-
 
105
    @Override
-
 
106
    public int hashCode() {
-
 
107
        final int prime = 31;
-
 
108
        int result = 1;
-
 
109
        result = prime * result + Arrays.hashCode(this.formattedValues);
-
 
110
        return result;
-
 
111
    }
-
 
112
 
-
 
113
    @Override
-
 
114
    public boolean equals(Object obj) {
-
 
115
        if (this == obj)
-
 
116
            return true;
-
 
117
        if (obj == null)
-
 
118
            return false;
-
 
119
        if (getClass() != obj.getClass())
-
 
120
            return false;
-
 
121
        final BooleanFormat other = (BooleanFormat) obj;
-
 
122
        return Arrays.equals(this.formattedValues, other.formattedValues);
-
 
123
    }
-
 
124
 
-
 
125
    @Override
-
 
126
    public String toString() {
-
 
127
        return this.getClass().getSimpleName() + " with " + Arrays.asList(this.formattedValues);
-
 
128
    }
91
}
129
}