-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecating methods in TranslationMessage; adding new method getMessage
- Loading branch information
1 parent
b805d36
commit 17bc16c
Showing
17 changed files
with
301 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,15 @@ public MessageCacheItem (Map<String, String> dataMap) { | |
private long timestamp; | ||
private Long maxAgeMillis = 86400000l; | ||
|
||
public final Map<String, String> cachedData = new HashMap<String, String>(); | ||
private final Map<String, String> cachedData = new HashMap<String, String>(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jessiejuachon
Author
Contributor
|
||
|
||
public void addCacheData(String key, String value) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
this.cachedData.put(key, value); | ||
} | ||
|
||
public boolean isCachedDataEmpty() { | ||
return this.cachedData.isEmpty(); | ||
} | ||
|
||
public synchronized void addCachedData(Map<String, String> cachedData) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (cachedData != null) | ||
|
@@ -94,5 +102,5 @@ public boolean isExpired() { | |
|
||
return System.currentTimeMillis() - responseTimeStamp > maxAgeMillis; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/vmware/vipclient/i18n/messages/api/opt/SourceOpt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2019 VMware, Inc. | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package com.vmware.vipclient.i18n.messages.api.opt; | ||
|
||
import com.vmware.vipclient.i18n.base.cache.MessageCacheItem; | ||
|
||
public interface SourceOpt { | ||
public void getComponentMessages(MessageCacheItem cacheItem); | ||
public String getMessage(String key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/vmware/vipclient/i18n/messages/api/opt/source/ResourceBundleSrcOpt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2019 VMware, Inc. | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package com.vmware.vipclient.i18n.messages.api.opt.source; | ||
|
||
import java.util.Enumeration; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
import com.vmware.vipclient.i18n.base.cache.MessageCacheItem; | ||
import com.vmware.vipclient.i18n.messages.api.opt.SourceOpt; | ||
|
||
public class ResourceBundleSrcOpt implements SourceOpt { | ||
|
||
private ResourceBundle rb; | ||
|
||
public ResourceBundleSrcOpt(String bundle, Locale locale) { | ||
this.rb = ResourceBundle.getBundle(bundle, locale); | ||
} | ||
|
||
@Override | ||
public void getComponentMessages(MessageCacheItem cacheItem) { | ||
Enumeration<String> keys = rb.getKeys(); | ||
while (keys.hasMoreElements()) { | ||
String key = keys.nextElement(); | ||
cacheItem.addCacheData(key, rb.getString(key)); | ||
} | ||
} | ||
|
||
@Override | ||
public String getMessage(String key) { | ||
return rb.getString(key); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Suggest to use ConcurrentHashMap to guarantee concurrency safety. Remove keyword 'synchronized' on methods related to 'cachedData'.