OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 156
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.utils.i18n;
14
 package org.openconcerto.utils.i18n;
15
 
15
 
16
import java.util.HashMap;
16
import java.util.Collections;
17
import java.util.LinkedHashMap;
17
import java.util.LinkedHashMap;
18
import java.util.Map;
18
import java.util.Map;
19
import java.util.TreeSet;
19
import java.util.TreeSet;
20
 
20
 
21
import net.jcip.annotations.ThreadSafe;
-
 
22
 
-
 
23
import com.ibm.icu.text.MessageFormat;
21
import com.ibm.icu.text.MessageFormat;
24
 
22
 
-
 
23
import net.jcip.annotations.ThreadSafe;
-
 
24
 
25
/**
25
/**
26
 * {@link MessageFormat} can take numbered or named arguments, this class unifies both. This class
26
 * {@link MessageFormat} can take numbered or named arguments, this class unifies both. This class
27
 * is thread safe if the array or map isn't modified.
27
 * is thread safe if the array or map isn't modified.
28
 */
28
 */
29
@ThreadSafe
29
@ThreadSafe
Line 31... Line 31...
31
 
31
 
32
    static protected boolean isOrdered(final Map<?, ?> m) {
32
    static protected boolean isOrdered(final Map<?, ?> m) {
33
        return m instanceof LinkedHashMap;
33
        return m instanceof LinkedHashMap;
34
    }
34
    }
35
 
35
 
-
 
36
    static private final MessageArgs EMPTY = new MessageArgs(new Object[0]);
-
 
37
 
-
 
38
    public final static MessageArgs getEmpty() {
-
 
39
        return EMPTY;
-
 
40
    }
-
 
41
 
-
 
42
    public final static MessageArgs create(final String key, final Object value) {
-
 
43
        return new MessageArgs(Collections.singletonMap(key, value));
-
 
44
    }
-
 
45
 
36
    private final boolean mapPrimary;
46
    private final boolean mapPrimary;
37
    private Object[] array;
47
    private Object[] array;
38
    private Map<String, ?> map;
48
    private Map<String, ?> map;
39
 
49
 
40
    public MessageArgs(final Object[] array) {
50
    public MessageArgs(final Object[] array) {
Line 80... Line 90...
80
    }
90
    }
81
 
91
 
82
    protected synchronized Map<String, ?> getMap() {
92
    protected synchronized Map<String, ?> getMap() {
83
        if (this.map == null) {
93
        if (this.map == null) {
84
            final int stop = this.array.length;
94
            final int stop = this.array.length;
-
 
95
            if (stop == 0) {
-
 
96
                this.map = Collections.emptyMap();
-
 
97
            } else {
85
            final Map<String, Object> res = new HashMap<String, Object>(stop);
98
                final Map<String, Object> res = new LinkedHashMap<>(stop);
86
            for (int i = 0; i < stop; i++) {
99
                for (int i = 0; i < stop; i++) {
87
                res.put(String.valueOf(i), this.array[i]);
100
                    res.put(String.valueOf(i), this.array[i]);
88
            }
101
                }
-
 
102
                this.map = Collections.unmodifiableMap(res);
89
            this.map = res;
103
            }
90
        }
104
        }
91
        return this.map;
105
        return this.map;
92
    }
106
    }
93
 
107
 
94
    public final Object getArgument(int i) {
108
    public final Object getArgument(int i) {