Skip to content

Method: getLocales()

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * SteelBlue: DCI User Interfaces
5: * http://tidalwave.it/projects/steelblue
6: *
7: * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/steelblue-src
22: * git clone https://github.com/tidalwave-it/steelblue-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.ui.core.role.impl;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.Collections;
30: import java.util.HashMap;
31: import java.util.Locale;
32: import java.util.Map;
33: import java.util.SortedSet;
34: import java.util.TreeSet;
35: import java.io.Serializable;
36: import it.tidalwave.ui.core.role.Displayable;
37:
38: /***************************************************************************************************************************************************************
39: *
40: * A default implementation of {@link Displayable} which a single, immutable display name in {@code Locale.ENGLISH} language.
41: *
42: * This is no more a public class; use {@link it.tidalwave.ui.core.role.Displayable#of(String)} or {@link Displayable#fromBundle(Class, String)}}
43: *
44: * @author Fabrizio Giudici
45: * @it.tidalwave.javadoc.stable
46: *
47: **************************************************************************************************************************************************************/
48: public class DefaultDisplayable implements Displayable, Serializable
49: {
50: private static final long serialVersionUID = 45345436345634734L;
51:
52: @Nonnull
53: private final String displayName;
54:
55: @Nonnull
56: private final String toStringName;
57:
58: @Nonnull
59: private final Map<Locale, String> displayNameMap = new HashMap<>();
60:
61: /***********************************************************************************************************************************************************
62: * Creates an instance with a given display name.
63: *
64: * @param displayName the display name
65: **********************************************************************************************************************************************************/
66: public DefaultDisplayable (@Nonnull final String displayName)
67: {
68: this(displayName, "???");
69: }
70:
71: /***********************************************************************************************************************************************************
72: * Creates an instance with a given display name in {@code Locale.ENGLISH} and an explicit identifier for
73: * {@code toString()}.
74: *
75: * @param displayName the display name
76: * @param toStringName the name to be rendered when {@code toString()} is called
77: **********************************************************************************************************************************************************/
78: public DefaultDisplayable (@Nonnull final String displayName, @Nonnull final String toStringName)
79: {
80: this.displayName = displayName;
81: this.toStringName = toStringName;
82: displayNameMap.put(Locale.getDefault(), displayName);
83: }
84:
85: /***********************************************************************************************************************************************************
86: * {@inheritDoc}
87: **********************************************************************************************************************************************************/
88: @Override @Nonnull
89: public String getDisplayName()
90: {
91: return displayName;
92: }
93:
94: /***********************************************************************************************************************************************************
95: * {@inheritDoc}
96: **********************************************************************************************************************************************************/
97: @Override @Nonnull
98: public String getDisplayName (@Nonnull final Locale locale)
99: {
100: return displayNameMap.get(locale);
101: }
102:
103: /***********************************************************************************************************************************************************
104: * {@inheritDoc}
105: **********************************************************************************************************************************************************/
106: @Override @Nonnull
107: public SortedSet<Locale> getLocales()
108: {
109: return new TreeSet<>(displayNameMap.keySet());
110: }
111:
112: /***********************************************************************************************************************************************************
113: * {@inheritDoc}
114: **********************************************************************************************************************************************************/
115: @Override @Nonnull
116: public Map<Locale, String> getDisplayNames()
117: {
118: return Collections.unmodifiableMap(displayNameMap);
119: }
120:
121: /***********************************************************************************************************************************************************
122: * {@inheritDoc}
123: **********************************************************************************************************************************************************/
124: @Override @Nonnull
125: public String toString()
126: {
127: return String.format("%s@%x$Displayable[]", toStringName, System.identityHashCode(this));
128: }
129: }