本文整理匯總了Java中java.util.Map.entrySet方法的典型用法代碼示例。如果您正苦於以下問題:Java Map.entrySet方法的具體用法?Java Map.entrySet怎麽用?Java Map.entrySet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Map
的用法示例。
在下文中一共展示了Map.entrySet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEntrySetSetValue
import java.util.Map; //導入方法依賴的package包/類
public void testEntrySetSetValue() {
// TODO: Investigate the extent to which, in practice, maps that support
// put() also support Entry.setValue().
if (!supportsPut) {
return;
}
final Map<K, V> map;
final V valueToSet;
try {
map = makePopulatedMap();
valueToSet = getValueNotInPopulatedMap();
} catch (UnsupportedOperationException e) {
return;
}
Set<Entry<K, V>> entrySet = map.entrySet();
Entry<K, V> entry = entrySet.iterator().next();
final V oldValue = entry.getValue();
final V returnedValue = entry.setValue(valueToSet);
assertEquals(oldValue, returnedValue);
assertTrue(entrySet.contains(mapEntry(entry.getKey(), valueToSet)));
assertEquals(valueToSet, map.get(entry.getKey()));
assertInvariants(map);
}
示例2: write
import java.util.Map; //導入方法依賴的package包/類
public void write(final ByteArrayData buffer , final Object obj ) throws IOException{
if( ! ( obj instanceof Map ) ){
return;
}
Map<Object,Object> mapObj = (Map<Object,Object>)obj;
int i = 0;
for( Map.Entry<Object,Object> entry : mapObj.entrySet() ){
String key = entry.getKey().toString();
ITextFormatter childFormatter = childFormatterContainer.get( key );
if( childFormatter == null ){
childFormatter = defaultFormatter;
}
if( i != 0 ){
buffer.append( delimiter );
}
buffer.append( key.getBytes( "UTF-8" ) );
buffer.append( fieldDelimiter );
childFormatter.write( buffer , entry.getValue() );
i++;
}
}
示例3: getAllImage
import java.util.Map; //導入方法依賴的package包/類
/**
* Scan the list of pictures in the library.
*/
@WorkerThread
public ArrayList<AlbumFolder> getAllImage() {
Map<String, AlbumFolder> albumFolderMap = new HashMap<>();
AlbumFolder allFileFolder = new AlbumFolder();
allFileFolder.setChecked(true);
allFileFolder.setName(mContext.getString(R.string.album_all_images));
scanImageFile(albumFolderMap, allFileFolder);
ArrayList<AlbumFolder> albumFolders = new ArrayList<>();
Collections.sort(allFileFolder.getAlbumFiles());
albumFolders.add(allFileFolder);
for (Map.Entry<String, AlbumFolder> folderEntry : albumFolderMap.entrySet()) {
AlbumFolder albumFolder = folderEntry.getValue();
Collections.sort(albumFolder.getAlbumFiles());
albumFolders.add(albumFolder);
}
return albumFolders;
}
示例4: testBug49598
import java.util.Map; //導入方法依賴的package包/類
@Test
public void testBug49598() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "servlet", new Bug49598Servlet());
ctx.addServletMapping("/", "servlet");
tomcat.start();
Map<String,List<String>> headers = new HashMap<String,List<String>>();
getUrl("http://localhost:" + getPort() + "/", new ByteChunk(), headers);
// Check for headers without a name
for (Map.Entry<String,List<String>> header : headers.entrySet()) {
if (header.getKey() == null) {
// Expected if this is the response line
List<String> values = header.getValue();
if (values.size() == 1 &&
values.get(0).startsWith("HTTP/1.1")) {
continue;
}
fail("Null header name detected for value " + values);
}
}
// Check for exactly one Set-Cookie header
int count = 0;
for (String headerName : headers.keySet()) {
if ("Set-Cookie".equals(headerName)) {
count ++;
}
}
assertEquals(1, count);
}
示例5: updateProperties
import java.util.Map; //導入方法依賴的package包/類
public static boolean updateProperties(Document doc, Map<String, String> propertyChanges) {
Element rootElement = doc.getRootElement();
boolean update = false;
Element properties = DecentXmlHelper.firstChild(rootElement, "properties");
if (properties != null) {
for (Map.Entry<String, String> entry : propertyChanges.entrySet()) {
String propertyName = entry.getKey();
String propertyVersion = entry.getValue();
if (DecentXmlHelper.updateFirstChild(properties, propertyName, propertyVersion)) {
update = true;
}
}
}
return update;
}
示例6: deserialize
import java.util.Map; //導入方法依賴的package包/類
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
String key = null;
Map<String, String> value = new HashMap<String, String>();
for (Map.Entry<String, Object> valEntry : map.entrySet()) {
if (valEntry.getKey().equals("key")) {
key = (String) valEntry.getValue();
} else if (valEntry.getKey().startsWith("value.")) {
value.put(((String) valEntry.getKey()).substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
}
}
return new ComplexTextTypeComponent(key, value);
}
示例7: equalsBranches
import java.util.Map; //導入方法依賴的package包/類
private static boolean equalsBranches (Map<String, GitBranch> oldBranches, Map<String, GitBranch> newBranches) {
boolean retval = oldBranches.size() == newBranches.size() && oldBranches.keySet().equals(newBranches.keySet());
if (retval) {
for (Map.Entry<String, GitBranch> e : oldBranches.entrySet()) {
GitBranch oldBranch = e.getValue();
GitBranch newBranch = newBranches.get(e.getKey());
if (!oldBranch.getId().equals(newBranch.getId())
|| !equalTracking(newBranch, oldBranch)) {
retval = false;
break;
}
}
}
return retval;
}
示例8: setMobileBrowsers
import java.util.Map; //導入方法依賴的package包/類
/**
* Sets the map of mobile browsers. This sets a flag on the request called "isMobile" and also
* provides the custom flag called browserType which can be mapped into the theme.
* <p>
* Themes that understand isMobile should provide an alternative stylesheet.
*
* @param mobileOverrides the list of mobile browsers.
*/
public void setMobileBrowsers(final Map<String, String> mobileOverrides) {
// initialize the overrides variable to an empty map
this.overrides = new HashMap<>();
for (final Map.Entry<String, String> entry : mobileOverrides.entrySet()) {
this.overrides.put(Pattern.compile(entry.getKey()), entry.getValue());
}
}
示例9: printMap
import java.util.Map; //導入方法依賴的package包/類
/**
* Prints metrics data in a multi-line text form.
*/
void printMap(PrintWriter out, Map<String, Map<String, List<TagsMetricsPair>>> map) {
for (Map.Entry<String, Map<String, List<TagsMetricsPair>>> context : map.entrySet()) {
out.print(context.getKey());
out.print("\n");
for (Map.Entry<String, List<TagsMetricsPair>> record : context.getValue().entrySet()) {
indent(out, 1);
out.print(record.getKey());
out.print("\n");
for (TagsMetricsPair pair : record.getValue()) {
indent(out, 2);
// Prints tag values in the form "{key=value,key=value}:"
out.print("{");
boolean first = true;
for (Map.Entry<String, Object> tagValue : pair.tagMap.entrySet()) {
if (first) {
first = false;
} else {
out.print(",");
}
out.print(tagValue.getKey());
out.print("=");
out.print(tagValue.getValue().toString());
}
out.print("}:\n");
// Now print metric values, one per line
for (Map.Entry<String, Number> metricValue :
pair.metricMap.entrySet()) {
indent(out, 3);
out.print(metricValue.getKey());
out.print("=");
out.print(metricValue.getValue().toString());
out.print("\n");
}
}
}
}
}
示例10: revertNotify
import java.util.Map; //導入方法依賴的package包/類
public static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify) {
if (notify != null && notify.size() > 0) {
Map<String, Map<String, String>> newNotify = new HashMap<String, Map<String, String>>();
for (Map.Entry<String, Map<String, String>> entry : notify.entrySet()) {
String serviceName = entry.getKey();
Map<String, String> serviceUrls = entry.getValue();
if (!serviceName.contains(":") && !serviceName.contains("/")) {
if (serviceUrls != null && serviceUrls.size() > 0) {
for (Map.Entry<String, String> entry2 : serviceUrls.entrySet()) {
String url = entry2.getKey();
String query = entry2.getValue();
Map<String, String> params = StringUtils.parseQueryString(query);
String group = params.get("group");
String version = params.get("version");
// params.remove("group");
// params.remove("version");
String name = serviceName;
if (group != null && group.length() > 0) {
name = group + "/" + name;
}
if (version != null && version.length() > 0) {
name = name + ":" + version;
}
Map<String, String> newUrls = newNotify.get(name);
if (newUrls == null) {
newUrls = new HashMap<String, String>();
newNotify.put(name, newUrls);
}
newUrls.put(url, StringUtils.toQueryString(params));
}
}
} else {
newNotify.put(serviceName, serviceUrls);
}
}
return newNotify;
}
return notify;
}
示例11: Distribution
import java.util.Map; //導入方法依賴的package包/類
public Distribution(String name, Map<String, Integer> distribution)
{
this.name = checkNotNull(name, "name is null");
checkNotNull(distribution, "distribution is null");
ImmutableList.Builder<String> values = ImmutableList.builder();
this.weights = new int[distribution.size()];
int runningWeight = 0;
int index = 0;
boolean isValidDistribution = true;
for (Entry<String, Integer> entry : distribution.entrySet()) {
values.add(entry.getKey());
runningWeight += entry.getValue();
weights[index] = runningWeight;
isValidDistribution = isValidDistribution && entry.getValue() > 0;
index++;
}
this.values = values.build();
// "nations" is hack and not a valid distribution so we need to skip it
if (isValidDistribution) {
this.maxWeight = weights[weights.length - 1];
this.distribution = new String[maxWeight];
index = 0;
for (String value : this.values) {
int count = distribution.get(value);
for (int i = 0; i < count; i++) {
this.distribution[index++] = value;
}
}
} else {
this.maxWeight = -1;
this.distribution = null;
}
}
示例12: clean
import java.util.Map; //導入方法依賴的package包/類
private void clean(Jedis jedis) {
Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
if (keys != null && keys.size() > 0) {
for (String key : keys) {
Map<String, String> values = jedis.hgetAll(key);
if (values != null && values.size() > 0) {
boolean delete = false;
long now = System.currentTimeMillis();
for (Map.Entry<String, String> entry : values.entrySet()) {
URL url = URL.valueOf(entry.getKey());
if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
long expire = Long.parseLong(entry.getValue());
if (expire < now) {
jedis.hdel(key, entry.getKey());
delete = true;
if (logger.isWarnEnabled()) {
logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now));
}
}
}
}
if (delete) {
jedis.publish(key, Constants.UNREGISTER);
}
}
}
}
}
示例13: unzipLibFiles
import java.util.Map; //導入方法依賴的package包/類
/**
* unzipLibFiles
*
* @param zipFile zipFile
* @param abis abis
* @param libFiles libFiles
*/
private final static void unzipLibFiles(String zipFile, String[] abis, Map<String, Map<String, String>> libFiles) {
for (int i = 0; i < abis.length; i++) {
Map<String, String> files = libFiles.get(abis[i]);
if (files != null && !files.isEmpty()) {
for (Map.Entry<String, String> entry : files.entrySet()) {
unzipSingleFile(zipFile, entry.getKey(), entry.getValue());
}
}
}
}
示例14: doInBackground
import java.util.Map; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... params) {
SharedPreferences sp = CacheHelper.getPreferences(CacheHelper.FAV);
Map<String, ?> map = sp.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getValue() instanceof Integer) {
Integer testId = (Integer) entry.getValue();
mData.add(readTestCache(testId));
}
}
return null;
}
示例15: putAll
import java.util.Map; //導入方法依賴的package包/類
@Override
public void putAll(Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> entry: map.entrySet()) put(entry.getKey(), entry.getValue());
}