Remove magic numbers and in-line string constants in UiExtensionManager.
Change-Id: I574db918c46835c6033a1a4b90a30caa3540f144
Showing
1 changed file
with
18 additions
and
10 deletions
... | @@ -74,13 +74,20 @@ import static org.onosproject.ui.UiView.Category.PLATFORM; | ... | @@ -74,13 +74,20 @@ import static org.onosproject.ui.UiView.Category.PLATFORM; |
74 | */ | 74 | */ |
75 | @Component(immediate = true) | 75 | @Component(immediate = true) |
76 | @Service | 76 | @Service |
77 | -public class UiExtensionManager implements UiExtensionService, UiPreferencesService, SpriteService { | 77 | +public class UiExtensionManager |
78 | + implements UiExtensionService, UiPreferencesService, SpriteService { | ||
78 | 79 | ||
79 | private static final ClassLoader CL = UiExtensionManager.class.getClassLoader(); | 80 | private static final ClassLoader CL = UiExtensionManager.class.getClassLoader(); |
81 | + | ||
82 | + private static final String ONOS_USER_PREFERENCES = "onos-user-preferences"; | ||
80 | private static final String CORE = "core"; | 83 | private static final String CORE = "core"; |
81 | private static final String GUI_ADDED = "guiAdded"; | 84 | private static final String GUI_ADDED = "guiAdded"; |
82 | private static final String GUI_REMOVED = "guiRemoved"; | 85 | private static final String GUI_REMOVED = "guiRemoved"; |
83 | private static final String UPDATE_PREFS = "updatePrefs"; | 86 | private static final String UPDATE_PREFS = "updatePrefs"; |
87 | + private static final String SLASH = "/"; | ||
88 | + | ||
89 | + private static final int IDX_USER = 0; | ||
90 | + private static final int IDX_KEY = 1; | ||
84 | 91 | ||
85 | private final Logger log = LoggerFactory.getLogger(getClass()); | 92 | private final Logger log = LoggerFactory.getLogger(getClass()); |
86 | 93 | ||
... | @@ -162,13 +169,13 @@ public class UiExtensionManager implements UiExtensionService, UiPreferencesServ | ... | @@ -162,13 +169,13 @@ public class UiExtensionManager implements UiExtensionService, UiPreferencesServ |
162 | KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() | 169 | KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() |
163 | .register(KryoNamespaces.API) | 170 | .register(KryoNamespaces.API) |
164 | .register(ObjectNode.class, ArrayNode.class, | 171 | .register(ObjectNode.class, ArrayNode.class, |
165 | - JsonNodeFactory.class, LinkedHashMap.class, | 172 | + JsonNodeFactory.class, LinkedHashMap.class, |
166 | - TextNode.class, BooleanNode.class, | 173 | + TextNode.class, BooleanNode.class, |
167 | - LongNode.class, DoubleNode.class, ShortNode.class, | 174 | + LongNode.class, DoubleNode.class, ShortNode.class, |
168 | - IntNode.class, NullNode.class); | 175 | + IntNode.class, NullNode.class); |
169 | 176 | ||
170 | prefs = storageService.<String, ObjectNode>eventuallyConsistentMapBuilder() | 177 | prefs = storageService.<String, ObjectNode>eventuallyConsistentMapBuilder() |
171 | - .withName("onos-user-preferences") | 178 | + .withName(ONOS_USER_PREFERENCES) |
172 | .withSerializer(kryoBuilder) | 179 | .withSerializer(kryoBuilder) |
173 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) | 180 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
174 | .withPersistence() | 181 | .withPersistence() |
... | @@ -229,7 +236,7 @@ public class UiExtensionManager implements UiExtensionService, UiPreferencesServ | ... | @@ -229,7 +236,7 @@ public class UiExtensionManager implements UiExtensionService, UiPreferencesServ |
229 | public Map<String, ObjectNode> getPreferences(String userName) { | 236 | public Map<String, ObjectNode> getPreferences(String userName) { |
230 | ImmutableMap.Builder<String, ObjectNode> builder = ImmutableMap.builder(); | 237 | ImmutableMap.Builder<String, ObjectNode> builder = ImmutableMap.builder(); |
231 | prefs.entrySet().stream() | 238 | prefs.entrySet().stream() |
232 | - .filter(e -> e.getKey().startsWith(userName + "/")) | 239 | + .filter(e -> e.getKey().startsWith(userName + SLASH)) |
233 | .forEach(e -> builder.put(keyName(e.getKey()), e.getValue())); | 240 | .forEach(e -> builder.put(keyName(e.getKey()), e.getValue())); |
234 | return builder.build(); | 241 | return builder.build(); |
235 | } | 242 | } |
... | @@ -261,15 +268,16 @@ public class UiExtensionManager implements UiExtensionService, UiPreferencesServ | ... | @@ -261,15 +268,16 @@ public class UiExtensionManager implements UiExtensionService, UiPreferencesServ |
261 | } | 268 | } |
262 | 269 | ||
263 | private String key(String userName, String keyName) { | 270 | private String key(String userName, String keyName) { |
264 | - return userName + "/" + keyName; | 271 | + return userName + SLASH + keyName; |
265 | } | 272 | } |
266 | 273 | ||
274 | + | ||
267 | private String userName(String key) { | 275 | private String userName(String key) { |
268 | - return key.split("/")[0]; | 276 | + return key.split(SLASH)[IDX_USER]; |
269 | } | 277 | } |
270 | 278 | ||
271 | private String keyName(String key) { | 279 | private String keyName(String key) { |
272 | - return key.split("/")[1]; | 280 | + return key.split(SLASH)[IDX_KEY]; |
273 | } | 281 | } |
274 | 282 | ||
275 | // Auxiliary listener to preference map events. | 283 | // Auxiliary listener to preference map events. | ... | ... |
-
Please register or login to post a comment