• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stasha / flex / 16

27 Apr 2025 11:53PM UTC coverage: 74.123% (+17.2%) from 56.927%
16

push

circleci

stasha
Re-factored project and directory name and added ordinals and plurals for 56 of countries

164 of 247 branches covered (66.4%)

Branch coverage included in aggregate %.

260 of 286 new or added lines in 10 files covered. (90.91%)

3 existing lines in 2 files now uncovered.

343 of 437 relevant lines covered (78.49%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.27
/src/main/java/com/stasha/info/flex/FlexLocalization.java
1
package com.stasha.info.flex;
2

3
import com.stasha.info.flex.store.FlexStore;
4
import com.stasha.info.flex.store.FlexStoreImpl;
5
import com.stasha.info.flex.store.FlexStringStore;
6

7
/**
8
 * Flexible localization.
9
 *
10
 * @author stasha
11
 */
12
public class FlexLocalization extends Flex {
1✔
13

14
    @Override
15
    public void setFlexStore(FlexStringStore store) {
16
        if (store.getObjectStore() == null) {
1!
UNCOV
17
            store.setObjectStore(new FlexStoreImpl<>());
×
18
        }
19
        super.setFlexStore(store);
1✔
20
    }
1✔
21

22
    /**
23
     * Object factory interface used as argument passed to getObject methods.
24
     *
25
     * @param <T>
26
     */
27
    @FunctionalInterface
28
    public static interface ObjectFactory<T> {
29

30
        T create(String localizedMessage);
31
    }
32

33
    /**
34
     * Returns object stored in FlexStore based on passed key and arguments.
35
     *
36
     * @param <V>
37
     * @param key
38
     * @param arguments
39
     * @return
40
     */
41
    public <V> V getObject(String key, Object... arguments) {
42
        return getObject(key, getFlexStore(), arguments);
×
43
    }
44

45
    /**
46
     * Returns object stored in passed FlextStore based on passed key and
47
     * arguments.
48
     *
49
     * @param <V>
50
     * @param key
51
     * @param store
52
     * @param arguments
53
     * @return
54
     */
55
    public <V> V getObject(String key, FlexStore store, Object... arguments) {
56
        String msg = getMessage(key, arguments);
×
57
        return (V) getFlexStore().getObjectStore().get(msg);
×
58
    }
59

60
    /**
61
     * Returns object stored in FlextStore based on passed key and arguments. In
62
     * case object is not found under specified key, than new object is created
63
     * by passed ObjectFactory and stored into store.
64
     *
65
     * @param <V>
66
     * @param key
67
     * @param factory
68
     * @param arguments
69
     * @return
70
     */
71
    public <V> V getObject(String key, ObjectFactory<V> factory, Object... arguments) {
72
        return getMessage(key, factory, getFlexStore(), arguments);
×
73
    }
74

75
    /**
76
     * Returns object stored in passed FlextStore based on passed key and
77
     * arguments. In case object is not found under specified key, than new
78
     * object is created by passed ObjectFactory and stored into store.
79
     *
80
     * @param <V>
81
     * @param key
82
     * @param factory
83
     * @param store
84
     * @param arguments
85
     * @return
86
     */
87
    public <V> V getMessage(String key, ObjectFactory<V> factory, FlexStore store, Object... arguments) {
88
        String msg = getMessage(key, arguments);
×
89
        FlexStore objectStore = getFlexStore().getObjectStore();
×
90
        if (objectStore.get(msg) == null) {
×
91
            V obj = factory.create(msg);
×
92
            getFlexStore().getObjectStore().put(msg, obj);
×
93
            return obj;
×
94
        }
95
        return (V) getFlexStore().getObjectStore().get(msg);
×
96
    }
97

98
    /**
99
     * Get localized message based on passed key and arguments.
100
     *
101
     * @param key
102
     * @param arguments Arguments used in string interpolation. Argument
103
     * example: welcome {0}. You are visitor number {1}. Arguments {0} and {1}
104
     * will be replaced with passed arguments to the method: getMessage("Jon
105
     * Doe", 1234) = welcome Jon Doe. You are visitor number 1234.
106
     * @return Localized string
107
     */
108
    public String getMessage(String key, Object... arguments) {
109
        return getFlexInterpolator().interpolate(key, null, getFlexStore(), arguments);
1✔
110
    }
111

112
    /**
113
     * Get localized message based on passed key and arguments.
114
     *
115
     * @param key
116
     * @param store store to use in localization
117
     * @param arguments Arguments used in string interpolation. Argument
118
     * example: welcome {0}. You are visitor number {1}. Arguments {0} and {1}
119
     * will be replaced with passed arguments to the method: getMessage("Jon
120
     * Doe", 1234) = welcome Jon Doe. You are visitor number 1234.
121
     * @return Localized string
122
     */
123
    public String getMessage(String key, FlexStore<String, String> store, Object... arguments) {
124
        return getFlexInterpolator().interpolate(key, null, store, arguments);
×
125
    }
126

127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc